From: Giovanni Meo Date: Tue, 17 Sep 2013 07:53:43 +0000 (+0000) Subject: Merge "Reorder public/private modifiers as per JLS. (fixes sonar warnings)" X-Git-Tag: releasepom-0.1.0~84 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=commitdiff_plain;h=e383b2e0b9072b7b5b3e3903b8a42ab3917b7f63;hp=c2c3c27ad44909d5a6b8601a43c9ce381042277f Merge "Reorder public/private modifiers as per JLS. (fixes sonar warnings)" --- diff --git a/opendaylight/forwardingrulesmanager/implementation/src/main/java/org/opendaylight/controller/forwardingrulesmanager/internal/ForwardingRulesManager.java b/opendaylight/forwardingrulesmanager/implementation/src/main/java/org/opendaylight/controller/forwardingrulesmanager/internal/ForwardingRulesManager.java index d08b24d078..58d23655ca 100644 --- a/opendaylight/forwardingrulesmanager/implementation/src/main/java/org/opendaylight/controller/forwardingrulesmanager/internal/ForwardingRulesManager.java +++ b/opendaylight/forwardingrulesmanager/implementation/src/main/java/org/opendaylight/controller/forwardingrulesmanager/internal/ForwardingRulesManager.java @@ -2096,51 +2096,78 @@ public class ForwardingRulesManager implements addStaticFlowInternal(allowARP, true); // skip validation on internal static flow name } + /** + * (non-Javadoc) + * + * @see org.opendaylight.controller.switchmanager.ISwitchManagerAware#modeChangeNotify(org.opendaylight.controller.sal.core.Node, + * boolean) + * + * This method can be called from within the OSGi framework context, + * given the programming operation can take sometime, it not good + * pratice to have in it's context operations that can take time, + * hence moving off to a different thread for async processing. + */ @Override - public void modeChangeNotify(Node node, boolean proactive) { - List defaultConfigs = new ArrayList(); - - List puntAction = new ArrayList(); - puntAction.add(ActionType.CONTROLLER.toString()); - - FlowConfig allowARP = new FlowConfig(); - allowARP.setInstallInHw(true); - allowARP.setName(FlowConfig.INTERNALSTATICFLOWBEGIN + "Punt ARP" + FlowConfig.INTERNALSTATICFLOWEND); - allowARP.setPriority("1"); - allowARP.setNode(node); - allowARP.setEtherType("0x" + Integer.toHexString(EtherTypes.ARP.intValue()).toUpperCase()); - allowARP.setActions(puntAction); - defaultConfigs.add(allowARP); - - FlowConfig allowLLDP = new FlowConfig(); - allowLLDP.setInstallInHw(true); - allowLLDP.setName(FlowConfig.INTERNALSTATICFLOWBEGIN + "Punt LLDP" + FlowConfig.INTERNALSTATICFLOWEND); - allowLLDP.setPriority("1"); - allowLLDP.setNode(node); - allowLLDP.setEtherType("0x" + Integer.toHexString(EtherTypes.LLDP.intValue()).toUpperCase()); - allowLLDP.setActions(puntAction); - defaultConfigs.add(allowLLDP); - - List dropAction = new ArrayList(); - dropAction.add(ActionType.DROP.toString()); - - FlowConfig dropAllConfig = new FlowConfig(); - dropAllConfig.setInstallInHw(true); - dropAllConfig.setName(FlowConfig.INTERNALSTATICFLOWBEGIN + "Catch-All Drop" + FlowConfig.INTERNALSTATICFLOWEND); - dropAllConfig.setPriority("0"); - dropAllConfig.setNode(node); - dropAllConfig.setActions(dropAction); - defaultConfigs.add(dropAllConfig); - - log.info("Forwarding mode for node {} set to {}", node, (proactive ? "proactive" : "reactive")); - for (FlowConfig fc : defaultConfigs) { - Status status = (proactive) ? addStaticFlowInternal(fc, false) : removeStaticFlow(fc); - if (status.isSuccess()) { - log.info("{} Proactive Static flow: {}", (proactive ? "Installed" : "Removed"), fc.getName()); - } else { - log.warn("Failed to {} Proactive Static flow: {}", (proactive ? "install" : "remove"), fc.getName()); + public void modeChangeNotify(final Node node, final boolean proactive) { + Callable modeChangeCallable = new Callable() { + @Override + public Status call() throws Exception { + List defaultConfigs = new ArrayList(); + + List puntAction = new ArrayList(); + puntAction.add(ActionType.CONTROLLER.toString()); + + FlowConfig allowARP = new FlowConfig(); + allowARP.setInstallInHw(true); + allowARP.setName(FlowConfig.INTERNALSTATICFLOWBEGIN + "Punt ARP" + FlowConfig.INTERNALSTATICFLOWEND); + allowARP.setPriority("1"); + allowARP.setNode(node); + allowARP.setEtherType("0x" + Integer.toHexString(EtherTypes.ARP.intValue()) + .toUpperCase()); + allowARP.setActions(puntAction); + defaultConfigs.add(allowARP); + + FlowConfig allowLLDP = new FlowConfig(); + allowLLDP.setInstallInHw(true); + allowLLDP.setName(FlowConfig.INTERNALSTATICFLOWBEGIN + "Punt LLDP" + FlowConfig.INTERNALSTATICFLOWEND); + allowLLDP.setPriority("1"); + allowLLDP.setNode(node); + allowLLDP.setEtherType("0x" + Integer.toHexString(EtherTypes.LLDP.intValue()) + .toUpperCase()); + allowLLDP.setActions(puntAction); + defaultConfigs.add(allowLLDP); + + List dropAction = new ArrayList(); + dropAction.add(ActionType.DROP.toString()); + + FlowConfig dropAllConfig = new FlowConfig(); + dropAllConfig.setInstallInHw(true); + dropAllConfig.setName(FlowConfig.INTERNALSTATICFLOWBEGIN + "Catch-All Drop" + + FlowConfig.INTERNALSTATICFLOWEND); + dropAllConfig.setPriority("0"); + dropAllConfig.setNode(node); + dropAllConfig.setActions(dropAction); + defaultConfigs.add(dropAllConfig); + + log.info("Forwarding mode for node {} set to {}", node, (proactive ? "proactive" : "reactive")); + for (FlowConfig fc : defaultConfigs) { + Status status = (proactive) ? addStaticFlowInternal(fc, false) : removeStaticFlow(fc); + if (status.isSuccess()) { + log.info("{} Proactive Static flow: {}", (proactive ? "Installed" : "Removed"), fc.getName()); + } else { + log.warn("Failed to {} Proactive Static flow: {}", (proactive ? "install" : "remove"), + fc.getName()); + } + } + return new Status(StatusCode.SUCCESS); } - } + }; + + /* + * Execute the work outside the caller context, this could be an + * expensive operation and we don't want to block the caller for it. + */ + this.executor.submit(modeChangeCallable); } /** diff --git a/opendaylight/web/devices/pom.xml b/opendaylight/web/devices/pom.xml index b322f5845f..ac52095aea 100644 --- a/opendaylight/web/devices/pom.xml +++ b/opendaylight/web/devices/pom.xml @@ -40,6 +40,7 @@ org.opendaylight.controller.usermanager, org.opendaylight.controller.web, com.google.gson, + com.google.gson.reflect, javax.annotation, javax.naming, javax.servlet, diff --git a/opendaylight/web/devices/src/main/java/org/opendaylight/controller/devices/web/Devices.java b/opendaylight/web/devices/src/main/java/org/opendaylight/controller/devices/web/Devices.java index 4e08f99bfd..6ca60e857d 100644 --- a/opendaylight/web/devices/src/main/java/org/opendaylight/controller/devices/web/Devices.java +++ b/opendaylight/web/devices/src/main/java/org/opendaylight/controller/devices/web/Devices.java @@ -8,6 +8,7 @@ package org.opendaylight.controller.devices.web; +import java.lang.reflect.Type; import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; @@ -54,6 +55,7 @@ import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; import com.google.gson.Gson; +import com.google.gson.reflect.TypeToken; @Controller @RequestMapping("/") @@ -634,6 +636,11 @@ public class Devices implements IDaylightWeb { // Add switch portName value (non-configuration field) config.put("nodeName", getNodeDesc(config_data.get("nodeId"), containerName)); + NodeConnector spanPortNodeConnector = NodeConnector.fromString(config_data.get("spanPort")); + Name ncName = ((Name) switchManager.getNodeConnectorProp(spanPortNodeConnector, + Name.NamePropName)); + String spanPortName = (ncName != null) ? ncName.getValue() : ""; + config.put("spanPortName", spanPortName); } config.put("json", config_json); spanConfigs.add(config); @@ -746,22 +753,21 @@ public class Devices implements IDaylightWeb { Gson gson = new Gson(); ISwitchManager switchManager = (ISwitchManager) ServiceHelper .getInstance(ISwitchManager.class, containerName, this); - String[] spans = spanPortsToDelete.split("###"); - resultBean.setStatus(true); - resultBean.setMessage("SPAN Port(s) deleted successfully"); - for (String span : spans) { - if (!span.isEmpty()) { - SpanConfig cfgObject = gson - .fromJson(span, SpanConfig.class); - Status result = switchManager.removeSpanConfig(cfgObject); - if (!result.isSuccess()) { - resultBean.setStatus(false); - resultBean.setMessage(result.getDescription()); - break; - } - DaylightWebUtil.auditlog("SPAN Port", userName, "removed", cfgObject.getNodeId(), containerName); + Type collectionType = new TypeToken>() {}.getType(); + List jsonBeanList = gson.fromJson(spanPortsToDelete, collectionType); + for (SpanPortJsonBean jsonBean : jsonBeanList) { + SpanConfig cfgObject = gson + .fromJson(gson.toJson(jsonBean), SpanConfig.class); + Status result = switchManager.removeSpanConfig(cfgObject); + if (!result.isSuccess()) { + resultBean.setStatus(false); + resultBean.setMessage(result.getDescription()); + break; } + DaylightWebUtil.auditlog("SPAN Port", userName, "removed", cfgObject.getNodeId(), containerName); } + resultBean.setStatus(true); + resultBean.setMessage("SPAN Port(s) deleted successfully"); } catch (Exception e) { resultBean.setStatus(false); resultBean.setMessage("Error occurred while deleting span port. " diff --git a/opendaylight/web/devices/src/main/java/org/opendaylight/controller/devices/web/SpanPortJsonBean.java b/opendaylight/web/devices/src/main/java/org/opendaylight/controller/devices/web/SpanPortJsonBean.java new file mode 100644 index 0000000000..b9be40b3d3 --- /dev/null +++ b/opendaylight/web/devices/src/main/java/org/opendaylight/controller/devices/web/SpanPortJsonBean.java @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.controller.devices.web; + +public class SpanPortJsonBean { + + private String nodeId; + private String spanPort; + + public String getNodeId() { + return nodeId; + } + + public void setNodeId(String nodeId) { + this.nodeId = nodeId; + } + + public String getSpanPort() { + return spanPort; + } + + public void setSpanPort(String spanPort) { + this.spanPort = spanPort; + } + +} diff --git a/opendaylight/web/devices/src/main/resources/js/page.js b/opendaylight/web/devices/src/main/resources/js/page.js index 813df23f82..2488d06d0c 100644 --- a/opendaylight/web/devices/src/main/resources/js/page.js +++ b/opendaylight/web/devices/src/main/resources/js/page.js @@ -1239,7 +1239,12 @@ one.f.switchmanager.spanPortConfig = { return false; } checkedCheckBoxes.each(function(index, value) { - spanPortsToDelete.push(decodeURIComponent(checkedCheckBoxes[index].getAttribute("spanPort"))); + var spanPortObj = {}; + spanPortObj['spanPortJson'] = decodeURIComponent(checkedCheckBoxes[index].getAttribute("spanPort")); + spanPortObj['spanPortNodeName'] = checkedCheckBoxes[index].getAttribute("spanPortNode"); + spanPortObj['spanPortPortName'] = checkedCheckBoxes[index].getAttribute("spanPortPort"); + + spanPortsToDelete.push(spanPortObj); }); one.f.switchmanager.spanPortConfig.modal.removeMultiple.dialog(spanPortsToDelete); }); @@ -1392,12 +1397,12 @@ one.f.switchmanager.spanPortConfig = { // bind remove rule button $('#'+one.f.switchmanager.spanPortConfig.id.modal.remove, $modal).click(this, function(e) { var requestData = {}; - var spanPorts=""; - $(spanPortsToDelete).each(function(){ - spanPorts = spanPorts + "###" + this.toString(); + var spanPorts = []; + $(spanPortsToDelete).each(function(index, spanPort) { + spanPorts.push(JSON.parse(spanPort.spanPortJson)); }); - requestData["spanPortsToDelete"] = spanPorts.slice(3,spanPorts.length); - + requestData["spanPortsToDelete"] = JSON.stringify(spanPorts); + var url = one.f.switchmanager.rootUrl + "/spanPorts/delete"; one.f.switchmanager.spanPortConfig.ajax.main(url, requestData, function(response) { $modal.modal('hide'); @@ -1429,10 +1434,9 @@ one.f.switchmanager.spanPortConfig = { var p = 'Remove the following Span Port(s)?'; //creata a BS label for each rule and append to list - var spanPortList = JSON.parse("["+spanPortToDelete.toString()+"]"); - $(spanPortList).each(function(){ + $(spanPortToDelete).each(function(index, spanPortItem) { var $span = $(document.createElement('span')); - $span.append(this.nodeId+"-"+this.spanPort); + $span.append(this.spanPortNodeName+"-"+this.spanPortPortName); p += '
' + $span[0].outerHTML; }); $p.append(p); @@ -1457,7 +1461,7 @@ one.f.switchmanager.spanPortConfig = { sortable: true }, { - property: 'spanPort', + property: 'spanPortName', label: 'SPAN Port', sortable: true }, @@ -1465,7 +1469,7 @@ one.f.switchmanager.spanPortConfig = { data: data.nodeData, formatter: function(items) { $.each(items, function(index, item) { - item["selector"] = ''; + item["selector"] = ''; }); }, delay: 0 diff --git a/opendaylight/web/troubleshoot/src/main/resources/js/page.js b/opendaylight/web/troubleshoot/src/main/resources/js/page.js index 1eb2cf0094..bcf911f0a5 100644 --- a/opendaylight/web/troubleshoot/src/main/resources/js/page.js +++ b/opendaylight/web/troubleshoot/src/main/resources/js/page.js @@ -119,6 +119,9 @@ one.f.troubleshooting.existingNodes = { }, flows: function(nodeId) { try { + if(one.f.troubleshooting === undefined){ + return; + } clearTimeout(one.f.troubleshooting.existingNodes.registry.refreshTimer); $.getJSON(one.main.constants.address.prefix + "/troubleshoot/flowStats?nodeId=" + nodeId, function(content) { $rightBottomDashlet = one.f.troubleshooting.rightBottomDashlet.get(); @@ -150,6 +153,9 @@ one.f.troubleshooting.existingNodes = { }, ports: function(nodeId) { try { + if(one.f.troubleshooting === undefined){ + return; + } clearTimeout(one.f.troubleshooting.existingNodes.registry.refreshTimer); $.getJSON(one.main.constants.address.prefix + "/troubleshoot/portStats?nodeId=" + nodeId, function(content) { $rightBottomDashlet = one.f.troubleshooting.rightBottomDashlet.get();