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;
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,
}
}
- public void started() {
- connectionEventThread = new Thread(new EventHandler(), "ConnectionEvent Thread");
+
+ 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();
}
public void init() {
- String schemeStr = System.getProperty("connection.scheme");
+ connectionEventThread = new Thread(new EventHandler(), "ConnectionEvent Thread");
this.connectionEvents = new LinkedBlockingQueue<ConnectionMgmtEvent>();
schemes = new ConcurrentHashMap<ConnectionMgmtScheme, AbstractScheme>();
- 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;
- }
- }
- }
}
- public void stop() {
+ public void stopping() {
connectionEventThread.interrupt();
Set<Node> localNodes = getLocalNodes();
if (localNodes != null) {
*/
protected ConcurrentMap <Node, Set<InetAddress>> 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);
}
}
return isConnectionAllowedInternal(node);
}
- @SuppressWarnings("deprecation")
public void handleClusterViewChanged() {
log.debug("Handling Cluster View changed notification");
List<InetAddress> controllers = clusterServices.getClusteredControllers();
}
public Set<Node> getNodes(InetAddress controller) {
- if (nodeConnections == null) return null;
ConcurrentMap <InetAddress, Set<Node>> controllerNodesMap = getControllerToNodesMap();
return controllerNodesMap.get(controller);
}
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) {
}
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) {
*/
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());
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 {
}
}
- @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<Node, Set<InetAddress>>) clusterServices.getCache("connectionmanager."+name+".nodeconnections");
+ nodeConnections = (ConcurrentMap<Node, Set<InetAddress>>) 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) {
import java.net.InetAddress;
import java.util.Set;
+
import org.opendaylight.controller.clustering.services.IClusterGlobalServices;
import org.opendaylight.controller.connectionmanager.ConnectionMgmtScheme;
import org.opendaylight.controller.sal.core.Node;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
class AnyControllerScheme extends AbstractScheme {
- private static final Logger logger = LoggerFactory.getLogger(AnyControllerScheme.class);
private static AbstractScheme myScheme= null;
protected AnyControllerScheme(IClusterGlobalServices clusterServices) {
return myScheme;
}
- @SuppressWarnings("deprecation")
@Override
public boolean isConnectionAllowedInternal(Node node) {
- if (nodeConnections == null) return true;
Set <InetAddress> controllers = nodeConnections.get(node);
if (controllers == null || controllers.size() == 0) return true;
return (controllers.size() == 1 && controllers.contains(clusterServices.getMyAddress()));
class SingleControllerScheme extends AbstractScheme {
- private static AbstractScheme myScheme= null;
+ private static AbstractScheme myScheme = null;
protected SingleControllerScheme(IClusterGlobalServices clusterServices) {
super(clusterServices, ConnectionMgmtScheme.SINGLE_CONTROLLER);
return myScheme;
}
- @SuppressWarnings("deprecation")
@Override
public boolean isConnectionAllowedInternal(Node node) {
- if (nodeConnections == null) return true;
// Lets make it simple. The Cluster Coordinator is the master
- if (clusterServices.amICoordinator()) return true;
- return false;
+ return clusterServices.amICoordinator();
}
}
\ No newline at end of file
props.addAll(prop);
}
nodeConnectorProps.put(entry.getKey(), props);
- notifyInventoryShimListener(entry.getKey(), UpdateType.ADDED,
- entry.getValue());
+ notifyInventoryShimListener(entry.getKey(), UpdateType.ADDED, entry.getValue());
}
// Add this node
}
}
- private void notifyInventoryShimExternalListener(Node node,
- UpdateType type, Set<Property> props) {
+ private void notifyInventoryShimExternalListener(Node node, UpdateType type, Set<Property> props) {
for (IInventoryShimExternalListener s : this.inventoryShimExternalListeners) {
s.updateNode(node, type, props);
}
}
- private void notifyInventoryShimExternalListener(
- NodeConnector nodeConnector, UpdateType type, Set<Property> props) {
+ private void notifyInventoryShimExternalListener(NodeConnector nodeConnector, UpdateType type, Set<Property> props) {
for (IInventoryShimExternalListener s : this.inventoryShimExternalListeners) {
s.updateNodeConnector(nodeConnector, type, props);
}
private void notifyInventoryShimInternalListener(String container,
NodeConnector nodeConnector, UpdateType type, Set<Property> props) {
- IInventoryShimInternalListener inventoryShimInternalListener = inventoryShimInternalListeners
- .get(container);
+ IInventoryShimInternalListener inventoryShimInternalListener = inventoryShimInternalListeners.get(container);
if (inventoryShimInternalListener != null) {
- inventoryShimInternalListener.updateNodeConnector(nodeConnector,
- type, props);
- logger.trace(
- "notifyInventoryShimInternalListener {} type {} for container {}",
- new Object[] { nodeConnector, type, container });
+ inventoryShimInternalListener.updateNodeConnector(nodeConnector, type, props);
+ logger.trace("notifyInventoryShimInternalListener {} type {} for container {}", new Object[] {
+ nodeConnector, type, container });
}
}
notifyInventoryShimInternalListener(container, nodeConnector, type, props);
}
- // Notify DiscoveryService
+ // Notify plugin listeners (Discovery, DataPacket, OFstats etc.)
notifyInventoryShimExternalListener(nodeConnector, type, props);
logger.debug("Connection service accepted the inventory notification for {} {}", nodeConnector, type);
if (isNodeLocal) {
// Now notify other containers
- Set<String> containers = (nodeContainerMap.get(node) == null) ? new HashSet<String>() : new HashSet<String>(
- nodeContainerMap.get(node));
+ Set<String> containers = (nodeContainerMap.get(node) == null) ? new HashSet<String>()
+ : new HashSet<String>(nodeContainerMap.get(node));
containers.add(GlobalConstants.DEFAULT.toString());
for (String container : containers) {
notifyInventoryShimInternalListener(container, node, type, props);
}
- // Notify external listener
+
+ // Notify plugin listeners (Discovery, DataPacket, OFstats etc.)
notifyInventoryShimExternalListener(node, type, props);
logger.debug("Connection service accepted the inventory notification for {} {}", node, type);
private void notifyGlobalInventoryShimInternalListener(Node node, UpdateType type, Set<Property> props) {
for (IInventoryShimInternalListener globalListener : globalInventoryShimInternalListeners) {
globalListener.updateNode(node, type, props);
- logger.trace(
- "notifyGlobalInventoryShimInternalListener {} type {}",
- new Object[] { node, type });
+ logger.trace("notifyGlobalInventoryShimInternalListener {} type {}", new Object[] { node, type });
}
}
import org.slf4j.LoggerFactory;
/**
- * It periodically polls the different OF statistics from the OF switches and
- * caches them for quick retrieval for the above layers' modules It also
- * provides an API to directly query the switch about the statistics
+ * Periodically polls the different OF statistics from the OF switches, caches
+ * them, and publishes results towards SAL. It also provides an API to directly
+ * query the switch for any specific statistics.
*/
-public class OFStatisticsManager implements IOFStatisticsManager,
-IInventoryShimExternalListener, CommandProvider {
+public class OFStatisticsManager implements IOFStatisticsManager, IInventoryShimExternalListener, CommandProvider {
private static final Logger log = LoggerFactory.getLogger(OFStatisticsManager.class);
private static final int INITIAL_SIZE = 64;
private static final long FLOW_STATS_PERIOD = 10000;
}
for (InetAddress i : IPs) {
Subnet existingSubnet = subnets.get(i);
- if ((existingSubnet != null)
- && !existingSubnet.isMutualExclusive(newSubnet)) {
- return new Status(StatusCode.CONFLICT);
+ if ((existingSubnet != null) && !existingSubnet.isMutualExclusive(newSubnet)) {
+ return new Status(StatusCode.CONFLICT, "This subnet conflicts with an existing one.");
}
}
return new Status(StatusCode.SUCCESS);
// Presence check
if (subnetsConfigList.containsKey(conf.getName())) {
return new Status(StatusCode.CONFLICT,
- "Subnet with the specified name already configured.");
+ "Subnet with the specified name already exists.");
}
// Semantic check
status = semanticCheck(conf);
}
@RequestMapping(value = "logout")
- public String login(Map<String, Object> model,
- final HttpServletRequest request) {
+ public String logout(Map<String, Object> model, final HttpServletRequest request) {
IUserManager userManager = (IUserManager) ServiceHelper
.getGlobalInstance(IUserManager.class, this);