X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fswitchmanager%2Fimplementation%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fswitchmanager%2Finternal%2FSwitchManagerImpl.java;h=a91edb0c25a8f437f737f4e379f921463a3b385a;hp=c24c93c65ddaa738136c065713461fe62e659b4c;hb=18a0612ed336b6499956fb15e65da295cb4b899d;hpb=a21ad10dca48977b9c4ea885bc728563f920371b diff --git a/opendaylight/switchmanager/implementation/src/main/java/org/opendaylight/controller/switchmanager/internal/SwitchManagerImpl.java b/opendaylight/switchmanager/implementation/src/main/java/org/opendaylight/controller/switchmanager/internal/SwitchManagerImpl.java index c24c93c65d..a91edb0c25 100644 --- a/opendaylight/switchmanager/implementation/src/main/java/org/opendaylight/controller/switchmanager/internal/SwitchManagerImpl.java +++ b/opendaylight/switchmanager/implementation/src/main/java/org/opendaylight/controller/switchmanager/internal/SwitchManagerImpl.java @@ -42,6 +42,7 @@ import org.opendaylight.controller.sal.core.Bandwidth; import org.opendaylight.controller.sal.core.Config; import org.opendaylight.controller.sal.core.ConstructionException; import org.opendaylight.controller.sal.core.Description; +import org.opendaylight.controller.sal.core.ForwardingMode; import org.opendaylight.controller.sal.core.MacAddress; import org.opendaylight.controller.sal.core.Name; import org.opendaylight.controller.sal.core.Node; @@ -670,10 +671,7 @@ CommandProvider { if (propMapCurr == null) { return; } - Map propMap = new HashMap(); - for (String s : propMapCurr.keySet()) { - propMap.put(s, propMapCurr.get(s).clone()); - } + Map propMap = new HashMap(propMapCurr); Property desc = new Description(cfgObject.getNodeDescription()); propMap.put(desc.getName(), desc); Property tier = new Tier(Integer.parseInt(cfgObject.getTier())); @@ -691,6 +689,120 @@ CommandProvider { } } + @Override + public Status updateNodeConfig(SwitchConfig switchConfig) { + Status status = switchConfig.validate(); + if (!status.isSuccess()) { + return status; + } + + 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."); + } + } else { + return new Status(StatusCode.NOTACCEPTABLE, + "Forwarding Mode modification is allowed only in default container"); + } + } + boolean modeChange = false; + SwitchConfig sc = nodeConfigList.get(nodeId); + Map prevNodeProperties = new HashMap(); + if (sc == null) { + if ((mode != null) && mode.isProactive()) { + modeChange = true; + } + if (!updateProperties.isEmpty()) { + if (nodeConfigList.putIfAbsent(nodeId, switchConfig) != null) { + return new Status(StatusCode.CONFLICT, "Cluster conflict: Unable to update node configuration"); + } + } + } else { + prevNodeProperties = new HashMap(sc.getNodeProperties()); + ForwardingMode prevMode = (ForwardingMode) sc.getProperty(ForwardingMode.name); + if (mode == null) { + if ((prevMode != null) && (prevMode.isProactive())) { + modeChange = true; + } + } else { + if (((prevMode != null) && (prevMode.getValue() != mode.getValue())) + || (prevMode == null && mode.isProactive())) { + modeChange = true; + } + } + if (updateProperties.isEmpty()) { + nodeConfigList.remove(nodeId); + } else { + if (!nodeConfigList.replace(nodeId, sc, switchConfig)) { + return new Status(StatusCode.CONFLICT, "Cluster conflict: Unable to update node configuration"); + } + } + } + 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; + } + } + 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."); + } + if (modeChange) { + notifyModeChange(node, (mode == null) ? false : mode.isProactive()); + } + return new Status(StatusCode.SUCCESS); + } + + @Override + public Status removeNodeConfig(String nodeId) { + if ((nodeId == null) || (nodeId.isEmpty())) { + return new Status(StatusCode.BADREQUEST, "nodeId cannot be empty."); + } + Map nodeProperties = getSwitchConfig(nodeId).getNodeProperties(); + Node node = Node.fromString(nodeId); + Map propMapCurr = nodeProps.get(node); + if ((propMapCurr != null) && (nodeProperties != null) && (!nodeProperties.isEmpty())) { + Map propMap = new HashMap(propMapCurr); + for (String prop : nodeProperties.keySet()) { + 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; + } + } + propMap.remove(prop); + } + if (!nodeProps.replace(node, propMapCurr, propMap)) { + return new Status(StatusCode.CONFLICT, "Cluster conflict: Unable to update node configuration."); + } + } + if (nodeConfigList != null) { + nodeConfigList.remove(nodeId); + } + return new Status(StatusCode.SUCCESS); + } + @Override public Status saveSwitchConfig() { // Publish the save config event to the cluster nodes @@ -708,7 +820,6 @@ CommandProvider { spanConfigList), spanFileName); retS = objWriter.write(new ConcurrentHashMap( nodeConfigList), switchConfigFileName); - if (retS.equals(retP)) { if (retS.isSuccess()) { return retS; @@ -791,12 +902,8 @@ CommandProvider { } Map propMapCurr = nodeProps.get(node); - Map propMap = new HashMap(); - if (propMapCurr != null) { - for (String s : propMapCurr.keySet()) { - propMap.put(s, propMapCurr.get(s).clone()); - } - } + Map propMap = (propMapCurr == null) ? new HashMap() + : new HashMap(propMapCurr); // copy node properties from plugin if (props != null) { @@ -809,14 +916,13 @@ CommandProvider { boolean proactiveForwarding = false; if (nodeConfigList != null) { String nodeId = node.toString(); - for (SwitchConfig conf : nodeConfigList.values()) { - if (conf.getNodeId().equals(nodeId)) { - Property description = new Description(conf.getNodeDescription()); - propMap.put(description.getName(), description); - Property tier = new Tier(Integer.parseInt(conf.getTier())); - propMap.put(tier.getName(), tier); - proactiveForwarding = conf.isProactive(); - break; + SwitchConfig conf = nodeConfigList.get(nodeId); + if (conf != null && (conf.getNodeProperties() != null)) { + Map nodeProperties = conf.getNodeProperties(); + propMap.putAll(nodeProperties); + if (nodeProperties.get(ForwardingMode.name) != null) { + ForwardingMode mode = (ForwardingMode) nodeProperties.get(ForwardingMode.name); + proactiveForwarding = mode.isProactive(); } } } @@ -829,10 +935,8 @@ CommandProvider { } else { result = nodeProps.replace(node, propMapCurr, propMap); } - if (!result) { - log.debug( - "Cluster conflict: Conflict while adding the node properties. Node: {} Properties: {}", + log.debug("Cluster conflict: Conflict while adding the node properties. Node: {} Properties: {}", node.getID(), props); addNodeProps(node, propMap); } @@ -871,15 +975,19 @@ CommandProvider { } Map propMapCurr = nodeProps.get(node); - Map propMap = new HashMap(); - if (propMapCurr != null) { - for (String s : propMapCurr.keySet()) { - propMap.put(s, propMapCurr.get(s).clone()); - } - } + Map propMap = (propMapCurr == null) ? new HashMap() + : new HashMap(propMapCurr); // copy node properties from plugin + String nodeId = node.toString(); for (Property prop : props) { + if (nodeConfigList != null) { + SwitchConfig conf = nodeConfigList.get(nodeId); + if (conf != null && (conf.getNodeProperties() != null) + && conf.getNodeProperties().containsKey(prop.getName())) { + continue; + } + } propMap.put(prop.getName(), prop); } @@ -1003,11 +1111,7 @@ CommandProvider { return; } - Map propMap = new HashMap(); - for (String s : propMapCurr.keySet()) { - propMap.put(s, propMapCurr.get(s).clone()); - } - + Map propMap = new HashMap(propMapCurr); propMap.put(prop.getName(), prop); if (nodeProps.replace(node, propMapCurr, propMap)) { @@ -1029,11 +1133,7 @@ CommandProvider { if (!propMapCurr.containsKey(propName)) { return new Status(StatusCode.SUCCESS); } - Map propMap = new HashMap(); - for (String s : propMapCurr.keySet()) { - propMap.put(s, propMapCurr.get(s).clone()); - } - + Map propMap = new HashMap(propMapCurr); propMap.remove(propName); if (nodeProps.replace(node, propMapCurr, propMap)) { return new Status(StatusCode.SUCCESS); @@ -1196,13 +1296,8 @@ CommandProvider { public Status addNodeConnectorProp(NodeConnector nodeConnector, Property prop) { Map propMapCurr = getNodeConnectorProps(nodeConnector); - Map propMap = new HashMap(); - - if (propMapCurr != null) { - for (String s : propMapCurr.keySet()) { - propMap.put(s, propMapCurr.get(s).clone()); - } - } + Map propMap = (propMapCurr == null) ? new HashMap() + : new HashMap(propMapCurr); String msg = "Cluster conflict: Unable to add NodeConnector Property."; // Just add the nodeConnector if prop is not available (in a non-default @@ -1282,12 +1377,7 @@ CommandProvider { return new Status(StatusCode.SUCCESS); } - Map propMap = new HashMap(); - - for (String s : propMapCurr.keySet()) { - propMap.put(s, propMapCurr.get(s).clone()); - } - + Map propMap = new HashMap(propMapCurr); propMap.remove(propName); boolean result = nodeConnectorProps.replace(nodeConnector, propMapCurr, propMap); String msg = "Cluster conflict: Unable to remove NodeConnector property."; @@ -1559,7 +1649,8 @@ CommandProvider { for (Node node : getNodes()) { SwitchConfig sc = getSwitchConfig(node.toString()); if ((sc != null) && isDefaultContainer) { - service.modeChangeNotify(node, sc.isProactive()); + ForwardingMode mode = (ForwardingMode) sc.getProperty(ForwardingMode.name); + service.modeChangeNotify(node, (mode == null) ? false : mode.isProactive()); } } } @@ -1965,6 +2056,9 @@ CommandProvider { } else if (propName.equalsIgnoreCase(Bandwidth.BandwidthPropName)) { long bw = Long.parseLong(propValue); return new Bandwidth(bw); + } else if (propName.equalsIgnoreCase(ForwardingMode.name)) { + int mode = Integer.parseInt(propValue); + return new ForwardingMode(mode); } else { log.debug("Not able to create {} property", propName); }