You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by ag...@apache.org on 2018/11/13 08:27:18 UTC

ignite git commit: IGNITE-10134 Add exception handling for job reduce results - Fixes #5250.

Repository: ignite
Updated Branches:
  refs/heads/master ecf750fcd -> ded41e9d1


IGNITE-10134 Add exception handling for job reduce results - Fixes #5250.

Signed-off-by: Alexey Goncharuk <al...@gmail.com>


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

Branch: refs/heads/master
Commit: ded41e9d126fea58e40c03d7ba86b577dbeb47ca
Parents: ecf750f
Author: Sergey Antonov <an...@gmail.com>
Authored: Tue Nov 13 11:26:36 2018 +0300
Committer: Alexey Goncharuk <al...@gmail.com>
Committed: Tue Nov 13 11:26:36 2018 +0300

----------------------------------------------------------------------
 .../VisorCacheConfigurationCollectorTask.java   | 40 +++++++++++
 .../ignite/util/GridCommandHandlerTest.java     | 72 ++++++++++++++++----
 2 files changed, 99 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/ded41e9d/modules/core/src/main/java/org/apache/ignite/internal/visor/cache/VisorCacheConfigurationCollectorTask.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/visor/cache/VisorCacheConfigurationCollectorTask.java b/modules/core/src/main/java/org/apache/ignite/internal/visor/cache/VisorCacheConfigurationCollectorTask.java
index fd224a8..418eb1b 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/visor/cache/VisorCacheConfigurationCollectorTask.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/visor/cache/VisorCacheConfigurationCollectorTask.java
@@ -17,9 +17,15 @@
 
 package org.apache.ignite.internal.visor.cache;
 
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
+import org.apache.ignite.IgniteException;
+import org.apache.ignite.compute.ComputeJobResult;
 import org.apache.ignite.internal.processors.task.GridInternal;
 import org.apache.ignite.internal.visor.VisorOneNodeTask;
+import org.jetbrains.annotations.Nullable;
 
 /**
  * Task that collect cache metrics from all nodes.
@@ -34,4 +40,38 @@ public class VisorCacheConfigurationCollectorTask
     @Override protected VisorCacheConfigurationCollectorJob job(VisorCacheConfigurationCollectorTaskArg arg) {
         return new VisorCacheConfigurationCollectorJob(arg, debug);
     }
+
+    /** {@inheritDoc} */
+    @Override protected @Nullable Map<String, VisorCacheConfiguration> reduce0(
+        List<ComputeJobResult> results
+    ) throws IgniteException {
+        if (results == null)
+            return null;
+
+        Map<String, VisorCacheConfiguration> map = new HashMap<>();
+
+        List<Exception> resultsExceptions = null;
+
+        for (ComputeJobResult res : results) {
+            if (res.getException() == null)
+                map.putAll(res.getData());
+            else {
+                if (resultsExceptions == null)
+                    resultsExceptions = new ArrayList<>(results.size());
+
+                resultsExceptions.add(new IgniteException("Job failed on node: " + res.getNode().id(), res.getException()));
+            }
+        }
+
+        if (resultsExceptions != null) {
+            IgniteException e = new IgniteException("Reduce failed because of job failed on some nodes");
+
+            for (Exception ex : resultsExceptions)
+                e.addSuppressed(ex);
+
+            throw e;
+        }
+
+        return map;
+    }
 }

http://git-wip-us.apache.org/repos/asf/ignite/blob/ded41e9d/modules/core/src/test/java/org/apache/ignite/util/GridCommandHandlerTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/util/GridCommandHandlerTest.java b/modules/core/src/test/java/org/apache/ignite/util/GridCommandHandlerTest.java
index 6cbbb3f..6edde59 100644
--- a/modules/core/src/test/java/org/apache/ignite/util/GridCommandHandlerTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/util/GridCommandHandlerTest.java
@@ -1264,29 +1264,71 @@ public class GridCommandHandlerTest extends GridCommonAbstractTest {
 
     /** */
     public void testCacheConfigNoOutputFormat() throws Exception {
-        testCacheConfig(null);
+        testCacheConfig(null, 1, 1);
     }
 
     /** */
-    public void testCacheConfigSingleLineOutputFormat() throws Exception {
-        testCacheConfig(SINGLE_LINE);
+    public void testCacheConfigSingleLineOutputFormatSingleNodeSignleCache() throws Exception {
+        testCacheConfigSingleLineOutputFormat(1, 1);
     }
 
     /** */
-    public void testCacheConfigMultiLineOutputFormat() throws Exception {
-        testCacheConfig(MULTI_LINE);
+    public void testCacheConfigSingleLineOutputFormatTwoNodeSignleCache() throws Exception {
+        testCacheConfigSingleLineOutputFormat(2, 1);
     }
 
     /** */
-    private void testCacheConfig(OutputFormat outputFormat) throws Exception {
-        Ignite ignite = startGrid();
+    public void testCacheConfigSingleLineOutputFormatTwoNodeManyCaches() throws Exception {
+        testCacheConfigSingleLineOutputFormat(2, 100);
+    }
+
+    /** */
+    public void testCacheConfigMultiLineOutputFormatSingleNodeSingleCache() throws Exception {
+        testCacheConfigMultiLineOutputFormat(1, 1);
+    }
+
+    /** */
+    public void testCacheConfigMultiLineOutputFormatTwoNodeSingleCache() throws Exception {
+        testCacheConfigMultiLineOutputFormat(2, 1);
+    }
+
+    /** */
+    public void testCacheConfigMultiLineOutputFormatTwoNodeManyCaches() throws Exception {
+        testCacheConfigMultiLineOutputFormat(2, 100);
+    }
+
+    /** */
+    private void testCacheConfigSingleLineOutputFormat(int nodesCnt, int cachesCnt) throws Exception {
+        testCacheConfig(SINGLE_LINE, nodesCnt, cachesCnt);
+    }
+
+    /** */
+    private void testCacheConfigMultiLineOutputFormat(int nodesCnt, int cachesCnt) throws Exception {
+        testCacheConfig(MULTI_LINE, nodesCnt, cachesCnt);
+    }
+
+    /** */
+    private void testCacheConfig(OutputFormat outputFormat, int nodesCnt, int cachesCnt) throws Exception {
+        assertTrue("Invalid number of nodes or caches", nodesCnt > 0 && cachesCnt > 0);
+
+        Ignite ignite = startGrid(nodesCnt);
 
         ignite.cluster().active(true);
 
-        IgniteCache<Object, Object> cache1 = ignite.createCache(new CacheConfiguration<>()
-            .setAffinity(new RendezvousAffinityFunction(false, 32))
-            .setBackups(1)
-            .setName(DEFAULT_CACHE_NAME));
+        List<CacheConfiguration> ccfgs = new ArrayList<>(cachesCnt);
+
+        for (int i = 0; i < cachesCnt; i++) {
+            ccfgs.add(
+                new CacheConfiguration<>()
+                    .setAffinity(new RendezvousAffinityFunction(false, 32))
+                    .setBackups(1)
+                    .setName(DEFAULT_CACHE_NAME + i)
+            );
+        }
+
+        ignite.createCaches(ccfgs);
+
+        IgniteCache<Object, Object> cache1 = ignite.cache(DEFAULT_CACHE_NAME + 0);
 
         for (int i = 0; i < 100; i++)
             cache1.put(i, i);
@@ -1305,12 +1347,16 @@ public class GridCommandHandlerTest extends GridCommonAbstractTest {
         String outStr = testOut.toString();
 
         if (outputFormat == null || outputFormat == SINGLE_LINE) {
-            assertTrue(outStr.contains("name=" + DEFAULT_CACHE_NAME));
+            for (int i = 0; i < cachesCnt; i++)
+                assertTrue(outStr.contains("name=" + DEFAULT_CACHE_NAME + i));
+
             assertTrue(outStr.contains("partitions=32"));
             assertTrue(outStr.contains("function=o.a.i.cache.affinity.rendezvous.RendezvousAffinityFunction"));
         }
         else if (outputFormat == MULTI_LINE) {
-            assertTrue(outStr.contains("[cache = '" + DEFAULT_CACHE_NAME + "']"));
+            for (int i = 0; i < cachesCnt; i++)
+                assertTrue(outStr.contains("[cache = '" + DEFAULT_CACHE_NAME + i + "']"));
+
             assertTrue(outStr.contains("Affinity Partitions: 32"));
             assertTrue(outStr.contains("Affinity Function: o.a.i.cache.affinity.rendezvous.RendezvousAffinityFunction"));
         }