OPNFLWPLUG-1032: Neon-MRI: Bump odlparent, yangtools, mdsal
[openflowplugin.git] / applications / southbound-cli / src / main / java / org / opendaylight / openflowplugin / applications / southboundcli / util / ShellUtil.java
index 0da9d0d4541e49055f29fe779d15913db23369ae..f3dc9cada82b70979c2317c94b1c46c5fa94e7aa 100644 (file)
@@ -9,16 +9,14 @@
 package org.opendaylight.openflowplugin.applications.southboundcli.util;
 
 import com.google.common.base.Optional;
-import com.google.common.util.concurrent.CheckedFuture;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
 import java.util.concurrent.ExecutionException;
+import javax.annotation.Nonnull;
 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.controller.md.sal.common.api.data.ReadFailedException;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeConnector;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
@@ -26,6 +24,8 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnector;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflowplugin.app.reconciliation.service.rev180227.ReconciliationCounter;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflowplugin.app.reconciliation.service.rev180227.reconciliation.counter.ReconcileCounter;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -38,14 +38,13 @@ public final class ShellUtil {
     private ShellUtil() {
     }
 
+    @Nonnull
     public static List<OFNode> getAllNodes(final DataBroker broker) {
         List<Node> nodes = null;
         ReadOnlyTransaction tx = broker.newReadOnlyTransaction();
         InstanceIdentifier<Nodes> path = InstanceIdentifier.builder(Nodes.class).build();
         try {
-            CheckedFuture<Optional<Nodes>, ReadFailedException> checkedFuture =
-                    tx.read(LogicalDatastoreType.OPERATIONAL, path);
-            Optional<Nodes> result = checkedFuture.get();
+            Optional<Nodes> result = tx.read(LogicalDatastoreType.OPERATIONAL, path).get();
             if (result.isPresent()) {
                 nodes = result.get().getNode();
             }
@@ -57,18 +56,16 @@ public final class ShellUtil {
             for (Node node : nodes) {
                 String[] nodeId = node.getId().getValue().split(":");
                 String name = null;
-                FlowCapableNode flowCapableNode = node.<FlowCapableNode>getAugmentation(FlowCapableNode.class);
+                FlowCapableNode flowCapableNode = node.<FlowCapableNode>augmentation(FlowCapableNode.class);
                 if (flowCapableNode != null) {
-                    name = node.<FlowCapableNode>getAugmentation(FlowCapableNode.class).getDescription();
+                    name = node.<FlowCapableNode>augmentation(FlowCapableNode.class).getDescription();
                 } else {
                     LOG.error("Error while converting OFNode: {} to FlowCapableNode", node.getId());
-                    return null;
+                    return Collections.emptyList();
                 }
                 OFNode ofNode = new OFNode(Long.parseLong(nodeId[1]), name);
-                if (ofNode != null) {
-                    LOG.trace("Added OFNode: {} to the list", ofNode.getNodeId());
-                    nodeList.add(ofNode);
-                }
+                LOG.trace("Added OFNode: {} to the list", ofNode.getNodeId());
+                nodeList.add(ofNode);
             }
             Collections.sort(nodeList);
             return nodeList;
@@ -101,44 +98,58 @@ public final class ShellUtil {
         ReadOnlyTransaction tx = broker.newReadOnlyTransaction();
         InstanceIdentifier<Node> path = InstanceIdentifier.builder(Nodes.class)
                 .child(Node.class, new NodeKey(new NodeId(NODE_PREFIX + nodeId))).build();
-        Optional<Node> result;
+
         try {
-            CheckedFuture<Optional<Node>, ReadFailedException> checkedFuture =
-                    tx.read(LogicalDatastoreType.OPERATIONAL, path);
-            result = checkedFuture.get();
+            Optional<Node> result = tx.read(LogicalDatastoreType.OPERATIONAL, path).get();
             if (result.isPresent()) {
                 Node node = result.get();
                 String name = null;
                 List<NodeConnector> nodeConnectors = null;
                 List<String> portList = new ArrayList<>();
-                FlowCapableNode flowCapableNode = node.<FlowCapableNode>getAugmentation(FlowCapableNode.class);
+                FlowCapableNode flowCapableNode = node.<FlowCapableNode>augmentation(FlowCapableNode.class);
                 if (flowCapableNode != null) {
-                    name = node.<FlowCapableNode>getAugmentation(FlowCapableNode.class).getDescription();
+                    name = node.<FlowCapableNode>augmentation(FlowCapableNode.class).getDescription();
                 } else {
-                    LOG.error("Error while converting OFNode:{} to FlowCapableNode: {}", node.getId());
+                    LOG.error("Error while converting OFNode:{} to FlowCapableNode", node.getId());
                     return null;
                 }
                 nodeConnectors = node.getNodeConnector();
                 for (NodeConnector nodeConnector : nodeConnectors) {
                     FlowCapableNodeConnector flowCapableNodeConnector =
-                            nodeConnector.getAugmentation(FlowCapableNodeConnector.class);
+                            nodeConnector.augmentation(FlowCapableNodeConnector.class);
                     if (flowCapableNodeConnector == null) {
-                        LOG.error("Error for OFNode:{} while reading nodeConnectors {}", node.getId());
+                        LOG.error("Error for OFNode:{} while reading nodeConnectors", node.getId());
                         return null;
                     } else {
-                        MacAddress hardwareAddress = flowCapableNodeConnector.getHardwareAddress();
                         String portName = flowCapableNodeConnector.getName();
                         portList.add(portName);
                     }
                 }
                 ofNode = new OFNode(nodeId, name, portList);
             } else {
-                LOG.error("OFNode with nodeId {} not present Inventory DS: {}", nodeId);
+                LOG.error("OFNode with nodeId {} not present Inventory DS", nodeId);
                 return null;
             }
         } catch (ExecutionException | InterruptedException e) {
-            LOG.error("Error reading node {} from Inventory DS: {}", nodeId, e);
+            LOG.error("Error reading node {} from Inventory DS", nodeId, e);
         }
         return ofNode;
     }
+
+    public static List<ReconcileCounter> getReconcileCount(final DataBroker dataBroker) {
+        ReadOnlyTransaction tx = dataBroker.newReadOnlyTransaction();
+        InstanceIdentifier<ReconciliationCounter> instanceIdentifier = InstanceIdentifier
+                .builder(ReconciliationCounter.class).build();
+        List<ReconcileCounter> output = Collections.emptyList();
+        try {
+            Optional<ReconciliationCounter> result =
+                    tx.read(LogicalDatastoreType.OPERATIONAL, instanceIdentifier).get();
+            if (result.isPresent()) {
+                output = result.get().getReconcileCounter();
+            }
+        } catch (ExecutionException | InterruptedException | NullPointerException e) {
+            LOG.error("Error reading reconciliation counter from datastore", e);
+        }
+        return output;
+    }
 }