From: Alessandro Boch Date: Fri, 27 Sep 2013 00:47:33 +0000 (+0000) Subject: Merge "Introduce ASYNC caches and use them in FRM" X-Git-Tag: releasepom-0.1.0~7 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=commitdiff_plain;h=f3547ac7799c832edb82e61180bd03766fa4df89;hp=05a4e5db3a98ef1c38a8257ae3e947187aa56e13 Merge "Introduce ASYNC caches and use them in FRM" --- diff --git a/opendaylight/clustering/services/src/main/java/org/opendaylight/controller/clustering/services/IClusterServices.java b/opendaylight/clustering/services/src/main/java/org/opendaylight/controller/clustering/services/IClusterServices.java index 5551f23f72..77e300e95a 100644 --- a/opendaylight/clustering/services/src/main/java/org/opendaylight/controller/clustering/services/IClusterServices.java +++ b/opendaylight/clustering/services/src/main/java/org/opendaylight/controller/clustering/services/IClusterServices.java @@ -62,7 +62,19 @@ public interface IClusterServices { * immediately committed in the cache. * */ - NON_TRANSACTIONAL; + NON_TRANSACTIONAL, + /** + * Set on a cache that can transfer the updates asynchronously from the + * calling thread. The caller when doing put/clear/remove cannot expect + * that the operation has happened clusterwide + */ + ASYNC, + /** + * Set on a cache that transfer the updates synchronously to the calling + * thread so when getting back the operation is supposed to have + * completed on all the cluster nodes. Slow but safe. + */ + SYNC; } /** @@ -237,6 +249,7 @@ public interface IClusterServices { * * @return true if the role is the one of standby, else false */ + @Deprecated boolean amIStandby(); /** @@ -247,6 +260,7 @@ public interface IClusterServices { * * @return Address of the active controller */ + @Deprecated InetAddress getActiveAddress(); /** @@ -271,6 +285,7 @@ public interface IClusterServices { * * @param i Interface that will be called when the Role Change happens */ + @Deprecated void listenRoleChange(IListenRoleChange i) throws ListenRoleChangeAddException; @@ -281,5 +296,6 @@ public interface IClusterServices { * * @param i Interface that will be called when the Role Change happens */ + @Deprecated void unlistenRoleChange(IListenRoleChange i); } 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 4a67e76ab2..122063abba 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 @@ -33,6 +33,7 @@ import javax.transaction.TransactionManager; import org.infinispan.Cache; import org.infinispan.configuration.cache.Configuration; +import org.infinispan.configuration.cache.ConfigurationBuilder; import org.infinispan.configuration.global.GlobalConfigurationBuilder; import org.infinispan.configuration.parsing.ConfigurationBuilderHolder; import org.infinispan.configuration.parsing.ParserRegistry; @@ -304,24 +305,54 @@ public class ClusterManager implements IClusterServices { throw new CacheExistException(); } - // Sanity check to avoid contrasting parameters - if (cMode.containsAll(EnumSet.of( - IClusterServices.cacheMode.NON_TRANSACTIONAL, + // Sanity check to avoid contrasting parameters between transactional + // and not + if (cMode.containsAll(EnumSet.of(IClusterServices.cacheMode.NON_TRANSACTIONAL, IClusterServices.cacheMode.TRANSACTIONAL))) { throw new CacheConfigException(); } - if (cMode.contains(IClusterServices.cacheMode.NON_TRANSACTIONAL)) { - c = manager.getCache(realCacheName); - return c; - } else if (cMode.contains(IClusterServices.cacheMode.TRANSACTIONAL)) { - Configuration rc = manager - .getCacheConfiguration("transactional-type"); - manager.defineConfiguration(realCacheName, rc); - c = manager.getCache(realCacheName); - return c; + // Sanity check to avoid contrasting parameters between sync and async + if (cMode.containsAll(EnumSet.of(IClusterServices.cacheMode.SYNC, IClusterServices.cacheMode.ASYNC))) { + throw new CacheConfigException(); } - return null; + + Configuration fromTemplateConfig = null; + /* + * Fetch transactional/non-transactional templates + */ + // Check if transactional + if (cMode.contains(IClusterServices.cacheMode.TRANSACTIONAL)) { + fromTemplateConfig = manager.getCacheConfiguration("transactional-type"); + } else if (cMode.contains(IClusterServices.cacheMode.NON_TRANSACTIONAL)) { + fromTemplateConfig = manager.getDefaultCacheConfiguration(); + } + + // If none set the transactional property then just return null + if (fromTemplateConfig == null) { + return null; + } + + ConfigurationBuilder builder = new ConfigurationBuilder(); + builder.read(fromTemplateConfig); + /* + * Now evaluate async/sync + */ + if (cMode.contains(IClusterServices.cacheMode.ASYNC)) { + builder.clustering() + .cacheMode(fromTemplateConfig.clustering() + .cacheMode() + .toAsync()); + } else if (cMode.contains(IClusterServices.cacheMode.SYNC)) { + builder.clustering() + .cacheMode(fromTemplateConfig.clustering() + .cacheMode() + .toSync()); + } + + manager.defineConfiguration(realCacheName, builder.build()); + c = manager.getCache(realCacheName); + return c; } @Override diff --git a/opendaylight/clustering/services_implementation/src/test/java/org/opendaylight/controller/clustering/services_implementation/internal/ClusterManagerTest.java b/opendaylight/clustering/services_implementation/src/test/java/org/opendaylight/controller/clustering/services_implementation/internal/ClusterManagerTest.java index 736a2b23ec..ab0b63eb6d 100644 --- a/opendaylight/clustering/services_implementation/src/test/java/org/opendaylight/controller/clustering/services_implementation/internal/ClusterManagerTest.java +++ b/opendaylight/clustering/services_implementation/src/test/java/org/opendaylight/controller/clustering/services_implementation/internal/ClusterManagerTest.java @@ -89,8 +89,22 @@ public class ClusterManagerTest { Assert.assertTrue(true); } - // Create second cache properly this time, as non_transactional + // Create second cache NON_TRANSACTIONAL but with both ASYNC and SYNC, + // expect to complain cacheModeSet.remove(cacheMode.TRANSACTIONAL); + cacheModeSet.add(cacheMode.SYNC); + cacheModeSet.add(cacheMode.ASYNC); + try { + c2 = (CacheImpl) cm.createCache("Container1", "Cache2", cacheModeSet); + } catch (CacheExistException cee) { + Assert.assertTrue(false); + } catch (CacheConfigException cce) { + Assert.assertTrue(true); + } + + // Create second cache properly this time, as non_transactional and + // ASYNC + cacheModeSet.remove(cacheMode.SYNC); try { c2 = (CacheImpl) cm.createCache("Container1", "Cache2", cacheModeSet); diff --git a/opendaylight/forwardingrulesmanager/implementation/src/main/java/org/opendaylight/controller/forwardingrulesmanager/internal/ForwardingRulesManager.java b/opendaylight/forwardingrulesmanager/implementation/src/main/java/org/opendaylight/controller/forwardingrulesmanager/internal/ForwardingRulesManager.java index defe9b4a82..3c918ec0e1 100644 --- a/opendaylight/forwardingrulesmanager/implementation/src/main/java/org/opendaylight/controller/forwardingrulesmanager/internal/ForwardingRulesManager.java +++ b/opendaylight/forwardingrulesmanager/implementation/src/main/java/org/opendaylight/controller/forwardingrulesmanager/internal/ForwardingRulesManager.java @@ -1382,10 +1382,10 @@ public class ForwardingRulesManager implements EnumSet.of(IClusterServices.cacheMode.TRANSACTIONAL)); clusterContainerService.createCache(WORKSTATUSCACHE, - EnumSet.of(IClusterServices.cacheMode.NON_TRANSACTIONAL)); + EnumSet.of(IClusterServices.cacheMode.NON_TRANSACTIONAL, IClusterServices.cacheMode.ASYNC)); clusterContainerService.createCache(WORKORDERCACHE, - EnumSet.of(IClusterServices.cacheMode.NON_TRANSACTIONAL)); + EnumSet.of(IClusterServices.cacheMode.NON_TRANSACTIONAL, IClusterServices.cacheMode.ASYNC)); } catch (CacheConfigException cce) { log.error("CacheConfigException");