You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@heron.apache.org by nw...@apache.org on 2019/04/30 18:17:23 UTC

[incubator-heron] branch master updated: Check invalid number of container in round robin packing algorithm (#3251)

This is an automated email from the ASF dual-hosted git repository.

nwang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-heron.git


The following commit(s) were added to refs/heads/master by this push:
     new 776abe2  Check invalid number of container in round robin packing algorithm (#3251)
776abe2 is described below

commit 776abe2b5a45b93a0eb957fd65cbc149d901a92a
Author: Ning Wang <nw...@twitter.com>
AuthorDate: Tue Apr 30 11:17:18 2019 -0700

    Check invalid number of container in round robin packing algorithm (#3251)
---
 .../heron/packing/roundrobin/RoundRobinPacking.java       |  4 +++-
 .../heron/packing/roundrobin/RoundRobinPackingTest.java   | 15 +++++++++++++++
 2 files changed, 18 insertions(+), 1 deletion(-)

diff --git a/heron/packing/src/java/org/apache/heron/packing/roundrobin/RoundRobinPacking.java b/heron/packing/src/java/org/apache/heron/packing/roundrobin/RoundRobinPacking.java
index b02700e..3f87bf7 100644
--- a/heron/packing/src/java/org/apache/heron/packing/roundrobin/RoundRobinPacking.java
+++ b/heron/packing/src/java/org/apache/heron/packing/roundrobin/RoundRobinPacking.java
@@ -364,7 +364,9 @@ public class RoundRobinPacking implements IPacking, IRepacking {
       int numContainer, Map<String, Integer> parallelismMap) {
     Map<Integer, List<InstanceId>> allocation = new HashMap<>();
     int totalInstance = TopologyUtils.getTotalInstance(parallelismMap);
-    if (numContainer > totalInstance) {
+    if (numContainer < 1) {
+      throw new RuntimeException(String.format("Invlaid number of container: %d", numContainer));
+    } else if (numContainer > totalInstance) {
       throw new RuntimeException(
           String.format("More containers (%d) allocated than instances (%d).",
               numContainer, totalInstance));
diff --git a/heron/packing/tests/java/org/apache/heron/packing/roundrobin/RoundRobinPackingTest.java b/heron/packing/tests/java/org/apache/heron/packing/roundrobin/RoundRobinPackingTest.java
index 854eef6..5c3d3ac 100644
--- a/heron/packing/tests/java/org/apache/heron/packing/roundrobin/RoundRobinPackingTest.java
+++ b/heron/packing/tests/java/org/apache/heron/packing/roundrobin/RoundRobinPackingTest.java
@@ -545,4 +545,19 @@ public class RoundRobinPackingTest extends CommonPackingTests {
         getDefaultUnspecifiedContainerResource(boltParallelism + spoutParallelism,
             numContainers, getDefaultPadding()));
   }
+
+  @Test(expected = RuntimeException.class)
+  public void testZeroContainersFailure() throws Exception {
+    // Explicit set insufficient RAM for container
+    ByteAmount containerRam = ByteAmount.fromGigabytes(10);
+    topologyConfig.setContainerRamRequested(containerRam);
+    topologyConfig.setNumStmgrs(0);
+    topology = getTopology(spoutParallelism, boltParallelism, topologyConfig);
+
+    doPackingTest(topology, instanceDefaultResources, boltParallelism,
+        instanceDefaultResources, spoutParallelism,
+        0,  // 0 containers
+        getDefaultUnspecifiedContainerResource(boltParallelism + spoutParallelism,
+            numContainers, getDefaultPadding()).cloneWithRam(containerRam));
+  }
 }