From: Andrew Kim Date: Fri, 12 Apr 2013 19:24:05 +0000 (-0700) Subject: Fix stale cached links in visual topology X-Git-Tag: releasepom-0.1.0~575 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=commitdiff_plain;h=2274b888b9e60ab94147a455326b92e0f9914676 Fix stale cached links in visual topology Links weren't properly updated everytime there was a topology state change. Change-Id: Ia65e02009aa7da65bbedb3d8ed8e72e8de433791 Signed-off-by: Andrew Kim --- 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..5749357c1c 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; @@ -101,7 +101,7 @@ public class Topology { nodeSingleHash = nodes.hashCode(); nodeConfigurationHash = switchConfigurations.hashCode(); - stage = new HashMap>(); + stagedNodes = new HashMap>(); newNodes = new HashMap>(); // nodeEdges addition @@ -149,13 +149,18 @@ public class Topology { node.setLinks(adjacencies); 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); } - stage.put(node.id(), nodeEntry); + // 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()); } @@ -178,16 +183,21 @@ public class Topology { for (Switch sw : nodes) { Node n = sw.getNode(); SwitchConfig config = switchManager.getSwitchConfig(n.getNodeIDString()); - if (cache.containsKey(n.toString()) || newNodes.containsKey(n.toString())) continue; + + if ((stagedNodes.containsKey(n.toString()) && cache.containsKey(n.toString())) || newNodes.containsKey(n.toString())) { + continue; + } NodeBean node = createNodeBean(config, n); - if (cache.containsKey(node.id())) { + + // 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); + stagedNodes.put(node.id(), nodeEntry); } else { newNodes.put(node.id(), node.out()); } @@ -213,15 +223,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 +248,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());