From 273701a44eb6ac914289649870c2a739b961ee8d Mon Sep 17 00:00:00 2001 From: Alessandro Boch Date: Fri, 12 Apr 2013 13:40:59 -0700 Subject: [PATCH] ISSUE: Topology does not show Node description as learned by the OFA Signed-off-by: Alessandro Boch --- .../internal/SwitchManagerImpl.java | 2 +- .../controller/devices/web/Devices.java | 4 +- .../controller/flows/web/Flows.java | 2 +- .../controller/topology/web/Topology.java | 48 +++++++++---------- .../controller/topology/web/TopologyTest.java | 10 +++- 5 files changed, 34 insertions(+), 32 deletions(-) diff --git a/opendaylight/switchmanager/src/main/java/org/opendaylight/controller/switchmanager/internal/SwitchManagerImpl.java b/opendaylight/switchmanager/src/main/java/org/opendaylight/controller/switchmanager/internal/SwitchManagerImpl.java index d3dcc65b2a..281ba52a0a 100755 --- a/opendaylight/switchmanager/src/main/java/org/opendaylight/controller/switchmanager/internal/SwitchManagerImpl.java +++ b/opendaylight/switchmanager/src/main/java/org/opendaylight/controller/switchmanager/internal/SwitchManagerImpl.java @@ -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()) { diff --git a/opendaylight/web/devices/src/main/java/org/opendaylight/controller/devices/web/Devices.java b/opendaylight/web/devices/src/main/java/org/opendaylight/controller/devices/web/Devices.java index ff6fc835f9..f451204d36 100644 --- a/opendaylight/web/devices/src/main/java/org/opendaylight/controller/devices/web/Devices.java +++ b/opendaylight/web/devices/src/main/java/org/opendaylight/controller/devices/web/Devices.java @@ -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); diff --git a/opendaylight/web/flows/src/main/java/org/opendaylight/controller/flows/web/Flows.java b/opendaylight/web/flows/src/main/java/org/opendaylight/controller/flows/web/Flows.java index 35237999b8..0254ab3152 100644 --- a/opendaylight/web/flows/src/main/java/org/opendaylight/controller/flows/web/Flows.java +++ b/opendaylight/web/flows/src/main/java/org/opendaylight/controller/flows/web/Flows.java @@ -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(); } diff --git a/opendaylight/web/topology/src/main/java/org/opendaylight/controller/topology/web/Topology.java b/opendaylight/web/topology/src/main/java/org/opendaylight/controller/topology/web/Topology.java index 5749357c1c..51cdcfb434 100644 --- a/opendaylight/web/topology/src/main/java/org/opendaylight/controller/topology/web/Topology.java +++ b/opendaylight/web/topology/src/main/java/org/opendaylight/controller/topology/web/Topology.java @@ -83,7 +83,7 @@ public class Topology { List switchConfigurations = new ArrayList(); 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> 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> adjacencies = new LinkedList>(); Set links = e.getValue(); @@ -151,12 +151,11 @@ public class Topology { if (cache.containsKey(node.id())) { // retrieve node from cache Map nodeEntry = cache.get(node.id()); - // update node name when appropriate - if (config != null) { - Map data = (Map) nodeEntry.get("data"); - data.put("$desc", config.getNodeDescription()); - nodeEntry.put("data", data); - } + + Map data = (Map) 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 nodes, ISwitchManager switchManager) { + @SuppressWarnings("unchecked") + private void addSingleNodes(List 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 nodeEntry = cache.get(node.id()); - if (config != null) { - Map data = (Map) nodeEntry.get("data"); - data.put("$desc", config.getNodeDescription()); - nodeEntry.put("data", data); - } + Map data = (Map) nodeEntry.get("data"); + data.put("$desc", description); + nodeEntry.put("data", data); stagedNodes.put(node.id(), nodeEntry); } else { newNodes.put(node.id(), node.out()); diff --git a/opendaylight/web/topology/src/test/java/org/opendaylight/controller/topology/web/TopologyTest.java b/opendaylight/web/topology/src/test/java/org/opendaylight/controller/topology/web/TopologyTest.java index e41d93deb8..e26e7c666b 100644 --- a/opendaylight/web/topology/src/test/java/org/opendaylight/controller/topology/web/TopologyTest.java +++ b/opendaylight/web/topology/src/test/java/org/opendaylight/controller/topology/web/TopologyTest.java @@ -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); } } -- 2.36.6