Fix multi-host caching in visual topology 03/1303/1
authorAndrew Kim <andrekim@cisco.com>
Fri, 20 Sep 2013 02:43:10 +0000 (21:43 -0500)
committerAndrew Kim <andrekim@cisco.com>
Fri, 20 Sep 2013 02:43:10 +0000 (21:43 -0500)
Change-Id: I68cd3de135d8422b3994387f43bc0df67c612f3f
Signed-off-by: Andrew Kim <andrekim@cisco.com>
opendaylight/web/topology/src/main/java/org/opendaylight/controller/topology/web/Topology.java

index a6c390d799bb1fa54ac1329436ab2a3b47d2b037..f6a05882833ccc2f03851405f57e2b5480e159d4 100644 (file)
@@ -114,6 +114,7 @@ public class Topology implements IObjectReader, IConfigurationAware {
         Map<Node, Set<Edge>> nodeEdges = topologyManager.getNodeEdges();
         Map<Node, Set<NodeConnector>> hostEdges = topologyManager
                 .getNodesWithNodeConnectorHost();
+        int hostEdgesHashCode = getHostHashCode(hostEdges, topologyManager);
         List<Switch> nodes = switchManager.getNetworkDevices();
 
         List<SwitchConfig> switchConfigurations = new ArrayList<SwitchConfig>();
@@ -136,14 +137,14 @@ public class Topology implements IObjectReader, IConfigurationAware {
         // return cache if topology hasn't changed
         if (
                 (metaNodeHash.get(containerName) != null && metaHostHash.get(containerName) != null && metaNodeSingleHash.get(containerName) != null && metaNodeConfigurationHash.get(containerName) != null) &&
-                metaNodeHash.get(containerName).equals(nodeEdges.hashCode()) && metaHostHash.get(containerName).equals(hostEdges.hashCode()) && metaNodeSingleHash.get(containerName).equals(nodes.hashCode()) && metaNodeConfigurationHash.get(containerName).equals(switchConfigurations.hashCode())
+                metaNodeHash.get(containerName).equals(nodeEdges.hashCode()) && metaHostHash.get(containerName).equals(hostEdgesHashCode) && metaNodeSingleHash.get(containerName).equals(nodes.hashCode()) && metaNodeConfigurationHash.get(containerName).equals(switchConfigurations.hashCode())
         ) {
                 return metaCache.get(containerName).values();
         }
 
         // cache has changed, we must assign the new values
         metaNodeHash.put(containerName, nodeEdges.hashCode());
-        metaHostHash.put(containerName, hostEdges.hashCode());
+        metaHostHash.put(containerName, hostEdgesHashCode);
         metaNodeSingleHash.put(containerName, nodes.hashCode());
         metaNodeConfigurationHash.put(containerName, switchConfigurations.hashCode());
 
@@ -330,6 +331,29 @@ public class Topology implements IObjectReader, IConfigurationAware {
         }
     }
 
+    /**
+     * Calculate the total host hashcode
+     *
+     * This is to handle cases where there are multiple hosts per NodeConnector
+     *
+     * @param hostEdges
+     *            - hostEdges data structure
+     * @param topology
+     *            - topology bundle
+     * @return this topology's host hashcode
+     */
+    private int getHostHashCode(Map<Node, Set<NodeConnector>> hostEdges, ITopologyManager topology) {
+        List<Host> hosts = new ArrayList<Host>();
+        for (Set<NodeConnector> nodeConnectors : hostEdges.values()) {
+            for (NodeConnector nodeConnector : nodeConnectors) {
+                List<Host> theseHosts = topology.getHostsAttachedToNodeConnector(nodeConnector);
+                hosts.addAll(theseHosts);
+            }
+        }
+
+        return hosts.hashCode();
+    }
+
     /**
      * Add regular hosts to main topology
      *