X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fclustering%2Fservices_implementation%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fclustering%2Fservices_implementation%2Finternal%2FClusterManager.java;h=c3fd30ae9b65629c8e83bb7f789229b0b6bc5870;hp=476b1b12f55370acaf22465f31378ad67a21bb6f;hb=4e06c6354cac421b1fd74a00a22df9afffc5e494;hpb=d192c699590d441eb96a697b9e8ab7a028f18860 diff --git a/opendaylight/clustering/services_implementation/src/main/java/org/opendaylight/controller/clustering/services_implementation/internal/ClusterManager.java b/opendaylight/clustering/services_implementation/src/main/java/org/opendaylight/controller/clustering/services_implementation/internal/ClusterManager.java index 476b1b12f5..c3fd30ae9b 100644 --- a/opendaylight/clustering/services_implementation/src/main/java/org/opendaylight/controller/clustering/services_implementation/internal/ClusterManager.java +++ b/opendaylight/clustering/services_implementation/src/main/java/org/opendaylight/controller/clustering/services_implementation/internal/ClusterManager.java @@ -9,8 +9,6 @@ package org.opendaylight.controller.clustering.services_implementation.internal; -import java.io.PrintWriter; -import java.io.StringWriter; import java.net.InetAddress; import java.net.NetworkInterface; import java.net.SocketException; @@ -54,10 +52,11 @@ import org.opendaylight.controller.clustering.services.IClusterServices; import org.opendaylight.controller.clustering.services.IGetUpdates; import org.opendaylight.controller.clustering.services.IListenRoleChange; import org.opendaylight.controller.clustering.services.ListenRoleChangeAddException; +import org.opendaylight.controller.sal.core.IContainerAware; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public class ClusterManager implements IClusterServices { +public class ClusterManager implements IClusterServices, IContainerAware { protected static final Logger logger = LoggerFactory .getLogger(ClusterManager.class); private DefaultCacheManager cm; @@ -99,10 +98,10 @@ public class ClusterManager implements IClusterServices { try { Enumeration e = NetworkInterface.getNetworkInterfaces(); while (e.hasMoreElements()) { - NetworkInterface n = (NetworkInterface) e.nextElement(); + NetworkInterface n = e.nextElement(); Enumeration ee = n.getInetAddresses(); while (ee.hasMoreElements()) { - InetAddress i = (InetAddress) ee.nextElement(); + InetAddress i = ee.nextElement(); myAddresses.add(i); } } @@ -113,15 +112,15 @@ public class ClusterManager implements IClusterServices { } while (supernodes.hasMoreTokens()) { String curr_supernode = supernodes.nextToken(); - logger.debug("Examining supernode " + curr_supernode); + logger.debug("Examining supernode {}", curr_supernode); StringTokenizer host_port = new StringTokenizer(curr_supernode, "[]"); String host; String port; Integer port_num = gossipRouterPortDefault; if (host_port.countTokens() > 2) { - logger.error("Error parsing supernode " + curr_supernode - + " proceed to the next one"); + logger.error("Error parsing supernode {} proceed to the next one", + curr_supernode); continue; } host = host_port.nextToken(); @@ -184,13 +183,13 @@ public class ClusterManager implements IClusterServices { for (InetAddress myAddr : myAddresses) { if (myAddr.isLoopbackAddress() || myAddr.isLinkLocalAddress()) { - logger.debug("Skipping local address " - + myAddr.getHostAddress()); + logger.debug("Skipping local address {}", + myAddr.getHostAddress()); continue; } else { // First non-local address myBind = myAddr.getHostAddress(); - logger.debug("First non-local address " + myBind); + logger.debug("First non-local address {}", myBind); break; } } @@ -199,7 +198,7 @@ public class ClusterManager implements IClusterServices { .getProperty("jgroups.tcp.address"); if (jgroupAddress == null) { if (myBind != null) { - logger.debug("Set bind address to be " + myBind); + logger.debug("Set bind address to be {}", myBind); System.setProperty("jgroups.tcp.address", myBind); } else { logger @@ -207,8 +206,8 @@ public class ClusterManager implements IClusterServices { System.setProperty("jgroups.tcp.address", "127.0.0.1"); } } else { - logger.debug("jgroup.tcp.address already set to be " - + jgroupAddress); + logger.debug("jgroup.tcp.address already set to be {}", + jgroupAddress); } } catch (UnknownHostException uhe) { logger @@ -220,14 +219,14 @@ public class ClusterManager implements IClusterServices { // host list System.setProperty("jgroups.tcpgossip.initial_hosts", sanitized_supernodes_list.toString()); - logger.debug("jgroups.tcp.address set to " - + System.getProperty("jgroups.tcp.address")); - logger.debug("jgroups.tcpgossip.initial_hosts set to " - + System.getProperty("jgroups.tcpgossip.initial_hosts")); + logger.debug("jgroups.tcp.address set to {}", + System.getProperty("jgroups.tcp.address")); + logger.debug("jgroups.tcpgossip.initial_hosts set to {}", + System.getProperty("jgroups.tcpgossip.initial_hosts")); GossipRouter res = null; if (amIGossipRouter) { - logger.info("I'm a GossipRouter will listen on port " - + gossipRouterPort); + logger.info("I'm a GossipRouter will listen on port {}", + gossipRouterPort); res = new GossipRouter(gossipRouterPort); } return res; @@ -241,16 +240,14 @@ public class ClusterManager implements IClusterServices { this.gossiper.start(); logger.info("Started GossipRouter"); } catch (Exception e) { - logger.error("GossipRouter didn't start exception " + e - + " met"); - logger.error("Stack Trace that raised the exception"); - logger.error("",e); + logger.error("GossipRouter didn't start. Exception Stack Trace", + e); } } logger.info("Starting the ClusterManager"); try { //FIXME keeps throwing FileNotFoundException - this.cm = new DefaultCacheManager("/config/infinispan-config.xml"); + this.cm = new DefaultCacheManager("config/infinispan-config.xml"); logger.debug("Allocated ClusterManager"); if (this.cm != null) { this.cm.start(); @@ -264,7 +261,7 @@ public class ClusterManager implements IClusterServices { this.cm = null; this.stop(); } - logger.debug("Cache Manager has value " + this.cm); + logger.debug("Cache Manager has value {}", this.cm); } public void stop() { @@ -564,25 +561,29 @@ public class ClusterManager implements IClusterServices { return null; } + @Override public List getClusteredControllers() { EmbeddedCacheManager manager = this.cm; if (manager == null) { return null; } List
controllers = manager.getMembers(); - if ((controllers == null) || controllers.size() == 0) + if ((controllers == null) || controllers.size() == 0) { return null; + } List clusteredControllers = new ArrayList(); for (Address a : controllers) { InetAddress inetAddress = addressToInetAddress(a); if (inetAddress != null - && !inetAddress.getHostAddress().equals(loopbackAddress)) + && !inetAddress.getHostAddress().equals(loopbackAddress)) { clusteredControllers.add(inetAddress); + } } return clusteredControllers; } + @Override public InetAddress getMyAddress() { EmbeddedCacheManager manager = this.cm; if (manager == null) { @@ -662,4 +663,21 @@ public class ClusterManager implements IClusterServices { } } } + + private void removeContainerCaches(String containerName) { + logger.info("Destroying caches for container {}", containerName); + for (String cacheName : this.getCacheList(containerName)) { + this.destroyCache(containerName, cacheName); + } + } + + @Override + public void containerCreate(String arg0) { + // no op + } + + @Override + public void containerDestroy(String container) { + removeContainerCaches(container); + } }