Added Configurable parameter for the Connection Manager scheme and Container profile.
[controller.git] / opendaylight / web / devices / src / main / java / org / opendaylight / controller / devices / web / Devices.java
index 15ad9e9887d8eb2aba1250bc278a48f7441db00a..f6704775029d178233795e6afb075a4b1030892f 100644 (file)
@@ -11,6 +11,7 @@ package org.opendaylight.controller.devices.web;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.HashSet;
+import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
@@ -145,7 +146,6 @@ public class Devices implements IDaylightWeb {
                         State portState = ((State) switchManager
                                 .getNodeConnectorProp(nodeConnector,
                                         State.StatePropName));
-
                         String nodeConnectorName = (ncName != null) ? ncName
                                 .getValue() : "";
                         nodeConnectorName += " (" + nodeConnector.getID() + ")";
@@ -416,7 +416,22 @@ public class Devices implements IDaylightWeb {
                     Map<String, String> subnet = new HashMap<String, String>();
                     subnet.put("name", conf.getName());
                     subnet.put("subnet", conf.getSubnet());
-                    subnet.put("json", gson.toJson(conf));
+                    List<SubnetGatewayPortBean> portsList = new ArrayList<SubnetGatewayPortBean>();
+                    Iterator<NodeConnector> itor = conf.getSubnetNodeConnectors().iterator();
+                    while(itor.hasNext()) {
+                        SubnetGatewayPortBean bean = new SubnetGatewayPortBean();
+                        NodeConnector nodeConnector = itor.next();
+                        String nodeName = getNodeDesc(nodeConnector.getNode().toString(), containerName);
+                        Name ncName = ((Name) switchManager.getNodeConnectorProp(nodeConnector, Name.NamePropName));
+                        String nodeConnectorName = (ncName != null) ? ncName.getValue() : "";
+                        nodeConnectorName += " (" + nodeConnector.getID() + ")";
+                        bean.setNodeName(nodeName);
+                        bean.setNodePortName(nodeConnectorName);
+                        bean.setNodeId(nodeConnector.getNode().toString());
+                        bean.setNodePortId(nodeConnector.getID().toString());
+                        portsList.add(bean);
+                    }
+                    subnet.put("nodePorts", gson.toJson(portsList));
                     subnets.add(subnet);
                 }
             }
@@ -636,7 +651,7 @@ public class Devices implements IDaylightWeb {
 
     @RequestMapping(value = "/nodeports")
     @ResponseBody
-    public Map<String, Object> getNodePorts(HttpServletRequest request,
+    public List<NodeJsonBean> getNodePorts(HttpServletRequest request,
             @RequestParam(required = false) String container) {
         String containerName = (container == null) ? GlobalConstants.DEFAULT
                 .toString() : container;
@@ -647,18 +662,16 @@ public class Devices implements IDaylightWeb {
             return null;
         }
 
-
         ISwitchManager switchManager = (ISwitchManager) ServiceHelper
                 .getInstance(ISwitchManager.class, containerName, this);
         if (switchManager == null) {
             return null;
         }
-
-        Map<String, Object> nodes = new HashMap<String, Object>();
-        Map<Short, String> port;
+        List<NodeJsonBean> nodeJsonBeans = new ArrayList<NodeJsonBean>();
 
         for (Switch node : switchManager.getNetworkDevices()) {
-            port = new HashMap<Short, String>(); // new port
+            NodeJsonBean nodeJsonBean = new NodeJsonBean();
+            List<String> port = new ArrayList<String>();
             Set<NodeConnector> nodeConnectorSet = node.getNodeConnectors();
 
             if (nodeConnectorSet != null) {
@@ -666,15 +679,17 @@ public class Devices implements IDaylightWeb {
                     String nodeConnectorName = ((Name) switchManager
                             .getNodeConnectorProp(nodeConnector,
                                     Name.NamePropName)).getValue();
-                    port.put((Short) nodeConnector.getID(), nodeConnectorName
+                    port.add(nodeConnectorName
                             + "(" + nodeConnector.getID() + ")");
                 }
             }
-
-            nodes.put(node.getNode().toString(), port);
+            nodeJsonBean.setNodeId(node.getNode().toString());
+            nodeJsonBean.setNodeName(getNodeDesc(node.getNode().toString(), containerName));
+            nodeJsonBean.setNodePorts(port);
+            nodeJsonBeans.add(nodeJsonBean);
         }
 
-        return nodes;
+        return nodeJsonBeans;
     }
 
     @RequestMapping(value = "/spanPorts/add", method = RequestMethod.GET)