X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fweb%2Ftopology%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Ftopology%2Fweb%2FTopology.java;h=285e33f53b91690ef7711bd1352b8956da90a63c;hb=077392a1ab706962b0da04b78a9cae5422e70e6c;hp=791358c18a476fbb4ddc0c2a96f822ce06c38e43;hpb=86a8fcb92de5475f366cda9e79e1b494834267b1;p=controller.git 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 791358c18a..285e33f53b 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 @@ -51,7 +51,7 @@ import edu.uci.ics.jung.graph.SparseMultigraph; public class Topology { protected Map> cache = new HashMap>(); - protected Map> stage; + protected Map> stagedNodes; protected Map> newNodes; protected Integer nodeHash = null; protected Integer hostHash = null; @@ -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); } @@ -101,7 +101,7 @@ public class Topology { nodeSingleHash = nodes.hashCode(); nodeConfigurationHash = switchConfigurations.hashCode(); - stage = new HashMap>(); + stagedNodes = new HashMap>(); newNodes = new HashMap>(); // nodeEdges addition @@ -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(); @@ -149,45 +149,51 @@ public class Topology { node.setLinks(adjacencies); if (cache.containsKey(node.id())) { + // retrieve node from cache Map nodeEntry = cache.get(node.id()); - if (config != null) { - Map data = (Map) nodeEntry.get("data"); - data.put("$desc", config.getNodeDescription()); - nodeEntry.put("data", data); - } - stage.put(node.id(), nodeEntry); + + 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) + stagedNodes.put(node.id(), nodeEntry); } else { newNodes.put(node.id(), node.out()); } } } - 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()); - if (cache.containsKey(n.toString()) || newNodes.containsKey(n.toString())) continue; - NodeBean node = createNodeBean(config, n); - if (cache.containsKey(node.id())) { + + String description = switchManager.getNodeDescription(n); + + if ((stagedNodes.containsKey(n.toString()) && cache.containsKey(n.toString())) || newNodes.containsKey(n.toString())) { + continue; + } + 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); - } - stage.put(node.id(), nodeEntry); + 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()); } @@ -213,15 +219,18 @@ public class Topology { addressByteBuffer.rewind(); long hid = addressByteBuffer.getLong(); + String hostId = String.valueOf(hid); - NodeBean hostBean = new NodeBean(String.valueOf(hid), host.getNetworkAddressAsString(), NodeType.HOST); + NodeBean hostBean = new NodeBean(hostId, host.getNetworkAddressAsString(), NodeType.HOST); List> adjacencies = new LinkedList>(); EdgeBean edge = new EdgeBean(connector, hid); adjacencies.add(edge.out()); hostBean.setLinks(adjacencies); - if (cache.containsKey(String.valueOf(hid))) { - stage.put(String.valueOf(hid), cache.get(String.valueOf(hid))); + if (cache.containsKey(hostId)) { + Map hostEntry = cache.get(hostId); + hostEntry.put("adjacencies", adjacencies); + stagedNodes.put(hostId, hostEntry); } else { newNodes.put(String.valueOf(hid), hostBean.out()); } @@ -235,7 +244,7 @@ public class Topology { private void repositionTopology() { Graph graph = new SparseMultigraph(); cache.clear(); - cache.putAll(stage); + cache.putAll(stagedNodes); cache.putAll(newNodes); for (Map on : cache.values()) { graph.addVertex(on.toString()); @@ -250,7 +259,7 @@ public class Topology { } } - CircleLayout layout = new CircleLayout(graph); + CircleLayout layout = new CircleLayout(graph); layout.setSize(new Dimension(1200, 365)); for (Map.Entry> v : newNodes.entrySet()) { Double x = layout.transform(v.getKey()).getX();