package org.opendaylight.controller.topologymanager;
+import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentMap;
public Set<NodeConnector> 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<Host> 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
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;
// NodeConnector of a Production Edge is not part of this DB.
private ConcurrentMap<NodeConnector, Set<Property>> nodeConnectorsDB;
// DB of all the NodeConnectors with an Host attached to it
- private ConcurrentMap<NodeConnector, ImmutablePair<Host, Set<Property>>> hostsDB;
+ private ConcurrentMap<NodeConnector, Set<ImmutablePair<Host, Set<Property>>>> hostsDB;
// Topology Manager Aware listeners
private Set<ITopologyManagerAware> topologyManagerAware = new CopyOnWriteArraySet<ITopologyManagerAware>();
// Topology Manager Aware listeners - for clusterwide updates
void nonClusterObjectCreate() {
edgesDB = new ConcurrentHashMap<Edge, Set<Property>>();
- hostsDB = new ConcurrentHashMap<NodeConnector, ImmutablePair<Host, Set<Property>>>();
+ hostsDB = new ConcurrentHashMap<NodeConnector, Set<ImmutablePair<Host, Set<Property>>>>();
nodeConnectorsDB = new ConcurrentHashMap<NodeConnector, Set<Property>>();
userLinksDB = new ConcurrentHashMap<String, TopologyUserLinkConfig>();
}
try {
this.hostsDB =
- (ConcurrentMap<NodeConnector, ImmutablePair<Host, Set<Property>>>) this.clusterContainerService.createCache(
+ (ConcurrentMap<NodeConnector, Set<ImmutablePair<Host, Set<Property>>>>) this.clusterContainerService.createCache(
TOPOHOSTSDB, EnumSet.of(IClusterServices.cacheMode.NON_TRANSACTIONAL));
} catch (CacheExistException cee) {
log.debug(TOPOHOSTSDB + " Cache already exists - destroy and recreate if needed");
}
this.hostsDB =
- (ConcurrentMap<NodeConnector, ImmutablePair<Host, Set<Property>>>) this.clusterContainerService.getCache(TOPOHOSTSDB);
+ (ConcurrentMap<NodeConnector, Set<ImmutablePair<Host, Set<Property>>>>) this.clusterContainerService.getCache(TOPOHOSTSDB);
if (hostsDB == null) {
log.error("Failed to get cache for " + TOPOHOSTSDB);
}
@Override
public Host getHostAttachedToNodeConnector(NodeConnector port) {
- ImmutablePair<Host, Set<Property>> host;
- if ((this.hostsDB == null) || ((host = this.hostsDB.get(port)) == null)) {
+ List<Host> hosts = getHostsAttachedToNodeConnector(port);
+ if(hosts != null && !hosts.isEmpty()){
+ return hosts.get(0);
+ }
+ return null;
+ }
+
+ @Override
+ public List<Host> getHostsAttachedToNodeConnector(NodeConnector p) {
+ Set<ImmutablePair<Host, Set<Property>>> hosts;
+ if (this.hostsDB == null || (hosts = this.hostsDB.get(p)) == null) {
return null;
}
- return host.getLeft();
+ // create a list of hosts
+ List<Host> retHosts = new LinkedList<Host>();
+ for(ImmutablePair<Host, Set<Property>> host : hosts) {
+ retHosts.add(host.getLeft());
+ }
+ return retHosts;
}
@Override
}
ImmutablePair<Host, Set<Property>> thisHost = new ImmutablePair<Host, Set<Property>>(h, props);
+ // get the host list
+ Set<ImmutablePair<Host, Set<Property>>> hostSet = this.hostsDB.get(port);
+ if(hostSet == null) {
+ hostSet = new HashSet<ImmutablePair<Host, Set<Property>>>();
+ }
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;
}
}