Update MRI projects for Aluminium
[netconf.git] / netconf / netconf-console / src / main / java / org / opendaylight / netconf / console / utils / NetconfConsoleUtils.java
index c967413884f45552c25f23c8ee2f11220742117c..691d793ea9da2d4ae55e8ca607a89c6cf920d29d 100644 (file)
@@ -5,18 +5,19 @@
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
-
 package org.opendaylight.netconf.console.utils;
 
-import com.google.common.base.Optional;
+import com.google.common.collect.ImmutableList;
 import com.google.common.util.concurrent.ListenableFuture;
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Collection;
 import java.util.List;
+import java.util.Optional;
 import java.util.concurrent.ExecutionException;
-import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
-import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.mdsal.binding.api.DataBroker;
+import org.opendaylight.mdsal.binding.api.ReadTransaction;
+import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
 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.network.topology.Topology;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
@@ -41,13 +42,11 @@ public final class NetconfConsoleUtils {
     public static List<Node> getNetconfNodeFromIp(final String deviceIp, final DataBroker db) {
         final Topology topology = read(LogicalDatastoreType.OPERATIONAL, NetconfIidFactory.NETCONF_TOPOLOGY_IID, db);
         List<Node> nodes = new ArrayList<>();
-        if (isNetconfNodesPresent(topology)) {
-            for (Node node : topology.getNode()) {
-                final NetconfNode netconfNode = node.augmentation(NetconfNode.class);
-                if (netconfNode != null
-                        && netconfNode.getHost().getIpAddress().getIpv4Address().getValue().equals(deviceIp)) {
-                    nodes.add(node);
-                }
+        for (Node node : netconfNodes(topology)) {
+            final NetconfNode netconfNode = node.augmentation(NetconfNode.class);
+            if (netconfNode != null
+                    && netconfNode.getHost().getIpAddress().getIpv4Address().getValue().equals(deviceIp)) {
+                nodes.add(node);
             }
         }
         return nodes.isEmpty() ? null : nodes;
@@ -77,14 +76,11 @@ public final class NetconfConsoleUtils {
     public static Node getNetconfNodeFromIpAndPort(final String deviceIp, final String devicePort,
                                                    final DataBroker db) {
         final Topology topology = read(LogicalDatastoreType.OPERATIONAL, NetconfIidFactory.NETCONF_TOPOLOGY_IID, db);
-        if (isNetconfNodesPresent(topology)) {
-            for (Node node : topology.getNode()) {
-                final NetconfNode netconfNode = node.augmentation(NetconfNode.class);
-                if (netconfNode != null
-                        && netconfNode.getHost().getIpAddress().getIpv4Address().getValue().equals(deviceIp)
-                        && devicePort.equals(netconfNode.getPort().getValue().toString())) {
-                    return node;
-                }
+        for (Node node : netconfNodes(topology)) {
+            final NetconfNode netconfNode = node.augmentation(NetconfNode.class);
+            if (netconfNode != null && netconfNode.getHost().getIpAddress().getIpv4Address().getValue().equals(deviceIp)
+                    && devicePort.equals(netconfNode.getPort().getValue().toString())) {
+                return node;
             }
         }
         return null;
@@ -95,20 +91,8 @@ public final class NetconfConsoleUtils {
      * @param topology :NETCONF topology instance
      * @return :<code>true</code> if not empty, else, <code>false</code>
      */
-    private static boolean isNetconfNodesPresent(final Topology topology) {
-        return topology != null && topology.getNode() != null && !topology.getNode().isEmpty();
-    }
-
-    /**
-     * Wait for datastore to populate NETCONF data.
-     * @param deviceIp :IP address of NETCONF device
-     */
-    public static void waitForUpdate(final String deviceIp) {
-        try {
-            Thread.sleep(NetconfConsoleConstants.DEFAULT_TIMEOUT_MILLIS);
-        } catch (final InterruptedException e) {
-            LOG.warn("Interrupted while waiting after Netconf node {}", deviceIp, e);
-        }
+    private static Collection<Node> netconfNodes(final Topology topology) {
+        return topology == null ? ImmutableList.of() : topology.nonnullNode().values();
     }
 
     /**
@@ -121,7 +105,7 @@ public final class NetconfConsoleUtils {
     public static <D extends org.opendaylight.yangtools.yang.binding.DataObject> D read(
             final LogicalDatastoreType store, final InstanceIdentifier<D> path, final DataBroker db) {
         final ListenableFuture<Optional<D>> future;
-        try (ReadOnlyTransaction transaction = db.newReadOnlyTransaction()) {
+        try (ReadTransaction transaction = db.newReadOnlyTransaction()) {
             future = transaction.read(store, path);
         }