X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fswitchmanager%2Fimplementation%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fswitchmanager%2Finternal%2FSwitchManager.java;h=6bd89a806e3174b13c074038a2fecef86859bf97;hb=78be0f7d861ed290e9a57853080c98c019989780;hp=f50f303a3f6b07dd325bc4d488d86092499b61a8;hpb=c3e3c2ceaecea472a899d65f40826a65a9079003;p=controller.git diff --git a/opendaylight/switchmanager/implementation/src/main/java/org/opendaylight/controller/switchmanager/internal/SwitchManager.java b/opendaylight/switchmanager/implementation/src/main/java/org/opendaylight/controller/switchmanager/internal/SwitchManager.java index f50f303a3f..6bd89a806e 100644 --- a/opendaylight/switchmanager/implementation/src/main/java/org/opendaylight/controller/switchmanager/internal/SwitchManager.java +++ b/opendaylight/switchmanager/implementation/src/main/java/org/opendaylight/controller/switchmanager/internal/SwitchManager.java @@ -54,6 +54,7 @@ import org.opendaylight.controller.sal.core.Tier; import org.opendaylight.controller.sal.core.UpdateType; import org.opendaylight.controller.sal.inventory.IInventoryService; import org.opendaylight.controller.sal.inventory.IListenInventoryUpdates; +import org.opendaylight.controller.sal.reader.NodeDescription; import org.opendaylight.controller.sal.utils.GlobalConstants; import org.opendaylight.controller.sal.utils.HexEncode; import org.opendaylight.controller.sal.utils.IObjectReader; @@ -61,6 +62,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.statisticsmanager.IStatisticsManager; import org.opendaylight.controller.switchmanager.IInventoryListener; import org.opendaylight.controller.switchmanager.ISpanAware; import org.opendaylight.controller.switchmanager.ISwitchManager; @@ -92,7 +94,7 @@ CommandProvider { private static final String SAVE = "Save"; private String subnetFileName, spanFileName, switchConfigFileName; private final List spanNodeConnectors = new CopyOnWriteArrayList(); - // set of Subnets keyed by the InetAddress + // Collection of Subnets keyed by the InetAddress private ConcurrentMap subnets; private ConcurrentMap subnetsConfigList; private ConcurrentMap spanConfigList; @@ -104,6 +106,7 @@ CommandProvider { private ConcurrentMap> nodeConnectorNames; private ConcurrentMap controllerProps; private IInventoryService inventoryService; + private IStatisticsManager statisticsManager; private final Set switchManagerAware = Collections .synchronizedSet(new HashSet()); private final Set inventoryListeners = Collections @@ -401,19 +404,21 @@ CommandProvider { Set sp = conf.getSubnetNodeConnectors(); subnet.addNodeConnectors(sp); } - boolean result = false; + boolean putNewSubnet = false; if(subnetCurr == null) { if(subnets.putIfAbsent(conf.getIPnum(), subnet) == null) { - result = true; + putNewSubnet = true; } } else { - result = subnets.replace(conf.getIPnum(), subnetCurr, subnet); + putNewSubnet = subnets.replace(conf.getIPnum(), subnetCurr, subnet); } - if(!result) { + if(!putNewSubnet) { String msg = "Cluster conflict: Conflict while adding the subnet " + conf.getIPnum(); return new Status(StatusCode.CONFLICT, msg); } - } else { // This is the deletion of the whole subnet + + // Subnet removal case + } else { subnets.remove(conf.getIPnum()); } return new Status(StatusCode.SUCCESS); @@ -435,7 +440,7 @@ CommandProvider { return new Status(StatusCode.SUCCESS); } - private Status addRemoveSubnet(SubnetConfig conf, boolean add) { + private Status addRemoveSubnet(SubnetConfig conf, boolean isAdding) { // Valid config check if (!conf.isValidConfig()) { String msg = "Invalid Subnet configuration"; @@ -443,13 +448,13 @@ CommandProvider { return new Status(StatusCode.BADREQUEST, msg); } - if (add) { + if (isAdding) { // Presence check if (subnetsConfigList.containsKey(conf.getName())) { return new Status(StatusCode.CONFLICT, - "Same subnet config already exists"); + "Subnet with the specified name already configured."); } - // Semantyc check + // Semantic check Status rc = semanticCheck(conf); if (!rc.isSuccess()) { return rc; @@ -457,13 +462,13 @@ CommandProvider { } // Update Database - Status rc = updateDatabase(conf, add); + Status rc = updateDatabase(conf, isAdding); if (rc.isSuccess()) { // Update Configuration - rc = updateConfig(conf, add); + rc = updateConfig(conf, isAdding); if(!rc.isSuccess()) { - updateDatabase(conf, (!add)); + updateDatabase(conf, (!isAdding)); } } @@ -512,8 +517,8 @@ CommandProvider { Subnet sub = subCurr.clone(); Set sp = confCurr.getNodeConnectors(switchPorts); sub.addNodeConnectors(sp); - boolean subnetsReplace = subnets.replace(confCurr.getIPnum(), subCurr, sub); - if (!subnetsReplace) { + boolean subnetsReplaced = subnets.replace(confCurr.getIPnum(), subCurr, sub); + if (!subnetsReplaced) { String msg = "Cluster conflict: Conflict while adding ports to the subnet " + name; return new Status(StatusCode.CONFLICT, msg); } @@ -521,8 +526,8 @@ CommandProvider { // Update Configuration SubnetConfig conf = confCurr.clone(); conf.addNodeConnectors(switchPorts); - boolean result = subnetsConfigList.replace(name, confCurr, conf); - if (!result) { + boolean configReplaced = subnetsConfigList.replace(name, confCurr, conf); + if (!configReplaced) { // TODO: recovery using Transactionality String msg = "Cluster conflict: Conflict while adding ports to the subnet " + name; return new Status(StatusCode.CONFLICT, msg); @@ -696,18 +701,42 @@ CommandProvider { } Map updateProperties = switchConfig.getNodeProperties(); - String nodeId = switchConfig.getNodeId(); ForwardingMode mode = (ForwardingMode) updateProperties.get(ForwardingMode.name); if (mode != null) { if (isDefaultContainer) { if (!mode.isValid()) { - return new Status(StatusCode.BADREQUEST, "Invalid Forwarding Mode Value."); + return new Status(StatusCode.BADREQUEST, "Invalid Forwarding Mode Value"); } } else { return new Status(StatusCode.NOTACCEPTABLE, "Forwarding Mode modification is allowed only in default container"); } } + + Description description = (Description) switchConfig.getProperty(Description.propertyName); + String nodeId = switchConfig.getNodeId(); + Node node = Node.fromString(nodeId); + NodeDescription nodeDesc = (this.statisticsManager == null) ? null : this.statisticsManager + .getNodeDescription(node); + String advertisedDesc = (nodeDesc == null) ? "" : nodeDesc.getDescription(); + if (description != null && description.getValue() != null) { + if (description.getValue().isEmpty() || description.getValue().equals(advertisedDesc)) { + updateProperties.remove(Description.propertyName); + switchConfig = new SwitchConfig(nodeId, updateProperties); + } else { + // check if description is configured or was published by any other node + for (Node n : nodeProps.keySet()) { + Description desc = (Description) getNodeProp(n, Description.propertyName); + NodeDescription nDesc = (this.statisticsManager == null) ? null : this.statisticsManager + .getNodeDescription(n); + String advDesc = (nDesc == null) ? "" : nDesc.getDescription(); + if ((description.equals(desc) || description.getValue().equals(advDesc)) && !node.equals(n)) { + return new Status(StatusCode.CONFLICT, "Node name already in use"); + } + } + } + } + boolean modeChange = false; SwitchConfig sc = nodeConfigList.get(nodeId); Map prevNodeProperties = new HashMap(); @@ -741,30 +770,27 @@ CommandProvider { } } } - Node node = Node.fromString(nodeId); Map propMapCurr = nodeProps.get(node); if (propMapCurr == null) { return new Status(StatusCode.SUCCESS); } Map propMap = new HashMap(propMapCurr); - if (!prevNodeProperties.isEmpty()) { - for (String prop : prevNodeProperties.keySet()) { - if (!updateProperties.containsKey(prop)) { - if (prop.equals(Description.propertyName)) { - Map> nodeProp = this.inventoryService.getNodeProps(); - if (nodeProp.get(node) != null) { - propMap.put(Description.propertyName, nodeProp.get(node).get(Description.propertyName)); - continue; - } + for (String prop : prevNodeProperties.keySet()) { + if (!updateProperties.containsKey(prop)) { + if (prop.equals(Description.propertyName)) { + if (!advertisedDesc.isEmpty()) { + Property desc = new Description(advertisedDesc); + propMap.put(Description.propertyName, desc); } - propMap.remove(prop); + continue; } + propMap.remove(prop); } } propMap.putAll(updateProperties); if (!nodeProps.replace(node, propMapCurr, propMap)) { // TODO rollback using Transactionality - return new Status(StatusCode.CONFLICT, "Cluster conflict: Unable to update node configuration."); + return new Status(StatusCode.CONFLICT, "Cluster conflict: Unable to update node configuration"); } if (modeChange) { notifyModeChange(node, (mode == null) ? false : mode.isProactive()); @@ -885,7 +911,7 @@ CommandProvider { } @Override - public void entryUpdated(Long key, String new_value, String cacheName, + public void entryUpdated(Long key, String newValue, String cacheName, boolean originLocal) { saveSwitchConfigInternal(); } @@ -1444,9 +1470,13 @@ CommandProvider { } } map.remove(name.getValue()); - if (!nodeConnectorNames.replace(node, mapCurr, map)) { - log.warn("Cluster conflict: Unable remove Name property of nodeconnector {}, skip.", - nodeConnector.getID()); + if (map.isEmpty()) { + nodeConnectorNames.remove(node); + } else { + if (!nodeConnectorNames.replace(node, mapCurr, map)) { + log.warn("Cluster conflict: Unable remove Name property of nodeconnector {}, skip.", + nodeConnector.getID()); + } } } @@ -1530,6 +1560,16 @@ CommandProvider { clearInventories(); } + public void setStatisticsManager(IStatisticsManager statisticsManager) { + log.trace("Got statistics manager set request {}", statisticsManager); + this.statisticsManager = statisticsManager; + } + + public void unsetStatisticsManager(IStatisticsManager statisticsManager) { + log.trace("Got statistics manager UNset request"); + this.statisticsManager = null; + } + public void setSwitchManagerAware(ISwitchManagerAware service) { log.trace("Got inventory service set request {}", service); if (this.switchManagerAware != null) { @@ -2022,12 +2062,6 @@ CommandProvider { nodeProps.put(node, propMap); } - private void removeNodeProps(Node node) { - if (getUpNodeConnectors(node).size() == 0) { - nodeProps.remove(node); - } - } - @Override public Status saveConfiguration() { return saveSwitchConfig();