- @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;
- }
- return Collections.emptyList();
- }
-