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 4ef841643691bdb145c377c85199fa1635f49d29..d9333e9f824d1cdd7c6bd2dc579e9efb0cd009fb 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.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;
 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;
     }
 
                 : 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
     /*
      * Returns a copy of a list of properties for a given node
-     * 
+     *
      * (non-Javadoc)
      * (non-Javadoc)
-     * 
+     *
      * @see
      * org.opendaylight.controller.switchmanager.ISwitchManager#getNodeProps
      * (org.opendaylight.controller.sal.core.Node)
      * @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()) {
 
         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;
                 continue;
+            }
             if (isNodeConnectorEnabled(nodeConnector))
                 nodeConnectorSet.add(nodeConnector);
         }
             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()) {
 
         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;
                 continue;
+            }
             nodeConnectorSet.add(nodeConnector);
         }
 
             nodeConnectorSet.add(nodeConnector);
         }
 
@@ -997,24 +981,6 @@ public class SwitchManagerImpl implements ISwitchManager,
         return nodeConnectorSet;
     }
 
         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) {
     @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
 
     /**
      * Adds a node connector and its property if any
-     * 
+     *
      * @param nodeConnector
      *            {@link org.opendaylight.controller.sal.core.NodeConnector}
      * @param propName
      * @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
 
     /**
      * Removes one property of a node connector
-     * 
+     *
      * @param nodeConnector
      *            {@link org.opendaylight.controller.sal.core.NodeConnector}
      * @param propName
      * @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
 
     /**
      * Removes all the properties of a node connector
-     * 
+     *
      * @param nodeConnector
      *            {@link org.opendaylight.controller.sal.core.NodeConnector}
      * @return success or failed reason
      * @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
     /**
      * Function called by the dependency manager when all the required
      * dependencies are satisfied
-     * 
+     *
      */
     void init(Component c) {
         Dictionary<?, ?> props = c.getServiceProperties();
      */
     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.
      * 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();
      */
     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
     /**
      * 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
      */
     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
      * 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() {
     }
      */
     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.
     /**
      * 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
      * @param propName
      *            Name of the Property
      * @param propValue
index bec194bf1cc67432a53320cd8fc4911af98977f2..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.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;
 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>();
                         .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();
                     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());
                     }
                 }
                 nodeDatum.put("ports", sb1.toString());
@@ -624,7 +636,7 @@ public class Devices implements IDaylightWeb {
 
     /**
      * Is the operation permitted for the given level
 
     /**
      * Is the operation permitted for the given level
-     * 
+     *
      * @param level
      */
     private boolean authorize(UserLevel level, HttpServletRequest request) {
      * @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"; }
          * IUserManager userManager = (IUserManager) ServiceHelper
          * .getGlobalInstance(IUserManager.class, this); if (userManager ==
          * null) { return "User Manager is not available"; }
-         * 
+         *
          * String username = request.getUserPrincipal().getName();
          * String username = request.getUserPrincipal().getName();
-         * 
-         * 
+         *
+         *
          * model.addAttribute("username", username); model.addAttribute("role",
          * userManager.getUserLevel(username).toNumber());
          */
          * model.addAttribute("username", username); model.addAttribute("role",
          * userManager.getUserLevel(username).toNumber());
          */