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=45a8a5880b70982d83748a3e3d2392dd3e93de1f;hp=7452abbbb4af7952ae7b569b36d1498bb51f0dfe;hb=b29204146ca6957b5f968e07d9e7e2052ba70ef1;hpb=17e56497531f66554f6d533ef0f85ac7264f48fa 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 7452abbbb4..45a8a5880b 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 @@ -49,6 +49,7 @@ import org.opendaylight.controller.sal.topology.ITopologyService; import org.opendaylight.controller.sal.topology.TopoEdgeUpdate; import org.opendaylight.controller.sal.utils.GlobalConstants; import org.opendaylight.controller.sal.utils.IObjectReader; +import org.opendaylight.controller.sal.utils.NodeConnectorCreator; import org.opendaylight.controller.sal.utils.ObjectReader; import org.opendaylight.controller.sal.utils.ObjectWriter; import org.opendaylight.controller.sal.utils.Status; @@ -75,10 +76,10 @@ public class TopologyManagerImpl implements IListenTopoUpdates, IObjectReader, CommandProvider { - static final String TOPOEDGESDB = "topologymanager.edgesDB"; - static final String TOPOHOSTSDB = "topologymanager.hostsDB"; - static final String TOPONODECONNECTORDB = "topologymanager.nodeConnectorDB"; - static final String TOPOUSERLINKSDB = "topologymanager.userLinksDB"; + protected static final String TOPOEDGESDB = "topologymanager.edgesDB"; + protected static final String TOPOHOSTSDB = "topologymanager.hostsDB"; + protected static final String TOPONODECONNECTORDB = "topologymanager.nodeConnectorDB"; + protected static final String TOPOUSERLINKSDB = "topologymanager.userLinksDB"; private static final Logger log = LoggerFactory.getLogger(TopologyManagerImpl.class); private ITopologyService topoService; private IClusterContainerServices clusterContainerService; @@ -194,7 +195,9 @@ public class TopologyManagerImpl implements userLinksFileName = ROOT + "userTopology_" + containerName + ".conf"; registerWithOSGIConsole(); - loadConfiguration(); + if ((clusterContainerService != null) && (clusterContainerService.amICoordinator())) { + loadConfiguration(); + } // Restore the shuttingDown status on init of the component shuttingDown = false; notifyThread = new Thread(new TopologyNotify(notifyQ)); @@ -202,45 +205,30 @@ public class TopologyManagerImpl implements @SuppressWarnings({ "unchecked" }) private void allocateCaches() { - try { this.edgesDB = - (ConcurrentMap>) this.clusterContainerService.createCache(TOPOEDGESDB, - EnumSet.of(IClusterServices.cacheMode.TRANSACTIONAL)); - } catch (CacheExistException cee) { - log.debug(TOPOEDGESDB + " Cache already exists - destroy and recreate if needed"); - } catch (CacheConfigException cce) { - log.error(TOPOEDGESDB + " Cache configuration invalid - check cache mode"); - } + (ConcurrentMap>) allocateCache(TOPOEDGESDB,EnumSet.of(IClusterServices.cacheMode.TRANSACTIONAL)); - try { this.hostsDB = - (ConcurrentMap>>>) this.clusterContainerService.createCache( - TOPOHOSTSDB, EnumSet.of(IClusterServices.cacheMode.TRANSACTIONAL)); - } catch (CacheExistException cee) { - log.debug(TOPOHOSTSDB + " Cache already exists - destroy and recreate if needed"); - } catch (CacheConfigException cce) { - log.error(TOPOHOSTSDB + " Cache configuration invalid - check cache mode"); - } + (ConcurrentMap>>>) allocateCache(TOPOHOSTSDB, EnumSet.of(IClusterServices.cacheMode.TRANSACTIONAL)); - try { this.nodeConnectorsDB = - (ConcurrentMap>) this.clusterContainerService.createCache( + (ConcurrentMap>) allocateCache( TOPONODECONNECTORDB, EnumSet.of(IClusterServices.cacheMode.TRANSACTIONAL)); - } catch (CacheExistException cee) { - log.debug(TOPONODECONNECTORDB + " Cache already exists - destroy and recreate if needed"); - } catch (CacheConfigException cce) { - log.error(TOPONODECONNECTORDB + " Cache configuration invalid - check cache mode"); - } - - try { this.userLinksDB = - (ConcurrentMap) this.clusterContainerService.createCache( + (ConcurrentMap) allocateCache( TOPOUSERLINKSDB, EnumSet.of(IClusterServices.cacheMode.TRANSACTIONAL)); - } catch (CacheExistException cee) { - log.debug(TOPOUSERLINKSDB + " Cache already exists - destroy and recreate if needed"); - } catch (CacheConfigException cce) { - log.error(TOPOUSERLINKSDB + " Cache configuration invalid - check cache mode"); + } + + private ConcurrentMap allocateCache(String cacheName, Set cacheModes) { + ConcurrentMap cache = null; + try { + cache = this.clusterContainerService.createCache(cacheName, cacheModes); + } catch (CacheExistException e) { + log.debug(cacheName + " cache already exists - destroy and recreate if needed"); + } catch (CacheConfigException e) { + log.error(cacheName + " cache configuration invalid - check cache mode"); } + return cache; } @SuppressWarnings({ "unchecked" }) @@ -398,6 +386,56 @@ public class TopologyManagerImpl implements || e.getTailNodeConnector().getType().equals(NodeConnector.NodeConnectorIDType.PRODUCTION)); } + /** + * This method cross checks the determination of nodeConnector type by Discovery Service + * against the information in SwitchManager and updates it accordingly. + * @param e + * The edge + */ + private void crossCheckNodeConnectors(Edge e) { + NodeConnector nc; + if (e.getHeadNodeConnector().getType().equals(NodeConnector.NodeConnectorIDType.PRODUCTION)) { + nc = updateNCTypeFromSwitchMgr(e.getHeadNodeConnector()); + if (nc != null) { + e.setHeadNodeConnector(nc); + } + } + if (e.getTailNodeConnector().getType().equals(NodeConnector.NodeConnectorIDType.PRODUCTION)) { + nc = updateNCTypeFromSwitchMgr(e.getTailNodeConnector()); + if (nc != null) { + e.setTailNodeConnector(nc); + } + } + } + + /** + * A NodeConnector may have been categorized as of type Production by Discovery Service. + * But at the time when this determination was made, only OF nodes were known to Discovery + * Service. This method checks if the node of nodeConnector is known to SwitchManager. If + * so, then it returns a new NodeConnector with correct type. + * + * @param nc + * NodeConnector as passed on in the edge + * @return + * If Node of the NodeConnector is in SwitchManager, then return a new NodeConnector + * with correct type, null otherwise + */ + + private NodeConnector updateNCTypeFromSwitchMgr(NodeConnector nc) { + + for (Node node : switchManager.getNodes()) { + String nodeName = node.getNodeIDString(); + log.trace("Switch Manager Node Name: {}, NodeConnector Node Name: {}", nodeName, + nc.getNode().getNodeIDString()); + if (nodeName.equals(nc.getNode().getNodeIDString())) { + NodeConnector nodeConnector = NodeConnectorCreator + .createNodeConnector(node.getType(), nc.getID(), node); + return nodeConnector; + } + } + return null; + } + /** * The Map returned is a copy of the current topology hence if the topology * changes the copy doesn't @@ -548,6 +586,10 @@ public class TopologyManagerImpl implements return null; } + // Check if nodeConnectors of the edge were correctly categorized + // by OF plugin + crossCheckNodeConnectors(e); + // Make sure the props are non-null if (props == null) { props = new HashSet();