Adding Tri-states to the connection manager locality check. 65/1265/1
authorMadhu Venugopal <vmadhu@cisco.com>
Wed, 18 Sep 2013 13:04:10 +0000 (06:04 -0700)
committerMadhu Venugopal <vmadhu@cisco.com>
Wed, 18 Sep 2013 13:04:10 +0000 (06:04 -0700)
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 <vmadhu@cisco.com>
opendaylight/connectionmanager/api/src/main/java/org/opendaylight/controller/connectionmanager/ConnectionLocality.java [new file with mode: 0644]
opendaylight/connectionmanager/api/src/main/java/org/opendaylight/controller/connectionmanager/IConnectionManager.java
opendaylight/connectionmanager/implementation/src/main/java/org/opendaylight/controller/connectionmanager/internal/ConnectionManager.java
opendaylight/connectionmanager/implementation/src/main/java/org/opendaylight/controller/connectionmanager/scheme/AbstractScheme.java
opendaylight/forwardingrulesmanager/implementation/src/main/java/org/opendaylight/controller/forwardingrulesmanager/internal/ForwardingRulesManager.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 (file)
index 0000000..347ca07
--- /dev/null
@@ -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;
+    }
+}
index 12b196989e4a0c4fa1f608cd7a479d224064555c..788af16248ccd62c8cc0760dbcb20134983b3cac 100644 (file)
@@ -54,12 +54,27 @@ public interface IConnectionManager {
     public Set<Node> 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.<br>
+     *         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.
      *
index bd377190f2d2f2911f3ae9b43edda2b2b0c39bc2..df5175083b1870ef99b29443d42003eb2bb179c5 100644 (file)
@@ -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<Property> props) {
         logger.debug("updateNode: {} type {} props {}", node, type, props);
index 06b72219f7fbddc5b5b17357f421f003691a36f7..78f274c717585993d13a3deeb86812a32ad4ad5a 100644 (file)
@@ -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<InetAddress> 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());
     }
index 4e6818c3062511b01c9b8f73d3f5fa610c73134d..6e3e6b6633b0fc6098ee6795dac661df71a20fed 100644 (file)
@@ -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<Future<Status>> worker = new DistributeOrderCallable(e, u, t);
             if (worker != null) {
                 Future<Future<Status>> 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