X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Ftopologymanager%2Fimplementation%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Ftopologymanager%2Finternal%2FTopologyManagerImpl.java;h=526ba41c354c3166db9ba26f18e55b1483c1ab36;hp=5ecddcfc88bd501e65164303e946a29ef36ec46e;hb=b14a280bf25b8fc7e0d8d04bd1c43c49987a583b;hpb=6b64494fd8e4654a298312afb4b8e6e827b75d5d diff --git a/opendaylight/topologymanager/implementation/src/main/java/org/opendaylight/controller/topologymanager/internal/TopologyManagerImpl.java b/opendaylight/topologymanager/implementation/src/main/java/org/opendaylight/controller/topologymanager/internal/TopologyManagerImpl.java index 5ecddcfc88..526ba41c35 100644 --- a/opendaylight/topologymanager/implementation/src/main/java/org/opendaylight/controller/topologymanager/internal/TopologyManagerImpl.java +++ b/opendaylight/topologymanager/implementation/src/main/java/org/opendaylight/controller/topologymanager/internal/TopologyManagerImpl.java @@ -53,6 +53,7 @@ import org.opendaylight.controller.sal.utils.ObjectReader; import org.opendaylight.controller.sal.utils.ObjectWriter; import org.opendaylight.controller.sal.utils.Status; import org.opendaylight.controller.sal.utils.StatusCode; +import org.opendaylight.controller.switchmanager.ISwitchManager; import org.opendaylight.controller.topologymanager.ITopologyManager; import org.opendaylight.controller.topologymanager.ITopologyManagerAware; import org.opendaylight.controller.topologymanager.ITopologyManagerClusterWideAware; @@ -68,7 +69,7 @@ import org.slf4j.LoggerFactory; * topology database and notifies all the listeners of topology changes. */ public class TopologyManagerImpl implements - ICacheUpdateAware, + ICacheUpdateAware, ITopologyManager, IConfigurationContainerAware, IListenTopoUpdates, @@ -81,6 +82,7 @@ public class TopologyManagerImpl implements private static final Logger log = LoggerFactory.getLogger(TopologyManagerImpl.class); private ITopologyService topoService; private IClusterContainerServices clusterContainerService; + private ISwitchManager switchManager; // DB of all the Edges with properties which constitute our topology private ConcurrentMap> edgesDB; // DB of all NodeConnector which are part of ISL Edges, meaning they @@ -161,6 +163,18 @@ public class TopologyManagerImpl implements } } + void setSwitchManager(ISwitchManager s) { + log.debug("Adding ISwitchManager: {}", s); + this.switchManager = s; + } + + void unsetSwitchManager(ISwitchManager s) { + if (this.switchManager == s) { + log.debug("Removing ISwitchManager: {}", s); + this.switchManager = null; + } + } + /** * Function called by the dependency manager when all the required * dependencies are satisfied @@ -186,7 +200,7 @@ public class TopologyManagerImpl implements notifyThread = new Thread(new TopologyNotify(notifyQ)); } - @SuppressWarnings({ "unchecked", "deprecation" }) + @SuppressWarnings({ "unchecked" }) private void allocateCaches() { try { this.edgesDB = @@ -229,7 +243,7 @@ public class TopologyManagerImpl implements } } - @SuppressWarnings({ "unchecked", "deprecation" }) + @SuppressWarnings({ "unchecked" }) private void retrieveCaches() { if (this.clusterContainerService == null) { log.error("Cluster Services is null, can't retrieve caches."); @@ -507,9 +521,27 @@ public class TopologyManagerImpl implements } } + private boolean nodeConnectorsExist(Edge e) { + NodeConnector head = e.getHeadNodeConnector(); + NodeConnector tail = e.getTailNodeConnector(); + return (switchManager.doesNodeConnectorExist(head) && + switchManager.doesNodeConnectorExist(tail)); + } + private TopoEdgeUpdate edgeUpdate(Edge e, UpdateType type, Set props) { switch (type) { case ADDED: + // Avoid redundant update as notifications trigger expensive tasks + if (edgesDB.containsKey(e)) { + log.trace("Skipping redundant edge addition: {}", e); + return null; + } + // Ensure that both tail and head node connectors exist. + if (!nodeConnectorsExist(e)) { + log.warn("Ignore edge that contains invalid node connector: {}", e); + return null; + } + // Make sure the props are non-null if (props == null) { props = new HashSet(); @@ -631,18 +663,21 @@ public class TopologyManagerImpl implements Set p = topoedgeupdateList.get(i).getProperty(); UpdateType type = topoedgeupdateList.get(i).getUpdateType(); TopoEdgeUpdate teu = edgeUpdate(e, type, p); - teuList.add(teu); + if (teu != null) { + teuList.add(teu); + } } - // Now update the listeners - for (ITopologyManagerAware s : this.topologyManagerAware) { - try { - s.edgeUpdate(teuList); - } catch (Exception exc) { - log.error("Exception on edge update:", exc); + if (!teuList.isEmpty()) { + // Now update the listeners + for (ITopologyManagerAware s : this.topologyManagerAware) { + try { + s.edgeUpdate(teuList); + } catch (Exception exc) { + log.error("Exception on edge update:", exc); + } } } - } private Edge getReverseLinkTuple(TopologyUserLinkConfig link) { @@ -692,7 +727,14 @@ public class TopologyManagerImpl implements Edge linkTuple = getLinkTuple(userLink); if (linkTuple != null) { if (!isProductionLink(linkTuple)) { - edgeUpdate(linkTuple, UpdateType.ADDED, new HashSet()); + TopoEdgeUpdate teu = edgeUpdate(linkTuple, UpdateType.ADDED, + new HashSet()); + if (teu == null) { + userLinksDB.remove(userLink.getName()); + return new Status(StatusCode.NOTFOUND, + "Link configuration contains invalid node connector: " + + userLink); + } } linkTuple = getReverseLinkTuple(userLink); @@ -859,7 +901,7 @@ public class TopologyManagerImpl implements public void entryUpdated(final Object key, final Object new_value, final String cacheName, final boolean originLocal) { if (cacheName.equals(TOPOEDGESDB)) { final Edge e = (Edge) key; - log.trace("Edge {} CHANGED isLocal:{}", e, originLocal); + log.trace("Edge {} UPDATED isLocal:{}", e, originLocal); final Set props = (Set) new_value; edgeUpdateClusterWide(e, UpdateType.CHANGED, props, originLocal); }