ISSUE: Topology does not show Node description as learned by the OFA 44/144/1
authorAlessandro Boch <aboch@cisco.com>
Fri, 12 Apr 2013 20:40:59 +0000 (13:40 -0700)
committerAlessandro Boch <aboch@cisco.com>
Fri, 12 Apr 2013 20:40:59 +0000 (13:40 -0700)
Signed-off-by: Alessandro Boch <aboch@cisco.com>
opendaylight/switchmanager/src/main/java/org/opendaylight/controller/switchmanager/internal/SwitchManagerImpl.java
opendaylight/web/devices/src/main/java/org/opendaylight/controller/devices/web/Devices.java
opendaylight/web/flows/src/main/java/org/opendaylight/controller/flows/web/Flows.java
opendaylight/web/topology/src/main/java/org/opendaylight/controller/topology/web/Topology.java
opendaylight/web/topology/src/test/java/org/opendaylight/controller/topology/web/TopologyTest.java

index d3dcc65..281ba52 100755 (executable)
@@ -1764,7 +1764,7 @@ public class SwitchManagerImpl implements ISwitchManager,
        @Override
        public String getNodeDescription(Node node) {
        // Check first if user configured a name
-        SwitchConfig config = getSwitchConfig(node.getNodeIDString());
+        SwitchConfig config = getSwitchConfig(node.toString());
         if (config != null) {
                String configuredDesc = config.getNodeDescription();
                if (configuredDesc != null && !configuredDesc.isEmpty()) {
index ff6fc83..f451204 100644 (file)
@@ -95,14 +95,14 @@ public class Devices implements IDaylightWeb {
 
             nodeDatum.put("containerName", containerName);
             nodeDatum.put("nodeName", switchManager.getNodeDescription(node));
-            nodeDatum.put("nodeId", node.toString());//.getNodeIDString());
+            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()
-                    .getNodeIDString());
+                    .toString());
             String modeStr = (sc != null) ? sc.getMode() : "0";
             nodeDatum.put("mode", modeStr);
 
index 3523799..0254ab3 100644 (file)
@@ -176,7 +176,7 @@ public class Flows implements IDaylightWeb {
 
             String nodeDesc = node.toString();
             SwitchConfig config = switchManager.getSwitchConfig(node
-                    .getNodeIDString());
+                    .toString());
             if (config != null) {
                 nodeDesc = config.getNodeDescription();
             }
index 5749357..51cdcfb 100644 (file)
@@ -83,7 +83,7 @@ public class Topology {
         List<SwitchConfig> switchConfigurations = new ArrayList<SwitchConfig>();
         for(Switch sw : nodes) {
                Node n = sw.getNode();
-               SwitchConfig config = switchManager.getSwitchConfig(n.getNodeIDString());
+               SwitchConfig config = switchManager.getSwitchConfig(n.toString());
                switchConfigurations.add(config);
         }
         
@@ -131,8 +131,8 @@ public class Topology {
         
         for (Map.Entry<Node, Set<Edge>> e : nodeEdges.entrySet()) {
             Node n = e.getKey();
-            SwitchConfig config = switchManager.getSwitchConfig(n.getNodeIDString());
-            NodeBean node = createNodeBean(config, n);
+            String description = switchManager.getNodeDescription(n);
+            NodeBean node = createNodeBean(description, n);
             
             List<Map<String, Object>> adjacencies = new LinkedList<Map<String, Object>>();
             Set<Edge> links = e.getValue();
@@ -151,12 +151,11 @@ public class Topology {
             if (cache.containsKey(node.id())) {
                // retrieve node from cache
                Map<String, Object> nodeEntry = cache.get(node.id());
-               // update node name when appropriate
-               if (config != null) {
-                       Map<String, String> data = (Map<String, String>) nodeEntry.get("data");
-                       data.put("$desc", config.getNodeDescription());
-                       nodeEntry.put("data", data);
-               }
+
+                       Map<String, String> data = (Map<String, String>) nodeEntry.get("data");
+                       data.put("$desc", description);
+                       nodeEntry.put("data", data);
+                       
                // always update adjacencies
                nodeEntry.put("adjacencies", adjacencies);
                // stage this cached node (with position)
@@ -167,36 +166,33 @@ public class Topology {
         }
     }
     
-    protected NodeBean createNodeBean(SwitchConfig config, Node node) {
-       NodeBean bean = null;
-       if (config != null) {
-               bean = new NodeBean(node.toString(), config.getNodeDescription(), NodeType.NODE);
-       } else {
-               bean = new NodeBean(node.toString(), node.toString(), NodeType.NODE);
-       }
-       
-       return bean;
+    protected NodeBean createNodeBean(String description, Node node) {
+       String name = (description == null || 
+                       description.trim().isEmpty() ||
+                       description.equalsIgnoreCase("none"))?
+                                       node.toString() : description;
+               return  new NodeBean(node.toString(), name, NodeType.NODE);
     }
     
-    private void addSingleNodes(List<Switch> nodes, ISwitchManager switchManager) {
+    @SuppressWarnings("unchecked")
+       private void addSingleNodes(List<Switch> nodes, ISwitchManager switchManager) {
        if (nodes == null) return;
        for (Switch sw : nodes) {
                Node n = sw.getNode();
-               SwitchConfig config = switchManager.getSwitchConfig(n.getNodeIDString());
+
+               String description = switchManager.getNodeDescription(n);
                
                if ((stagedNodes.containsKey(n.toString()) && cache.containsKey(n.toString())) || newNodes.containsKey(n.toString())) {
                        continue;
                }
-               NodeBean node = createNodeBean(config, n);
+               NodeBean node = createNodeBean(description, n);
                
                // FIXME still doesn't display standalone node when last remaining link is removed
                if (cache.containsKey(node.id()) && !stagedNodes.containsKey(node.id())) {
                        Map<String, Object> nodeEntry = cache.get(node.id());
-                       if (config != null) {
-                               Map<String, String> data = (Map<String, String>) nodeEntry.get("data");
-                       data.put("$desc", config.getNodeDescription());
-                       nodeEntry.put("data", data);
-                       }
+                               Map<String, String> data = (Map<String, String>) nodeEntry.get("data");
+                       data.put("$desc", description);
+                       nodeEntry.put("data", data);
                stagedNodes.put(node.id(), nodeEntry);
             } else {
                newNodes.put(node.id(), node.out());
index e41d93d..e26e7c6 100644 (file)
@@ -23,9 +23,9 @@ public class TopologyTest {
        public void testCreateNodeBean() {
                Topology topology = new Topology();
                Node node = NodeCreator.createOFNode(new Long(3));
-               SwitchConfig mockSwitchConfig = new SwitchConfig(node.getNodeIDString(), "foo", null, null);
+               String description = "foo";
                
-               NodeBean bean = topology.createNodeBean(mockSwitchConfig, node);
+               NodeBean bean = topology.createNodeBean(description, node);
                
                assertNotNull(bean);
                assertEquals(bean.id, node.toString());
@@ -36,6 +36,12 @@ public class TopologyTest {
                assertNotNull(bean);
                assertEquals(bean.id, node.toString());
                assertEquals(bean.name, bean.id);
+               
+               bean = topology.createNodeBean("   ", node);
+               
+               assertNotNull(bean);
+               assertEquals(bean.id, node.toString());
+               assertEquals(bean.name, bean.id);
        }
 
 }