Synchronize sdnr/wt data-provider, websocketmanager, netconfstate-provider 99/125799/2
authorhighstreetherbert <herbert.eiselt@highstreet-technologies.com>
Fri, 19 Nov 2021 17:22:06 +0000 (18:22 +0100)
committerKAPIL SINGAL <ks220y@att.com>
Sat, 27 Nov 2021 17:24:42 +0000 (17:24 +0000)
Synchronize sdnr/wt artifacts

Issue-ID: CCSDK-3530
Signed-off-by: highstreetherbert <herbert.eiselt@highstreet-technologies.com>
Change-Id: I6e6c25a03e12acf0bd666675aaeb5a8518ed7b1e
Signed-off-by: highstreetherbert <herbert.eiselt@highstreet-technologies.com>
sdnr/wt/data-provider/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/dataprovider/http/about/AboutHttpServlet.java
sdnr/wt/netconfnode-state-service/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/netconfnodestateservice/Capabilities.java
sdnr/wt/netconfnode-state-service/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/netconfnodestateservice/impl/access/NetconfAccessorImpl.java
sdnr/wt/netconfnode-state-service/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/netconfnodestateservice/impl/access/binding/GenericTransactionUtils.java
sdnr/wt/netconfnode-state-service/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/netconfnodestateservice/impl/access/binding/NetconfBindingAccessorImpl.java
sdnr/wt/netconfnode-state-service/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/netconfnodestateservice/impl/access/dom/NetconfDomAccessorImpl.java
sdnr/wt/netconfnode-state-service/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/netconfnodestateservice/impl/conf/odlAkka/ClusterNodeInfo.java
sdnr/wt/netconfnode-state-service/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/netconfnodestateservice/impl/conf/odlGeo/ClusterRoleInfo.java
sdnr/wt/websocketmanager/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/websocketmanager/WebSocketManagerSocket.java
sdnr/wt/websocketmanager/provider/src/main/java/org/onap/ccsdk/features/sdnr/wt/websocketmanager/utils/AkkaConfig.java

index 310444f..6eae55f 100644 (file)
@@ -184,7 +184,7 @@ public class AboutHttpServlet extends HttpServlet {
      * collect dynamic data for about.md
      */
     private void collectData(ContentType ctype) {
-        LOG.info("collecting dynamic data");
+        LOG.info("collecting dynamic data with content-type {}", ctype);
         try {
             this.data.put(PLACEHOLDER_KARAF_INFO, SystemInfo.get());
             this.data.put(PLACEHOLDER_DEVICEMANAGER_TABLE, this.getDevicemanagerBundles(ctype));
index f12c53a..133868f 100644 (file)
@@ -34,6 +34,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev15
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.netconf.node.connection.status.available.capabilities.AvailableCapability;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.netconf.node.connection.status.unavailable.capabilities.UnavailableCapability;
 import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.common.Revision;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -210,7 +211,10 @@ public class Capabilities {
         String namespace = qCapability.getNamespace().toString();
         for (String capability : capabilities) {
             if (capability.contains(namespace)) {
-                return QName.create(capability).getRevision().get().toString();
+                Optional<Revision> revisionOpt = QName.create(capability).getRevision();
+                if (revisionOpt.isPresent()) {
+                    return revisionOpt.get().toString();
+                }
             }
         }
         return UNSUPPORTED;
@@ -223,7 +227,7 @@ public class Capabilities {
      * @return true if namespace is supported.
      */
     static public boolean isNamespaceSupported(String revision) {
-        return revision != UNSUPPORTED;
+        return !UNSUPPORTED.equals(revision);
     }
 
     @Override
index a1a3540..3407361 100644 (file)
@@ -63,7 +63,7 @@ public class NetconfAccessorImpl implements NetconfAccessor {
         this.domContext = Objects.requireNonNull(domContext);
         this.netconfNodeStateService = Objects.requireNonNull(netconfNodeStateService);
 
-        ConnectionStatus csts = netconfNode != null ? netconfNode.getConnectionStatus() : null;
+        ConnectionStatus csts = netconfNode.getConnectionStatus();
         if (csts == null) {
             throw new IllegalStateException(String.format("connection status for %s is not connected", nodeId));
         }
index 2820484..1aa3afe 100644 (file)
@@ -115,14 +115,10 @@ public final class GenericTransactionUtils implements TransactionUtils {
                 if (od != null) {
                     statusIndicator.set("Unwrap checkFuture done");
                     Optional<T> optionalData = od.get();
-                    if (optionalData != null) {
-                        statusIndicator.set("Unwrap optional done");
-                        data = optionalData.orElse(null);
-                        statusIndicator.set("Read transaction done");
-                        noErrorIndication.set(true);
-                    } else {
-                        statusIndicator.set("optional Data is null");
-                    }
+                    statusIndicator.set("Unwrap optional done");
+                    data = optionalData.orElse(null);
+                    statusIndicator.set("Read transaction done");
+                    noErrorIndication.set(true);
                 } else {
                     statusIndicator.set("od feature is null");
                 }
index 6f3a592..b36e476 100644 (file)
@@ -111,7 +111,7 @@ public class NetconfBindingAccessorImpl extends NetconfAccessorImpl implements N
 
     @Override
     public ListenableFuture<RpcResult<CreateSubscriptionOutput>> registerNotificationsStream(
-            @NonNull String streamName) {
+            String streamName) {
         final CreateSubscriptionInputBuilder createSubscriptionInputBuilder = new CreateSubscriptionInputBuilder();
         if (streamName != null) {
             createSubscriptionInputBuilder.setStream(new StreamNameType(streamName));
index b6843fb..97d48d1 100644 (file)
@@ -127,16 +127,21 @@ public class NetconfDomAccessorImpl extends NetconfAccessorImpl implements Netco
             YangInstanceIdentifier path) {
         LOG.debug("Read to node datastore:{} path:{}", dataStoreType, path);
 
-        try (DOMDataTreeReadTransaction readOnlyTransaction = dataBroker.newReadOnlyTransaction()) {
+        // Don't use try with resource because the implicit close of this construct is not handled
+        // correctly by underlying opendaylight NETCONF service
+        DOMDataTreeReadTransaction readOnlyTransaction = dataBroker.newReadOnlyTransaction();
+        try {
             FluentFuture<Optional<NormalizedNode<?, ?>>> foData = readOnlyTransaction.read(dataStoreType, path);
-            // RAVI - Add a few debug here, like what ? Speak to Micha....
 
             Optional<NormalizedNode<?, ?>> data = foData.get(120, TimeUnit.SECONDS);
-            LOG.info("read is done - {} ", foData.isDone());
+            LOG.trace("read is done - {} ", foData.isDone());
             return data;
-
-        } catch (InterruptedException | ExecutionException | TimeoutException e) {
-            LOG.info("Incomplete read to node transaction {} {}", dataStoreType, path, e);
+        } 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();
         }
     }
@@ -217,9 +222,7 @@ public class NetconfDomAccessorImpl extends NetconfAccessorImpl implements Netco
             replayIsSupported = Boolean.TRUE.equals(stream.isReplaySupport());
 
         }
-        if (filter.isPresent()) {
-            inputBuilder.setFilter(filter.get());
-        }
+        filter.ifPresent(inputBuilder::setFilter);
         if (startTime.isPresent()) {
             if (replayIsSupported) {
                 inputBuilder.setStartTime(getDateAndTime(startTime.get()));
@@ -253,8 +256,12 @@ public class NetconfDomAccessorImpl extends NetconfAccessorImpl implements Netco
                     if (!res.get().getErrors().isEmpty()) {
                         return res;
                     }
-                } catch (InterruptedException | ExecutionException e) {
-                    LOG.warn("Exception during rpc call", e);
+                } catch (InterruptedException e) {
+                    LOG.warn("InterruptedException during rpc call", e);
+                    Thread.currentThread().interrupt();
+                    return res;
+                } catch (ExecutionException e) {
+                    LOG.warn("ExecutionException during rpc call", e);
                     return res;
                 }
             }
@@ -265,7 +272,7 @@ public class NetconfDomAccessorImpl extends NetconfAccessorImpl implements Netco
     @Override
     public @NonNull Map<StreamKey, Stream> getNotificationStreamsAsMap() {
         Optional<Streams> oStreams = readData(LogicalDatastoreType.OPERATIONAL, STREAMS_PATH, Streams.class);
-        return oStreams.isPresent() ? oStreams.get().nonnullStream() : Collections.emptyMap();
+        return oStreams.map(Streams::nonnullStream).orElse(Collections.emptyMap());
     }
 
     @Override
index b27a7bd..ccce583 100644 (file)
@@ -32,7 +32,7 @@ public class ClusterNodeInfo {
     }
 
     public ClusterNodeInfo(String s) throws Exception {
-        final String regex = "([a-z.]*):\\/\\/([a-zA-Z0-9-]*)@([a-zA-Z0-9.-]*):([0-9]*)";
+        final String regex = "([a-z.]{0,10}):\\/\\/([a-zA-Z0-9-]{0,1024})@([a-zA-Z0-9.-]{0,1024}):([0-9]{0,10})";
         final Pattern pattern = Pattern.compile(regex);
         final Matcher matcher = pattern.matcher(s);
         if (!matcher.find()) {
index 8f4446b..f11ce40 100644 (file)
@@ -25,7 +25,10 @@ public class ClusterRoleInfo {
     private final int Index;
 
     public ClusterRoleInfo(String s) throws Exception {
-        final String regex = "([a-zA-Z]*)-([0-9]*)";
+        // role with minimum 1 character
+        // index with minimum 1 character or Integer.parseInt raise an exception
+        // index with maximum 10 because it's an integer
+        final String regex = "([a-zA-Z]{1,1024})-([0-9]{1,10})";
         final Pattern pattern = Pattern.compile(regex);
         final Matcher matcher = pattern.matcher(s);
         if (!matcher.find()) {
index 7cc6d72..95715be 100644 (file)
@@ -18,6 +18,7 @@
 package org.onap.ccsdk.features.sdnr.wt.websocketmanager;
 
 import com.fasterxml.jackson.core.JsonProcessingException;
+import java.security.SecureRandom;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
@@ -59,7 +60,7 @@ public class WebSocketManagerSocket extends WebSocketAdapter {
     private static final String REGEX_SCOPEREGISTRATION = "\"data\"[\\s]*:[\\s]*\"scopes\"";
     private static final Pattern PATTERN_SCOPEREGISTRATION =
             Pattern.compile(REGEX_SCOPEREGISTRATION, Pattern.MULTILINE);
-    private static final Random RND = new Random();
+    private static final SecureRandom RND = new SecureRandom();
     private static final long SEND_MESSAGE_TIMEOUT_MILLIS = 1500;
     private static final int QUEUE_SIZE = 100;
 
index 794515b..7bbbfea 100644 (file)
@@ -49,7 +49,7 @@ public class AkkaConfig {
         }
 
         public ClusterNodeInfo(String s) throws Exception {
-            final String regex = "([a-z.]*):\\/\\/([a-zA-Z0-9-]*)@([a-zA-Z0-9.-]*):([0-9]*)";
+            final String regex = "([a-z.]{0,10}):\\/\\/([a-zA-Z0-9-]{0,1024})@([a-zA-Z0-9.-]{0,1024}):([0-9]{0,10})";
             final Pattern pattern = Pattern.compile(regex);
             final Matcher matcher = pattern.matcher(s);
             if (!matcher.find()) {
@@ -71,7 +71,10 @@ public class AkkaConfig {
         private final int Index;
 
         public ClusterRoleInfo(String s) throws Exception {
-            final String regex = "([a-z]*)-([0-9]*)";
+            // role with minimum 1 character
+            // index with minimum 1 character or Integer.parseInt raise an exception
+            // index with maximum 10 because it's an integer
+            final String regex = "([a-z]{1,1024})-([0-9]{1,10})";
             final Pattern pattern = Pattern.compile(regex);
             final Matcher matcher = pattern.matcher(s);
             if (!matcher.find()) {
@@ -177,7 +180,7 @@ public class AkkaConfig {
     }
 
     public boolean isCluster() {
-        return this.cluserConfig != null ? this.cluserConfig.isCluster() : false;
+        return this.cluserConfig != null && this.cluserConfig.isCluster();
     }
 
     public static AkkaConfig load() throws Exception {