From f42b00f090653cebe0cc969a98ae4377337f2a26 Mon Sep 17 00:00:00 2001 From: Gabriel Robitaille-Montpetit Date: Thu, 5 Nov 2015 18:35:10 -0500 Subject: [PATCH] Streamlined UnimgrMapper, cleaned up the code Change-Id: I5267fb1e9179f9fcaa1a41b384ea7a2a0f2fef4c Signed-off-by: Gabriel Robitaille-Montpetit --- .../unimgr/command/EvcCreateCommand.java | 10 +- .../unimgr/command/UniCreateCommand.java | 12 +- .../unimgr/impl/UnimgrDataChangeListener.java | 6 +- .../unimgr/impl/UnimgrMapper.java | 136 +++++++++++------- .../opendaylight/unimgr/impl/UnimgrUtils.java | 65 ++++++--- 5 files changed, 141 insertions(+), 88 deletions(-) diff --git a/impl/src/main/java/org/opendaylight/unimgr/command/EvcCreateCommand.java b/impl/src/main/java/org/opendaylight/unimgr/command/EvcCreateCommand.java index 8346220f..295f338f 100644 --- a/impl/src/main/java/org/opendaylight/unimgr/command/EvcCreateCommand.java +++ b/impl/src/main/java/org/opendaylight/unimgr/command/EvcCreateCommand.java @@ -30,7 +30,7 @@ public class EvcCreateCommand extends AbstractCreateCommand { private static final Logger LOG = LoggerFactory.getLogger(EvcCreateCommand.class); public EvcCreateCommand(DataBroker dataBroker, - Map, DataObject> changes) { + Map, DataObject> changes) { super.dataBroker = dataBroker; super.changes = changes; } @@ -58,10 +58,10 @@ public class EvcCreateCommand extends AbstractCreateCommand { if (evc.getUniSource().iterator().next().getUni() != null) { sourceUniIid = (InstanceIdentifier) evc.getUniSource().iterator().next().getUni(); } else { - sourceUniIid = UnimgrMapper.createUniIid(dataBroker, evc.getUniSource().iterator().next().getIpAddress()); + sourceUniIid = UnimgrMapper.getUniIid(dataBroker, evc.getUniSource().iterator().next().getIpAddress()); } if (evc.getUniDest().iterator().next().getUni() != null) { - destinationUniIid = UnimgrMapper.createUniIid(dataBroker, evc.getUniDest().iterator().next().getIpAddress());; + destinationUniIid = UnimgrMapper.getUniIid(dataBroker, evc.getUniDest().iterator().next().getIpAddress());; } else { destinationUniIid = (InstanceIdentifier) evc.getUniDest().iterator().next().getUni(); } @@ -85,13 +85,13 @@ public class EvcCreateCommand extends AbstractCreateCommand { } // Set source and destination InstanceIdentifier sourceBridgeIid = - UnimgrMapper.getOvsdbBridgeNodeIID(uniSource.getNodeId(), + UnimgrMapper.getOvsdbBridgeNodeIid(uniSource.getNodeId(), UnimgrConstants.DEFAULT_BRIDGE_NAME); Optional optionalSourceBr = UnimgrUtils.readNode(dataBroker, LogicalDatastoreType.CONFIGURATION, sourceBridgeIid); InstanceIdentifier destinationBridgeIid = - UnimgrMapper.getOvsdbBridgeNodeIID(uniSource.getNodeId(), + UnimgrMapper.getOvsdbBridgeNodeIid(uniSource.getNodeId(), UnimgrConstants.DEFAULT_BRIDGE_NAME); Optional optionalDestinationBr = UnimgrUtils.readNode(dataBroker, LogicalDatastoreType.CONFIGURATION, diff --git a/impl/src/main/java/org/opendaylight/unimgr/command/UniCreateCommand.java b/impl/src/main/java/org/opendaylight/unimgr/command/UniCreateCommand.java index 2dd4a544..b41975c7 100644 --- a/impl/src/main/java/org/opendaylight/unimgr/command/UniCreateCommand.java +++ b/impl/src/main/java/org/opendaylight/unimgr/command/UniCreateCommand.java @@ -81,7 +81,7 @@ public class UniCreateCommand extends AbstractCreateCommand { ovsdbNode = UnimgrUtils.createOvsdbNode(dataBroker, uni); LOG.info("Could not retrieve the OVSDB node," - + "created a new one: {}", ovsdbNode.getNodeId()); + + " created a new one: {}", ovsdbNode.getNodeId()); UnimgrUtils.updateUniNode(LogicalDatastoreType.CONFIGURATION, uniKey, uni, @@ -144,8 +144,9 @@ public class UniCreateCommand extends AbstractCreateCommand { ovsdbIid); if (optionalOvsdbNode.isPresent()) { InstanceIdentifier uniIid = - UnimgrMapper.createUniIid(dataBroker, - uniAugmentation.getIpAddress()); + UnimgrMapper.getUniIid(dataBroker, + uniAugmentation.getIpAddress(), + LogicalDatastoreType.CONFIGURATION); UnimgrUtils.createBridgeNode(dataBroker, ovsdbIid, uniAugmentation, @@ -161,8 +162,9 @@ public class UniCreateCommand extends AbstractCreateCommand { .getConnectionInfo() .getRemoteIp() .equals(uniAugmentation.getIpAddress())) { - InstanceIdentifier uniIid = UnimgrMapper.createUniIid(dataBroker, - uniAugmentation.getIpAddress()); + InstanceIdentifier uniIid = UnimgrMapper.getUniIid(dataBroker, + uniAugmentation.getIpAddress(), + LogicalDatastoreType.CONFIGURATION); UnimgrUtils.createBridgeNode(dataBroker, ovsdbIid, uniAugmentation, diff --git a/impl/src/main/java/org/opendaylight/unimgr/impl/UnimgrDataChangeListener.java b/impl/src/main/java/org/opendaylight/unimgr/impl/UnimgrDataChangeListener.java index 2bdc6afd..9441ed8f 100644 --- a/impl/src/main/java/org/opendaylight/unimgr/impl/UnimgrDataChangeListener.java +++ b/impl/src/main/java/org/opendaylight/unimgr/impl/UnimgrDataChangeListener.java @@ -45,15 +45,15 @@ public class UnimgrDataChangeListener implements IUnimgrDataChangeListener { this.invoker = invoker; listeners = new HashSet>(); listeners.add(dataBroker.registerDataChangeListener(LogicalDatastoreType.CONFIGURATION, - UnimgrMapper.createUniIid(), + UnimgrMapper.getUniTopologyIid(), this, DataChangeScope.SUBTREE)); listeners.add(dataBroker.registerDataChangeListener(LogicalDatastoreType.CONFIGURATION, - UnimgrMapper.createEvcIid(), + UnimgrMapper.getEvcTopologyIid(), this, DataChangeScope.SUBTREE)); listeners.add(dataBroker.registerDataChangeListener(LogicalDatastoreType.OPERATIONAL, - UnimgrMapper.getOvsdbTopologyIdentifier(), + UnimgrMapper.getOvsdbTopologyIid(), this, DataChangeScope.SUBTREE)); } diff --git a/impl/src/main/java/org/opendaylight/unimgr/impl/UnimgrMapper.java b/impl/src/main/java/org/opendaylight/unimgr/impl/UnimgrMapper.java index 5eeda0ff..5223f1ab 100755 --- a/impl/src/main/java/org/opendaylight/unimgr/impl/UnimgrMapper.java +++ b/impl/src/main/java/org/opendaylight/unimgr/impl/UnimgrMapper.java @@ -10,6 +10,7 @@ package org.opendaylight.unimgr.impl; import java.util.List; import org.opendaylight.controller.md.sal.binding.api.DataBroker; +import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.UniAugmentation; import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.LinkId; @@ -25,26 +26,42 @@ import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology. import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPoint; import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.node.TerminationPointKey; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; public class UnimgrMapper { - private static final Logger LOG = LoggerFactory.getLogger(UnimgrMapper.class); + public static InstanceIdentifier getEvcLinkIID(LinkId id) { + InstanceIdentifier linkPath = InstanceIdentifier + .create(NetworkTopology.class) + .child(Topology.class, + new TopologyKey(UnimgrConstants.EVC_TOPOLOGY_ID)) + .child(Link.class, + new LinkKey(id)); + return linkPath; + } + + public static InstanceIdentifier getEvcTopologyIid() { + InstanceIdentifier topoPath = InstanceIdentifier + .create(NetworkTopology.class) + .child(Topology.class, + new TopologyKey(UnimgrConstants.EVC_TOPOLOGY_ID)); + return topoPath; + } - public static InstanceIdentifier getOvsdbNodeIID(NodeId nodeId) { + public static InstanceIdentifier getEvcTopologyNodeIid() { InstanceIdentifier nodePath = InstanceIdentifier .create(NetworkTopology.class) .child(Topology.class, - new TopologyKey(UnimgrConstants.OVSDB_TOPOLOGY_ID)) - .child(Node.class, - new NodeKey(nodeId)); + new TopologyKey(UnimgrConstants.EVC_TOPOLOGY_ID)) + .child(Node.class); return nodePath; } - public static InstanceIdentifier getOvsdbBridgeNodeIID(NodeId ovsdbNode, + public static InstanceIdentifier getOvsdbBridgeNodeIid(NodeId ovsdbNode, String bridgeName) { - NodeId bridgeNodeId = new NodeId(ovsdbNode + UnimgrConstants.DEFAULT_BRIDGE_NODE_ID_SUFFIX + bridgeName); + String ovsdbNodeId = ovsdbNode.getValue(); + NodeId bridgeNodeId = new NodeId(ovsdbNodeId + + UnimgrConstants.DEFAULT_BRIDGE_NODE_ID_SUFFIX + + bridgeName); InstanceIdentifier nodePath = InstanceIdentifier .create(NetworkTopology.class) .child(Topology.class, @@ -54,11 +71,11 @@ public class UnimgrMapper { return nodePath; } - public static InstanceIdentifier getOvsdbNodeIID(IpAddress ipAddress) { + public static InstanceIdentifier getOvsdbNodeIid(IpAddress ipAddress) { String nodeId = UnimgrConstants.OVSDB_PREFIX - + ipAddress.getIpv4Address().getValue().toString() - + ":" - + UnimgrConstants.OVSDB_PORT; + + ipAddress.getIpv4Address().getValue().toString() + + ":" + + UnimgrConstants.OVSDB_PORT; InstanceIdentifier nodePath = InstanceIdentifier .create(NetworkTopology.class) .child(Topology.class, @@ -68,16 +85,25 @@ public class UnimgrMapper { return nodePath; } - public static InstanceIdentifier getOvsdbTopologyIdentifier() { - InstanceIdentifier path = InstanceIdentifier - .create(NetworkTopology.class) - .child(Topology.class, - new TopologyKey(UnimgrConstants.OVSDB_TOPOLOGY_ID)) - .child(Node.class); - return path; + public static InstanceIdentifier getOvsdbNodeIid(NodeId nodeId) { + InstanceIdentifier nodePath = InstanceIdentifier + .create(NetworkTopology.class) + .child(Topology.class, + new TopologyKey(UnimgrConstants.OVSDB_TOPOLOGY_ID)) + .child(Node.class, + new NodeKey(nodeId)); + return nodePath; + } + + public static InstanceIdentifier getOvsdbTopologyIid() { + InstanceIdentifier topoPath = InstanceIdentifier + .create(NetworkTopology.class) + .child(Topology.class, + new TopologyKey(UnimgrConstants.OVSDB_TOPOLOGY_ID)); + return topoPath; } - public static InstanceIdentifier createTerminationPointInstanceIdentifier( + public static InstanceIdentifier getTerminationPointIid( Node bridgeNode, String portName) { InstanceIdentifier terminationPointPath = @@ -85,25 +111,17 @@ public class UnimgrMapper { .create(NetworkTopology.class) .child(Topology.class, new TopologyKey(UnimgrConstants.OVSDB_TOPOLOGY_ID)) - .child(Node.class,bridgeNode.getKey()) + .child(Node.class, bridgeNode.getKey()) .child(TerminationPoint.class, new TerminationPointKey(new TpId(portName))); - - LOG.debug("Termination point InstanceIdentifier generated : {}",terminationPointPath); return terminationPointPath; } - public static InstanceIdentifier createUniIid() { - InstanceIdentifier iid = InstanceIdentifier.create(NetworkTopology.class) - .child(Topology.class, new TopologyKey(UnimgrConstants.UNI_TOPOLOGY_ID)) - .child(Node.class); - return iid; - } - - public static InstanceIdentifier createUniIid(DataBroker dataBroker, - IpAddress ip) { - List uniNodes = UnimgrUtils.getUniNodes(dataBroker); - for (Node node: uniNodes) { + public static InstanceIdentifier getUniIid(DataBroker dataBroker, + IpAddress ip) { + List uniNodes = UnimgrUtils.getUniNodes(dataBroker, + LogicalDatastoreType.OPERATIONAL); + for (Node node : uniNodes) { UniAugmentation uniAugmentation = node.getAugmentation(UniAugmentation.class); if (uniAugmentation.getIpAddress().equals(ip)) { InstanceIdentifier uniNode = InstanceIdentifier @@ -118,29 +136,41 @@ public class UnimgrMapper { return null; } - public static InstanceIdentifier createEvcIid() { - InstanceIdentifier iid = InstanceIdentifier - .create(NetworkTopology.class) - .child(Topology.class, - new TopologyKey(UnimgrConstants.EVC_TOPOLOGY_ID)) - .child(Node.class); - return iid; + public static InstanceIdentifier getUniIid(DataBroker dataBroker, + IpAddress ip, + LogicalDatastoreType store) { + List uniNodes = UnimgrUtils.getUniNodes(dataBroker, + store); + for (Node node : uniNodes) { + UniAugmentation uniAugmentation = node.getAugmentation(UniAugmentation.class); + if (uniAugmentation.getIpAddress().equals(ip)) { + InstanceIdentifier uniNode = InstanceIdentifier + .create(NetworkTopology.class) + .child(Topology.class, + new TopologyKey(UnimgrConstants.UNI_TOPOLOGY_ID)) + .child(Node.class, + new NodeKey(node.getKey())); + return uniNode; + } + } + return null; } - public static InstanceIdentifier createTopologyIid() { - InstanceIdentifier iid = InstanceIdentifier - .create(NetworkTopology.class) - .child(Topology.class, - new TopologyKey(UnimgrConstants.UNI_TOPOLOGY_ID)); - return iid; + public static InstanceIdentifier getUniTopologyIid() { + InstanceIdentifier topoPath = InstanceIdentifier + .create(NetworkTopology.class) + .child(Topology.class, + new TopologyKey(UnimgrConstants.UNI_TOPOLOGY_ID)); + return topoPath; } - public static InstanceIdentifier getEvcLinkIID(LinkId id) { - InstanceIdentifier linkPath = InstanceIdentifier + public static InstanceIdentifier getUniTopologyNodeIid() { + InstanceIdentifier nodePath = InstanceIdentifier .create(NetworkTopology.class) .child(Topology.class, - new TopologyKey(UnimgrConstants.EVC_TOPOLOGY_ID)) - .child(Link.class,new LinkKey(id)); - return linkPath; + new TopologyKey(UnimgrConstants.UNI_TOPOLOGY_ID)) + .child(Node.class); + return nodePath; } + } diff --git a/impl/src/main/java/org/opendaylight/unimgr/impl/UnimgrUtils.java b/impl/src/main/java/org/opendaylight/unimgr/impl/UnimgrUtils.java index c4b775f2..78f3efbb 100644 --- a/impl/src/main/java/org/opendaylight/unimgr/impl/UnimgrUtils.java +++ b/impl/src/main/java/org/opendaylight/unimgr/impl/UnimgrUtils.java @@ -48,7 +48,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.re import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.bridge.attributes.ProtocolEntryBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.ConnectionInfo; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.ConnectionInfoBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.ManagedNodeEntry; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.port._interface.attributes.Options; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.port._interface.attributes.OptionsBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.port._interface.attributes.OptionsKey; @@ -85,12 +84,12 @@ public class UnimgrUtils { String bridgeName) { LOG.info("Creating a bridge on node {}", ovsdbNodeId); InstanceIdentifier ovsdbNodeIid = UnimgrMapper - .getOvsdbNodeIID(uni.getIpAddress()); + .getOvsdbNodeIid(uni.getIpAddress()); ConnectionInfo connectionInfo = UnimgrUtils.getConnectionInfo(dataBroker, ovsdbNodeId); if (connectionInfo != null) { NodeBuilder bridgeNodeBuilder = new NodeBuilder(); InstanceIdentifier bridgeIid = UnimgrMapper - .getOvsdbBridgeNodeIID(ovsdbNodeId, bridgeName); + .getOvsdbBridgeNodeIid(ovsdbNodeId, bridgeName); NodeId bridgeNodeId = new NodeId(ovsdbNodeId + UnimgrConstants.DEFAULT_BRIDGE_NODE_ID_SUFFIX + bridgeName); @@ -122,7 +121,7 @@ public class UnimgrUtils { InstanceIdentifier ovsdbNodeIid = (InstanceIdentifier) uni.getOvsdbNodeRef().getValue(); if (ovsdbNodeIid != null) { NodeBuilder bridgeNodeBuilder = new NodeBuilder(); - InstanceIdentifier bridgeIid = UnimgrMapper.getOvsdbBridgeNodeIID(ovsdbNode.getNodeId(), + InstanceIdentifier bridgeIid = UnimgrMapper.getOvsdbBridgeNodeIid(ovsdbNode.getNodeId(), bridgeName); NodeId bridgeNodeId = new NodeId(ovsdbNode.getNodeId() + UnimgrConstants.DEFAULT_BRIDGE_NODE_ID_SUFFIX @@ -154,9 +153,9 @@ public class UnimgrUtils { ovsdbNodeIid); if (optionalOvsdbNode.isPresent()) { Node ovsdbNode = optionalOvsdbNode.get(); - InstanceIdentifier bridgeIid = UnimgrMapper.getOvsdbBridgeNodeIID(ovsdbNode.getNodeId(), + InstanceIdentifier bridgeIid = UnimgrMapper.getOvsdbBridgeNodeIid(ovsdbNode.getNodeId(), bridgeName); - NodeId bridgeNodeId = new NodeId(ovsdbNode.getNodeId() + NodeId bridgeNodeId = new NodeId(ovsdbNode.getNodeId().getValue() + UnimgrConstants.DEFAULT_BRIDGE_NODE_ID_SUFFIX + bridgeName); bridgeNodeBuilder.setNodeId(bridgeNodeId); @@ -193,8 +192,8 @@ public class UnimgrUtils { String bridgeName, String portName) { InstanceIdentifier tpIid = - UnimgrMapper.createTerminationPointInstanceIdentifier(bridgeNode, - portName); + UnimgrMapper.getTerminationPointIid(bridgeNode, + portName); OvsdbTerminationPointAugmentationBuilder tpAugmentationBuilder = new OvsdbTerminationPointAugmentationBuilder(); tpAugmentationBuilder.setName(portName); @@ -246,7 +245,7 @@ public class UnimgrUtils { public static void createOvsdbNode(DataBroker dataBroker, NodeId ovsdbNodeId, Uni uni) { - InstanceIdentifier ovsdbNodeIid = UnimgrMapper.getOvsdbNodeIID(uni.getIpAddress()); + InstanceIdentifier ovsdbNodeIid = UnimgrMapper.getOvsdbNodeIid(uni.getIpAddress()); try { NodeKey ovsdbNodeKey = new NodeKey(ovsdbNodeId); Node nodeData = new NodeBuilder() @@ -269,7 +268,7 @@ public class UnimgrUtils { UniAugmentation uni) { NodeId ovsdbNodeId = new NodeId(createOvsdbNodeId(uni.getIpAddress())); try { - InstanceIdentifier ovsdbNodeIid = UnimgrMapper.getOvsdbNodeIID(ovsdbNodeId); + InstanceIdentifier ovsdbNodeIid = UnimgrMapper.getOvsdbNodeIid(ovsdbNodeId); NodeKey ovsdbNodeKey = new NodeKey(ovsdbNodeId); Node nodeData = new NodeBuilder() .setNodeId(ovsdbNodeId) @@ -325,8 +324,8 @@ public class UnimgrUtils { String portName, String type) { InstanceIdentifier tpIid = UnimgrMapper - .createTerminationPointInstanceIdentifier(bridgeNode, - portName); + .getTerminationPointIid(bridgeNode, + portName); OvsdbTerminationPointAugmentationBuilder tpAugmentationBuilder = new OvsdbTerminationPointAugmentationBuilder(); tpAugmentationBuilder.setName(portName); if (type != null) { @@ -421,7 +420,7 @@ public class UnimgrUtils { public static ConnectionInfo getConnectionInfo(DataBroker dataBroker, NodeId ovsdbNodeId) { - InstanceIdentifier nodeIid = UnimgrMapper.getOvsdbNodeIID(ovsdbNodeId); + InstanceIdentifier nodeIid = UnimgrMapper.getOvsdbNodeIid(ovsdbNodeId); Optional node = readNode(dataBroker, LogicalDatastoreType.OPERATIONAL, nodeIid); @@ -439,11 +438,11 @@ public class UnimgrUtils { public static List getEvcLinks(DataBroker dataBroker, IpAddress ipAddress) { List evcLinks = new ArrayList<>(); - InstanceIdentifier topologyInstanceIdentifier = UnimgrMapper.createTopologyIid(); + InstanceIdentifier evcTopology = UnimgrMapper.getEvcTopologyIid(); Topology topology = UnimgrUtils.read(dataBroker, LogicalDatastoreType.OPERATIONAL, - topologyInstanceIdentifier); - if (topology != null && topology.getNode() != null) { + evcTopology); + if (topology != null && topology.getLink() != null) { for (Link link : topology.getLink()) { EvcAugmentation evcAugmentation = link.getAugmentation(EvcAugmentation.class); if (evcAugmentation != null) { @@ -469,10 +468,10 @@ public class UnimgrUtils { public static List getOvsdbNodes(DataBroker dataBroker) { List ovsdbNodes = new ArrayList<>(); - InstanceIdentifier topologyInstanceIdentifier = UnimgrMapper.createTopologyIid(); + InstanceIdentifier ovsdbTopoIdentifier = UnimgrMapper.getOvsdbTopologyIid(); Topology topology = UnimgrUtils.read(dataBroker, LogicalDatastoreType.OPERATIONAL, - topologyInstanceIdentifier); + ovsdbTopoIdentifier); if (topology != null && topology.getNode() != null) { for (Node node : topology.getNode()) { OvsdbNodeAugmentation ovsdbNodeAugmentation = node.getAugmentation(OvsdbNodeAugmentation.class); @@ -486,7 +485,7 @@ public class UnimgrUtils { public static List getUniNodes(DataBroker dataBroker) { List uniNodes = new ArrayList<>(); - InstanceIdentifier topologyInstanceIdentifier = UnimgrMapper.createTopologyIid(); + InstanceIdentifier topologyInstanceIdentifier = UnimgrMapper.getUniTopologyIid(); Topology topology = read(dataBroker, LogicalDatastoreType.CONFIGURATION, topologyInstanceIdentifier); @@ -501,6 +500,24 @@ public class UnimgrUtils { return uniNodes; } + public static List getUniNodes(DataBroker dataBroker, + LogicalDatastoreType store) { + List uniNodes = new ArrayList<>(); + InstanceIdentifier topologyInstanceIdentifier = UnimgrMapper.getUniTopologyIid(); + Topology topology = read(dataBroker, + store, + topologyInstanceIdentifier); + if (topology != null && topology.getNode() != null) { + for (Node node : topology.getNode()) { + UniAugmentation uniAugmentation = node.getAugmentation(UniAugmentation.class); + if (uniAugmentation != null) { + uniNodes.add(node); + } + } + } + return uniNodes; + } + public static D read( DataBroker dataBroker, final LogicalDatastoreType store, @@ -560,13 +577,15 @@ public class UnimgrUtils { UniAugmentation uni, Node ovsdbNode, DataBroker dataBroker) { - InstanceIdentifier ovsdbNodeIid = UnimgrMapper.getOvsdbNodeIID(ovsdbNode.getNodeId()); + InstanceIdentifier ovsdbNodeIid = UnimgrMapper.getOvsdbNodeIid(ovsdbNode.getNodeId()); OvsdbNodeRef ovsdbNodeRef = new OvsdbNodeRef(ovsdbNodeIid); UniAugmentationBuilder updatedUniBuilder = new UniAugmentationBuilder(uni); if (ovsdbNodeRef != null) { updatedUniBuilder.setOvsdbNodeRef(ovsdbNodeRef); } - Optional optionalNode = readNode(dataBroker, LogicalDatastoreType.CONFIGURATION, uniKey); + Optional optionalNode = readNode(dataBroker, + LogicalDatastoreType.CONFIGURATION, + uniKey); if (optionalNode.isPresent()) { Node node = optionalNode.get(); WriteTransaction transaction = dataBroker.newWriteOnlyTransaction(); @@ -589,7 +608,9 @@ public class UnimgrUtils { if (ovsdbNodeRef != null) { updatedUniBuilder.setOvsdbNodeRef(ovsdbNodeRef); } - Optional optionalNode = readNode(dataBroker, LogicalDatastoreType.CONFIGURATION, uniKey); + Optional optionalNode = readNode(dataBroker, + LogicalDatastoreType.CONFIGURATION, + uniKey); if (optionalNode.isPresent()) { Node node = optionalNode.get(); WriteTransaction transaction = dataBroker.newWriteOnlyTransaction(); -- 2.36.6