Repository: incubator-ignite
Updated Branches:
  refs/heads/ignite-286 6ff11b6a2 -> 8a0e27c9e


ignite-446


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

Branch: refs/heads/ignite-286
Commit: e37888eb253e4bde8ba5d56cf3e904fbbc244e19
Parents: 0cf79e4
Author: avinogradov <avinogra...@gridgain.com>
Authored: Wed Apr 8 16:36:30 2015 +0300
Committer: avinogradov <avinogra...@gridgain.com>
Committed: Wed Apr 8 16:36:30 2015 +0300

----------------------------------------------------------------------
 .../configuration/CacheConfiguration.java       | 19 +++++
 .../ignite/configuration/TopologyValidator.java | 35 +++++++++
 .../GridDhtPartitionsExchangeFuture.java        |  6 ++
 .../cache/IgniteTopologyValidatorCacheTest.java | 76 ++++++++++++++++++++
 4 files changed, 136 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e37888eb/modules/core/src/main/java/org/apache/ignite/configuration/CacheConfiguration.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/main/java/org/apache/ignite/configuration/CacheConfiguration.java
 
b/modules/core/src/main/java/org/apache/ignite/configuration/CacheConfiguration.java
index c90de92..169b524 100644
--- 
a/modules/core/src/main/java/org/apache/ignite/configuration/CacheConfiguration.java
+++ 
b/modules/core/src/main/java/org/apache/ignite/configuration/CacheConfiguration.java
@@ -321,6 +321,9 @@ public class CacheConfiguration<K, V> extends 
MutableConfiguration<K, V> {
     /** Cache plugin configurations. */
     private CachePluginConfiguration[] pluginCfgs;
 
+    /** Cache topology validator. */
+    private TopologyValidator topValidator;
+
     /** Empty constructor (all values are initialized to their defaults). */
     public CacheConfiguration() {
         /* No-op. */
@@ -1566,6 +1569,22 @@ public class CacheConfiguration<K, V> extends 
MutableConfiguration<K, V> {
         this.pluginCfgs = pluginCfgs;
     }
 
+    /**
+     * Gets topology validator.
+     * @return validator.
+     */
+    public TopologyValidator getTopologyValidator() {
+        return topValidator;
+    }
+
+    /**
+     * Sets topology validator.
+     * @param topValidator validator.
+     */
+    public void setTopologyValidator(TopologyValidator topValidator) {
+        this.topValidator = topValidator;
+    }
+
     /** {@inheritDoc} */
     @Override public String toString() {
         return S.toString(CacheConfiguration.class, this);

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e37888eb/modules/core/src/main/java/org/apache/ignite/configuration/TopologyValidator.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/main/java/org/apache/ignite/configuration/TopologyValidator.java
 
b/modules/core/src/main/java/org/apache/ignite/configuration/TopologyValidator.java
new file mode 100644
index 0000000..995d7a5
--- /dev/null
+++ 
b/modules/core/src/main/java/org/apache/ignite/configuration/TopologyValidator.java
@@ -0,0 +1,35 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.configuration;
+
+import org.apache.ignite.cluster.*;
+
+import java.io.*;
+import java.util.*;
+
+/**
+ * Topology validator.
+ */
+public interface TopologyValidator extends Serializable {
+    /**
+     * Validates topology.
+     * @param nodes nodes collection to be validated.
+     * @return is topology valid or not.
+     */
+    boolean validate(Collection<ClusterNode> nodes);
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e37888eb/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionsExchangeFuture.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionsExchangeFuture.java
 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionsExchangeFuture.java
index f6a0763..cc4843f 100644
--- 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionsExchangeFuture.java
+++ 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionsExchangeFuture.java
@@ -145,6 +145,8 @@ public class GridDhtPartitionsExchangeFuture extends 
GridFutureAdapter<AffinityT
     /** Dynamic cache change requests. */
     private Collection<DynamicCacheChangeRequest> reqs;
 
+    private Map<String, Boolean> cacheValidRes = new ConcurrentHashMap8<>();
+
     /**
      * Dummy future created to trigger reassignments if partition
      * topology changed while preloading.
@@ -789,6 +791,10 @@ public class GridDhtPartitionsExchangeFuture extends 
GridFutureAdapter<AffinityT
 
     /** {@inheritDoc} */
     @Override public boolean onDone(AffinityTopologyVersion res, Throwable 
err) {
+        for (GridCacheContext cacheCtx : cctx.cacheContexts()) {
+            cacheValidRes.put(cacheCtx.name(), 
cacheCtx.config().getTopologyValidator().validate(discoEvt.topologyNodes()));
+        }
+
         cctx.cache().onExchangeDone(exchId.topologyVersion(), reqs, err);
 
         cctx.exchange().onExchangeDone(this, err);

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e37888eb/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteTopologyValidatorCacheTest.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteTopologyValidatorCacheTest.java
 
b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteTopologyValidatorCacheTest.java
new file mode 100644
index 0000000..ec29358
--- /dev/null
+++ 
b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteTopologyValidatorCacheTest.java
@@ -0,0 +1,76 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.cache;
+
+import org.apache.ignite.cache.*;
+import org.apache.ignite.cluster.*;
+import org.apache.ignite.configuration.*;
+
+import java.util.*;
+
+import static org.apache.ignite.cache.CacheAtomicWriteOrderMode.*;
+import static org.apache.ignite.cache.CacheAtomicityMode.*;
+
+public class IgniteTopologyValidatorCacheTest extends IgniteCacheAbstractTest {
+    /** {@inheritDoc} */
+    @Override protected int gridCount() {
+        return 2;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected CacheMode cacheMode() {
+        return CacheMode.PARTITIONED;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected CacheAtomicityMode atomicityMode() {
+        return ATOMIC;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected CacheAtomicWriteOrderMode atomicWriteOrderMode() {
+        return PRIMARY;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected NearCacheConfiguration nearConfiguration() {
+        return null;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String gridName) 
throws Exception {
+        IgniteConfiguration iCfg = super.getConfiguration(gridName);
+
+        for (CacheConfiguration cCfg : iCfg.getCacheConfiguration()) {
+            cCfg.setTopologyValidator(new TopologyValidator() {
+                @Override public boolean validate(Collection<ClusterNode> 
nodes) {
+                    return nodes.size() >= 3;
+                }
+            });
+        }
+
+        return iCfg;
+    }
+
+    /** topology validator test */
+    public void testTopologyValidator() throws Exception {
+
+
+        jcache().getName();
+    }
+}

Reply via email to