You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by vk...@apache.org on 2017/04/27 11:52:56 UTC

[05/11] ignite git commit: IGNITE-4832: Prevent service deployment on client by default when configuration is provided on startup. This closes #1748.

IGNITE-4832: Prevent service deployment on client by default when configuration is provided on startup. This closes #1748.


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

Branch: refs/heads/ignite-security-fixes
Commit: b7ab27301b59bf93fc73b52fdf8e0bcf124fec1d
Parents: 8d9ade2
Author: Andrey V. Mashenkov <an...@gmail.com>
Authored: Thu Apr 6 14:43:50 2017 +0300
Committer: Andrey V. Mashenkov <an...@gmail.com>
Committed: Thu Apr 6 14:43:50 2017 +0300

----------------------------------------------------------------------
 .../service/GridServiceProcessor.java           |  10 +-
 .../GridServiceProcessorAbstractSelfTest.java   |  11 ++
 ...ServiceProcessorMultiNodeConfigSelfTest.java |  74 ++++++++--
 .../GridServiceProcessorMultiNodeSelfTest.java  | 139 ++++++++++++++++---
 4 files changed, 202 insertions(+), 32 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/b7ab2730/modules/core/src/main/java/org/apache/ignite/internal/processors/service/GridServiceProcessor.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/service/GridServiceProcessor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/service/GridServiceProcessor.java
index bd81518..a8af983 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/service/GridServiceProcessor.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/service/GridServiceProcessor.java
@@ -70,11 +70,11 @@ import org.apache.ignite.internal.processors.cache.IgniteInternalCache;
 import org.apache.ignite.internal.processors.cache.query.CacheQuery;
 import org.apache.ignite.internal.processors.cache.query.GridCacheQueryManager;
 import org.apache.ignite.internal.processors.cache.transactions.IgniteInternalTx;
-import org.apache.ignite.internal.processors.continuous.AbstractContinuousMessage;
 import org.apache.ignite.internal.processors.task.GridInternal;
 import org.apache.ignite.internal.processors.timeout.GridTimeoutObject;
 import org.apache.ignite.internal.util.GridEmptyIterator;
 import org.apache.ignite.internal.util.GridSpinBusyLock;
+import org.apache.ignite.internal.util.SerializableTransient;
 import org.apache.ignite.internal.util.future.GridCompoundFuture;
 import org.apache.ignite.internal.util.future.GridFinishedFuture;
 import org.apache.ignite.internal.util.future.GridFutureAdapter;
@@ -92,7 +92,6 @@ import org.apache.ignite.lang.IgniteFuture;
 import org.apache.ignite.lang.IgniteProductVersion;
 import org.apache.ignite.lang.IgniteUuid;
 import org.apache.ignite.marshaller.Marshaller;
-import org.apache.ignite.internal.util.SerializableTransient;
 import org.apache.ignite.resources.IgniteInstanceResource;
 import org.apache.ignite.resources.JobContextResource;
 import org.apache.ignite.resources.LoggerResource;
@@ -296,8 +295,13 @@ public class GridServiceProcessor extends GridProcessorAdapter {
         if (cfgs != null) {
             Collection<IgniteInternalFuture<?>> futs = new ArrayList<>();
 
-            for (ServiceConfiguration c : ctx.config().getServiceConfiguration())
+            for (ServiceConfiguration c : cfgs) {
+                // Deploy only on server nodes by default.
+                if (c.getNodeFilter() == null)
+                    c.setNodeFilter(ctx.cluster().get().forServers().predicate());
+
                 futs.add(deploy(c));
+            }
 
             // Await for services to deploy.
             for (IgniteInternalFuture<?> f : futs)

http://git-wip-us.apache.org/repos/asf/ignite/blob/b7ab2730/modules/core/src/test/java/org/apache/ignite/internal/processors/service/GridServiceProcessorAbstractSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/service/GridServiceProcessorAbstractSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/service/GridServiceProcessorAbstractSelfTest.java
index 111cb71..0f79855 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/service/GridServiceProcessorAbstractSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/service/GridServiceProcessorAbstractSelfTest.java
@@ -129,6 +129,17 @@ public abstract class GridServiceProcessorAbstractSelfTest extends GridCommonAbs
             startGrid(nodeCount() + i);
     }
 
+    /** */
+    protected void startExtraNodes(int servers, int clients) throws Exception {
+        startExtraNodes(servers);
+
+        for (int i = 0; i < clients; i++) {
+            final String nodeName = getTestGridName(nodeCount() + servers + i);
+
+            startGrid(nodeName, getConfiguration(nodeName).setClientMode(true));
+        }
+    }
+
     /**
      * @throws Exception If failed.
      */

http://git-wip-us.apache.org/repos/asf/ignite/blob/b7ab2730/modules/core/src/test/java/org/apache/ignite/internal/processors/service/GridServiceProcessorMultiNodeConfigSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/service/GridServiceProcessorMultiNodeConfigSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/service/GridServiceProcessorMultiNodeConfigSelfTest.java
index b819cc9..1bd3b03 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/service/GridServiceProcessorMultiNodeConfigSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/service/GridServiceProcessorMultiNodeConfigSelfTest.java
@@ -19,7 +19,9 @@ package org.apache.ignite.internal.processors.service;
 
 import java.util.concurrent.CountDownLatch;
 import org.apache.ignite.Ignite;
+import org.apache.ignite.configuration.CacheConfiguration;
 import org.apache.ignite.internal.util.lang.GridAbsPredicateX;
+import org.apache.ignite.services.Service;
 import org.apache.ignite.services.ServiceConfiguration;
 import org.apache.ignite.testframework.GridTestUtils;
 
@@ -33,6 +35,9 @@ public class GridServiceProcessorMultiNodeConfigSelfTest extends GridServiceProc
     /** Node singleton name. */
     private static final String NODE_SINGLE = "serviceConfigEachNode";
 
+    /** Node singleton name. */
+    private static final String NODE_SINGLE_BUT_CLIENT = "serviceConfigEachNodeButClient";
+
     /** Affinity service name. */
     private static final String AFFINITY = "serviceConfigAffinity";
 
@@ -46,7 +51,7 @@ public class GridServiceProcessorMultiNodeConfigSelfTest extends GridServiceProc
 
     /** {@inheritDoc} */
     @Override protected ServiceConfiguration[] services() {
-        ServiceConfiguration[] arr = new ServiceConfiguration[3];
+        ServiceConfiguration[] arr = new ServiceConfiguration[4];
 
         ServiceConfiguration cfg = new ServiceConfiguration();
 
@@ -59,7 +64,7 @@ public class GridServiceProcessorMultiNodeConfigSelfTest extends GridServiceProc
 
         cfg = new ServiceConfiguration();
 
-        cfg.setName(NODE_SINGLE);
+        cfg.setName(NODE_SINGLE_BUT_CLIENT);
         cfg.setMaxPerNodeCount(1);
         cfg.setService(new DummyService());
 
@@ -76,6 +81,15 @@ public class GridServiceProcessorMultiNodeConfigSelfTest extends GridServiceProc
 
         arr[2] = cfg;
 
+        cfg = new ServiceConfiguration();
+
+        cfg.setName(NODE_SINGLE);
+        cfg.setMaxPerNodeCount(1);
+        cfg.setNodeFilter(new CacheConfiguration.IgniteAllNodesPredicate());
+        cfg.setService(new DummyService());
+
+        arr[3] = cfg;
+
         return arr;
     }
 
@@ -91,6 +105,8 @@ public class GridServiceProcessorMultiNodeConfigSelfTest extends GridServiceProc
                         DummyService.cancelled(CLUSTER_SINGLE) == 0 &&
                         DummyService.started(NODE_SINGLE) == nodeCount() &&
                         DummyService.cancelled(NODE_SINGLE) == 0 &&
+                        DummyService.started(NODE_SINGLE_BUT_CLIENT) == nodeCount() &&
+                        DummyService.cancelled(NODE_SINGLE_BUT_CLIENT) == 0 &&
                         actualCount(AFFINITY, randomGrid().services().serviceDescriptors()) == 1;
                 }
             },
@@ -115,11 +131,22 @@ public class GridServiceProcessorMultiNodeConfigSelfTest extends GridServiceProc
     /**
      * @throws Exception If failed.
      */
+    public void testDeployOnEachNodeButClientUpdateTopology() throws Exception {
+        checkDeployOnEachNodeButClientUpdateTopology(NODE_SINGLE_BUT_CLIENT);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
     public void testAll() throws Exception {
         checkSingletonUpdateTopology(CLUSTER_SINGLE);
 
         DummyService.reset();
 
+        checkDeployOnEachNodeButClientUpdateTopology(NODE_SINGLE_BUT_CLIENT);
+
+        DummyService.reset();
+
         checkDeployOnEachNodeUpdateTopology(NODE_SINGLE);
 
         DummyService.reset();
@@ -152,9 +179,7 @@ public class GridServiceProcessorMultiNodeConfigSelfTest extends GridServiceProc
     private void checkSingletonUpdateTopology(String name) throws Exception {
         Ignite g = randomGrid();
 
-        int nodeCnt = 2;
-
-        startExtraNodes(nodeCnt);
+        startExtraNodes(2, 2);
 
         try {
             assertEquals(name, 0, DummyService.started(name));
@@ -165,7 +190,7 @@ public class GridServiceProcessorMultiNodeConfigSelfTest extends GridServiceProc
             checkCount(name, g.services().serviceDescriptors(), 1);
         }
         finally {
-            stopExtraNodes(nodeCnt);
+            stopExtraNodes(4);
         }
     }
 
@@ -176,17 +201,21 @@ public class GridServiceProcessorMultiNodeConfigSelfTest extends GridServiceProc
     private void checkDeployOnEachNodeUpdateTopology(String name) throws Exception {
         Ignite g = randomGrid();
 
-        int newNodes = 2;
+        int newNodes = 4;
 
         CountDownLatch latch = new CountDownLatch(newNodes);
 
         DummyService.exeLatch(name, latch);
 
-        startExtraNodes(newNodes);
+        startExtraNodes(2, 2);
 
         try {
             latch.await();
 
+            // Ensure service is deployed.
+            assertNotNull(grid(nodeCount() + newNodes - 1).services()
+                .serviceProxy(NODE_SINGLE_BUT_CLIENT, Service.class, false, 2000));
+
             assertEquals(name, newNodes, DummyService.started(name));
             assertEquals(name, 0, DummyService.cancelled(name));
 
@@ -196,4 +225,33 @@ public class GridServiceProcessorMultiNodeConfigSelfTest extends GridServiceProc
             stopExtraNodes(newNodes);
         }
     }
+
+    /**
+     * @param name Name.
+     * @throws Exception If failed.
+     */
+    private void checkDeployOnEachNodeButClientUpdateTopology(String name) throws Exception {
+        Ignite g = randomGrid();
+
+        int servers = 2;
+        int clients = 2;
+
+        CountDownLatch latch = new CountDownLatch(servers);
+
+        DummyService.exeLatch(name, latch);
+
+        startExtraNodes(servers, clients);
+
+        try {
+            latch.await();
+
+            assertEquals(name, servers, DummyService.started(name));
+            assertEquals(name, 0, DummyService.cancelled(name));
+
+            checkCount(name, g.services().serviceDescriptors(), nodeCount() + servers);
+        }
+        finally {
+            stopExtraNodes(servers + clients);
+        }
+    }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/b7ab2730/modules/core/src/test/java/org/apache/ignite/internal/processors/service/GridServiceProcessorMultiNodeSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/service/GridServiceProcessorMultiNodeSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/service/GridServiceProcessorMultiNodeSelfTest.java
index 39336ef..f7403dc 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/service/GridServiceProcessorMultiNodeSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/service/GridServiceProcessorMultiNodeSelfTest.java
@@ -21,7 +21,10 @@ import java.util.concurrent.CountDownLatch;
 import junit.framework.TestCase;
 import org.apache.ignite.Ignite;
 import org.apache.ignite.IgniteServices;
+import org.apache.ignite.configuration.CacheConfiguration;
 import org.apache.ignite.lang.IgniteFuture;
+import org.apache.ignite.services.Service;
+import org.apache.ignite.services.ServiceConfiguration;
 
 /**
  * Single node services test.
@@ -121,50 +124,144 @@ public class GridServiceProcessorMultiNodeSelfTest extends GridServiceProcessorA
     /**
      * @throws Exception If failed.
      */
-    public void testDeployOnEachNodeUpdateTopology() throws Exception {
-        String name = "serviceOnEachNodeUpdateTopology";
+    public void testDeployOnEachNodeButClientUpdateTopology() throws Exception {
+        // Prestart client node.
+        Ignite client = startGrid("client", getConfiguration("client").setClientMode(true));
 
-        Ignite g = randomGrid();
+        try {
+            final int prestartedNodes = nodeCount() + 1;
 
-        CountDownLatch latch = new CountDownLatch(nodeCount());
+            String name = "serviceOnEachNodeButClientUpdateTopology";
 
-        DummyService.exeLatch(name, latch);
+            Ignite g = randomGrid();
 
-        IgniteServices svcs = g.services().withAsync();
+            CountDownLatch latch = new CountDownLatch(nodeCount());
 
-        svcs.deployNodeSingleton(name, new DummyService());
+            DummyService.exeLatch(name, latch);
 
-        IgniteFuture<?> fut = svcs.future();
+            IgniteServices svcs = g.services().withAsync();
 
-        info("Deployed service: " + name);
+            svcs.deployNodeSingleton(name, new DummyService());
 
-        fut.get();
+            IgniteFuture<?> fut = svcs.future();
 
-        info("Finished waiting for service future: " + name);
+            info("Deployed service: " + name);
 
-        latch.await();
+            fut.get();
 
-        TestCase.assertEquals(name, nodeCount(), DummyService.started(name));
-        TestCase.assertEquals(name, 0, DummyService.cancelled(name));
+            info("Finished waiting for service future: " + name);
 
-        int newNodes = 2;
+            latch.await();
 
-        latch = new CountDownLatch(newNodes);
+            // Ensure service is deployed
+            assertNotNull(client.services().serviceProxy(name, Service.class, false, 2000));
 
-        DummyService.exeLatch(name, latch);
+            TestCase.assertEquals(name, nodeCount(), DummyService.started(name));
+            TestCase.assertEquals(name, 0, DummyService.cancelled(name));
+
+            int servers = 2;
+            int clients = 2;
+
+            latch = new CountDownLatch(servers);
+
+            DummyService.exeLatch(name, latch);
+
+            startExtraNodes(servers, clients);
+
+            try {
+                latch.await();
+
+                // Ensure service is deployed
+                assertNotNull(grid(prestartedNodes + servers - 1)
+                    .services().serviceProxy(name, Service.class, false, 2000));
+
+                TestCase.assertEquals(name, nodeCount() + servers, DummyService.started(name));
+                TestCase.assertEquals(name, 0, DummyService.cancelled(name));
+
+                checkCount(name, g.services().serviceDescriptors(), nodeCount() + servers);
+            }
+            finally {
+                stopExtraNodes(servers + clients);
+            }
+        }
+        finally {
+            stopGrid("client");
+        }
+    }
 
-        startExtraNodes(newNodes);
+    /**
+     * @throws Exception If failed.
+     */
+    public void testDeployOnEachNodeUpdateTopology() throws Exception {
+        // Prestart client node.
+        Ignite client = startGrid("client", getConfiguration("client").setClientMode(true));
 
         try {
+            String name = "serviceOnEachNodeUpdateTopology";
+
+            Ignite g = randomGrid();
+
+            final int prestartedNodes = nodeCount() + 1;
+
+            CountDownLatch latch = new CountDownLatch(prestartedNodes);
+
+            DummyService.exeLatch(name, latch);
+
+            ServiceConfiguration srvcCfg = new ServiceConfiguration();
+
+            srvcCfg.setNodeFilter(new CacheConfiguration.IgniteAllNodesPredicate());
+            srvcCfg.setName(name);
+            srvcCfg.setMaxPerNodeCount(1);
+            srvcCfg.setService(new DummyService());
+
+            IgniteServices svcs = g.services().withAsync();
+
+            svcs.deploy(srvcCfg);
+
+            IgniteFuture<?> fut = svcs.future();
+
+            info("Deployed service: " + name);
+
+            fut.get();
+
+            info("Finished waiting for service future: " + name);
+
             latch.await();
 
-            TestCase.assertEquals(name, nodeCount() + newNodes, DummyService.started(name));
+            // Ensure service is deployed
+            assertNotNull(client.services().serviceProxy(name, Service.class, false, 2000));
+
+            TestCase.assertEquals(name, prestartedNodes, DummyService.started(name));
             TestCase.assertEquals(name, 0, DummyService.cancelled(name));
 
-            checkCount(name, g.services().serviceDescriptors(), nodeCount() + newNodes);
+            int servers = 2;
+            int clients = 2;
+
+            int extraNodes = servers + clients;
+
+            latch = new CountDownLatch(extraNodes);
+
+            DummyService.exeLatch(name, latch);
+
+            startExtraNodes(servers, clients);
+
+            try {
+                latch.await();
+
+                // Ensure service is deployed
+                assertNotNull(client.services().serviceProxy(name, Service.class, false, 2000));
+
+                TestCase.assertEquals(name, prestartedNodes + extraNodes, DummyService.started(name));
+                TestCase.assertEquals(name, 0, DummyService.cancelled(name));
+
+                checkCount(name, g.services().serviceDescriptors(), prestartedNodes + extraNodes);
+            }
+            finally {
+                stopExtraNodes(extraNodes);
+            }
         }
         finally {
-            stopExtraNodes(newNodes);
+            stopGrid("client");
         }
     }
 }
\ No newline at end of file