ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sboi...@apache.org
Subject incubator-ignite git commit: implement remote validation mechanism for CachePlugin
Date Thu, 02 Apr 2015 10:40:22 GMT
Repository: incubator-ignite
Updated Branches:
  refs/heads/ignite-cacheplug-rmtvalid [created] 379c4801e


implement remote validation mechanism for CachePlugin


Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/379c4801
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/379c4801
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/379c4801

Branch: refs/heads/ignite-cacheplug-rmtvalid
Commit: 379c4801ec746b840da2b9b95b71ffeb3737bacc
Parents: 9b23109
Author: Artem Shutak <ashutak@gridgain.com>
Authored: Thu Apr 2 13:40:12 2015 +0300
Committer: Artem Shutak <ashutak@gridgain.com>
Committed: Thu Apr 2 13:40:12 2015 +0300

----------------------------------------------------------------------
 .../ignite/internal/GridCachePluginContext.java |  6 ++++
 .../processors/cache/GridCacheProcessor.java    | 38 ++++++++++++--------
 .../processors/plugin/CachePluginManager.java   | 37 ++++++++++++++-----
 .../ignite/plugin/CachePluginContext.java       | 10 ++++++
 .../ignite/plugin/CachePluginProvider.java      |  4 +--
 5 files changed, 71 insertions(+), 24 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/379c4801/modules/core/src/main/java/org/apache/ignite/internal/GridCachePluginContext.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/GridCachePluginContext.java
b/modules/core/src/main/java/org/apache/ignite/internal/GridCachePluginContext.java
index 2334bae..7c80db6 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/GridCachePluginContext.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/GridCachePluginContext.java
@@ -18,6 +18,7 @@
 package org.apache.ignite.internal;
 
 import org.apache.ignite.*;
+import org.apache.ignite.cluster.*;
 import org.apache.ignite.configuration.*;
 import org.apache.ignite.plugin.*;
 
@@ -64,6 +65,11 @@ public class GridCachePluginContext<C extends CachePluginConfiguration>
implemen
     @Override public Ignite grid() {        
         return ctx.grid();
     }
+    
+    /** {@inheritDoc} */
+    @Override public ClusterNode localNode() {
+        return ctx.discovery().localNode();
+    }
 
     /** {@inheritDoc} */
     @Override public IgniteLogger log(Class<?> cls) {

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/379c4801/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProcessor.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProcessor.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProcessor.java
index 00852fc..5f05396 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProcessor.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProcessor.java
@@ -626,6 +626,8 @@ public class GridCacheProcessor extends GridProcessorAdapter {
 
         ClusterNode locNode = ctx.discovery().localNode();
 
+        final Map<CacheConfiguration, CachePluginManager> ccfg2PluginMgr = new HashMap<>();
+        
         if (!getBoolean(IGNITE_SKIP_CONFIGURATION_CONSISTENCY_CHECK)) {
             for (ClusterNode n : ctx.discovery().remoteNodes()) {
                 checkTransactionConfiguration(n);
@@ -639,8 +641,18 @@ public class GridCacheProcessor extends GridProcessorAdapter {
                 for (DynamicCacheDescriptor desc : registeredCaches.values()) {
                     CacheConfiguration rmtCfg = desc.remoteConfiguration(n.id());
 
-                    if (rmtCfg != null)
-                        checkCache(desc.cacheConfiguration(), rmtCfg, n);
+                    if (rmtCfg != null) {
+                        CacheConfiguration locCfg = desc.cacheConfiguration();
+                        
+                        checkCache(locCfg, rmtCfg, n);
+
+                        // Check plugin cache configurations.
+                        CachePluginManager pluginMgr = new CachePluginManager(ctx, locCfg);
+                        
+                        pluginMgr.validateRemotes(rmtCfg, n);
+                        
+                        ccfg2PluginMgr.put(locCfg, pluginMgr);
+                    }
                 }
             }
         }
@@ -660,7 +672,9 @@ public class GridCacheProcessor extends GridProcessorAdapter {
             if (filter.apply(locNode)) {
                 CacheObjectContext cacheObjCtx = ctx.cacheObjects().contextForCache(null,
ccfg.getName(), ccfg);
 
-                GridCacheContext ctx = createCache(ccfg, cacheObjCtx);
+                System.out.println(">>>>>> ccfg2PluginMgr.get(ccfg)=" +
ccfg2PluginMgr.get(ccfg));
+
+                GridCacheContext ctx = createCache(ccfg, ccfg2PluginMgr.get(ccfg), cacheObjCtx);
 
                 ctx.dynamicDeploymentId(desc.deploymentId());
 
@@ -974,11 +988,13 @@ public class GridCacheProcessor extends GridProcessorAdapter {
 
     /**
      * @param cfg Cache configuration to use to create cache.
+     * @param pluginMgr Cache plugin manager.
      * @return Cache context.
      * @throws IgniteCheckedException If failed to create cache.
      */
     @SuppressWarnings({"unchecked"})
-    private GridCacheContext createCache(CacheConfiguration<?, ?> cfg, CacheObjectContext
cacheObjCtx) throws IgniteCheckedException {
+    private GridCacheContext createCache(CacheConfiguration<?, ?> cfg, @Nullable CachePluginManager
pluginMgr,
+        CacheObjectContext cacheObjCtx) throws IgniteCheckedException {
         assert cfg != null;
 
         CacheStore cfgStore = cfg.getCacheStoreFactory() != null ? cfg.getCacheStoreFactory().create()
: null;
@@ -1016,7 +1032,9 @@ public class GridCacheProcessor extends GridProcessorAdapter {
         CacheContinuousQueryManager contQryMgr = new CacheContinuousQueryManager();
         CacheDataStructuresManager dataStructuresMgr = new CacheDataStructuresManager();
         GridCacheTtlManager ttlMgr = new GridCacheTtlManager();
-        CachePluginManager pluginMgr = new CachePluginManager(ctx, cfg);
+        
+        if (pluginMgr == null)
+            pluginMgr = new CachePluginManager(ctx, cfg);
         
         pluginMgr.validate();
 
@@ -1353,7 +1371,7 @@ public class GridCacheProcessor extends GridProcessorAdapter {
 
             CacheObjectContext cacheObjCtx = ctx.cacheObjects().contextForCache(null, ccfg.getName(),
ccfg);
 
-            GridCacheContext cacheCtx = createCache(ccfg, cacheObjCtx);
+            GridCacheContext cacheCtx = createCache(ccfg, null, cacheObjCtx);
 
             cacheCtx.startTopologyVersion(topVer);
 
@@ -2026,14 +2044,6 @@ public class GridCacheProcessor extends GridProcessorAdapter {
                     true);
             }
         }
-        
-        // TODO 10006: implement remote configs validation.
-        // Check plugin configurations.
-//        for (CachePluginConfiguration locPluginCcfg : locCfg.getPluginConfigurations())
{
-//            CachePluginProvider provider = ...;
-//
-//            provider.validateRemote(locCfg, locPluginCcfg, rmtCfg, rmtNode);
-//        }
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/379c4801/modules/core/src/main/java/org/apache/ignite/internal/processors/plugin/CachePluginManager.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/plugin/CachePluginManager.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/plugin/CachePluginManager.java
index 69ca1ae..3496acd 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/plugin/CachePluginManager.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/plugin/CachePluginManager.java
@@ -18,6 +18,7 @@
 package org.apache.ignite.internal.processors.plugin;
 
 import org.apache.ignite.*;
+import org.apache.ignite.cluster.*;
 import org.apache.ignite.configuration.*;
 import org.apache.ignite.internal.*;
 import org.apache.ignite.internal.processors.cache.*;
@@ -30,8 +31,11 @@ import java.util.*;
  * Cache plugin manager.
  */
 public class CachePluginManager extends GridCacheManagerAdapter {
+    /** Providers list. To have providers order. */
+    private final List<CachePluginProvider> providersList = new ArrayList<>();
+
     /** */
-    private final List<CachePluginProvider> providers = new ArrayList<>();
+    private final Map<CachePluginContext, CachePluginProvider> providersMap = new HashMap<>();
 
     /**
      * @param ctx Context.
@@ -44,32 +48,33 @@ public class CachePluginManager extends GridCacheManagerAdapter {
 
                 CachePluginProvider provider = cachePluginCfg.createProvider(pluginCtx);
 
-                providers.add(provider);
+                providersList.add(provider);
+                providersMap.put(pluginCtx, provider);
             }
         }
     }
 
     /** {@inheritDoc} */
     @Override protected void onKernalStart0() throws IgniteCheckedException {
-        for (CachePluginProvider provider : providers)
+        for (CachePluginProvider provider : providersList)
             provider.onIgniteStart();
     }
 
     /** {@inheritDoc} */
     @Override protected void onKernalStop0(boolean cancel) {
-        for (ListIterator<CachePluginProvider> iter = providers.listIterator(); iter.hasPrevious();)
+        for (ListIterator<CachePluginProvider> iter = providersList.listIterator();
iter.hasPrevious();)
             iter.previous().onIgniteStop(cancel);
     }
 
     /** {@inheritDoc} */
     @Override protected void start0() throws IgniteCheckedException {
-        for (CachePluginProvider provider : providers)
+        for (CachePluginProvider provider : providersList)
             provider.start();
     }
 
     /** {@inheritDoc} */
     @Override protected void stop0(boolean cancel) {
-        for (ListIterator<CachePluginProvider> iter = providers.listIterator(); iter.hasPrevious();)
+        for (ListIterator<CachePluginProvider> iter = providersList.listIterator();
iter.hasPrevious();)
             iter.previous().stop(cancel);
     }
 
@@ -80,7 +85,7 @@ public class CachePluginManager extends GridCacheManagerAdapter {
      * @return Created component.
      */
     public <T> T createComponent(Class<T> cls) {
-        for (CachePluginProvider provider : providers) {
+        for (CachePluginProvider provider : providersList) {
             T res = (T)provider.createComponent(cls);
             
             if (res != null)
@@ -101,7 +106,23 @@ public class CachePluginManager extends GridCacheManagerAdapter {
      * @throws IgniteCheckedException If validation failed.
      */
     public void validate() throws IgniteCheckedException {
-        for (CachePluginProvider provider : providers)
+        for (CachePluginProvider provider : providersList)
             provider.validate();
     }
+
+    /**
+     * Checks that remote caches has configuration compatible with the local.
+     *    
+     * @param rmtCfg Remote cache configuration.
+     * @param rmtNode Remote rmtNode.
+     * @throws IgniteCheckedException If failed.
+     */
+    public void validateRemotes(CacheConfiguration rmtCfg, ClusterNode rmtNode) throws IgniteCheckedException
{
+        for (Map.Entry<CachePluginContext, CachePluginProvider> entry : providersMap.entrySet())
{
+            CachePluginContext cctx = entry.getKey();
+            CachePluginProvider provider = entry.getValue();
+            
+            provider.validateRemote(cctx.igniteCacheConfiguration(), cctx.cacheConfiguration(),
rmtCfg, rmtNode);
+        }
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/379c4801/modules/core/src/main/java/org/apache/ignite/plugin/CachePluginContext.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/plugin/CachePluginContext.java b/modules/core/src/main/java/org/apache/ignite/plugin/CachePluginContext.java
index 580b40d..f70f71e 100644
--- a/modules/core/src/main/java/org/apache/ignite/plugin/CachePluginContext.java
+++ b/modules/core/src/main/java/org/apache/ignite/plugin/CachePluginContext.java
@@ -18,6 +18,7 @@
 package org.apache.ignite.plugin;
 
 import org.apache.ignite.*;
+import org.apache.ignite.cluster.*;
 import org.apache.ignite.configuration.*;
 
 /**
@@ -45,6 +46,15 @@ public interface CachePluginContext<C extends CachePluginConfiguration>
{
     public Ignite grid();
 
     /**
+     * Gets local grid node. Instance of local node is provided by underlying {@link org.apache.ignite.spi.discovery.DiscoverySpi}
+     * implementation used.
+     *
+     * @return Local grid node.
+     * @see org.apache.ignite.spi.discovery.DiscoverySpi
+     */
+    public ClusterNode localNode();
+
+    /**
      * Gets logger for given class.
      *
      * @param cls Class to get logger for.

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/379c4801/modules/core/src/main/java/org/apache/ignite/plugin/CachePluginProvider.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/plugin/CachePluginProvider.java
b/modules/core/src/main/java/org/apache/ignite/plugin/CachePluginProvider.java
index 4006a70..ea5f795 100644
--- a/modules/core/src/main/java/org/apache/ignite/plugin/CachePluginProvider.java
+++ b/modules/core/src/main/java/org/apache/ignite/plugin/CachePluginProvider.java
@@ -77,8 +77,8 @@ public interface CachePluginProvider<C extends CachePluginConfiguration>
{
      * @param locCfg Local configuration.
      * @param locPluginCcfg Local plugin configuration.
      * @param rmtCfg Remote configuration.
-     * @param node Node.
+     * @param rmtNode Remote node.
      */
-    public void validateRemote(CacheConfiguration locCfg, C locPluginCcfg, CacheConfiguration
rmtCfg, ClusterNode node) 
+    public void validateRemote(CacheConfiguration locCfg, C locPluginCcfg, CacheConfiguration
rmtCfg, ClusterNode rmtNode)
         throws IgniteCheckedException;
 }


Mime
View raw message