ISSUE: Topology does not show Node description as learned by the OFA
[controller.git] / opendaylight / web / topology / src / main / java / org / opendaylight / controller / topology / web / Topology.java
index 5749357c1c4b5a839d9ebebf4328002a36b585d9..51cdcfb434807a601baef6c30ff21f9790f7a540 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());