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%2Fscheme%2FAbstractScheme.java;h=d7b1968429c7de4fb0053b76b8dc135984fc69e3;hp=f4c7bd2ff77fcda8874ca39db7d7c404ccf04aa7;hb=dfec2688d4213adc433187295d6667cea746d68c;hpb=74c92401812b8e77e8ceade6e8714d0fc1c35d3a 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 f4c7bd2ff7..d7b1968429 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 @@ -10,13 +10,12 @@ import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; -import javax.transaction.SystemException; - 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.ConnectionMgmtScheme; +import org.opendaylight.controller.sal.connection.ConnectionLocality; import org.opendaylight.controller.sal.core.Node; import org.opendaylight.controller.sal.utils.Status; import org.opendaylight.controller.sal.utils.StatusCode; @@ -36,15 +35,18 @@ public abstract class AbstractScheme { */ protected ConcurrentMap > nodeConnections; protected abstract boolean isConnectionAllowedInternal(Node node); - private String name; + private final String name; + private final String nodeConnectionsCacheName; protected AbstractScheme(IClusterGlobalServices clusterServices, ConnectionMgmtScheme type) { this.clusterServices = clusterServices; - if (type != null) name = type.name(); - else name = "UNKNOWN"; + name = (type != null ? type.name() : "UNKNOWN"); + nodeConnectionsCacheName = "connectionmanager."+name+".nodeconnections"; if (clusterServices != null) { allocateCaches(); retrieveCaches(); + } else { + log.error("Couldn't retrieve caches for scheme %s. Clustering service unavailable", name); } } @@ -73,7 +75,6 @@ public abstract class AbstractScheme { return isConnectionAllowedInternal(node); } - @SuppressWarnings("deprecation") public void handleClusterViewChanged() { log.debug("Handling Cluster View changed notification"); List controllers = clusterServices.getClusteredControllers(); @@ -123,12 +124,10 @@ public abstract class AbstractScheme { } public Set getNodes(InetAddress controller) { - if (nodeConnections == null) return null; ConcurrentMap > controllerNodesMap = getControllerToNodesMap(); return controllerNodesMap.get(controller); } - @SuppressWarnings("deprecation") public Set getNodes() { return getNodes(clusterServices.getMyAddress()); } @@ -142,7 +141,6 @@ public abstract class AbstractScheme { return nodeConnections; } - @SuppressWarnings("deprecation") public boolean isLocal(Node node) { if (nodeConnections == null) return false; InetAddress myController = clusterServices.getMyAddress(); @@ -150,14 +148,22 @@ public abstract class AbstractScheme { return (controllers != null && controllers.contains(myController)); } - @SuppressWarnings("deprecation") + 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()); } protected Status removeNodeFromController (Node node, InetAddress controller) { if (node == null || controller == null) { - return new Status(StatusCode.BADREQUEST); + return new Status(StatusCode.BADREQUEST, "Invalid Node or Controller Address Specified."); } if (clusterServices == null || nodeConnections == null) { @@ -184,7 +190,7 @@ public abstract class AbstractScheme { } clusterServices.tcommit(); } catch (Exception e) { - log.error("Excepion in removing Controller from a Node", e); + log.error("Exception in removing Controller from a Node", e); try { clusterServices.trollback(); } catch (Exception e1) { @@ -205,7 +211,7 @@ public abstract class AbstractScheme { */ private Status putNodeToController (Node node, InetAddress controller) { if (clusterServices == null || nodeConnections == null) { - return new Status(StatusCode.SUCCESS); + return new Status(StatusCode.INTERNALERROR, "Cluster service unavailable, or node connections info missing."); } log.debug("Trying to Put {} to {}", controller.getHostAddress(), node.toString()); @@ -272,7 +278,9 @@ public abstract class AbstractScheme { if (node == null || controller == null) { return new Status(StatusCode.BADREQUEST); } - if (isLocal(node)) return new Status(StatusCode.SUCCESS); + if (isLocal(node)) { + return new Status(StatusCode.SUCCESS); + } if (isConnectionAllowed(node)) { return putNodeToController(node, controller); } else { @@ -280,36 +288,34 @@ public abstract class AbstractScheme { } } - @SuppressWarnings("deprecation") public Status addNode (Node node) { return addNode(node, clusterServices.getMyAddress()); } - @SuppressWarnings({ "unchecked", "deprecation" }) + @SuppressWarnings({ "unchecked" }) private void retrieveCaches() { if (this.clusterServices == null) { - log.error("un-initialized clusterServices, can't retrieve cache"); + log.error("Un-initialized Cluster Services, can't retrieve caches for scheme: {}", name); return; } - nodeConnections = (ConcurrentMap>) clusterServices.getCache("connectionmanager."+name+".nodeconnections"); + nodeConnections = (ConcurrentMap>) clusterServices.getCache(nodeConnectionsCacheName); if (nodeConnections == null) { - log.error("\nFailed to get caches"); + log.error("\nFailed to get cache: {}", nodeConnectionsCacheName); } } - @SuppressWarnings("deprecation") private void allocateCaches() { if (this.clusterServices == null) { - log.error("un-initialized clusterServices, can't create cache"); + log.error("Un-initialized clusterServices, can't create cache"); return; } try { - clusterServices.createCache("connectionmanager."+name+".nodeconnections", EnumSet.of(IClusterServices.cacheMode.TRANSACTIONAL)); + clusterServices.createCache(nodeConnectionsCacheName, EnumSet.of(IClusterServices.cacheMode.TRANSACTIONAL)); } catch (CacheExistException cee) { - log.error("\nCache already exists - destroy and recreate if needed"); + log.debug("\nCache already exists: {}", nodeConnectionsCacheName); } catch (CacheConfigException cce) { log.error("\nCache configuration invalid - check cache mode"); } catch (Exception e) {