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=cc1a8b868d3d376c9eb4a66b5443707adbfbff31;hp=45a8a5880b70982d83748a3e3d2392dd3e93de1f;hb=6fd408a04fe4a3611843e2246ece6d7c34b76903;hpb=6145a414aa83be539b377c1952a3a33ed7031322 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 45a8a5880b..cc1a8b868d 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 @@ -36,7 +36,9 @@ import org.opendaylight.controller.clustering.services.CacheExistException; import org.opendaylight.controller.clustering.services.ICacheUpdateAware; import org.opendaylight.controller.clustering.services.IClusterContainerServices; import org.opendaylight.controller.clustering.services.IClusterServices; +import org.opendaylight.controller.configuration.ConfigurationObject; import org.opendaylight.controller.configuration.IConfigurationContainerAware; +import org.opendaylight.controller.configuration.IConfigurationContainerService; import org.opendaylight.controller.sal.core.Edge; import org.opendaylight.controller.sal.core.Host; import org.opendaylight.controller.sal.core.Node; @@ -47,11 +49,8 @@ import org.opendaylight.controller.sal.core.UpdateType; import org.opendaylight.controller.sal.topology.IListenTopoUpdates; 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; import org.opendaylight.controller.sal.utils.StatusCode; import org.opendaylight.controller.switchmanager.ISwitchManager; @@ -80,9 +79,11 @@ public class TopologyManagerImpl implements protected static final String TOPOHOSTSDB = "topologymanager.hostsDB"; protected static final String TOPONODECONNECTORDB = "topologymanager.nodeConnectorDB"; protected static final String TOPOUSERLINKSDB = "topologymanager.userLinksDB"; + private static final String USER_LINKS_FILE_NAME = "userTopology.conf"; private static final Logger log = LoggerFactory.getLogger(TopologyManagerImpl.class); private ITopologyService topoService; private IClusterContainerServices clusterContainerService; + private IConfigurationContainerService configurationService; private ISwitchManager switchManager; // DB of all the Edges with properties which constitute our topology private ConcurrentMap> edgesDB; @@ -97,8 +98,6 @@ public class TopologyManagerImpl implements // Topology Manager Aware listeners - for clusterwide updates private Set topologyManagerClusterWideAware = new CopyOnWriteArraySet(); - private static String ROOT = GlobalConstants.STARTUPHOME.toString(); - private String userLinksFileName; private ConcurrentMap userLinksDB; private BlockingQueue notifyQ = new LinkedBlockingQueue(); private volatile Boolean shuttingDown = false; @@ -164,6 +163,16 @@ public class TopologyManagerImpl implements } } + public void setConfigurationContainerService(IConfigurationContainerService service) { + log.trace("Got configuration service set request {}", service); + this.configurationService = service; + } + + public void unsetConfigurationContainerService(IConfigurationContainerService service) { + log.trace("Got configuration service UNset request"); + this.configurationService = null; + } + void setSwitchManager(ISwitchManager s) { log.debug("Adding ISwitchManager: {}", s); this.switchManager = s; @@ -193,11 +202,9 @@ public class TopologyManagerImpl implements containerName = "UNKNOWN"; } - userLinksFileName = ROOT + "userTopology_" + containerName + ".conf"; registerWithOSGIConsole(); - if ((clusterContainerService != null) && (clusterContainerService.amICoordinator())) { - loadConfiguration(); - } + loadConfiguration(); + // Restore the shuttingDown status on init of the component shuttingDown = false; notifyThread = new Thread(new TopologyNotify(notifyQ)); @@ -292,16 +299,9 @@ public class TopologyManagerImpl implements notifyThread = null; } - @SuppressWarnings("unchecked") private void loadConfiguration() { - ObjectReader objReader = new ObjectReader(); - ConcurrentMap confList = - (ConcurrentMap) objReader.read(this, userLinksFileName); - - if (confList != null) { - for (TopologyUserLinkConfig conf : confList.values()) { - addUserLink(conf); - } + for (ConfigurationObject conf : configurationService.retrieveConfiguration(this, USER_LINKS_FILE_NAME)) { + addUserLink((TopologyUserLinkConfig) conf); } } @@ -311,12 +311,10 @@ public class TopologyManagerImpl implements } public Status saveConfigInternal() { - ObjectWriter objWriter = new ObjectWriter(); + Status saveStatus = configurationService.persistConfiguration( + new ArrayList(userLinksDB.values()), USER_LINKS_FILE_NAME); - Status saveStatus = objWriter.write( - new ConcurrentHashMap(userLinksDB), userLinksFileName); - - if (! saveStatus.isSuccess()) { + if (!saveStatus.isSuccess()) { return new Status(StatusCode.INTERNALERROR, "Topology save failed: " + saveStatus.getDescription()); } return saveStatus; @@ -524,7 +522,7 @@ public class TopologyManagerImpl implements } @Override - public void updateHostLink(NodeConnector port, Host h, UpdateType t, Set props) { + public synchronized void updateHostLink(NodeConnector port, Host h, UpdateType t, Set props) { // Clone the property set in case non null else just // create an empty one. Caches allocated via infinispan @@ -574,36 +572,38 @@ public class TopologyManagerImpl implements 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 head node connector exists - if (!headNodeConnectorExist(e)) { - log.warn("Ignore edge that contains invalid node connector: {}", e); - return null; - } - - // Check if nodeConnectors of the edge were correctly categorized - // by OF plugin - crossCheckNodeConnectors(e); - // Make sure the props are non-null + // Make sure the props are non-null or create a copy if (props == null) { props = new HashSet(); } else { props = new HashSet(props); } - //in case of node switch-over to a different cluster controller, - //let's retain edge props Set currentProps = this.edgesDB.get(e); - if (currentProps != null){ + if (currentProps != null) { + + if (currentProps.equals(props)) { + // Avoid redundant updates as notifications trigger expensive tasks + log.trace("Skipping redundant edge addition: {}", e); + return null; + } + + // In case of node switch-over to a different cluster controller, + // let's retain edge props (e.g. creation time) props.addAll(currentProps); } + // Ensure that head node connector exists + if (!headNodeConnectorExist(e)) { + log.warn("Ignore edge that contains invalid node connector: {}", e); + return null; + } + + // Check if nodeConnectors of the edge were correctly categorized + // by protocol plugin + crossCheckNodeConnectors(e); + // Now make sure there is the creation timestamp for the // edge, if not there, stamp with the first update boolean found_create = false;