diff options
author | 2016-02-18 17:02:26 +0100 | |
---|---|---|
committer | 2016-02-18 17:30:40 +0100 | |
commit | 89fd34ab4d8c082e7d89af4edaa48f6022581854 (patch) | |
tree | 548ac2634888085acf5bac9e58b4aec3c83c477a /v3po/impl/src/main/java/org | |
parent | ed2805a57ca103d82092b6758c54d505568d312a (diff) |
Initialize v3po data structures
This is a workaround to avoid posible DataTree exception
when submitting new interface configuration without pre-existing
day0 configuration.
Applies for all list nodes and a proper fix will follow in ODL.
Change-Id: I6ee6e7ae189542d5ae2ad742f431b88745c42c4d
Signed-off-by: Maros Marsalek <mmarsale@cisco.com>
Diffstat (limited to 'v3po/impl/src/main/java/org')
-rw-r--r-- | v3po/impl/src/main/java/org/opendaylight/yang/gen/v1/urn/opendaylight/params/xml/ns/yang/v3po/impl/rev141210/V3poModule.java | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/v3po/impl/src/main/java/org/opendaylight/yang/gen/v1/urn/opendaylight/params/xml/ns/yang/v3po/impl/rev141210/V3poModule.java b/v3po/impl/src/main/java/org/opendaylight/yang/gen/v1/urn/opendaylight/params/xml/ns/yang/v3po/impl/rev141210/V3poModule.java index 5a5fd1147..0805452c5 100644 --- a/v3po/impl/src/main/java/org/opendaylight/yang/gen/v1/urn/opendaylight/params/xml/ns/yang/v3po/impl/rev141210/V3poModule.java +++ b/v3po/impl/src/main/java/org/opendaylight/yang/gen/v1/urn/opendaylight/params/xml/ns/yang/v3po/impl/rev141210/V3poModule.java @@ -16,6 +16,21 @@ package org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.impl.rev141210; import io.fd.honeycomb.v3po.impl.V3poProvider; +import java.util.Collection; +import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; +import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException; +import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker; +import org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction; +import org.opendaylight.controller.sal.core.api.Broker; +import org.opendaylight.controller.sal.core.api.Provider; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.Interfaces; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.Vpp; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.BridgeDomains; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.bridge.domains.BridgeDomain; +import org.opendaylight.yangtools.yang.common.QName; +import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; +import org.opendaylight.yangtools.yang.data.impl.schema.Builders; public class V3poModule extends org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.impl.rev141210.AbstractV3poModule { public V3poModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) { @@ -33,9 +48,53 @@ public class V3poModule extends org.opendaylight.yang.gen.v1.urn.opendaylight.pa @Override public java.lang.AutoCloseable createInstance() { + getDomBrokerDependency().registerProvider(new InitializationProvider()); + V3poProvider provider = new V3poProvider(); getBrokerDependency().registerProvider(provider); return provider; } + /** + * Writes list parents as a workaround for ODL issue + * TODO remove (also remove from yang model and cfg) and fix ODL bug-5382 + */ + private class InitializationProvider implements Provider { + @Override + public void onSessionInitiated(final Broker.ProviderSession providerSession) { + final DOMDataBroker service = providerSession.getService(DOMDataBroker.class); + final DOMDataWriteTransaction domDataWriteTransaction = service.newWriteOnlyTransaction(); + + // Initialize interfaces list + YangInstanceIdentifier.NodeIdentifier nodeId = getNodeId(Interfaces.QNAME); + YangInstanceIdentifier interfacesYid = YangInstanceIdentifier.create(nodeId); + domDataWriteTransaction.merge(LogicalDatastoreType.CONFIGURATION, + interfacesYid, Builders.containerBuilder().withNodeIdentifier(nodeId) + .withChild(Builders.mapBuilder().withNodeIdentifier(getNodeId(Interface.QNAME)).build()) + .build()); + + // Initialize bridge domains list + nodeId = getNodeId(BridgeDomains.QNAME); + interfacesYid = YangInstanceIdentifier.create(getNodeId(Vpp.QNAME), nodeId); + domDataWriteTransaction.merge(LogicalDatastoreType.CONFIGURATION, + interfacesYid, Builders.containerBuilder().withNodeIdentifier(nodeId) + .withChild(Builders.mapBuilder().withNodeIdentifier(getNodeId(BridgeDomain.QNAME)).build()) + .build()); + + try { + domDataWriteTransaction.submit().checkedGet(); + } catch (TransactionCommitFailedException e) { + throw new IllegalStateException("Unable to initialize parent data structures", e); + } + } + + private YangInstanceIdentifier.NodeIdentifier getNodeId(final QName qname) { + return new YangInstanceIdentifier.NodeIdentifier(qname); + } + + @Override + public Collection<ProviderFunctionality> getProviderFunctionality() { + return null; + } + } } |