X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;ds=sidebyside;f=applications%2Fsouthbound-cli%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fopenflowplugin%2Fapplications%2Fsouthboundcli%2Futil%2FShellUtil.java;h=d72029bf366bc574b8bb28a389d3617c10c6519b;hb=05f8db12159673d0e0a95642fe86e62c14b7dc7b;hp=fc43de58bdc7c2279d67b39e37f8b41ea2b47b81;hpb=b72e1b1c524657dab54e83e4c201e2fe680d18b1;p=openflowplugin.git diff --git a/applications/southbound-cli/src/main/java/org/opendaylight/openflowplugin/applications/southboundcli/util/ShellUtil.java b/applications/southbound-cli/src/main/java/org/opendaylight/openflowplugin/applications/southboundcli/util/ShellUtil.java index fc43de58bd..d72029bf36 100644 --- a/applications/southbound-cli/src/main/java/org/opendaylight/openflowplugin/applications/southboundcli/util/ShellUtil.java +++ b/applications/southbound-cli/src/main/java/org/opendaylight/openflowplugin/applications/southboundcli/util/ShellUtil.java @@ -9,14 +9,16 @@ package org.opendaylight.openflowplugin.applications.southboundcli.util; import java.util.ArrayList; +import java.util.Collection; import java.util.Collections; import java.util.List; +import java.util.Map; 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; +import org.opendaylight.openflowplugin.applications.southboundcli.NodeListener; 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; @@ -38,38 +40,15 @@ public final class ShellUtil { private ShellUtil() { } - @NonNull - public static List getAllNodes(final DataBroker broker) { - List nodes = null; - InstanceIdentifier path = InstanceIdentifier.builder(Nodes.class).build(); - try (ReadTransaction tx = broker.newReadOnlyTransaction()) { - Optional 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 nodeList = new ArrayList<>(); - for (Node node : nodes) { - String[] nodeId = node.getId().getValue().split(":"); - String name = null; - FlowCapableNode flowCapableNode = node.augmentation(FlowCapableNode.class); - if (flowCapableNode != null) { - name = node.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; + public static List getAllNodes(final NodeListener nodeListener) { + List dpnList = new ArrayList<>(); + for (Map.Entry entry : nodeListener.getDpnIdToNameCache().entrySet()) { + OFNode dpn = new OFNode(entry.getKey(), entry.getValue()); + dpnList.add(dpn); + LOG.trace("Added OFNode: {} to the list", dpn.getNodeId()); } - return Collections.emptyList(); + Collections.sort(dpnList); + return dpnList; } public static OFNode getNode(final long nodeId, final DataBroker broker) { @@ -101,8 +80,8 @@ public final class ShellUtil { Optional result = tx.read(LogicalDatastoreType.OPERATIONAL, path).get(); if (result.isPresent()) { Node node = result.get(); - String name = null; - List nodeConnectors = null; + String name; + Collection nodeConnectors = node.nonnullNodeConnector().values(); List portList = new ArrayList<>(); FlowCapableNode flowCapableNode = node.augmentation(FlowCapableNode.class); if (flowCapableNode != null) { @@ -111,7 +90,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,15 +112,15 @@ public final class ShellUtil { return ofNode; } - public static List getReconcileCount(final DataBroker dataBroker) { + public static Collection getReconcileCount(final DataBroker dataBroker) { InstanceIdentifier instanceIdentifier = InstanceIdentifier .builder(ReconciliationCounter.class).build(); - List output = Collections.emptyList(); + Collection output = Collections.emptyList(); try (ReadTransaction tx = dataBroker.newReadOnlyTransaction()) { Optional result = tx.read(LogicalDatastoreType.OPERATIONAL, instanceIdentifier).get(); if (result.isPresent()) { - output = result.get().getReconcileCounter(); + output = result.get().nonnullReconcileCounter().values(); } } catch (ExecutionException | InterruptedException | NullPointerException e) { LOG.error("Error reading reconciliation counter from datastore", e);