Repository: brooklyn-server Updated Branches: refs/heads/master 2683b89fe -> 86070d8a1
Adds cluster.max.size to dynamic cluster Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/b48a8d65 Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/b48a8d65 Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/b48a8d65 Branch: refs/heads/master Commit: b48a8d65eaa824bc090fa0e158253ce0ed37df8d Parents: d961de3 Author: Martin Harris <[email protected]> Authored: Tue Aug 22 09:10:39 2017 +0100 Committer: Martin Harris <[email protected]> Committed: Tue Aug 22 14:28:14 2017 +0100 ---------------------------------------------------------------------- .../brooklyn/entity/group/DynamicCluster.java | 2 ++ .../brooklyn/entity/group/DynamicClusterImpl.java | 4 ++++ .../core/test/entity/TestClusterImpl.java | 4 ++-- .../brooklyn/entity/group/DynamicClusterTest.java | 18 ++++++++++++++++++ 4 files changed, 26 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/b48a8d65/core/src/main/java/org/apache/brooklyn/entity/group/DynamicCluster.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/brooklyn/entity/group/DynamicCluster.java b/core/src/main/java/org/apache/brooklyn/entity/group/DynamicCluster.java index ff4163f..59a28c3 100644 --- a/core/src/main/java/org/apache/brooklyn/entity/group/DynamicCluster.java +++ b/core/src/main/java/org/apache/brooklyn/entity/group/DynamicCluster.java @@ -183,6 +183,8 @@ public interface DynamicCluster extends AbstractGroup, Cluster, MemberReplaceabl "Time to wait (after members' start() effectors return) for SERVICE_UP before failing (default is not to wait)", null); + ConfigKey<Integer> MAX_SIZE = ConfigKeys.newIntegerConfigKey("cluster.max.size", "Size after which it will throw InsufficientCapacityException", Integer.MAX_VALUE); + @Beta @SetFromFlag("maxConcurrentChildCommands") ConfigKey<Integer> MAX_CONCURRENT_CHILD_COMMANDS = ConfigKeys.builder(Integer.class) http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/b48a8d65/core/src/main/java/org/apache/brooklyn/entity/group/DynamicClusterImpl.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/brooklyn/entity/group/DynamicClusterImpl.java b/core/src/main/java/org/apache/brooklyn/entity/group/DynamicClusterImpl.java index a1f2b16..23b48f0 100644 --- a/core/src/main/java/org/apache/brooklyn/entity/group/DynamicClusterImpl.java +++ b/core/src/main/java/org/apache/brooklyn/entity/group/DynamicClusterImpl.java @@ -595,6 +595,10 @@ public class DynamicClusterImpl extends AbstractGroupImpl implements DynamicClus @Override public Integer resize(Integer desiredSize) { synchronized (mutex) { + Optional<Integer> optionalMaxSize = Optional.fromNullable(config().get(MAX_SIZE)); + if (optionalMaxSize.isPresent() && desiredSize > optionalMaxSize.get()) { + throw new Resizable.InsufficientCapacityException("Desired cluster size " + desiredSize + " exceeds maximum size of " + optionalMaxSize.get()); + } int originalSize = getCurrentSize(); int delta = desiredSize - originalSize; if (delta != 0) { http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/b48a8d65/core/src/test/java/org/apache/brooklyn/core/test/entity/TestClusterImpl.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/brooklyn/core/test/entity/TestClusterImpl.java b/core/src/test/java/org/apache/brooklyn/core/test/entity/TestClusterImpl.java index 0edea8f..7c57caf 100644 --- a/core/src/test/java/org/apache/brooklyn/core/test/entity/TestClusterImpl.java +++ b/core/src/test/java/org/apache/brooklyn/core/test/entity/TestClusterImpl.java @@ -59,7 +59,7 @@ public class TestClusterImpl extends DynamicClusterImpl implements TestCluster { @Override public Integer resize(Integer desiredSize) { desiredSizeHistory.add(desiredSize); - int achievableSize = Math.min(desiredSize, getConfig(MAX_SIZE)); + int achievableSize = Math.min(desiredSize, getConfig(TestCluster.MAX_SIZE)); if (achievableSize != size) { this.sizeHistory.add(achievableSize); @@ -67,7 +67,7 @@ public class TestClusterImpl extends DynamicClusterImpl implements TestCluster { } if (desiredSize > achievableSize) { - throw new InsufficientCapacityException("Simulating insufficient capacity (desiredSize="+desiredSize+"; maxSize="+getConfig(MAX_SIZE)+"; newSize="+size+")"); + throw new InsufficientCapacityException("Simulating insufficient capacity (desiredSize="+desiredSize+"; maxSize="+getConfig(TestCluster.MAX_SIZE)+"; newSize="+size+")"); } return size; http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/b48a8d65/core/src/test/java/org/apache/brooklyn/entity/group/DynamicClusterTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/brooklyn/entity/group/DynamicClusterTest.java b/core/src/test/java/org/apache/brooklyn/entity/group/DynamicClusterTest.java index 54b5731..80f1be6 100644 --- a/core/src/test/java/org/apache/brooklyn/entity/group/DynamicClusterTest.java +++ b/core/src/test/java/org/apache/brooklyn/entity/group/DynamicClusterTest.java @@ -1378,6 +1378,24 @@ public class DynamicClusterTest extends AbstractDynamicClusterOrFabricTest { assertEquals(clusterImpl.getChildTaskSemaphore().availablePermits(), 1); } + @Test + public void testClusterMaxSize() { + DynamicCluster cluster = app.createAndManageChild(EntitySpec.create(DynamicCluster.class) + .configure(DynamicCluster.MEMBER_SPEC, EntitySpec.create(TestEntity.class)) + .configure(DynamicCluster.INITIAL_SIZE, 2) + .configure(DynamicCluster.MAX_SIZE, 6)); + cluster.start(ImmutableList.of(loc)); + + cluster.resize(4); + EntityAsserts.assertAttributeEqualsEventually(cluster, DynamicCluster.GROUP_SIZE, 4); + try { + cluster.resize(8); + Asserts.shouldHaveFailedPreviously("Cluster resize should have failed because max size was exceeded"); + } catch (Exception e) { + assertNotNull(Exceptions.getFirstThrowableOfType(e, Resizable.InsufficientCapacityException.class), "Expected InsufficientCapacityException"); + } + } + @ImplementedBy(ThrowOnAsyncStartEntityImpl.class) public interface ThrowOnAsyncStartEntity extends TestEntity { ConfigKey<Integer> MAX_CONCURRENCY = ConfigKeys.newConfigKey(Integer.class, "concurrency", "max concurrency", 1);
