X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=applications%2Fsouthbound-cli%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fopenflowplugin%2Fapplications%2Fsouthboundcli%2Futil%2FShellUtil.java;h=d0be9bc924e5c37231412b2bdea27911426683b1;hb=HEAD;hp=4eb6735ec9cefda426016097e859210820857bb9;hpb=83ec4123ed23e20482f1f2753015c957fd4f39b4;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 4eb6735ec9..d0be9bc924 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,15 +9,13 @@ 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.Map; import java.util.Optional; import java.util.concurrent.ExecutionException; 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; @@ -34,22 +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() { } - 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()); - } - Collections.sort(dpnList); - return dpnList; - } - public static OFNode getNode(final long nodeId, final DataBroker broker) { OFNode nodeInfo = getNodeInfo(nodeId, broker); if (nodeInfo == null) { @@ -78,9 +66,9 @@ public final class ShellUtil { try (ReadTransaction tx = broker.newReadOnlyTransaction()) { Optional result = tx.read(LogicalDatastoreType.OPERATIONAL, path).get(); if (result.isPresent()) { - Node node = result.get(); - String name = null; - List nodeConnectors = null; + Node node = result.orElseThrow(); + String name; + Collection nodeConnectors = node.nonnullNodeConnector().values(); List portList = new ArrayList<>(); FlowCapableNode flowCapableNode = node.augmentation(FlowCapableNode.class); if (flowCapableNode != null) { @@ -89,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); @@ -112,19 +99,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(); try (ReadTransaction tx = dataBroker.newReadOnlyTransaction()) { - Optional 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; } }