Fix exceptions in SwitchManager Web in case of non-OF nodes and node connectors 21/421/1
authorJason Ye <yisye@cisco.com>
Mon, 3 Jun 2013 06:12:02 +0000 (23:12 -0700)
committerJason Ye <yisye@cisco.com>
Mon, 3 Jun 2013 06:12:02 +0000 (23:12 -0700)
Signed-off-by: Jason Ye <yisye@cisco.com>
opendaylight/switchmanager/implementation/src/main/java/org/opendaylight/controller/switchmanager/internal/SwitchManagerImpl.java
opendaylight/web/devices/src/main/java/org/opendaylight/controller/devices/web/Devices.java

index 4ef8416..d9333e9 100644 (file)
@@ -54,7 +54,6 @@ import org.opendaylight.controller.sal.inventory.IListenInventoryUpdates;
 import org.opendaylight.controller.sal.utils.StatusCode;
 import org.opendaylight.controller.sal.utils.GlobalConstants;
 import org.opendaylight.controller.sal.utils.IObjectReader;
-import org.opendaylight.controller.sal.utils.NodeCreator;
 import org.opendaylight.controller.sal.utils.ObjectReader;
 import org.opendaylight.controller.sal.utils.ObjectWriter;
 import org.opendaylight.controller.sal.utils.ServiceHelper;
@@ -869,26 +868,11 @@ public class SwitchManagerImpl implements ISwitchManager,
                 : null;
     }
 
-    /*
-     * test utility function which assumes all nodes are OF nodes
-     */
-    private Node getNode(Long id) {
-        Set<Node> nodes = getNodes();
-        if (nodes != null) {
-            for (Node node : nodes) {
-                if (id.equals((Long) node.getID())) {
-                    return node;
-                }
-            }
-        }
-        return null;
-    }
-
     /*
      * Returns a copy of a list of properties for a given node
-     * 
+     *
      * (non-Javadoc)
-     * 
+     *
      * @see
      * org.opendaylight.controller.switchmanager.ISwitchManager#getNodeProps
      * (org.opendaylight.controller.sal.core.Node)
@@ -954,9 +938,9 @@ public class SwitchManagerImpl implements ISwitchManager,
 
         Set<NodeConnector> nodeConnectorSet = new HashSet<NodeConnector>();
         for (NodeConnector nodeConnector : nodeConnectorProps.keySet()) {
-            if (((Long) nodeConnector.getNode().getID()).longValue() != (Long) node
-                    .getID())
+            if (!nodeConnector.getNode().equals(node)) {
                 continue;
+            }
             if (isNodeConnectorEnabled(nodeConnector))
                 nodeConnectorSet.add(nodeConnector);
         }
@@ -971,9 +955,9 @@ public class SwitchManagerImpl implements ISwitchManager,
 
         Set<NodeConnector> nodeConnectorSet = new HashSet<NodeConnector>();
         for (NodeConnector nodeConnector : nodeConnectorProps.keySet()) {
-            if (((Long) nodeConnector.getNode().getID()).longValue() != (Long) node
-                    .getID())
+            if (!nodeConnector.getNode().equals(node)) {
                 continue;
+            }
             nodeConnectorSet.add(nodeConnector);
         }
 
@@ -997,24 +981,6 @@ public class SwitchManagerImpl implements ISwitchManager,
         return nodeConnectorSet;
     }
 
-    /*
-     * testing utility function which assumes we are dealing with OF Node
-     * nodeconnectors only
-     */
-    @SuppressWarnings("unused")
-    private Set<Long> getEnabledNodeConnectorIds(Node node) {
-        Set<Long> ids = new HashSet<Long>();
-        Set<NodeConnector> nodeConnectors = getUpNodeConnectors(node);
-
-        if (nodeConnectors != null) {
-            for (NodeConnector nodeConnector : nodeConnectors) {
-                ids.add((Long) nodeConnector.getID());
-            }
-        }
-
-        return ids;
-    }
-
     @Override
     public Map<String, Property> getNodeConnectorProps(
             NodeConnector nodeConnector) {
@@ -1095,7 +1061,7 @@ public class SwitchManagerImpl implements ISwitchManager,
 
     /**
      * Adds a node connector and its property if any
-     * 
+     *
      * @param nodeConnector
      *            {@link org.opendaylight.controller.sal.core.NodeConnector}
      * @param propName
@@ -1139,7 +1105,7 @@ public class SwitchManagerImpl implements ISwitchManager,
 
     /**
      * Removes one property of a node connector
-     * 
+     *
      * @param nodeConnector
      *            {@link org.opendaylight.controller.sal.core.NodeConnector}
      * @param propName
@@ -1177,7 +1143,7 @@ public class SwitchManagerImpl implements ISwitchManager,
 
     /**
      * Removes all the properties of a node connector
-     * 
+     *
      * @param nodeConnector
      *            {@link org.opendaylight.controller.sal.core.NodeConnector}
      * @return success or failed reason
@@ -1204,7 +1170,7 @@ public class SwitchManagerImpl implements ISwitchManager,
     /**
      * Function called by the dependency manager when all the required
      * dependencies are satisfied
-     * 
+     *
      */
     void init(Component c) {
         Dictionary<?, ?> props = c.getServiceProperties();
@@ -1225,7 +1191,7 @@ public class SwitchManagerImpl implements ISwitchManager,
      * Function called by the dependency manager when at least one dependency
      * become unsatisfied or when the component is shutting down because for
      * example bundle is being stopped.
-     * 
+     *
      */
     void destroy() {
         shutDown();
@@ -1234,7 +1200,7 @@ public class SwitchManagerImpl implements ISwitchManager,
     /**
      * Function called by dependency manager after "init ()" is called and after
      * the services provided by the class are registered in the service registry
-     * 
+     *
      */
     void start() {
         // OSGI console
@@ -1253,7 +1219,7 @@ public class SwitchManagerImpl implements ISwitchManager,
      * Function called by the dependency manager before the services exported by
      * the component are unregistered, this will be followed by a "destroy ()"
      * calls
-     * 
+     *
      */
     void stop() {
     }
@@ -1756,7 +1722,7 @@ public class SwitchManagerImpl implements ISwitchManager,
     /**
      * Creates a Name/Tier/Bandwidth Property object based on given property
      * name and value. Other property types are not supported yet.
-     * 
+     *
      * @param propName
      *            Name of the Property
      * @param propValue
index bec194b..188be8a 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;
@@ -118,6 +117,7 @@ public class Devices implements IDaylightWeb {
                         .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();
@@ -142,17 +142,29 @@ public class Devices implements IDaylightWeb {
                             }
                         }
 
-                        portList.put(
-                                Short.parseShort(nodeConnectorNumberToStr),
-                                nodeConnectorName);
+                        Class<?> idClass = nodeConnector.getID().getClass();
+                        if (idClass.equals(Short.class)) {
+                            portList.put(
+                                    Short.parseShort(nodeConnectorNumberToStr),
+                                    nodeConnectorName);
+                        } else {
+                            intfList.add(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());
@@ -624,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) {
@@ -657,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());
          */