You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by dr...@apache.org on 2017/08/23 08:48:44 UTC

[1/2] brooklyn-server git commit: Adds cluster.max.size to dynamic cluster

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 <ma...@cloudsoft.io>
Authored: Tue Aug 22 09:10:39 2017 +0100
Committer: Martin Harris <gi...@nakomis.com>
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);


[2/2] brooklyn-server git commit: This closes #803

Posted by dr...@apache.org.
This closes #803


Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/86070d8a
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/86070d8a
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/86070d8a

Branch: refs/heads/master
Commit: 86070d8a13cca8b9487ec34ca17ac88a456d9f92
Parents: 2683b89 b48a8d6
Author: Duncan Godwin <dr...@googlemail.com>
Authored: Wed Aug 23 09:48:35 2017 +0100
Committer: Duncan Godwin <dr...@googlemail.com>
Committed: Wed Aug 23 09:48:35 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(-)
----------------------------------------------------------------------