diff options
author | Maros Marsalek <mmarsale@cisco.com> | 2016-02-18 17:02:26 +0100 |
---|---|---|
committer | Maros Marsalek <mmarsale@cisco.com> | 2016-02-18 17:30:40 +0100 |
commit | 89fd34ab4d8c082e7d89af4edaa48f6022581854 (patch) | |
tree | 548ac2634888085acf5bac9e58b4aec3c83c477a | |
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>
4 files changed, 86 insertions, 10 deletions
diff --git a/v3po/impl/src/main/config/default-config.xml b/v3po/impl/src/main/config/default-config.xml index 08a090ea2..7d0f19476 100644 --- a/v3po/impl/src/main/config/default-config.xml +++ b/v3po/impl/src/main/config/default-config.xml @@ -30,6 +30,10 @@ <type xmlns:binding="urn:opendaylight:params:xml:ns:yang:controller:md:sal:binding">binding:binding-broker-osgi-registry</type> <name>binding-osgi-broker</name> </broker> + <dom-broker> + <type xmlns:prefix="urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom">prefix:dom-broker-osgi-registry</type> + <name>dom-broker</name> + </dom-broker> </module> </modules> </data> 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; + } + } } diff --git a/v3po/impl/src/main/yang/v3po-impl.yang b/v3po/impl/src/main/yang/v3po-impl.yang index 7a6fd4277..2e113e566 100644 --- a/v3po/impl/src/main/yang/v3po-impl.yang +++ b/v3po/impl/src/main/yang/v3po-impl.yang @@ -5,6 +5,7 @@ module v3po-impl { import config { prefix config; revision-date 2013-04-05; } import opendaylight-md-sal-binding { prefix md-sal-binding; revision-date 2013-10-28;} + import opendaylight-md-sal-dom {prefix dom;} description "Service definition for v3po project"; @@ -30,6 +31,15 @@ module v3po-impl { } } } + + container dom-broker { + uses config:service-ref { + refine type { + mandatory true; + config:required-identity dom:dom-broker-osgi-registry; + } + } + } } } } diff --git a/v3po/impl/src/test/java/org/opendaylight/yang/gen/v1/urn/opendaylight/params/xml/ns/yang/v3po/impl/rev141210/V3poModuleTest.java b/v3po/impl/src/test/java/org/opendaylight/yang/gen/v1/urn/opendaylight/params/xml/ns/yang/v3po/impl/rev141210/V3poModuleTest.java index 99872549a..cee38b287 100644 --- a/v3po/impl/src/test/java/org/opendaylight/yang/gen/v1/urn/opendaylight/params/xml/ns/yang/v3po/impl/rev141210/V3poModuleTest.java +++ b/v3po/impl/src/test/java/org/opendaylight/yang/gen/v1/urn/opendaylight/params/xml/ns/yang/v3po/impl/rev141210/V3poModuleTest.java @@ -15,21 +15,20 @@ */ package org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.impl.rev141210; -import org.junit.Test; -import org.opendaylight.controller.config.api.DependencyResolver; -import org.opendaylight.controller.config.api.JmxAttribute; -import org.opendaylight.controller.config.api.ModuleIdentifier; -import org.opendaylight.controller.sal.binding.api.BindingAwareBroker; -import io.fd.honeycomb.v3po.impl.V3poProvider; - -import javax.management.ObjectName; - import static org.mockito.Matchers.any; import static org.mockito.Matchers.eq; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; +import io.fd.honeycomb.v3po.impl.V3poProvider; +import javax.management.ObjectName; +import org.junit.Test; +import org.opendaylight.controller.config.api.DependencyResolver; +import org.opendaylight.controller.config.api.JmxAttribute; +import org.opendaylight.controller.config.api.ModuleIdentifier; +import org.opendaylight.controller.sal.binding.api.BindingAwareBroker; + public class V3poModuleTest { @Test public void testCustomValidation() { @@ -45,7 +44,11 @@ public class V3poModuleTest { // configure mocks DependencyResolver dependencyResolver = mock(DependencyResolver.class); BindingAwareBroker broker = mock(BindingAwareBroker.class); - when(dependencyResolver.resolveInstance(eq(BindingAwareBroker.class), any(ObjectName.class), any(JmxAttribute.class))).thenReturn(broker); + when(dependencyResolver.resolveInstance(eq(BindingAwareBroker.class), any(ObjectName.class), any(JmxAttribute.class))) + .thenReturn(broker); + final org.opendaylight.controller.sal.core.api.Broker domBroker = mock(org.opendaylight.controller.sal.core.api.Broker.class); + when(dependencyResolver.resolveInstance(eq(org.opendaylight.controller.sal.core.api.Broker.class), any(ObjectName.class), any(JmxAttribute.class))) + .thenReturn(domBroker); // create instance of module with injected mocks V3poModule module = new V3poModule(mock(ModuleIdentifier.class), dependencyResolver); |