- Property desc = new Description(cfgObject.getNodeDescription());
- propMap.put(desc.getName(), desc);
- Property tier = new Tier(Integer.parseInt(cfgObject.getTier()));
- propMap.put(tier.getName(), tier);
- addNodeProps(node, propMap);
-
- log.info("Set Node {}'s Mode to {}", nodeId,
- cfgObject.getMode());
+ } else {
+ return new Status(StatusCode.NOTACCEPTABLE,
+ "Forwarding Mode modification is allowed only in default container");
+ }
+ }
+ boolean modeChange = false;
+ SwitchConfig sc = nodeConfigList.get(nodeId);
+ Map<String, Property> prevNodeProperties = new HashMap<String, Property>();
+ 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<String, Property>(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<String, Property> propMapCurr = nodeProps.get(node);
+ if (propMapCurr == null) {
+ return new Status(StatusCode.SUCCESS);
+ }
+ Map<String, Property> propMap = new HashMap<String, Property>(propMapCurr);
+ if (!prevNodeProperties.isEmpty()) {
+ for (String prop : prevNodeProperties.keySet()) {
+ if (!updateProperties.containsKey(prop)) {
+ if (prop.equals(Description.propertyName)) {
+ Map<Node, Map<String, Property>> 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);
+ }