Clean up command naming
[openflowplugin.git] / applications / southbound-cli / src / main / java / org / opendaylight / openflowplugin / applications / southboundcli / util / ShellUtil.java
index fc43de58bdc7c2279d67b39e37f8b41ea2b47b81..d0be9bc924e5c37231412b2bdea27911426683b1 100644 (file)
@@ -9,11 +9,10 @@
 package org.opendaylight.openflowplugin.applications.southboundcli.util;
 
 import java.util.ArrayList;
-import java.util.Collections;
+import java.util.Collection;
 import java.util.List;
 import java.util.Optional;
 import java.util.concurrent.ExecutionException;
-import org.eclipse.jdt.annotation.NonNull;
 import org.opendaylight.mdsal.binding.api.DataBroker;
 import org.opendaylight.mdsal.binding.api.ReadTransaction;
 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
@@ -33,45 +32,12 @@ import org.slf4j.LoggerFactory;
 public final class ShellUtil {
     private static final Logger LOG = LoggerFactory.getLogger(ShellUtil.class);
 
+    public static final String LINE_SEPARATOR = "-".repeat(100);
     public static final String NODE_PREFIX = "openflow:";
 
     private ShellUtil() {
     }
 
-    @NonNull
-    public static List<OFNode> getAllNodes(final DataBroker broker) {
-        List<Node> nodes = null;
-        InstanceIdentifier<Nodes> path = InstanceIdentifier.builder(Nodes.class).build();
-        try (ReadTransaction tx = broker.newReadOnlyTransaction()) {
-            Optional<Nodes> result = tx.read(LogicalDatastoreType.OPERATIONAL, path).get();
-            if (result.isPresent()) {
-                nodes = result.get().getNode();
-            }
-        } catch (ExecutionException | InterruptedException | NullPointerException e) {
-            LOG.error("Error reading nodes from Inventory DS", e);
-        }
-        if (nodes != null) {
-            List<OFNode> nodeList = new ArrayList<>();
-            for (Node node : nodes) {
-                String[] nodeId = node.getId().getValue().split(":");
-                String name = null;
-                FlowCapableNode flowCapableNode = node.<FlowCapableNode>augmentation(FlowCapableNode.class);
-                if (flowCapableNode != null) {
-                    name = node.<FlowCapableNode>augmentation(FlowCapableNode.class).getDescription();
-                } else {
-                    LOG.error("Error while converting OFNode: {} to FlowCapableNode", node.getId());
-                    return Collections.emptyList();
-                }
-                OFNode ofNode = new OFNode(Long.parseLong(nodeId[1]), name);
-                LOG.trace("Added OFNode: {} to the list", ofNode.getNodeId());
-                nodeList.add(ofNode);
-            }
-            Collections.sort(nodeList);
-            return nodeList;
-        }
-        return Collections.emptyList();
-    }
-
     public static OFNode getNode(final long nodeId, final DataBroker broker) {
         OFNode nodeInfo = getNodeInfo(nodeId, broker);
         if (nodeInfo == null) {
@@ -100,9 +66,9 @@ public final class ShellUtil {
         try (ReadTransaction tx = broker.newReadOnlyTransaction()) {
             Optional<Node> result = tx.read(LogicalDatastoreType.OPERATIONAL, path).get();
             if (result.isPresent()) {
-                Node node = result.get();
-                String name = null;
-                List<NodeConnector> nodeConnectors = null;
+                Node node = result.orElseThrow();
+                String name;
+                Collection<NodeConnector> nodeConnectors = node.nonnullNodeConnector().values();
                 List<String> portList = new ArrayList<>();
                 FlowCapableNode flowCapableNode = node.<FlowCapableNode>augmentation(FlowCapableNode.class);
                 if (flowCapableNode != null) {
@@ -111,7 +77,6 @@ public final class ShellUtil {
                     LOG.error("Error while converting OFNode:{} to FlowCapableNode", node.getId());
                     return null;
                 }
-                nodeConnectors = node.getNodeConnector();
                 for (NodeConnector nodeConnector : nodeConnectors) {
                     FlowCapableNodeConnector flowCapableNodeConnector =
                             nodeConnector.augmentation(FlowCapableNodeConnector.class);
@@ -134,19 +99,15 @@ public final class ShellUtil {
         return ofNode;
     }
 
-    public static List<ReconcileCounter> getReconcileCount(final DataBroker dataBroker) {
+    public static Collection<ReconcileCounter> getReconcileCount(final DataBroker dataBroker) {
         InstanceIdentifier<ReconciliationCounter> instanceIdentifier = InstanceIdentifier
                 .builder(ReconciliationCounter.class).build();
-        List<ReconcileCounter> output = Collections.emptyList();
         try (ReadTransaction tx = dataBroker.newReadOnlyTransaction()) {
-            Optional<ReconciliationCounter> result =
-                    tx.read(LogicalDatastoreType.OPERATIONAL, instanceIdentifier).get();
-            if (result.isPresent()) {
-                output = result.get().getReconcileCounter();
-            }
-        } catch (ExecutionException | InterruptedException | NullPointerException e) {
+            final var result = tx.read(LogicalDatastoreType.OPERATIONAL, instanceIdentifier).get();
+            return result.map(counter -> counter.nonnullReconcileCounter().values()).orElse(List.of());
+        } catch (ExecutionException | InterruptedException e) {
             LOG.error("Error reading reconciliation counter from datastore", e);
+            return List.of();
         }
-        return output;
     }
 }