From 077fec893ed63f17bb4c9b2952d27075fa50f737 Mon Sep 17 00:00:00 2001 From: Marek Gradzki Date: Mon, 11 Apr 2016 00:18:11 +0200 Subject: HONEYCOMB-34: Configurable OperationalDataTree dependency Change-Id: I675a4ae11845990dfcacbe99eb0a1b799485de35 Signed-off-by: Marek Gradzki --- .../data/impl/rev160411/ConfigDataTreeModule.java | 4 +- .../impl/rev160411/OperationalDataTreeModule.java | 57 ++++++++++++++++++++++ .../OperationalDataTreeModuleFactory.java | 13 +++++ v3po/data-impl/src/main/yang/data-impl.yang | 42 +++++++++++++++- v3po/impl/src/main/config/default-config.xml | 34 +++++++++++-- .../io/fd/honeycomb/v3po/impl/V3poProvider.java | 8 ++- .../impl/VppDataBrokerInitializationProvider.java | 26 ++++------ .../ns/yang/v3po/impl/rev141210/V3poModule.java | 2 +- v3po/impl/src/main/yang/v3po-impl.yang | 9 ++++ .../VppDataBrokerInitializationProviderTest.java | 6 ++- .../yang/v3po/impl/rev141210/V3poModuleTest.java | 3 ++ 11 files changed, 177 insertions(+), 27 deletions(-) create mode 100644 v3po/data-impl/src/main/java/org/opendaylight/yang/gen/v1/urn/honeycomb/params/xml/ns/yang/data/impl/rev160411/OperationalDataTreeModule.java create mode 100644 v3po/data-impl/src/main/java/org/opendaylight/yang/gen/v1/urn/honeycomb/params/xml/ns/yang/data/impl/rev160411/OperationalDataTreeModuleFactory.java (limited to 'v3po') diff --git a/v3po/data-impl/src/main/java/org/opendaylight/yang/gen/v1/urn/honeycomb/params/xml/ns/yang/data/impl/rev160411/ConfigDataTreeModule.java b/v3po/data-impl/src/main/java/org/opendaylight/yang/gen/v1/urn/honeycomb/params/xml/ns/yang/data/impl/rev160411/ConfigDataTreeModule.java index 88e87956b..115eb065f 100644 --- a/v3po/data-impl/src/main/java/org/opendaylight/yang/gen/v1/urn/honeycomb/params/xml/ns/yang/data/impl/rev160411/ConfigDataTreeModule.java +++ b/v3po/data-impl/src/main/java/org/opendaylight/yang/gen/v1/urn/honeycomb/params/xml/ns/yang/data/impl/rev160411/ConfigDataTreeModule.java @@ -33,8 +33,8 @@ public class ConfigDataTreeModule extends public java.lang.AutoCloseable createInstance() { final DataTree dataTree = InMemoryDataTreeFactory.getInstance().create(TreeType.CONFIGURATION); dataTree.setSchemaContext(getSchemaServiceDependency().getGlobalContext()); - return new CloseableConfigDataTree(new ConfigDataTree(getBindingNormalizedNodeSerializerDependency(), dataTree, - getWriterRegistryDependency())); + return new CloseableConfigDataTree( + new ConfigDataTree(getSerializerDependency(), dataTree, getWriterRegistryDependency())); } private static final class CloseableConfigDataTree implements ModifiableDataTree, AutoCloseable { diff --git a/v3po/data-impl/src/main/java/org/opendaylight/yang/gen/v1/urn/honeycomb/params/xml/ns/yang/data/impl/rev160411/OperationalDataTreeModule.java b/v3po/data-impl/src/main/java/org/opendaylight/yang/gen/v1/urn/honeycomb/params/xml/ns/yang/data/impl/rev160411/OperationalDataTreeModule.java new file mode 100644 index 000000000..48053c366 --- /dev/null +++ b/v3po/data-impl/src/main/java/org/opendaylight/yang/gen/v1/urn/honeycomb/params/xml/ns/yang/data/impl/rev160411/OperationalDataTreeModule.java @@ -0,0 +1,57 @@ +package org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.data.impl.rev160411; + +import com.google.common.base.Optional; +import com.google.common.util.concurrent.CheckedFuture; +import io.fd.honeycomb.v3po.data.ReadableDataTree; +import io.fd.honeycomb.v3po.data.impl.OperationalDataTree; +import javax.annotation.Nonnull; +import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException; +import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; +import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; + +public class OperationalDataTreeModule extends + org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.data.impl.rev160411.AbstractOperationalDataTreeModule { + public OperationalDataTreeModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, + org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) { + super(identifier, dependencyResolver); + } + + public OperationalDataTreeModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, + org.opendaylight.controller.config.api.DependencyResolver dependencyResolver, + org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.data.impl.rev160411.OperationalDataTreeModule oldModule, + java.lang.AutoCloseable oldInstance) { + super(identifier, dependencyResolver, oldModule, oldInstance); + } + + @Override + public void customValidation() { + // add custom validation form module attributes here. + } + + @Override + public java.lang.AutoCloseable createInstance() { + return new CloseableOperationalDataTree( + new OperationalDataTree(getSerializerDependency(), getSchemaServiceDependency().getGlobalContext(), + getReaderRegistryDependency())); + } + + private static final class CloseableOperationalDataTree implements ReadableDataTree, AutoCloseable { + + private final OperationalDataTree delegate; + + CloseableOperationalDataTree(final OperationalDataTree delegate) { + this.delegate = delegate; + } + + @Override + public void close() throws Exception { + // NOP + } + + @Override + public CheckedFuture>, ReadFailedException> read( + @Nonnull final YangInstanceIdentifier path) { + return delegate.read(path); + } + } +} diff --git a/v3po/data-impl/src/main/java/org/opendaylight/yang/gen/v1/urn/honeycomb/params/xml/ns/yang/data/impl/rev160411/OperationalDataTreeModuleFactory.java b/v3po/data-impl/src/main/java/org/opendaylight/yang/gen/v1/urn/honeycomb/params/xml/ns/yang/data/impl/rev160411/OperationalDataTreeModuleFactory.java new file mode 100644 index 000000000..221eabe5c --- /dev/null +++ b/v3po/data-impl/src/main/java/org/opendaylight/yang/gen/v1/urn/honeycomb/params/xml/ns/yang/data/impl/rev160411/OperationalDataTreeModuleFactory.java @@ -0,0 +1,13 @@ +/* +* Generated file +* +* Generated from: yang module name: data-impl yang module local name: honeycomb-operational-data-tree +* Generated by: org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator +* Generated at: Sun Apr 10 23:52:21 CEST 2016 +* +* Do not modify this file unless it is present under src/main directory +*/ +package org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.data.impl.rev160411; +public class OperationalDataTreeModuleFactory extends org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.data.impl.rev160411.AbstractOperationalDataTreeModuleFactory { + +} diff --git a/v3po/data-impl/src/main/yang/data-impl.yang b/v3po/data-impl/src/main/yang/data-impl.yang index 841cdb3df..a1dfee301 100644 --- a/v3po/data-impl/src/main/yang/data-impl.yang +++ b/v3po/data-impl/src/main/yang/data-impl.yang @@ -37,7 +37,7 @@ module data-impl { } } - container binding-normalized-node-serializer { + container serializer { uses config:service-ref { refine type { mandatory true; @@ -58,4 +58,44 @@ module data-impl { } } + identity honeycomb-operational-data-tree { + base config:module-type; + config:provided-service dapi:honeycomb-readable-data-tree; + config:java-name-prefix OperationalDataTree; + } + + augment "/config:modules/config:module/config:configuration" { + case honeycomb-operational-data-tree { + when "/config:modules/config:module/config:type = 'honeycomb-operational-data-tree'"; + + container schema-service { + uses config:service-ref { + refine type { + mandatory true; + config:required-identity dom:schema-service; + } + } + } + + container serializer { + uses config:service-ref { + refine type { + mandatory true; + config:required-identity md-sal-binding:binding-normalized-node-serializer; + } + } + } + + container reader-registry { + uses config:service-ref { + refine type { + mandatory true; + config:required-identity tapi:honeycomb-reader-registry; + } + } + } + + } + } + } \ No newline at end of file diff --git a/v3po/impl/src/main/config/default-config.xml b/v3po/impl/src/main/config/default-config.xml index 3d0e4f7fc..e35c3a421 100644 --- a/v3po/impl/src/main/config/default-config.xml +++ b/v3po/impl/src/main/config/default-config.xml @@ -88,21 +88,37 @@ prefix:honeycomb-config-data-tree config-data-tree - dom:schema-service yang-schema-service - + prefix:binding-dom-mapping-service runtime-mapping-singleton - + prefix:honeycomb-writer-registry write-registry + + prefix:honeycomb-operational-data-tree + operational-data-tree + + dom:schema-service + yang-schema-service + + + prefix:binding-dom-mapping-service + runtime-mapping-singleton + + + prefix:honeycomb-reader-registry + read-registry + + + prefix:v3po v3po-default @@ -134,6 +150,10 @@ prefix:honeycomb-modifiable-data-tree config-data-tree + + prefix:honeycomb-readable-data-tree + operational-data-tree + @@ -188,6 +208,14 @@ + + prefix:honeycomb-readable-data-tree + + operational-data-tree + /modules/module[type='honeycomb-operational-data-tree'][name='operational-data-tree'] + + + prefix:vpp-cfg-initializer diff --git a/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/V3poProvider.java b/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/V3poProvider.java index bd5141282..36eeb8598 100644 --- a/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/V3poProvider.java +++ b/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/V3poProvider.java @@ -21,6 +21,7 @@ import com.google.common.collect.Lists; import com.google.common.util.concurrent.CheckedFuture; import com.google.common.util.concurrent.Futures; import io.fd.honeycomb.v3po.data.ModifiableDataTree; +import io.fd.honeycomb.v3po.data.ReadableDataTree; import io.fd.honeycomb.v3po.translate.read.ReaderRegistry; import io.fd.honeycomb.v3po.translate.write.WriterRegistry; import java.util.Collections; @@ -80,18 +81,21 @@ public class V3poProvider implements BindingAwareProvider, AutoCloseable, Broker VppPollOperDataImpl vppPollOperData; private VppDataBrokerInitializationProvider vppDataBrokerInitializationProvider; private final ModifiableDataTree configDataTree; + private final ReadableDataTree operationalDataTree; public V3poProvider(@Nonnull final Broker domBroker, final vppApi vppJapi, @Nonnull final ReaderRegistry readerRegistry, @Nonnull final WriterRegistry writerRegistry, @Nonnull final BindingNormalizedNodeSerializer serializer, - @Nonnull final ModifiableDataTree configDataTree) { + @Nonnull final ModifiableDataTree configDataTree, + @Nonnull final ReadableDataTree operationalDataTree) { api = vppJapi; this.readerRegistry = Preconditions.checkNotNull(readerRegistry, "readerRegistry should not be null"); this.writerRegistry = Preconditions.checkNotNull(writerRegistry, "writerRegistry should not be null"); this.domBroker = Preconditions.checkNotNull(domBroker, "domBroker should not be null"); this.serializer = Preconditions.checkNotNull(serializer, "serializer should not be null"); this.configDataTree = Preconditions.checkNotNull(configDataTree, "configDataTree should not be null"); + this.operationalDataTree = Preconditions.checkNotNull(operationalDataTree, "operationalDataTree should not be null"); } private void initializeVppConfig() { @@ -202,7 +206,7 @@ public class V3poProvider implements BindingAwareProvider, AutoCloseable, Broker startOperationalUpdateTimer(); // TODO make configurable: - vppDataBrokerInitializationProvider = new VppDataBrokerInitializationProvider(db, readerRegistry, writerRegistry, serializer, configDataTree); + vppDataBrokerInitializationProvider = new VppDataBrokerInitializationProvider(db, readerRegistry, writerRegistry, serializer, configDataTree, operationalDataTree); // TODO pull the registration into Module domBroker.registerProvider(vppDataBrokerInitializationProvider); } diff --git a/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/VppDataBrokerInitializationProvider.java b/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/VppDataBrokerInitializationProvider.java index e0e8c999e..84301b711 100644 --- a/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/VppDataBrokerInitializationProvider.java +++ b/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/VppDataBrokerInitializationProvider.java @@ -26,7 +26,6 @@ import com.google.common.util.concurrent.ListenableFuture; import io.fd.honeycomb.v3po.data.ModifiableDataTree; import io.fd.honeycomb.v3po.data.ReadableDataTree; import io.fd.honeycomb.v3po.data.impl.DataBroker; -import io.fd.honeycomb.v3po.data.impl.OperationalDataTree; import io.fd.honeycomb.v3po.translate.Context; import io.fd.honeycomb.v3po.translate.TranslationException; import io.fd.honeycomb.v3po.translate.read.ReadContext; @@ -95,19 +94,22 @@ public final class VppDataBrokerInitializationProvider implements Provider, Auto private final BindingNormalizedNodeSerializer serializer; private ObjectRegistration mountPointRegistration; private DOMDataBroker broker; - private ModifiableDataTree configDataTree; + private final ModifiableDataTree configDataTree; + private final ReadableDataTree operationalDataTree; public VppDataBrokerInitializationProvider( @Nonnull final org.opendaylight.controller.md.sal.binding.api.DataBroker bindingBroker, @Nonnull final ReaderRegistry readerRegistry, @Nonnull final WriterRegistry writerRegistry, @Nonnull final BindingNormalizedNodeSerializer serializer, - @Nonnull final ModifiableDataTree configDataTree) { + @Nonnull final ModifiableDataTree configDataTree, + @Nonnull final ReadableDataTree operationalDataTree) { this.bindingBroker = checkNotNull(bindingBroker, "bindingBroker should not be null"); this.readerRegistry = checkNotNull(readerRegistry, "readerRegistry should not be null"); this.writerRegistry = checkNotNull(writerRegistry, "writerRegistry should not be null"); this.serializer = checkNotNull(serializer, "serializer should not be null"); this.configDataTree = checkNotNull(configDataTree, "configDataTree should not be null"); + this.operationalDataTree = checkNotNull(operationalDataTree, "configDataTree should not be null"); this.mountPointPath = getMountPointPath(); } @@ -129,13 +131,12 @@ public final class VppDataBrokerInitializationProvider implements Provider, Auto final SchemaService schemaService = providerSession.getService(SchemaService.class); final SchemaContext globalContext = schemaService.getGlobalContext(); - // final BindingNormalizedNodeSerializer serializer = initSerializer(globalContext); final YangInstanceIdentifier path = serializer.toYangInstanceIdentifier(mountPointPath); final DOMMountPointService.DOMMountPointBuilder mountPointBuilder = mountPointService.createMountPoint(path); mountPointBuilder.addInitialSchemaContext(globalContext); - broker = initVppDataBroker(globalContext, serializer, configDataTree); + broker = initVppDataBroker(operationalDataTree, serializer, configDataTree); mountPointBuilder.addService(DOMDataBroker.class, broker); mountPointRegistration = mountPointBuilder.register(); @@ -167,19 +168,9 @@ public final class VppDataBrokerInitializationProvider implements Provider, Auto } } - private DOMDataBroker initVppDataBroker(final SchemaContext globalContext, + private DOMDataBroker initVppDataBroker(final ReadableDataTree operationalDataTree, final BindingNormalizedNodeSerializer serializer, final ModifiableDataTree configDataTree) { - final ReadableDataTree operationalDataTree = - new OperationalDataTree(serializer, globalContext, readerRegistry); // TODO make configurable - -// final DataTree dataTree = -// InMemoryDataTreeFactory.getInstance().create(TreeType.CONFIGURATION); // TODO make configurable -// dataTree.setSchemaContext(globalContext); - -// final ModifiableDataTree configDataTree = -// new ConfigDataTree(serializer, dataTree, writerRegistry); // TODO make configurable - // init operational data tree before data broker is initialized try { @@ -191,6 +182,7 @@ public final class VppDataBrokerInitializationProvider implements Provider, Auto return new DataBroker(operationalDataTree, configDataTree); } + // FIXME move to initializer after wiring is finished private void initConfig(final BindingNormalizedNodeSerializer serializer, final ModifiableDataTree configDataTree) throws TranslationException, DataValidationFailedException { LOG.info("Config initialization"); @@ -230,7 +222,7 @@ public final class VppDataBrokerInitializationProvider implements Provider, Auto final List listOfBDs = new ArrayList<>(); - // TODO use reflexions + // TODO use reflexion for (BridgeDomain bd : bridgeDomainList) { org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.bridge.domains.BridgeDomainBuilder bdBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.bridge.domains.BridgeDomainBuilder(); bdBuilder.setLearn(bd.isLearn()); 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 0078f16fc..bae4a29d3 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 @@ -59,7 +59,7 @@ public class V3poModule extends final V3poProvider provider = new V3poProvider(domBroker, getVppJapiDependency(), getReaderRegistryDependency(), getWriterRegistryDependency(), getBindingNormalizedNodeSerializerDependency(), - getConfigDataTreeDependency()); + getConfigDataTreeDependency(), getOperationalDataTreeDependency()); getBrokerDependency().registerProvider(provider); return provider; } diff --git a/v3po/impl/src/main/yang/v3po-impl.yang b/v3po/impl/src/main/yang/v3po-impl.yang index 2c2e95028..b9868c450 100644 --- a/v3po/impl/src/main/yang/v3po-impl.yang +++ b/v3po/impl/src/main/yang/v3po-impl.yang @@ -90,6 +90,15 @@ module v3po-impl { } } + container operational-data-tree { + uses config:service-ref { + refine type { + mandatory true; + config:required-identity dapi:honeycomb-readable-data-tree; + } + } + } + } } diff --git a/v3po/impl/src/test/java/io/fd/honeycomb/v3po/impl/data/VppDataBrokerInitializationProviderTest.java b/v3po/impl/src/test/java/io/fd/honeycomb/v3po/impl/data/VppDataBrokerInitializationProviderTest.java index 166104d67..cd362345b 100644 --- a/v3po/impl/src/test/java/io/fd/honeycomb/v3po/impl/data/VppDataBrokerInitializationProviderTest.java +++ b/v3po/impl/src/test/java/io/fd/honeycomb/v3po/impl/data/VppDataBrokerInitializationProviderTest.java @@ -27,6 +27,7 @@ import static org.mockito.MockitoAnnotations.initMocks; import com.google.common.util.concurrent.CheckedFuture; import io.fd.honeycomb.v3po.data.ModifiableDataTree; +import io.fd.honeycomb.v3po.data.ReadableDataTree; import io.fd.honeycomb.v3po.impl.VppDataBrokerInitializationProvider; import io.fd.honeycomb.v3po.translate.read.ReaderRegistry; import io.fd.honeycomb.v3po.translate.write.WriterRegistry; @@ -55,6 +56,8 @@ public class VppDataBrokerInitializationProviderTest { private BindingNormalizedNodeSerializer serializer; @Mock private ModifiableDataTree configDataTree; + @Mock + private ReadableDataTree operationalDataTree; private VppDataBrokerInitializationProvider provider; @@ -62,7 +65,8 @@ public class VppDataBrokerInitializationProviderTest { public void setUp() throws Exception { initMocks(this); doReturn(writeTx).when(bindingBroker).newWriteOnlyTransaction(); - provider = new VppDataBrokerInitializationProvider(bindingBroker, readerRegistry, writerRegistry, serializer, configDataTree); + provider = new VppDataBrokerInitializationProvider(bindingBroker, readerRegistry, writerRegistry, serializer, + configDataTree, operationalDataTree); } @Test 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 fb8c7047b..060b436cd 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 @@ -22,6 +22,7 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import io.fd.honeycomb.v3po.data.ModifiableDataTree; +import io.fd.honeycomb.v3po.data.ReadableDataTree; import io.fd.honeycomb.v3po.impl.V3poProvider; import io.fd.honeycomb.v3po.translate.read.ReaderRegistry; import io.fd.honeycomb.v3po.translate.write.WriterRegistry; @@ -62,6 +63,8 @@ public class V3poModuleTest { .thenReturn(mock(BindingNormalizedNodeSerializer.class)); when(dependencyResolver.resolveInstance(eq(ModifiableDataTree.class), any(ObjectName.class), any(JmxAttribute.class))) .thenReturn(mock(ModifiableDataTree.class)); + when(dependencyResolver.resolveInstance(eq(ReadableDataTree.class), any(ObjectName.class), any(JmxAttribute.class))) + .thenReturn(mock(ReadableDataTree.class)); // create instance of module with injected mocks V3poModule module = new V3poModule(mock(ModuleIdentifier.class), dependencyResolver); -- cgit 1.2.3-korg