X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fconnectionmanager%2Fimplementation%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fconnectionmanager%2Finternal%2FConnectionManager.java;h=1beb7fe0bb609860865ed52347f27bfe126aeb2e;hp=fdba533b5bfa827bf2ccd79bf2f061785d06d597;hb=dfec2688d4213adc433187295d6667cea746d68c;hpb=b497dc0e387e4aa025e9cbe19d94b1406cc56fc2 diff --git a/opendaylight/connectionmanager/implementation/src/main/java/org/opendaylight/controller/connectionmanager/internal/ConnectionManager.java b/opendaylight/connectionmanager/implementation/src/main/java/org/opendaylight/controller/connectionmanager/internal/ConnectionManager.java index fdba533b5b..1beb7fe0bb 100644 --- a/opendaylight/connectionmanager/implementation/src/main/java/org/opendaylight/controller/connectionmanager/internal/ConnectionManager.java +++ b/opendaylight/connectionmanager/implementation/src/main/java/org/opendaylight/controller/connectionmanager/internal/ConnectionManager.java @@ -30,9 +30,6 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; import java.util.concurrent.LinkedBlockingQueue; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import org.eclipse.osgi.framework.console.CommandInterpreter; import org.eclipse.osgi.framework.console.CommandProvider; import org.opendaylight.controller.clustering.services.ICacheUpdateAware; @@ -43,17 +40,21 @@ import org.opendaylight.controller.connectionmanager.IConnectionManager; import org.opendaylight.controller.connectionmanager.scheme.AbstractScheme; import org.opendaylight.controller.connectionmanager.scheme.SchemeFactory; import org.opendaylight.controller.sal.connection.ConnectionConstants; +import org.opendaylight.controller.sal.connection.ConnectionLocality; import org.opendaylight.controller.sal.connection.IConnectionListener; import org.opendaylight.controller.sal.connection.IConnectionService; import org.opendaylight.controller.sal.core.Node; import org.opendaylight.controller.sal.core.NodeConnector; import org.opendaylight.controller.sal.core.Property; import org.opendaylight.controller.sal.core.UpdateType; +import org.opendaylight.controller.sal.inventory.IInventoryService; import org.opendaylight.controller.sal.inventory.IListenInventoryUpdates; import org.opendaylight.controller.sal.utils.Status; import org.opendaylight.controller.sal.utils.StatusCode; import org.osgi.framework.BundleContext; import org.osgi.framework.FrameworkUtil; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public class ConnectionManager implements IConnectionManager, IConnectionListener, ICoordinatorChangeAware, IListenInventoryUpdates, @@ -66,6 +67,7 @@ public class ConnectionManager implements IConnectionManager, IConnectionListene private IConnectionService connectionService; private Thread connectionEventThread; private BlockingQueue connectionEvents; + private IInventoryService inventoryService; public void setClusterServices(IClusterGlobalServices i) { this.clusterServices = i; @@ -87,24 +89,68 @@ public class ConnectionManager implements IConnectionManager, IConnectionListene } } - public void started() { - connectionEventThread = new Thread(new EventHandler(), "ConnectionEvent Thread"); + public void setInventoryService(IInventoryService service) { + logger.trace("Got inventory service set request {}", service); + this.inventoryService = service; + } + + public void unsetInventoryService(IInventoryService service) { + logger.trace("Got a service UNset request"); + this.inventoryService = null; + } + + private void getInventories() { + Map> nodeProp = this.inventoryService.getNodeProps(); + for (Map.Entry> entry : nodeProp.entrySet()) { + Node node = entry.getKey(); + logger.debug("getInventories for node:{}", new Object[] { node }); + Map propMap = entry.getValue(); + Set props = new HashSet(); + for (Property property : propMap.values()) { + props.add(property); + } + updateNode(node, UpdateType.ADDED, props); + } + + Map> nodeConnectorProp = this.inventoryService.getNodeConnectorProps(); + for (Map.Entry> entry : nodeConnectorProp.entrySet()) { + Map propMap = entry.getValue(); + Set props = new HashSet(); + for (Property property : propMap.values()) { + props.add(property); + } + updateNodeConnector(entry.getKey(), UpdateType.ADDED, props); + } + } + + + public void started() { + String schemeStr = System.getProperty("connection.scheme"); + for (ConnectionMgmtScheme scheme : ConnectionMgmtScheme.values()) { + AbstractScheme schemeImpl = SchemeFactory.getScheme(scheme, clusterServices); + if (schemeImpl != null) { + schemes.put(scheme, schemeImpl); + if (scheme.name().equalsIgnoreCase(schemeStr)) { + activeScheme = scheme; + } + } + } + connectionEventThread.start(); registerWithOSGIConsole(); notifyClusterViewChanged(); + // Should pull the Inventory updates in case we missed it + getInventories(); } public void init() { + connectionEventThread = new Thread(new EventHandler(), "ConnectionEvent Thread"); this.connectionEvents = new LinkedBlockingQueue(); schemes = new ConcurrentHashMap(); - for (ConnectionMgmtScheme scheme : ConnectionMgmtScheme.values()) { - AbstractScheme schemeImpl = SchemeFactory.getScheme(scheme, clusterServices); - if (schemeImpl != null) schemes.put(scheme, schemeImpl); - } } - public void stop() { + public void stopping() { connectionEventThread.interrupt(); Set localNodes = getLocalNodes(); if (localNodes != null) { @@ -142,6 +188,13 @@ public class ConnectionManager implements IConnectionManager, IConnectionListene return scheme.isLocal(node); } + @Override + public ConnectionLocality getLocalityStatus(Node node) { + AbstractScheme scheme = schemes.get(activeScheme); + if (scheme == null) return ConnectionLocality.NOT_CONNECTED; + return scheme.getLocalityStatus(node); + } + @Override public void updateNode(Node node, UpdateType type, Set props) { logger.debug("updateNode: {} type {} props {}", node, type, props); @@ -315,18 +368,23 @@ public class ConnectionManager implements IConnectionManager, IConnectionListene String controller = ci.nextArgument(); if (controller == null) { ci.println("Nodes connected to this controller : "); - if (this.getLocalNodes() == null) ci.println("None"); - else ci.println(this.getLocalNodes().toString()); + if (this.getLocalNodes() == null) { + ci.println("None"); + } else { + ci.println(this.getLocalNodes().toString()); + } return; } try { InetAddress address = InetAddress.getByName(controller); ci.println("Nodes connected to controller "+controller); - if (this.getNodes(address) == null) ci.println("None"); - else ci.println(this.getNodes(address).toString()); - return; + if (this.getNodes(address) == null) { + ci.println("None"); + } else { + ci.println(this.getNodes(address).toString()); + } } catch (UnknownHostException e) { - e.printStackTrace(); + logger.error("An error occured",e); } }