Merge "Replaced Equals/HashcodeBuilder for DatapacketListener"
[controller.git] / opendaylight / web / devices / src / main / java / org / opendaylight / controller / devices / web / Devices.java
index 1102a6382e649aa9389528ce5b6d438e5fc2ba8b..188be8aee6f1ee4865b159d1f2225ec6f1534021 100644 (file)
@@ -36,7 +36,6 @@ import org.opendaylight.controller.sal.core.Name;
 import org.opendaylight.controller.sal.core.Node;
 import org.opendaylight.controller.sal.core.NodeConnector;
 import org.opendaylight.controller.sal.core.Tier;
-import org.opendaylight.controller.sal.utils.GlobalConstants;
 import org.opendaylight.controller.sal.utils.HexEncode;
 import org.opendaylight.controller.sal.utils.ServiceHelper;
 import org.opendaylight.controller.sal.utils.Status;
@@ -89,66 +88,90 @@ public class Devices implements IDaylightWeb {
         ISwitchManager switchManager = (ISwitchManager) ServiceHelper
                 .getInstance(ISwitchManager.class, containerName, this);
         List<Map<String, String>> nodeData = new ArrayList<Map<String, String>>();
-        for (Switch device : switchManager.getNetworkDevices()) {
-            HashMap<String, String> nodeDatum = new HashMap<String, String>();
-            Node node = device.getNode();
-            Tier tier = (Tier) switchManager.getNodeProp(node,
-                    Tier.TierPropName);
-
-            nodeDatum.put("containerName", containerName);
-            nodeDatum.put("nodeName", switchManager.getNodeDescription(node));
-            nodeDatum.put("nodeId", node.toString());
-            int tierNumber = (tier == null) ? TierHelper.unknownTierNumber
-                    : tier.getValue();
-            nodeDatum.put("tierName", TierHelper.getTierName(tierNumber)
-                    + " (Tier-" + tierNumber + ")");
-            nodeDatum.put("tier", tierNumber + "");
-            SwitchConfig sc = switchManager.getSwitchConfig(device.getNode()
-                    .toString());
-            String modeStr = (sc != null) ? sc.getMode() : "0";
-            nodeDatum.put("mode", modeStr);
-
-            nodeDatum.put("json", gson.toJson(nodeDatum));
-            nodeDatum.put("mac",
-                    HexEncode.bytesToHexString(device.getDataLayerAddress()));
-            StringBuffer sb1 = new StringBuffer();
-            Set<NodeConnector> nodeConnectorSet = device.getNodeConnectors();
-            if (nodeConnectorSet != null && nodeConnectorSet.size() > 0) {
-                Map<Short, String> portList = new HashMap<Short, String>();
-                for (NodeConnector nodeConnector : nodeConnectorSet) {
-                    String nodeConnectorNumberToStr = nodeConnector.getID().toString();
-                    Name ncName = ((Name) switchManager.getNodeConnectorProp(
-                            nodeConnector, Name.NamePropName));
-                    Config portStatus = ((Config) switchManager
-                            .getNodeConnectorProp(nodeConnector,
-                                    Config.ConfigPropName));
-                    
-                    String nodeConnectorName = (ncName != null) ? ncName.getValue()
-                            : "";
-                    nodeConnectorName += " ("+nodeConnector.getID()+")";
-                    
-                    if (portStatus != null) {
-                        if (portStatus.getValue() == Config.ADMIN_UP) {
-                            nodeConnectorName = "<span style='color:green;'>"+nodeConnectorName+"</span>";
-                        } else if (portStatus.getValue() == Config.ADMIN_DOWN) {
-                            nodeConnectorName = "<span style='color:red;'>"+nodeConnectorName+"</span>";
+        if (switchManager != null) {
+            for (Switch device : switchManager.getNetworkDevices()) {
+                HashMap<String, String> nodeDatum = new HashMap<String, String>();
+                Node node = device.getNode();
+                Tier tier = (Tier) switchManager.getNodeProp(node,
+                        Tier.TierPropName);
+
+                nodeDatum.put("containerName", containerName);
+                nodeDatum.put("nodeName",
+                        switchManager.getNodeDescription(node));
+                nodeDatum.put("nodeId", node.toString());
+                int tierNumber = (tier == null) ? TierHelper.unknownTierNumber
+                        : tier.getValue();
+                nodeDatum.put("tierName", TierHelper.getTierName(tierNumber)
+                        + " (Tier-" + tierNumber + ")");
+                nodeDatum.put("tier", tierNumber + "");
+                SwitchConfig sc = switchManager.getSwitchConfig(device
+                        .getNode().toString());
+                String modeStr = (sc != null) ? sc.getMode() : "0";
+                nodeDatum.put("mode", modeStr);
+
+                nodeDatum.put("json", gson.toJson(nodeDatum));
+                nodeDatum.put("mac", HexEncode.bytesToHexString(device
+                        .getDataLayerAddress()));
+                StringBuffer sb1 = new StringBuffer();
+                Set<NodeConnector> nodeConnectorSet = device
+                        .getNodeConnectors();
+                if (nodeConnectorSet != null && nodeConnectorSet.size() > 0) {
+                    Map<Short, String> portList = new HashMap<Short, String>();
+                    List<String> intfList = new ArrayList<String>();
+                    for (NodeConnector nodeConnector : nodeConnectorSet) {
+                        String nodeConnectorNumberToStr = nodeConnector.getID()
+                                .toString();
+                        Name ncName = ((Name) switchManager
+                                .getNodeConnectorProp(nodeConnector,
+                                        Name.NamePropName));
+                        Config portStatus = ((Config) switchManager
+                                .getNodeConnectorProp(nodeConnector,
+                                        Config.ConfigPropName));
+
+                        String nodeConnectorName = (ncName != null) ? ncName
+                                .getValue() : "";
+                        nodeConnectorName += " (" + nodeConnector.getID() + ")";
+
+                        if (portStatus != null) {
+                            if (portStatus.getValue() == Config.ADMIN_UP) {
+                                nodeConnectorName = "<span style='color:green;'>"
+                                        + nodeConnectorName + "</span>";
+                            } else if (portStatus.getValue() == Config.ADMIN_DOWN) {
+                                nodeConnectorName = "<span style='color:red;'>"
+                                        + nodeConnectorName + "</span>";
+                            }
+                        }
+
+                        Class<?> idClass = nodeConnector.getID().getClass();
+                        if (idClass.equals(Short.class)) {
+                            portList.put(
+                                    Short.parseShort(nodeConnectorNumberToStr),
+                                    nodeConnectorName);
+                        } else {
+                            intfList.add(nodeConnectorName);
                         }
                     }
-                    
-                    portList.put(Short.parseShort(nodeConnectorNumberToStr),
-                            nodeConnectorName);
-                }
 
-                Map<Short, String> sortedPortList = new TreeMap<Short, String>(portList);
+                    if (portList.size() > 0) {
+                        Map<Short, String> sortedPortList = new TreeMap<Short, String>(
+                                portList);
 
-                for (Entry<Short, String> e : sortedPortList.entrySet()) {
-                    sb1.append(e.getValue());
-                    sb1.append("<br>");
+                        for (Entry<Short, String> e : sortedPortList.entrySet()) {
+                            sb1.append(e.getValue());
+                            sb1.append("<br>");
+                        }
+                    } else if (intfList.size() > 0) {
+                        for (String intf : intfList) {
+                            sb1.append(intf);
+                            sb1.append("<br>");
+                        }
+                    }
                 }
+                nodeDatum.put("ports", sb1.toString());
+                nodeData.add(nodeDatum);
             }
-            nodeDatum.put("ports", sb1.toString());
-            nodeData.add(nodeDatum);
         }
+
         DevicesJsonBean result = new DevicesJsonBean();
         result.setNodeData(nodeData);
         List<String> columnNames = new ArrayList<String>();
@@ -207,6 +230,9 @@ public class Devices implements IDaylightWeb {
         IForwardingStaticRouting staticRouting = (IForwardingStaticRouting) ServiceHelper
                 .getInstance(IForwardingStaticRouting.class, containerName,
                         this);
+        if (staticRouting == null) {
+            return null;
+        }
         List<Map<String, String>> staticRoutes = new ArrayList<Map<String, String>>();
         ConcurrentMap<String, StaticRouteConfig> routeConfigs = staticRouting
                 .getStaticRouteConfigs();
@@ -309,12 +335,14 @@ public class Devices implements IDaylightWeb {
         String containerName = DaylightWebUtil.getAuthorizedContainer(request, container, this);
         ISwitchManager switchManager = (ISwitchManager) ServiceHelper
                 .getInstance(ISwitchManager.class, containerName, this);
-        for (SubnetConfig conf : switchManager.getSubnetsConfigList()) {
-            Map<String, String> subnet = new HashMap<String, String>();
-            subnet.put("name", conf.getName());
-            subnet.put("subnet", conf.getSubnet());
-            subnet.put("json", gson.toJson(conf));
-            subnets.add(subnet);
+        if (switchManager != null) {
+            for (SubnetConfig conf : switchManager.getSubnetsConfigList()) {
+                Map<String, String> subnet = new HashMap<String, String>();
+                subnet.put("name", conf.getName());
+                subnet.put("subnet", conf.getSubnet());
+                subnet.put("json", gson.toJson(conf));
+                subnets.add(subnet);
+            }
         }
         DevicesJsonBean result = new DevicesJsonBean();
         result.setColumnNames(SubnetConfig.getGuiFieldsNames());
@@ -461,8 +489,10 @@ public class Devices implements IDaylightWeb {
         String containerName = DaylightWebUtil.getAuthorizedContainer(request, container, this);
         ISwitchManager switchManager = (ISwitchManager) ServiceHelper
                 .getInstance(ISwitchManager.class, containerName, this);
-        for (SpanConfig conf : switchManager.getSpanConfigList()) {
-            spanConfigs_json.add(gson.toJson(conf));
+        if (switchManager != null) {
+            for (SpanConfig conf : switchManager.getSpanConfigList()) {
+                spanConfigs_json.add(gson.toJson(conf));
+            }
         }
         ObjectMapper mapper = new ObjectMapper();
         List<Map<String, String>> spanConfigs = new ArrayList<Map<String, String>>();
@@ -496,8 +526,9 @@ public class Devices implements IDaylightWeb {
         String containerName = DaylightWebUtil.getAuthorizedContainer(request, container, this);
         ISwitchManager switchManager = (ISwitchManager) ServiceHelper
                 .getInstance(ISwitchManager.class, containerName, this);
-        if (switchManager == null)
+        if (switchManager == null) {
             return null;
+        }
 
         Map<String, Object> nodes = new HashMap<String, Object>();
         Map<Short, String> port;
@@ -605,7 +636,7 @@ public class Devices implements IDaylightWeb {
 
     /**
      * Is the operation permitted for the given level
-     * 
+     *
      * @param level
      */
     private boolean authorize(UserLevel level, HttpServletRequest request) {
@@ -638,10 +669,10 @@ public class Devices implements IDaylightWeb {
          * IUserManager userManager = (IUserManager) ServiceHelper
          * .getGlobalInstance(IUserManager.class, this); if (userManager ==
          * null) { return "User Manager is not available"; }
-         * 
+         *
          * String username = request.getUserPrincipal().getName();
-         * 
-         * 
+         *
+         *
          * model.addAttribute("username", username); model.addAttribute("role",
          * userManager.getUserLevel(username).toNumber());
          */