diff options
author | Maros Marsalek <mmarsale@cisco.com> | 2016-04-12 16:19:31 +0200 |
---|---|---|
committer | Maros Marsalek <mmarsale@cisco.com> | 2016-04-13 08:19:15 +0200 |
commit | 152ec1037001b867890aaaffe8a9e38a85b501b2 (patch) | |
tree | d94ccb141cb2f83020253390d90a2578c67a9386 /v3po/data-impl | |
parent | c4c4334ef4db37af07025523de4c2e2e25763599 (diff) |
HONEYCOMB-8: Fix netconf monitoring operational data provisioning
Local storage for netconf monitoring was not wired with
netconf northbound for vpp.
Change-Id: I864614ffcbf7acf16eccc65ab58b9821b2682f93
Signed-off-by: Maros Marsalek <mmarsale@cisco.com>
Diffstat (limited to 'v3po/data-impl')
5 files changed, 78 insertions, 8 deletions
diff --git a/v3po/data-impl/pom.xml b/v3po/data-impl/pom.xml index 954d25c30..1d716a6d9 100644 --- a/v3po/data-impl/pom.xml +++ b/v3po/data-impl/pom.xml @@ -54,6 +54,19 @@ <version>1.3.0-Beryllium</version> <!-- FIXME use dependency management --> </dependency> + <!-- FIXME workaround for https://git.opendaylight.org/gerrit/#/c/37499/--> + <dependency> + <groupId>org.opendaylight.netconf</groupId> + <artifactId>ietf-netconf-monitoring</artifactId> + <version>1.0.0-Beryllium</version> + </dependency> + <!-- FIXME workaround for https://git.opendaylight.org/gerrit/#/c/37499/--> + <dependency> + <groupId>org.opendaylight.netconf</groupId> + <artifactId>ietf-netconf-monitoring-extension</artifactId> + <version>1.0.0-Beryllium</version> + </dependency> + <!-- Testing Dependencies --> <dependency> <groupId>junit</groupId> diff --git a/v3po/data-impl/src/main/java/io/fd/honeycomb/v3po/data/impl/OperationalDataTree.java b/v3po/data-impl/src/main/java/io/fd/honeycomb/v3po/data/impl/OperationalDataTree.java index de737c729..5d3b00646 100644 --- a/v3po/data-impl/src/main/java/io/fd/honeycomb/v3po/data/impl/OperationalDataTree.java +++ b/v3po/data-impl/src/main/java/io/fd/honeycomb/v3po/data/impl/OperationalDataTree.java @@ -35,6 +35,10 @@ import java.util.Collection; import java.util.Map; import javax.annotation.Nonnull; import javax.annotation.Nullable; +import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; +import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker; +import org.opendaylight.controller.md.sal.dom.api.DOMDataReadOnlyTransaction; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.monitoring.rev101004.NetconfState; import org.opendaylight.yangtools.binding.data.codec.api.BindingNormalizedNodeSerializer; import org.opendaylight.yangtools.yang.binding.DataObject; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; @@ -64,17 +68,20 @@ public final class OperationalDataTree implements ReadableDataTree { private final BindingNormalizedNodeSerializer serializer; private final ReaderRegistry readerRegistry; private final SchemaContext globalContext; + private final DOMDataBroker netconfMonitoringDomDataBrokerDependency; /** * Creates operational data tree instance. - * - * @param serializer service for serialization between Java Binding Data representation and NormalizedNode + * @param serializer service for serialization between Java Binding Data representation and NormalizedNode * representation. * @param globalContext service for obtaining top level context data from all yang modules. * @param readerRegistry service responsible for translation between DataObjects and data provider. + * @param netconfMonitoringDomDataBrokerDependency */ public OperationalDataTree(@Nonnull BindingNormalizedNodeSerializer serializer, - @Nonnull final SchemaContext globalContext, @Nonnull ReaderRegistry readerRegistry) { + @Nonnull final SchemaContext globalContext, @Nonnull ReaderRegistry readerRegistry, + final DOMDataBroker netconfMonitoringDomDataBrokerDependency) { + this.netconfMonitoringDomDataBrokerDependency = netconfMonitoringDomDataBrokerDependency; this.globalContext = checkNotNull(globalContext, "globalContext should not be null"); this.serializer = checkNotNull(serializer, "serializer should not be null"); this.readerRegistry = checkNotNull(readerRegistry, "reader should not be null"); @@ -99,8 +106,14 @@ public final class OperationalDataTree implements ReadableDataTree { } private Optional<NormalizedNode<?, ?>> readNode(final YangInstanceIdentifier yangInstanceIdentifier, - final ReadContext ctx) - throws ReadFailedException { + final ReadContext ctx) throws ReadFailedException { + + // FIXME workaround for: https://git.opendaylight.org/gerrit/#/c/37499/ + if(yangInstanceIdentifier.getPathArguments().size() > 0 && + yangInstanceIdentifier.getPathArguments().get(0).getNodeType().equals(NetconfState.QNAME)) { + return readFromNetconfDs(yangInstanceIdentifier); + } + LOG.debug("OperationalDataTree.readNode(), yangInstanceIdentifier={}", yangInstanceIdentifier); final InstanceIdentifier<?> path = serializer.fromYangInstanceIdentifier(yangInstanceIdentifier); checkNotNull(path, "Invalid instance identifier %s. Cannot create BA equivalent.", yangInstanceIdentifier); @@ -117,6 +130,19 @@ public final class OperationalDataTree implements ReadableDataTree { } } + // FIXME workaround for: https://git.opendaylight.org/gerrit/#/c/37499/ + private Optional<NormalizedNode<?, ?>> readFromNetconfDs(final YangInstanceIdentifier yangInstanceIdentifier) + throws ReadFailedException { + try(final DOMDataReadOnlyTransaction domDataReadOnlyTransaction = + netconfMonitoringDomDataBrokerDependency.newReadOnlyTransaction()) { + try { + return domDataReadOnlyTransaction.read(LogicalDatastoreType.OPERATIONAL, yangInstanceIdentifier).checkedGet(); + } catch (org.opendaylight.controller.md.sal.common.api.data.ReadFailedException e) { + throw new ReadFailedException(InstanceIdentifier.create(NetconfState.class), e); + } + } + } + private Optional<NormalizedNode<?, ?>> readRoot(final ReadContext ctx) throws ReadFailedException { LOG.debug("OperationalDataTree.readRoot()"); @@ -134,6 +160,13 @@ public final class OperationalDataTree implements ReadableDataTree { dataNodeBuilder.withChild((DataContainerChild<?, ?>) node); } + // FIXME workaround for: https://git.opendaylight.org/gerrit/#/c/37499/ + final Optional<NormalizedNode<?, ?>> normalizedNodeOptional = + readFromNetconfDs(YangInstanceIdentifier.builder().node(NetconfState.QNAME).build()); + if(normalizedNodeOptional.isPresent()) { + dataNodeBuilder.withChild((DataContainerChild<?, ?>) normalizedNodeOptional.get()); + } + return Optional.<NormalizedNode<?, ?>>of(dataNodeBuilder.build()); } 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 index 24a1ca519..2fbba75fa 100644 --- 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 @@ -38,7 +38,7 @@ public class OperationalDataTreeModule extends LOG.debug("OperationalDataTreeModule.createInstance()"); return new CloseableOperationalDataTree( new OperationalDataTree(getSerializerDependency(), getSchemaServiceDependency().getGlobalContext(), - getReaderRegistryDependency())); + getReaderRegistryDependency(), getNetconfMonitoringDomDataBrokerDependency())); } private static final class CloseableOperationalDataTree implements ReadableDataTree, AutoCloseable { diff --git a/v3po/data-impl/src/main/yang/data-impl.yang b/v3po/data-impl/src/main/yang/data-impl.yang index 43201a084..5275e6556 100644 --- a/v3po/data-impl/src/main/yang/data-impl.yang +++ b/v3po/data-impl/src/main/yang/data-impl.yang @@ -121,6 +121,16 @@ module data-impl { } } + // FIXME workaround for: https://git.opendaylight.org/gerrit/#/c/37499/ + container netconf-monitoring-dom-data-broker { + uses config:service-ref { + refine type { + mandatory true; + config:required-identity dom:dom-async-data-broker; + } + } + } + } } }
\ No newline at end of file diff --git a/v3po/data-impl/src/test/java/io/fd/honeycomb/v3po/data/impl/OperationalDataTreeTest.java b/v3po/data-impl/src/test/java/io/fd/honeycomb/v3po/data/impl/OperationalDataTreeTest.java index fbd512915..7e6abcdcd 100644 --- a/v3po/data-impl/src/test/java/io/fd/honeycomb/v3po/data/impl/OperationalDataTreeTest.java +++ b/v3po/data-impl/src/test/java/io/fd/honeycomb/v3po/data/impl/OperationalDataTreeTest.java @@ -34,15 +34,20 @@ import com.google.common.collect.Iterables; import com.google.common.collect.LinkedListMultimap; import com.google.common.collect.Multimap; import com.google.common.util.concurrent.CheckedFuture; +import com.google.common.util.concurrent.Futures; import io.fd.honeycomb.v3po.translate.read.ReadContext; import io.fd.honeycomb.v3po.translate.read.ReaderRegistry; +import java.util.Collections; import java.util.Map; import org.junit.Before; import org.junit.Test; import org.mockito.Mock; +import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException; -import org.opendaylight.yangtools.binding.data.codec.api.BindingNormalizedNodeSerializer; +import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker; +import org.opendaylight.controller.md.sal.dom.api.DOMDataReadOnlyTransaction; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.VppState; +import org.opendaylight.yangtools.binding.data.codec.api.BindingNormalizedNodeSerializer; import org.opendaylight.yangtools.yang.binding.DataObject; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import org.opendaylight.yangtools.yang.common.QName; @@ -72,12 +77,20 @@ public class OperationalDataTreeTest { private DataSchemaNode schemaNode; @Mock private ReadContext readCtx; + @Mock + private DOMDataBroker netconfMonitoringBroker; + @Mock + private DOMDataReadOnlyTransaction domDataReadOnlyTransaction; @Before public void setUp() { initMocks(this); - operationalData = new OperationalDataTree(serializer, globalContext, reader); + operationalData = new OperationalDataTree(serializer, globalContext, reader, netconfMonitoringBroker); doReturn(schemaNode).when(globalContext).getDataChildByName(any(QName.class)); + + doReturn(domDataReadOnlyTransaction).when(netconfMonitoringBroker).newReadOnlyTransaction(); + doReturn(Futures.immediateCheckedFuture(Optional.absent())).when(domDataReadOnlyTransaction) + .read(any(LogicalDatastoreType.class), any(YangInstanceIdentifier.class)); } @Test @@ -85,6 +98,7 @@ public class OperationalDataTreeTest { final YangInstanceIdentifier yangId = mock(YangInstanceIdentifier.class); final YangInstanceIdentifier.PathArgument pArg = mock(YangInstanceIdentifier.PathArgument.class); doReturn(pArg).when(yangId).getLastPathArgument(); + doReturn(Collections.singletonList(pArg)).when(yangId).getPathArguments(); doReturn(QName.create("namespace", "2012-12-12", "local")).when(pArg).getNodeType(); doReturn(id).when(serializer).fromYangInstanceIdentifier(yangId); |