Fix for Span Port added to a Switch should show port name or port id. 08/1208/1
authorlakshya <lakshya@cisco.com>
Mon, 16 Sep 2013 17:52:36 +0000 (10:52 -0700)
committerlakshya <lakshya@cisco.com>
Mon, 16 Sep 2013 20:37:19 +0000 (13:37 -0700)
Change-Id: I395d0d10b4e983212f12bc1ac1b35e1fd4fa785b
Signed-off-by: lakshya <lakshya@cisco.com>
opendaylight/web/devices/pom.xml
opendaylight/web/devices/src/main/java/org/opendaylight/controller/devices/web/Devices.java
opendaylight/web/devices/src/main/java/org/opendaylight/controller/devices/web/SpanPortJsonBean.java [new file with mode: 0644]
opendaylight/web/devices/src/main/resources/js/page.js

index b322f58..ac52095 100644 (file)
@@ -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,
index 4e08f99..6ca60e8 100644 (file)
@@ -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<List<SpanPortJsonBean>>() {}.getType();
+            List<SpanPortJsonBean> 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 (file)
index 0000000..b9be40b
--- /dev/null
@@ -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;
+    }
+
+}
index 813df23..2488d06 100644 (file)
@@ -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 += '<br/>' + $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"] = '<input type="checkbox" class="spanPortConfig" spanPort=' + encodeURIComponent(item["json"]) + '></input>';
+                            item["selector"] = '<input type="checkbox" class="spanPortConfig" spanPort=' + encodeURIComponent(item["json"]) + ' spanPortNode=' + item["nodeName"] + ' spanPortPort=' + item["spanPortName"] + '></input>';
                         });
                     },
                     delay: 0