package org.opendaylight.openflowplugin.applications.southboundcli.util;
-import com.google.common.base.Optional;
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 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.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;
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 {
- 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;
+ 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());
}
- return Collections.emptyList();
+ Collections.sort(dpnList);
+ return dpnList;
}
public static OFNode getNode(final long nodeId, final DataBroker broker) {
public static OFNode getNodeInfo(final Long nodeId, final DataBroker broker) {
OFNode ofNode = null;
- ReadOnlyTransaction tx = broker.newReadOnlyTransaction();
InstanceIdentifier<Node> path = InstanceIdentifier.builder(Nodes.class)
.child(Node.class, new NodeKey(new NodeId(NODE_PREFIX + nodeId))).build();
- try {
+ 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;
+ String name;
+ Collection<NodeConnector> nodeConnectors = node.nonnullNodeConnector().values();
List<String> portList = new ArrayList<>();
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());
+ 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);
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 {
String portName = flowCapableNodeConnector.getName();
}
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();
+ public static Collection<ReconcileCounter> getReconcileCount(final DataBroker dataBroker) {
InstanceIdentifier<ReconciliationCounter> instanceIdentifier = InstanceIdentifier
.builder(ReconciliationCounter.class).build();
- List<ReconcileCounter> output = Collections.emptyList();
- try {
+ Collection<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();
+ output = result.get().nonnullReconcileCounter().values();
}
} catch (ExecutionException | InterruptedException | NullPointerException e) {
LOG.error("Error reading reconciliation counter from datastore", e);