ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From anovi...@apache.org
Subject [28/50] [abbrv] incubator-ignite git commit: #ignite-860: Change default behavior for Compute and Services not to execute on client nodes.
Date Mon, 01 Jun 2015 02:44:35 GMT
#ignite-860: Change default behavior for Compute and Services not to execute on client nodes.


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

Branch: refs/heads/ignite-868
Commit: b6fc8a9a02ddf115dce7f5c1ec43ad140acaf337
Parents: c783886
Author: ivasilinets <ivasilinets@gridgain.com>
Authored: Thu May 28 13:15:18 2015 +0300
Committer: ivasilinets <ivasilinets@gridgain.com>
Committed: Thu May 28 13:15:18 2015 +0300

----------------------------------------------------------------------
 .../src/main/java/org/apache/ignite/Ignite.java |   8 +-
 .../java/org/apache/ignite/IgniteServices.java  |   5 +-
 .../apache/ignite/internal/IgniteKernal.java    |   4 +-
 .../org/apache/ignite/services/Service.java     |   5 +-
 .../service/ClosureServiceClientsNodesTest.java | 245 +++++++++++++++++++
 .../ignite/testsuites/IgniteBasicTestSuite.java |   2 +
 6 files changed, 255 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/b6fc8a9a/modules/core/src/main/java/org/apache/ignite/Ignite.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/Ignite.java b/modules/core/src/main/java/org/apache/ignite/Ignite.java
index 40c9bbb..209946b 100644
--- a/modules/core/src/main/java/org/apache/ignite/Ignite.java
+++ b/modules/core/src/main/java/org/apache/ignite/Ignite.java
@@ -103,9 +103,9 @@ public interface Ignite extends AutoCloseable {
     public IgniteCluster cluster();
 
     /**
-     * Gets {@code compute} facade over all cluster nodes.
+     * Gets {@code compute} facade over all cluster nodes started in server mode.
      *
-     * @return Compute instance over all cluster nodes.
+     * @return Compute instance over all cluster nodes started in server mode.
      */
     public IgniteCompute compute();
 
@@ -154,9 +154,9 @@ public interface Ignite extends AutoCloseable {
     public IgniteEvents events(ClusterGroup grp);
 
     /**
-     * Gets {@code services} facade over all cluster nodes.
+     * Gets {@code services} facade over all cluster nodes started in server mode.
      *
-     * @return Services facade over all cluster nodes.
+     * @return Services facade over all cluster nodes started in server mode.
      */
     public IgniteServices services();
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/b6fc8a9a/modules/core/src/main/java/org/apache/ignite/IgniteServices.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/IgniteServices.java b/modules/core/src/main/java/org/apache/ignite/IgniteServices.java
index f800085..7d1ca7c 100644
--- a/modules/core/src/main/java/org/apache/ignite/IgniteServices.java
+++ b/modules/core/src/main/java/org/apache/ignite/IgniteServices.java
@@ -126,10 +126,7 @@ import java.util.*;
  * ...
  * GridServices svcs = grid.services();
  *
- * GridFuture&lt;?&gt; fut = svcs.deployClusterSingleton("mySingleton", new MyGridService());
- *
- * // Wait for deployment to complete.
- * fut.get();
+ * svcs.deployClusterSingleton("mySingleton", new MyGridService());
  * </pre>
  */
 public interface IgniteServices extends IgniteAsyncSupport {

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/b6fc8a9a/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java b/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java
index ffd264d..c4b93b8 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java
@@ -221,7 +221,7 @@ public class IgniteKernal implements IgniteEx, IgniteMXBean, Externalizable
{
 
     /** {@inheritDoc} */
     @Override public IgniteCompute compute() {
-        return ctx.cluster().get().compute();
+        return ((ClusterGroupAdapter)ctx.cluster().get().forServers()).compute();
     }
 
     /** {@inheritDoc} */
@@ -236,7 +236,7 @@ public class IgniteKernal implements IgniteEx, IgniteMXBean, Externalizable
{
 
     /** {@inheritDoc} */
     @Override public IgniteServices services() {
-        return ctx.cluster().get().services();
+        return ((ClusterGroupAdapter)ctx.cluster().get().forServers()).services();
     }
 
     /** {@inheritDoc} */

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/b6fc8a9a/modules/core/src/main/java/org/apache/ignite/services/Service.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/services/Service.java b/modules/core/src/main/java/org/apache/ignite/services/Service.java
index 2bd5649..4f927a3 100644
--- a/modules/core/src/main/java/org/apache/ignite/services/Service.java
+++ b/modules/core/src/main/java/org/apache/ignite/services/Service.java
@@ -55,10 +55,7 @@ import java.io.*;
  * ...
  * GridServices svcs = grid.services();
  *
- * GridFuture&lt;?&gt; fut = svcs.deployClusterSingleton("mySingleton", new MyGridService());
- *
- * // Wait for deployment to complete.
- * fut.get();
+ * svcs.deployClusterSingleton("mySingleton", new MyGridService());
  * </pre>
  * Or from grid configuration on startup:
  * <pre name="code" class="java">

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/b6fc8a9a/modules/core/src/test/java/org/apache/ignite/internal/processors/service/ClosureServiceClientsNodesTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/service/ClosureServiceClientsNodesTest.java
b/modules/core/src/test/java/org/apache/ignite/internal/processors/service/ClosureServiceClientsNodesTest.java
new file mode 100644
index 0000000..761f00f
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/service/ClosureServiceClientsNodesTest.java
@@ -0,0 +1,245 @@
+/*
+ * 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.service;
+
+import org.apache.ignite.*;
+import org.apache.ignite.cluster.*;
+import org.apache.ignite.configuration.*;
+import org.apache.ignite.internal.util.typedef.*;
+import org.apache.ignite.lang.*;
+import org.apache.ignite.marshaller.optimized.*;
+import org.apache.ignite.resources.*;
+import org.apache.ignite.services.Service;
+import org.apache.ignite.services.ServiceContext;
+import org.apache.ignite.services.ServiceDescriptor;
+import org.apache.ignite.spi.discovery.tcp.*;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.*;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.*;
+import org.apache.ignite.testframework.junits.common.*;
+
+import java.util.*;
+
+/**
+ * Test that compute and service run only on server nodes by default.
+ */
+public class ClosureServiceClientsNodesTest extends GridCommonAbstractTest {
+    /** Number of grids started for tests. */
+    private static final int NODES_CNT = 4;
+
+    /** Test singleton service name. */
+    private static final String SINGLETON_NAME = "testSingleton";
+
+    /** IP finder. */
+    private final TcpDiscoveryIpFinder ipFinder = new TcpDiscoveryVmIpFinder(true);
+
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception
{
+        IgniteConfiguration cfg = super.getConfiguration(gridName);
+
+        cfg.setMarshaller(new OptimizedMarshaller(false));
+
+        TcpDiscoverySpi discoSpi = new TcpDiscoverySpi();
+
+        discoSpi.setIpFinder(ipFinder);
+
+        cfg.setDiscoverySpi(discoSpi);
+
+        cfg.setCacheConfiguration();
+
+        if (gridName.equals(getTestGridName(0)))
+            cfg.setClientMode(true);
+
+        return cfg;
+    }
+
+    /** {@inheritDoc} */
+    @SuppressWarnings({"ConstantConditions"})
+    @Override protected void beforeTestsStarted() throws Exception {
+        startGrids(NODES_CNT);
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTestsStopped() throws Exception {
+        stopAllGrids();
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testDefaultClosure() throws Exception {
+        Set<String> srvNames = new HashSet<>(NODES_CNT - 1);
+
+        for (int i = 1; i < NODES_CNT; ++i)
+            srvNames.add(getTestGridName(i));
+
+        for (int i = 0 ; i < NODES_CNT; i++) {
+            Ignite ignite = grid(i);
+
+            Collection<String> res = ignite.compute().broadcast(new IgniteCallable<String>()
{
+                @IgniteInstanceResource
+                Ignite ignite;
+
+                @Override public String call() throws Exception {
+                    assertFalse(ignite.configuration().isClientMode());
+
+                    return ignite.name();
+                }
+            });
+
+            assertEquals(res.size(), NODES_CNT - 1);
+
+            for (String name : res)
+                assertTrue(srvNames.contains(name));
+        }
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testClientClosure() throws Exception {
+        for (int i = 0 ; i < NODES_CNT; i++) {
+            Ignite ignite = grid(i);
+
+            Collection<String> res = ignite.compute(ignite.cluster().forClients()).
+                broadcast(new IgniteCallable<String>() {
+                    @IgniteInstanceResource
+                    Ignite ignite;
+
+                    @Override public String call() throws Exception {
+                        assertTrue(ignite.configuration().isClientMode());
+
+                        return ignite.name();
+                    }
+                });
+
+            assertEquals(1, res.size());
+
+            assertEquals(getTestGridName(0), F.first(res));
+        }
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testCustomClosure() throws Exception {
+        for (int i = 0 ; i < NODES_CNT; i++) {
+            Ignite ignite = grid(i);
+
+            Collection<String> res = ignite.compute(ignite.cluster().forPredicate(F.<ClusterNode>alwaysTrue())).
+                broadcast(new IgniteCallable<String>() {
+                    @IgniteInstanceResource
+                    Ignite ignite;
+
+                    @Override public String call() throws Exception {
+                        return ignite.name();
+                    }
+                });
+
+            assertEquals(NODES_CNT, res.size());
+        }
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testDefaultService() throws Exception {
+        UUID clientNodeId = grid(0).cluster().localNode().id();
+
+        for (int i = 0 ; i < NODES_CNT; i++) {
+            Ignite ignite = grid(i);
+
+            ignite.services().deployNodeSingleton(SINGLETON_NAME, new TestService());
+
+            ClusterGroup grp = ignite.cluster();
+
+            assertEquals(NODES_CNT, grp.nodes().size());
+
+            Collection<ServiceDescriptor> srvDscs = ignite.services(grp).serviceDescriptors();
+
+            assertEquals(1, srvDscs.size());
+
+            Map<UUID, Integer> nodesMap = F.first(srvDscs).topologySnapshot();
+
+            assertEquals(NODES_CNT - 1, nodesMap.size());
+
+            for (Map.Entry<UUID, Integer> nodeInfo : nodesMap.entrySet()) {
+                assertFalse(clientNodeId.equals(nodeInfo.getKey()));
+
+                assertEquals(1, nodeInfo.getValue().intValue());
+            }
+
+            ignite.services().cancelAll();
+        }
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testClientService() throws Exception {
+        UUID clientNodeId = grid(0).cluster().localNode().id();
+
+        for (int i = 0 ; i < NODES_CNT; i++) {
+            Ignite ignite = grid(i);
+
+            ignite.services(ignite.cluster().forClients()).deployNodeSingleton(SINGLETON_NAME,
new TestService());
+
+            ClusterGroup grp = ignite.cluster();
+
+            assertEquals(NODES_CNT, grp.nodes().size());
+
+            Collection<ServiceDescriptor> srvDscs = ignite.services(grp).serviceDescriptors();
+
+            assertEquals(1, srvDscs.size());
+
+            Map<UUID, Integer> nodesMap = F.first(srvDscs).topologySnapshot();
+
+            assertEquals(1, nodesMap.size());
+
+            for (Map.Entry<UUID, Integer> nodeInfo : nodesMap.entrySet()) {
+                assertEquals(clientNodeId, nodeInfo.getKey());
+
+                assertEquals(1, nodeInfo.getValue().intValue());
+            }
+
+            ignite.services().cancelAll();
+        }
+    }
+
+    /**
+     * Test service.
+     */
+    private static class TestService implements Service {
+        @LoggerResource
+        private IgniteLogger log;
+
+        /** {@inheritDoc} */
+        @Override public void cancel(ServiceContext ctx) {
+          //No-op.
+        }
+
+        /** {@inheritDoc} */
+        @Override public void init(ServiceContext ctx) throws Exception {
+            //No-op.
+        }
+
+        /** {@inheritDoc} */
+        @Override public void execute(ServiceContext ctx) throws Exception {
+            log.info("Executing test service.");
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/b6fc8a9a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBasicTestSuite.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBasicTestSuite.java
b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBasicTestSuite.java
index 56ff951..6382059 100644
--- a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBasicTestSuite.java
+++ b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBasicTestSuite.java
@@ -24,6 +24,7 @@ import org.apache.ignite.internal.processors.affinity.*;
 import org.apache.ignite.internal.processors.cache.*;
 import org.apache.ignite.internal.processors.closure.*;
 import org.apache.ignite.internal.processors.continuous.*;
+import org.apache.ignite.internal.processors.service.*;
 import org.apache.ignite.internal.product.*;
 import org.apache.ignite.internal.util.typedef.internal.*;
 import org.apache.ignite.messaging.*;
@@ -61,6 +62,7 @@ public class IgniteBasicTestSuite extends TestSuite {
         suite.addTestSuite(GridProductVersionSelfTest.class);
         suite.addTestSuite(GridAffinityProcessorRendezvousSelfTest.class);
         suite.addTestSuite(GridClosureProcessorSelfTest.class);
+        suite.addTestSuite(ClosureServiceClientsNodesTest.class);
         suite.addTestSuite(GridStartStopSelfTest.class);
         suite.addTestSuite(GridProjectionForCachesSelfTest.class);
         suite.addTestSuite(GridProjectionForCachesOnDaemonNodeSelfTest.class);


Mime
View raw message