From 0b43ddf2ee9f30e67b3433906022045b8dcc2a4f Mon Sep 17 00:00:00 2001 From: Asad Ahmed Date: Fri, 9 Aug 2013 14:56:27 -0700 Subject: [PATCH] Adding code to handle multiple hosts per node connector Change-Id: I32b18fe019a2806f0bb2778321f0a3ac6c6b23a2 Signed-off-by: Asad Ahmed --- .../topologymanager/ITopologyManager.java | 16 ++++++- .../internal/TopologyManagerImpl.java | 47 ++++++++++++++----- 2 files changed, 50 insertions(+), 13 deletions(-) diff --git a/opendaylight/topologymanager/src/main/java/org/opendaylight/controller/topologymanager/ITopologyManager.java b/opendaylight/topologymanager/src/main/java/org/opendaylight/controller/topologymanager/ITopologyManager.java index de4f0d5347..1f377593bb 100644 --- a/opendaylight/topologymanager/src/main/java/org/opendaylight/controller/topologymanager/ITopologyManager.java +++ b/opendaylight/topologymanager/src/main/java/org/opendaylight/controller/topologymanager/ITopologyManager.java @@ -9,6 +9,7 @@ package org.opendaylight.controller.topologymanager; +import java.util.List; import java.util.Map; import java.util.Set; import java.util.concurrent.ConcurrentMap; @@ -67,12 +68,23 @@ public interface ITopologyManager { public Set getNodeConnectorWithHost(); /** - * Return the Host attached to a NodeConnector with Host - * + * Return the Host attached to a NodeConnector with Host. + * Multiple hosts maybe attached to a node connector. + * This method returns the first one only. Hence it has been + * deprecated. Use the new method getHostsAttachedToNodeConnector + * that returns the complete list of hosts. * @return The Host attached to a NodeConnector */ + @Deprecated public Host getHostAttachedToNodeConnector(NodeConnector p); + /** + * Returns a list of hosts attached to a NodeConnector + * @param p NodeConnector + * @return The list of hosts attached to a NodeConnector + */ + public List getHostsAttachedToNodeConnector(NodeConnector p); + /** * Returns a copy map which associates every node with all the * NodeConnectors of the node that have an Host attached to it diff --git a/opendaylight/topologymanager/src/main/java/org/opendaylight/controller/topologymanager/internal/TopologyManagerImpl.java b/opendaylight/topologymanager/src/main/java/org/opendaylight/controller/topologymanager/internal/TopologyManagerImpl.java index 4972d3b5b5..4bd295c62a 100644 --- a/opendaylight/topologymanager/src/main/java/org/opendaylight/controller/topologymanager/internal/TopologyManagerImpl.java +++ b/opendaylight/topologymanager/src/main/java/org/opendaylight/controller/topologymanager/internal/TopologyManagerImpl.java @@ -12,12 +12,12 @@ import java.io.FileNotFoundException; import java.io.IOException; import java.io.ObjectInputStream; import java.util.ArrayList; -import java.util.Date; import java.util.Dictionary; import java.util.EnumSet; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; +import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Set; @@ -89,7 +89,7 @@ public class TopologyManagerImpl implements // NodeConnector of a Production Edge is not part of this DB. private ConcurrentMap> nodeConnectorsDB; // DB of all the NodeConnectors with an Host attached to it - private ConcurrentMap>> hostsDB; + private ConcurrentMap>>> hostsDB; // Topology Manager Aware listeners private Set topologyManagerAware = new CopyOnWriteArraySet(); // Topology Manager Aware listeners - for clusterwide updates @@ -105,7 +105,7 @@ public class TopologyManagerImpl implements void nonClusterObjectCreate() { edgesDB = new ConcurrentHashMap>(); - hostsDB = new ConcurrentHashMap>>(); + hostsDB = new ConcurrentHashMap>>>(); nodeConnectorsDB = new ConcurrentHashMap>(); userLinksDB = new ConcurrentHashMap(); } @@ -201,7 +201,7 @@ public class TopologyManagerImpl implements try { this.hostsDB = - (ConcurrentMap>>) this.clusterContainerService.createCache( + (ConcurrentMap>>>) this.clusterContainerService.createCache( TOPOHOSTSDB, EnumSet.of(IClusterServices.cacheMode.NON_TRANSACTIONAL)); } catch (CacheExistException cee) { log.debug(TOPOHOSTSDB + " Cache already exists - destroy and recreate if needed"); @@ -243,7 +243,7 @@ public class TopologyManagerImpl implements } this.hostsDB = - (ConcurrentMap>>) this.clusterContainerService.getCache(TOPOHOSTSDB); + (ConcurrentMap>>>) this.clusterContainerService.getCache(TOPOHOSTSDB); if (hostsDB == null) { log.error("Failed to get cache for " + TOPOHOSTSDB); } @@ -451,11 +451,25 @@ public class TopologyManagerImpl implements @Override public Host getHostAttachedToNodeConnector(NodeConnector port) { - ImmutablePair> host; - if ((this.hostsDB == null) || ((host = this.hostsDB.get(port)) == null)) { + List hosts = getHostsAttachedToNodeConnector(port); + if(hosts != null && !hosts.isEmpty()){ + return hosts.get(0); + } + return null; + } + + @Override + public List getHostsAttachedToNodeConnector(NodeConnector p) { + Set>> hosts; + if (this.hostsDB == null || (hosts = this.hostsDB.get(p)) == null) { return null; } - return host.getLeft(); + // create a list of hosts + List retHosts = new LinkedList(); + for(ImmutablePair> host : hosts) { + retHosts.add(host.getLeft()); + } + return retHosts; } @Override @@ -471,14 +485,25 @@ public class TopologyManagerImpl implements } ImmutablePair> thisHost = new ImmutablePair>(h, props); + // get the host list + Set>> hostSet = this.hostsDB.get(port); + if(hostSet == null) { + hostSet = new HashSet>>(); + } switch (t) { case ADDED: case CHANGED: - this.hostsDB.put(port, thisHost); + hostSet.add(thisHost); + this.hostsDB.put(port, hostSet); break; case REMOVED: - //remove only if hasn't been concurrently modified - this.hostsDB.remove(port, thisHost); + hostSet.remove(thisHost); + if(hostSet.isEmpty()) { + //remove only if hasn't been concurrently modified + this.hostsDB.remove(port, hostSet); + } else { + this.hostsDB.put(port, hostSet); + } break; } } -- 2.36.6