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;
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<OFNode> getAllNodes(final NodeListener nodeListener) {
- List<OFNode> dpnList = new ArrayList<>();
- for (Map.Entry<Long, String> 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) {
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) {
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);
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;
}
}