From 3eaa42a454569639597eded0df4a181ca66f45d4 Mon Sep 17 00:00:00 2001 From: Ravi Pendurty Date: Mon, 31 Jan 2022 16:34:09 +0530 Subject: Enhance netconfnode-state-service bundle Add support for new capabilities and DOM functions Issue-ID: CCSDK-3576 Signed-off-by: Ravi Pendurty Change-Id: Ie7a4a4d5002dd846c4028457e19d00490f819a94 Signed-off-by: Ravi Pendurty --- .../wt/netconfnodestateservice/Capabilities.java | 24 ++++++++++++++++++++-- .../netconfnodestateservice/NetconfAccessor.java | 7 +++++++ .../NetconfDomAccessor.java | 11 ++++++++++ .../impl/NetconfNodeStateServiceImpl.java | 11 ++++++++++ .../impl/access/NetconfAccessorImpl.java | 6 ++++++ .../impl/access/NetconfAccessorManager.java | 3 --- .../impl/access/NetconfCommunicatorManager.java | 1 + .../impl/access/dom/NetconfDomAccessorImpl.java | 23 +++++++++++++++++++++ .../org/opendaylight/blueprint/impl-blueprint.xml | 3 +++ 9 files changed, 84 insertions(+), 5 deletions(-) diff --git a/sdnr/wt/netconfnode-state-service/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/netconfnodestateservice/Capabilities.java b/sdnr/wt/netconfnode-state-service/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/netconfnodestateservice/Capabilities.java index 133868fcf..82232b2d5 100644 --- a/sdnr/wt/netconfnode-state-service/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/netconfnodestateservice/Capabilities.java +++ b/sdnr/wt/netconfnode-state-service/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/netconfnodestateservice/Capabilities.java @@ -48,8 +48,9 @@ public class Capabilities { private static final Logger LOG = LoggerFactory.getLogger(Capabilities.class); private static final String UNSUPPORTED = "Unsupported"; + private static final DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); + private final List capabilities = new ArrayList<>(); - private final DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); private Capabilities() {} @@ -150,6 +151,25 @@ public class Capabilities { return revision == null ? false : isSupportingNamespaceAndRevision(namespace, revision); } + /** + * Provide namespace and its revision as String. + * + * @param qCapability capability from the model + * @return String + */ + public static String getNamespaceAndRevisionAsString(QName qCapability) { + StringBuffer res = new StringBuffer(); + res.append(qCapability.getNamespace().toString()); + + String revisionString = getRevisionString(qCapability); + if (revisionString != null) { + res.append("?"); + res.append(revisionString); + } + + return res.toString(); + } + /** * * @param namespace requested @@ -178,7 +198,7 @@ public class Capabilities { * @param qCapability that specifies the revision * @return String with revisiondate or null */ - private String getRevisionString(QName qCapability) { + private static String getRevisionString(QName qCapability) { Object revisionObject = qCapability.getRevision(); String revision = null; if (revisionObject instanceof Optional) { diff --git a/sdnr/wt/netconfnode-state-service/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/netconfnodestateservice/NetconfAccessor.java b/sdnr/wt/netconfnode-state-service/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/netconfnodestateservice/NetconfAccessor.java index a419b3ac3..46fbbacc0 100644 --- a/sdnr/wt/netconfnode-state-service/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/netconfnodestateservice/NetconfAccessor.java +++ b/sdnr/wt/netconfnode-state-service/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/netconfnodestateservice/NetconfAccessor.java @@ -19,6 +19,7 @@ package org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice; import java.util.Optional; import org.opendaylight.mdsal.binding.api.DataBroker; +import org.opendaylight.mdsal.dom.api.DOMDataBroker; import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNode; import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId; @@ -34,6 +35,12 @@ public interface NetconfAccessor { */ DataBroker getControllerBindingDataBroker(); + /** + * @return the Controller DOMDataBroker + */ + DOMDataBroker getControllerDOMDataBroker(); + + /** * @return the nodeId */ diff --git a/sdnr/wt/netconfnode-state-service/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/netconfnodestateservice/NetconfDomAccessor.java b/sdnr/wt/netconfnode-state-service/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/netconfnodestateservice/NetconfDomAccessor.java index e78579a47..1013e37c7 100644 --- a/sdnr/wt/netconfnode-state-service/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/netconfnodestateservice/NetconfDomAccessor.java +++ b/sdnr/wt/netconfnode-state-service/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/netconfnodestateservice/NetconfDomAccessor.java @@ -75,6 +75,16 @@ public interface NetconfDomAccessor extends NetconfAccessor { */ Optional> readDataNode(LogicalDatastoreType dataStoreType, YangInstanceIdentifier path); + /** + * Read data from Controller node - controller-config + * + * @param dataStoreType + * @param path + * @return NormalizedNode with data + */ + Optional> readControllerDataNode(LogicalDatastoreType dataStoreType, + YangInstanceIdentifier path); + /** * Register netconf notification listener for related mountpoint * @@ -153,4 +163,5 @@ public interface NetconfDomAccessor extends NetconfAccessor { * @return serialization object. */ BindingNormalizedNodeSerializer getBindingNormalizedNodeSerializer(); + } diff --git a/sdnr/wt/netconfnode-state-service/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/netconfnodestateservice/impl/NetconfNodeStateServiceImpl.java b/sdnr/wt/netconfnode-state-service/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/netconfnodestateservice/impl/NetconfNodeStateServiceImpl.java index d3752cdc4..f759971fb 100644 --- a/sdnr/wt/netconfnode-state-service/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/netconfnodestateservice/impl/NetconfNodeStateServiceImpl.java +++ b/sdnr/wt/netconfnode-state-service/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/netconfnodestateservice/impl/NetconfNodeStateServiceImpl.java @@ -58,6 +58,7 @@ import org.opendaylight.mdsal.binding.api.NotificationPublishService; import org.opendaylight.mdsal.binding.api.RpcProviderService; import org.opendaylight.mdsal.binding.dom.codec.api.BindingNormalizedNodeSerializer; import org.opendaylight.mdsal.common.api.LogicalDatastoreType; +import org.opendaylight.mdsal.dom.api.DOMDataBroker; import org.opendaylight.mdsal.dom.api.DOMMountPointService; import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceProvider; import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceRegistration; @@ -104,6 +105,7 @@ public class NetconfNodeStateServiceImpl // -- OSGi services, provided private DataBroker dataBroker; + private DOMDataBroker domDataBroker; private MountPointService mountPointService; private DOMMountPointService domMountPointService; private RpcProviderService rpcProviderRegistry; @@ -159,6 +161,7 @@ public class NetconfNodeStateServiceImpl LOG.info("Creating provider for {}", APPLICATION_NAME); this.dataBroker = null; + this.domDataBroker = null; this.mountPointService = null; this.domMountPointService = null; this.rpcProviderRegistry = null; @@ -182,6 +185,10 @@ public class NetconfNodeStateServiceImpl this.dataBroker = dataBroker; } + public void setDomDataBroker(DOMDataBroker domDataBroker) { + this.domDataBroker = domDataBroker; + } + public void setRpcProviderRegistry(RpcProviderService rpcProviderRegistry) { this.rpcProviderRegistry = rpcProviderRegistry; } @@ -270,6 +277,10 @@ public class NetconfNodeStateServiceImpl return dataBroker; } + public DOMDataBroker getDOMDataBroker() { + return domDataBroker; + } + public NetconfnodeStateServiceRpcApiImpl getNetconfnodeStateServiceRpcApiImpl() { return Objects.requireNonNull(rpcApiService, "Initialization not completed for rpcApiService" ); } diff --git a/sdnr/wt/netconfnode-state-service/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/netconfnodestateservice/impl/access/NetconfAccessorImpl.java b/sdnr/wt/netconfnode-state-service/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/netconfnodestateservice/impl/access/NetconfAccessorImpl.java index 34073614e..8cdf33d1b 100644 --- a/sdnr/wt/netconfnode-state-service/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/netconfnodestateservice/impl/access/NetconfAccessorImpl.java +++ b/sdnr/wt/netconfnode-state-service/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/netconfnodestateservice/impl/access/NetconfAccessorImpl.java @@ -26,6 +26,7 @@ import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfDomAccesso import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.impl.NetconfNodeStateServiceImpl; import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.impl.access.dom.DomContext; import org.opendaylight.mdsal.binding.api.DataBroker; +import org.opendaylight.mdsal.dom.api.DOMDataBroker; import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNode; import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNodeConnectionStatus.ConnectionStatus; import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId; @@ -113,6 +114,11 @@ public class NetconfAccessorImpl implements NetconfAccessor { return netconfNodeStateService.getDataBroker(); } + @Override + public DOMDataBroker getControllerDOMDataBroker() { + return netconfNodeStateService.getDOMDataBroker(); + } + /** * check if nc-notifications.yang is supported by the device */ diff --git a/sdnr/wt/netconfnode-state-service/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/netconfnodestateservice/impl/access/NetconfAccessorManager.java b/sdnr/wt/netconfnode-state-service/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/netconfnodestateservice/impl/access/NetconfAccessorManager.java index 6c3704421..3b68004bc 100644 --- a/sdnr/wt/netconfnode-state-service/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/netconfnodestateservice/impl/access/NetconfAccessorManager.java +++ b/sdnr/wt/netconfnode-state-service/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/netconfnodestateservice/impl/access/NetconfAccessorManager.java @@ -70,7 +70,4 @@ public class NetconfAccessorManager { public void removeAccessor(NodeId nNodeId) { accessorList.remove(nNodeId); } - - - } diff --git a/sdnr/wt/netconfnode-state-service/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/netconfnodestateservice/impl/access/NetconfCommunicatorManager.java b/sdnr/wt/netconfnode-state-service/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/netconfnodestateservice/impl/access/NetconfCommunicatorManager.java index 30afb4a20..f1cf906be 100644 --- a/sdnr/wt/netconfnode-state-service/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/netconfnodestateservice/impl/access/NetconfCommunicatorManager.java +++ b/sdnr/wt/netconfnode-state-service/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/netconfnodestateservice/impl/access/NetconfCommunicatorManager.java @@ -65,6 +65,7 @@ public class NetconfCommunicatorManager { private final DOMMountPointService domMountPointService; private final DomContext domContext; + public NetconfCommunicatorManager(MountPointService mountPointService, DOMMountPointService domMountPointService, DomContext domContext) { super(); diff --git a/sdnr/wt/netconfnode-state-service/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/netconfnodestateservice/impl/access/dom/NetconfDomAccessorImpl.java b/sdnr/wt/netconfnode-state-service/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/netconfnodestateservice/impl/access/dom/NetconfDomAccessorImpl.java index 97d48d130..54ca395f4 100644 --- a/sdnr/wt/netconfnode-state-service/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/netconfnodestateservice/impl/access/dom/NetconfDomAccessorImpl.java +++ b/sdnr/wt/netconfnode-state-service/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/netconfnodestateservice/impl/access/dom/NetconfDomAccessorImpl.java @@ -146,6 +146,28 @@ public class NetconfDomAccessorImpl extends NetconfAccessorImpl implements Netco } } + @Override + public Optional> readControllerDataNode(LogicalDatastoreType dataStoreType, + YangInstanceIdentifier path) { + LOG.debug("Read to controller node datastore:{} path:{}", dataStoreType, path); + + DOMDataTreeReadTransaction readOnlyTransaction = this.getControllerDOMDataBroker().newReadOnlyTransaction(); + try { + FluentFuture>> foData = readOnlyTransaction.read(dataStoreType, path); + + Optional> data = foData.get(120, TimeUnit.SECONDS); + LOG.trace("read is done - {} ", foData.isDone()); + return data; + } catch (InterruptedException e) { + LOG.debug("Incomplete read to node transaction {} {}", dataStoreType, path, e); + Thread.currentThread().interrupt(); + return Optional.empty(); + } catch (ExecutionException | TimeoutException e) { + LOG.debug("Incomplete read to node transaction {} {}", dataStoreType, path, e); + return Optional.empty(); + } + } + @SuppressWarnings("unchecked") private static Optional convertNormalizedNode(BindingNormalizedNodeSerializer serializer, Optional> oData, YangInstanceIdentifier path, Class clazz) @@ -284,4 +306,5 @@ public class NetconfDomAccessorImpl extends NetconfAccessorImpl implements Netco final String formattedDate = DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(dateTime); return new DateAndTime(formattedDate); } + } diff --git a/sdnr/wt/netconfnode-state-service/provider/src/main/resources/org/opendaylight/blueprint/impl-blueprint.xml b/sdnr/wt/netconfnode-state-service/provider/src/main/resources/org/opendaylight/blueprint/impl-blueprint.xml index fbf36e5a0..ec4c64e67 100644 --- a/sdnr/wt/netconfnode-state-service/provider/src/main/resources/org/opendaylight/blueprint/impl-blueprint.xml +++ b/sdnr/wt/netconfnode-state-service/provider/src/main/resources/org/opendaylight/blueprint/impl-blueprint.xml @@ -28,6 +28,8 @@ + + @@ -55,6 +57,7 @@ + -- cgit 1.2.3-korg