From baf00b337b0d54a1aa5a83f5b125470e2a856bdd Mon Sep 17 00:00:00 2001 From: Madhu Venugopal Date: Wed, 18 Sep 2013 06:04:10 -0700 Subject: [PATCH] Adding Tri-states to the connection manager locality check. As of now, the connection manager's isLocal() provides a binary true/false for a locality. But is missing a key state of not-connected. This is now included as part of a new API (getLocalityStatus). Retaining the isLocal as a deprecated method to be removed later once all the users have migrated. Change-Id: I0feddf2a86770740f441060bd411f28d1bb15610 Signed-off-by: Madhu Venugopal --- .../connectionmanager/ConnectionLocality.java | 28 +++++++++++++++++++ .../connectionmanager/IConnectionManager.java | 17 ++++++++++- .../internal/ConnectionManager.java | 8 ++++++ .../scheme/AbstractScheme.java | 10 +++++++ .../internal/ForwardingRulesManager.java | 7 +++-- 5 files changed, 66 insertions(+), 4 deletions(-) create mode 100644 opendaylight/connectionmanager/api/src/main/java/org/opendaylight/controller/connectionmanager/ConnectionLocality.java diff --git a/opendaylight/connectionmanager/api/src/main/java/org/opendaylight/controller/connectionmanager/ConnectionLocality.java b/opendaylight/connectionmanager/api/src/main/java/org/opendaylight/controller/connectionmanager/ConnectionLocality.java new file mode 100644 index 0000000000..347ca07ec1 --- /dev/null +++ b/opendaylight/connectionmanager/api/src/main/java/org/opendaylight/controller/connectionmanager/ConnectionLocality.java @@ -0,0 +1,28 @@ +package org.opendaylight.controller.connectionmanager; + +public enum ConnectionLocality { + /** + * This controller is the (or one of the) master for a given node + */ + LOCAL("This controller is the (or one of the) master for a given node"), + + /** + * This controller is not the master for a given node + */ + NOT_LOCAL("This controller is not the master for a given node"), + + /** + * The given node is not connected to any of the controllers in the cluster + */ + NOT_CONNECTED("The given node is not connected to any of the controllers in the cluster"); + + private ConnectionLocality(String description) { + this.description = description; + } + + private String description; + + public String toString() { + return description; + } +} diff --git a/opendaylight/connectionmanager/api/src/main/java/org/opendaylight/controller/connectionmanager/IConnectionManager.java b/opendaylight/connectionmanager/api/src/main/java/org/opendaylight/controller/connectionmanager/IConnectionManager.java index 12b196989e..788af16248 100644 --- a/opendaylight/connectionmanager/api/src/main/java/org/opendaylight/controller/connectionmanager/IConnectionManager.java +++ b/opendaylight/connectionmanager/api/src/main/java/org/opendaylight/controller/connectionmanager/IConnectionManager.java @@ -54,12 +54,27 @@ public interface IConnectionManager { public Set getLocalNodes(); /** + * @deprecated Use getLocalityStatus(Node node) instead. + * * Method to test if a node is local to a controller. * - * @return true if node is local to this controller. false otherwise. + * @param node The node for which the locality is being tested + * @return true if node is local to this controller.
+ * false if either node is not connected to this controller or + * not connected to any other controllers in the cluster. */ public boolean isLocal(Node node); + /** + * getLocalityStatus provides the tri-state connectivity status as opposed to the + * binary status returned by isLocal. + * ConnectionLocality enum that is returned by this method also includes the case of + * a Node not connected to any of the controllers in the cluster. + * @param node The node for which the locality is being verified + * @return ConnectionLocality + */ + public ConnectionLocality getLocalityStatus(Node node); + /** * Disconnect a Node from the controller. * 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 bd377190f2..df5175083b 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 @@ -37,6 +37,7 @@ import org.eclipse.osgi.framework.console.CommandProvider; import org.opendaylight.controller.clustering.services.ICacheUpdateAware; import org.opendaylight.controller.clustering.services.IClusterGlobalServices; import org.opendaylight.controller.clustering.services.ICoordinatorChangeAware; +import org.opendaylight.controller.connectionmanager.ConnectionLocality; import org.opendaylight.controller.connectionmanager.ConnectionMgmtScheme; import org.opendaylight.controller.connectionmanager.IConnectionManager; import org.opendaylight.controller.connectionmanager.scheme.AbstractScheme; @@ -185,6 +186,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); diff --git a/opendaylight/connectionmanager/implementation/src/main/java/org/opendaylight/controller/connectionmanager/scheme/AbstractScheme.java b/opendaylight/connectionmanager/implementation/src/main/java/org/opendaylight/controller/connectionmanager/scheme/AbstractScheme.java index 06b72219f7..78f274c717 100644 --- a/opendaylight/connectionmanager/implementation/src/main/java/org/opendaylight/controller/connectionmanager/scheme/AbstractScheme.java +++ b/opendaylight/connectionmanager/implementation/src/main/java/org/opendaylight/controller/connectionmanager/scheme/AbstractScheme.java @@ -14,6 +14,7 @@ import org.opendaylight.controller.clustering.services.CacheConfigException; import org.opendaylight.controller.clustering.services.CacheExistException; import org.opendaylight.controller.clustering.services.IClusterGlobalServices; import org.opendaylight.controller.clustering.services.IClusterServices; +import org.opendaylight.controller.connectionmanager.ConnectionLocality; import org.opendaylight.controller.connectionmanager.ConnectionMgmtScheme; import org.opendaylight.controller.sal.core.Node; import org.opendaylight.controller.sal.utils.Status; @@ -146,6 +147,15 @@ public abstract class AbstractScheme { return (controllers != null && controllers.contains(myController)); } + public ConnectionLocality getLocalityStatus(Node node) { + if (nodeConnections == null) return ConnectionLocality.NOT_CONNECTED; + Set controllers = nodeConnections.get(node); + if (controllers == null || controllers.size() == 0) return ConnectionLocality.NOT_CONNECTED; + InetAddress myController = clusterServices.getMyAddress(); + return controllers.contains(myController) ? ConnectionLocality.LOCAL: + ConnectionLocality.NOT_LOCAL; + } + public Status removeNode (Node node) { return removeNodeFromController(node, clusterServices.getMyAddress()); } diff --git a/opendaylight/forwardingrulesmanager/implementation/src/main/java/org/opendaylight/controller/forwardingrulesmanager/internal/ForwardingRulesManager.java b/opendaylight/forwardingrulesmanager/implementation/src/main/java/org/opendaylight/controller/forwardingrulesmanager/internal/ForwardingRulesManager.java index 4e6818c306..6e3e6b6633 100644 --- a/opendaylight/forwardingrulesmanager/implementation/src/main/java/org/opendaylight/controller/forwardingrulesmanager/internal/ForwardingRulesManager.java +++ b/opendaylight/forwardingrulesmanager/implementation/src/main/java/org/opendaylight/controller/forwardingrulesmanager/internal/ForwardingRulesManager.java @@ -39,6 +39,7 @@ import org.opendaylight.controller.clustering.services.ICacheUpdateAware; import org.opendaylight.controller.clustering.services.IClusterContainerServices; import org.opendaylight.controller.clustering.services.IClusterServices; import org.opendaylight.controller.configuration.IConfigurationContainerAware; +import org.opendaylight.controller.connectionmanager.ConnectionLocality; import org.opendaylight.controller.connectionmanager.IConnectionManager; import org.opendaylight.controller.forwardingrulesmanager.FlowConfig; import org.opendaylight.controller.forwardingrulesmanager.FlowEntry; @@ -273,7 +274,7 @@ public class ForwardingRulesManager implements } Node n = e.getNode(); - if (!connectionManager.isLocal(n)) { + if (connectionManager.getLocalityStatus(n) == ConnectionLocality.NOT_LOCAL) { Callable> worker = new DistributeOrderCallable(e, u, t); if (worker != null) { Future> workerRes = this.executor.submit(worker); @@ -291,7 +292,7 @@ public class ForwardingRulesManager implements } } - logsync.trace("LOCAL Node {} so processing Entry:{} UpdateType:{}", n, e, t); + logsync.trace("Node {} could be local. so processing Entry:{} UpdateType:{}", n, e, t); return null; } @@ -3109,7 +3110,7 @@ public class ForwardingRulesManager implements return; } Node n = fei.getNode(); - if (connectionManager.isLocal(n)) { + if (connectionManager.getLocalityStatus(n) == ConnectionLocality.LOCAL) { logsync.trace("workOrder for fe {} processed locally", fe); // I'm the controller in charge for the request, queue it for // processing -- 2.36.6