From 852462ad11284a22ca93e2c2ea96fd24eb3f0dd8 Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Sat, 7 Jun 2014 09:51:50 +0200 Subject: [PATCH] Topology manager: Pre-construct identifiers Another obvious optimization: we pre-construct identifiers for later use, so we do not end up performing "expensive" operations. Change-Id: I2f611dca6fb37363799dfbffc72588391008c041 Signed-off-by: Robert Varga --- .../manager/FlowCapableTopologyExporter.java | 36 +++++++------------ 1 file changed, 12 insertions(+), 24 deletions(-) diff --git a/opendaylight/md-sal/topology-manager/src/main/java/org/opendaylight/md/controller/topology/manager/FlowCapableTopologyExporter.java b/opendaylight/md-sal/topology-manager/src/main/java/org/opendaylight/md/controller/topology/manager/FlowCapableTopologyExporter.java index ae173a7117..cf53c9770e 100644 --- a/opendaylight/md-sal/topology-manager/src/main/java/org/opendaylight/md/controller/topology/manager/FlowCapableTopologyExporter.java +++ b/opendaylight/md-sal/topology-manager/src/main/java/org/opendaylight/md/controller/topology/manager/FlowCapableTopologyExporter.java @@ -60,6 +60,8 @@ import com.google.common.util.concurrent.JdkFutureAdapters; class FlowCapableTopologyExporter implements FlowTopologyDiscoveryListener, OpendaylightInventoryListener { protected final static Logger LOG = LoggerFactory.getLogger(FlowCapableTopologyExporter.class); public static final TopologyKey TOPOLOGY = new TopologyKey(new TopologyId("flow:1")); + private static final InstanceIdentifier TOPOLOGY_PATH = + InstanceIdentifier.builder(NetworkTopology.class).child(Topology.class, TOPOLOGY).build(); // FIXME: Flow capable topology exporter should use transaction chaining API private DataProviderService dataService; @@ -72,15 +74,10 @@ class FlowCapableTopologyExporter implements FlowTopologyDiscoveryListener, Open this.dataService = dataService; } - private InstanceIdentifier topologyPath; - public void start() { - TopologyBuilder tb = new TopologyBuilder(); - tb.setKey(TOPOLOGY); - topologyPath = InstanceIdentifier.builder(NetworkTopology.class).child(Topology.class, TOPOLOGY).build(); - Topology top = tb.build(); + TopologyBuilder tb = new TopologyBuilder().setKey(TOPOLOGY); DataModificationTransaction tx = dataService.beginTransaction(); - tx.putOperationalData(topologyPath, top); + tx.putOperationalData(TOPOLOGY_PATH, tb.build()); listenOnTransactionState(tx.getIdentifier(),tx.commit()); } @@ -182,10 +179,8 @@ class FlowCapableTopologyExporter implements FlowTopologyDiscoveryListener, Open private static InstanceIdentifier toNodeIdentifier(final NodeRef ref) { org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey invNodeKey = getNodeKey(ref); - NodeKey nodeKey = new NodeKey(toTopologyNodeId(invNodeKey.getId())); - return InstanceIdentifier.builder(NetworkTopology.class).child(Topology.class, TOPOLOGY) - .child(Node.class, nodeKey).build(); + return TOPOLOGY_PATH.child(Node.class, nodeKey); } private static InstanceIdentifier toTerminationPointIdentifier(final NodeConnectorRef ref) { @@ -197,49 +192,42 @@ class FlowCapableTopologyExporter implements FlowTopologyDiscoveryListener, Open private void removeAffectedLinks(final DataModificationTransaction transaction, final NodeId id) { TypeSafeDataReader reader = TypeSafeDataReader.forReader(transaction); - Topology topologyData = reader.readOperationalData(topologyPath); + Topology topologyData = reader.readOperationalData(TOPOLOGY_PATH); if (topologyData == null) { return; } for (Link link : topologyData.getLink()) { if (id.equals(link.getSource().getSourceNode()) || id.equals(link.getDestination().getDestNode())) { - InstanceIdentifier path = topologyPath.child(Link.class, link.getKey()); - transaction.removeOperationalData(path); + transaction.removeOperationalData(linkPath(link)); } } } private void removeAffectedLinks(final DataModificationTransaction transaction, final TpId id) { TypeSafeDataReader reader = TypeSafeDataReader.forReader(transaction); - Topology topologyData = reader.readOperationalData(topologyPath); + Topology topologyData = reader.readOperationalData(TOPOLOGY_PATH); if (topologyData == null) { return; } for (Link link : topologyData.getLink()) { if (id.equals(link.getSource().getSourceTp()) || id.equals(link.getDestination().getDestTp())) { - InstanceIdentifier path = topologyPath.child(Link.class, link.getKey()); - transaction.removeOperationalData(path); + transaction.removeOperationalData(linkPath(link)); } } } private static InstanceIdentifier getNodePath(final NodeId nodeId) { - NodeKey nodeKey = new NodeKey(nodeId); - return InstanceIdentifier.builder(NetworkTopology.class).child(Topology.class, TOPOLOGY) - .child(Node.class, nodeKey).build(); + return TOPOLOGY_PATH.child(Node.class, new NodeKey(nodeId)); } private static InstanceIdentifier tpPath(final NodeId nodeId, final TpId tpId) { NodeKey nodeKey = new NodeKey(nodeId); TerminationPointKey tpKey = new TerminationPointKey(tpId); - return InstanceIdentifier.builder(NetworkTopology.class).child(Topology.class, TOPOLOGY) - .child(Node.class, nodeKey).child(TerminationPoint.class, tpKey).build(); + return TOPOLOGY_PATH.child(Node.class, nodeKey).child(TerminationPoint.class, tpKey); } private static InstanceIdentifier linkPath(final Link link) { - InstanceIdentifier linkInstanceId = InstanceIdentifier.builder(NetworkTopology.class) - .child(Topology.class, TOPOLOGY).child(Link.class, link.getKey()).build(); - return linkInstanceId; + return TOPOLOGY_PATH.child(Link.class, link.getKey()); } /** -- 2.36.6