From: Alessandro Boch Date: Thu, 18 Jul 2013 19:47:56 +0000 (-0700) Subject: Cluster mgr to remove caches when container is destroyed X-Git-Tag: releasepom-0.1.0~274 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=commitdiff_plain;h=4e06c6354cac421b1fd74a00a22df9afffc5e494 Cluster mgr to remove caches when container is destroyed DESCRIPTION: When a container is destroyed, cluster manager should clear all the caches that were allocated in that container. CHANGE: Have cluster mgr implement IContainerAware and cleanup the caches on the container destroy notification Signed-off-by: Alessandro Boch --- diff --git a/opendaylight/clustering/services_implementation/src/main/java/org/opendaylight/controller/clustering/services_implementation/internal/Activator.java b/opendaylight/clustering/services_implementation/src/main/java/org/opendaylight/controller/clustering/services_implementation/internal/Activator.java index cb96ad5c8e..5a39e9ec4f 100644 --- a/opendaylight/clustering/services_implementation/src/main/java/org/opendaylight/controller/clustering/services_implementation/internal/Activator.java +++ b/opendaylight/clustering/services_implementation/src/main/java/org/opendaylight/controller/clustering/services_implementation/internal/Activator.java @@ -10,6 +10,7 @@ package org.opendaylight.controller.clustering.services_implementation.internal; import org.opendaylight.controller.sal.core.ComponentActivatorAbstractBase; +import org.opendaylight.controller.sal.core.IContainerAware; import org.opendaylight.controller.clustering.services.ICacheUpdateAware; import org.opendaylight.controller.clustering.services.IClusterContainerServices; @@ -30,6 +31,7 @@ public class Activator extends ComponentActivatorAbstractBase { * ComponentActivatorAbstractBase. * */ + @Override public void init() { } @@ -38,6 +40,7 @@ public class Activator extends ComponentActivatorAbstractBase { * cleanup done by ComponentActivatorAbstractBase * */ + @Override public void destroy() { } @@ -50,6 +53,7 @@ public class Activator extends ComponentActivatorAbstractBase { * instantiated in order to get an fully working implementation * Object */ + @Override public Object[] getGlobalImplementations() { Object[] res = { ClusterManager.class, ClusterGlobalManager.class }; return res; @@ -64,6 +68,7 @@ public class Activator extends ComponentActivatorAbstractBase { * instantiated in order to get an fully working implementation * Object */ + @Override public Object[] getImplementations() { Object[] res = { ClusterContainerManager.class }; return res; @@ -82,6 +87,7 @@ public class Activator extends ComponentActivatorAbstractBase { * also optional per-container different behavior if needed, usually * should not be the case though. */ + @Override public void configureInstance(Component c, Object imp, String containerName) { if (imp.equals(ClusterContainerManager.class)) { c.setInterface(new String[] { IClusterContainerServices.class.getName() }, @@ -118,10 +124,11 @@ public class Activator extends ComponentActivatorAbstractBase { * needed as long as the same routine can configure multiple * implementations */ + @Override public void configureGlobalInstance(Component c, Object imp) { if (imp.equals(ClusterManager.class)) { // export the service for Apps and Plugins - c.setInterface(new String[] { IClusterServices.class.getName() }, null); + c.setInterface(new String[] { IClusterServices.class.getName(), IContainerAware.class.getName() }, null); } if (imp.equals(ClusterGlobalManager.class)) { 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 0b2610797f..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); } } @@ -562,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) { @@ -660,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); + } }