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/06/20 09:04:49 UTC

[1/3] brooklyn-server git commit: DynamicFabric: add support for firstMemberSpec

Repository: brooklyn-server
Updated Branches:
  refs/heads/master e25832b26 -> 9ebc32c10


DynamicFabric: add support for firstMemberSpec

Just like DynamicCluster does.

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

Branch: refs/heads/master
Commit: cd29cdfb94f6e058ca9dd19b3636d03a8db52740
Parents: d7b8b0c
Author: Richard Downer <ri...@apache.org>
Authored: Wed Jun 7 11:13:17 2017 +0100
Committer: Richard Downer <ri...@apache.org>
Committed: Wed Jun 7 11:13:17 2017 +0100

----------------------------------------------------------------------
 .../apache/brooklyn/entity/group/DynamicFabric.java    |  4 ++++
 .../brooklyn/entity/group/DynamicFabricImpl.java       | 13 +++++++++++--
 2 files changed, 15 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/cd29cdfb/core/src/main/java/org/apache/brooklyn/entity/group/DynamicFabric.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/entity/group/DynamicFabric.java b/core/src/main/java/org/apache/brooklyn/entity/group/DynamicFabric.java
index 07fea0a..2f50511 100644
--- a/core/src/main/java/org/apache/brooklyn/entity/group/DynamicFabric.java
+++ b/core/src/main/java/org/apache/brooklyn/entity/group/DynamicFabric.java
@@ -54,6 +54,10 @@ public interface DynamicFabric extends AbstractGroup, Startable, Fabric {
     ConfigKey<EntitySpec<?>> MEMBER_SPEC = ConfigKeys.newConfigKey(
             new TypeToken<EntitySpec<?>>() {}, "dynamiccfabric.memberspec", "entity spec for creating new cluster members", null);
 
+    @SetFromFlag("firstMemberSpec")
+    ConfigKey<EntitySpec<?>> FIRST_MEMBER_SPEC = ConfigKeys.newConfigKey(
+            new TypeToken<EntitySpec<?>>() {}, "dynamiccfabric.firstmemberspec", "entity spec for creating new cluster members", null);
+
     @SetFromFlag("displayNamePrefix")
     ConfigKey<String> DISPLAY_NAME_PREFIX = ConfigKeys.newStringConfigKey(
             "dynamicfabric.displayNamePrefix", "Display name prefix, for created children");

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/cd29cdfb/core/src/main/java/org/apache/brooklyn/entity/group/DynamicFabricImpl.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/entity/group/DynamicFabricImpl.java b/core/src/main/java/org/apache/brooklyn/entity/group/DynamicFabricImpl.java
index 75ca4dc..ec03987 100644
--- a/core/src/main/java/org/apache/brooklyn/entity/group/DynamicFabricImpl.java
+++ b/core/src/main/java/org/apache/brooklyn/entity/group/DynamicFabricImpl.java
@@ -78,6 +78,10 @@ public class DynamicFabricImpl extends AbstractGroupImpl implements DynamicFabri
         sensors().set(SERVICE_UP, false);
     }
     
+    protected EntitySpec<?> getFirstMemberSpec() {
+        return getConfig(FIRST_MEMBER_SPEC);
+    }
+
     protected EntitySpec<?> getMemberSpec() {
         return getConfig(MEMBER_SPEC);
     }
@@ -272,10 +276,15 @@ public class DynamicFabricImpl extends AbstractGroupImpl implements DynamicFabri
     }
     
     protected Entity createCluster(Location location, Map flags) {
-        EntitySpec<?> memberSpec = getMemberSpec();
+        EntitySpec<?> memberSpec = null;
+        if (getMembers().isEmpty()) memberSpec = getFirstMemberSpec();
+        if (memberSpec == null) memberSpec = getMemberSpec();
+
         if (memberSpec == null) {
             throw new IllegalStateException("No member spec nor entity factory supplied for dynamic fabric "+this);
         }
-        return addChild(EntitySpec.create(memberSpec).configure(flags));
+        EntitySpec<?> specConfigured = EntitySpec.create(memberSpec).configure(flags);
+        if (location!=null) specConfigured.location(location);
+        return addChild(specConfigured);
     }
 }


[2/3] brooklyn-server git commit: Add tests for DynamicRegionFabric change

Posted by dr...@apache.org.
Add tests for DynamicRegionFabric change

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

Branch: refs/heads/master
Commit: 5ed32b2ee125bfc9a177cb9ea8e5073efb9e8d6c
Parents: cd29cdf
Author: Richard Downer <ri...@apache.org>
Authored: Mon Jun 19 16:33:53 2017 +0100
Committer: Richard Downer <ri...@apache.org>
Committed: Mon Jun 19 16:33:53 2017 +0100

----------------------------------------------------------------------
 .../AbstractDynamicClusterOrFabricTest.java     | 45 ++++++++++++++
 .../entity/group/DynamicClusterTest.java        | 16 +----
 .../entity/group/DynamicFabricTest.java         | 24 +++++++-
 .../entity/group/DynamicRegionsFabricTest.java  | 62 ++++++++++++++++++--
 4 files changed, 125 insertions(+), 22 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/5ed32b2e/core/src/test/java/org/apache/brooklyn/entity/group/AbstractDynamicClusterOrFabricTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/brooklyn/entity/group/AbstractDynamicClusterOrFabricTest.java b/core/src/test/java/org/apache/brooklyn/entity/group/AbstractDynamicClusterOrFabricTest.java
new file mode 100644
index 0000000..154a293
--- /dev/null
+++ b/core/src/test/java/org/apache/brooklyn/entity/group/AbstractDynamicClusterOrFabricTest.java
@@ -0,0 +1,45 @@
+/*
+ * 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.brooklyn.entity.group;
+
+import static org.testng.Assert.assertEquals;
+
+import java.util.Collection;
+import java.util.Set;
+
+import org.apache.brooklyn.api.entity.Entity;
+import org.apache.brooklyn.core.test.BrooklynAppUnitTestSupport;
+import org.apache.brooklyn.core.test.entity.TestEntity;
+import org.apache.brooklyn.util.collections.MutableSet;
+
+public class AbstractDynamicClusterOrFabricTest extends BrooklynAppUnitTestSupport {
+    void assertFirstAndNonFirstCounts(Collection<Entity> members, int expectedFirstCount, int expectedNonFirstCount) {
+        Set<Entity> found = MutableSet.of();
+        for (Entity e: members) {
+            if ("first".equals(e.getConfig(TestEntity.CONF_NAME))) found.add(e);
+        }
+        assertEquals(found.size(), expectedFirstCount, "when counting 'first' nodes");
+
+        found.clear();
+        for (Entity e: members) {
+            if ("non-first".equals(e.getConfig(TestEntity.CONF_NAME))) found.add(e);
+        }
+        assertEquals(found.size(), expectedNonFirstCount, "when counting 'non-first' nodes");
+    }
+}

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/5ed32b2e/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 b0e115c..5b76bbc 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
@@ -98,7 +98,7 @@ import com.google.common.collect.Iterables;
 import com.google.common.collect.Lists;
 
 
-public class DynamicClusterTest extends BrooklynAppUnitTestSupport {
+public class DynamicClusterTest extends AbstractDynamicClusterOrFabricTest {
 
     private static final int TIMEOUT_MS = 2000;
 
@@ -1158,20 +1158,6 @@ public class DynamicClusterTest extends BrooklynAppUnitTestSupport {
         }
     }
 
-    private void assertFirstAndNonFirstCounts(Collection<Entity> members, int expectedFirstCount, int expectedNonFirstCount) {
-        Set<Entity> found = MutableSet.of();
-        for (Entity e: members) {
-            if ("first".equals(e.getConfig(TestEntity.CONF_NAME))) found.add(e);
-        }
-        assertEquals(found.size(), expectedFirstCount);
-        
-        found.clear();
-        for (Entity e: members) {
-            if ("non-first".equals(e.getConfig(TestEntity.CONF_NAME))) found.add(e);
-        }
-        assertEquals(found.size(), expectedNonFirstCount);
-    }
-
     @DataProvider
     public Object[][] maxConcurrentCommandsTestProvider() {
         return new Object[][]{{1}, {2}, {3}};

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/5ed32b2e/core/src/test/java/org/apache/brooklyn/entity/group/DynamicFabricTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/brooklyn/entity/group/DynamicFabricTest.java b/core/src/test/java/org/apache/brooklyn/entity/group/DynamicFabricTest.java
index c41ddd5..e501b4d 100644
--- a/core/src/test/java/org/apache/brooklyn/entity/group/DynamicFabricTest.java
+++ b/core/src/test/java/org/apache/brooklyn/entity/group/DynamicFabricTest.java
@@ -35,6 +35,8 @@ import org.apache.brooklyn.api.location.Location;
 import org.apache.brooklyn.api.mgmt.Task;
 import org.apache.brooklyn.core.entity.Attributes;
 import org.apache.brooklyn.core.entity.Entities;
+import org.apache.brooklyn.core.entity.EntityAsserts;
+import org.apache.brooklyn.core.entity.lifecycle.Lifecycle;
 import org.apache.brooklyn.core.entity.trait.Startable;
 import org.apache.brooklyn.core.location.PortRanges;
 import org.apache.brooklyn.core.location.SimulatedLocation;
@@ -45,6 +47,7 @@ import org.apache.brooklyn.entity.stock.BasicEntity;
 import org.apache.brooklyn.test.Asserts;
 import org.apache.brooklyn.util.collections.MutableList;
 import org.apache.brooklyn.util.collections.MutableMap;
+import org.apache.brooklyn.util.collections.QuorumCheck;
 import org.apache.brooklyn.util.exceptions.Exceptions;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -57,7 +60,7 @@ import com.google.common.collect.ImmutableSet;
 import com.google.common.collect.Iterables;
 import com.google.common.collect.Lists;
 
-public class DynamicFabricTest extends BrooklynAppUnitTestSupport {
+public class DynamicFabricTest extends AbstractDynamicClusterOrFabricTest {
     private static final Logger log = LoggerFactory.getLogger(DynamicFabricTest.class);
 
     private static final int TIMEOUT_MS = 5*1000;
@@ -365,6 +368,25 @@ public class DynamicFabricTest extends BrooklynAppUnitTestSupport {
         return Iterables.get(child.getChildren(), grandchildIndex);
     }
 
+    @Test
+    public void testDifferentFirstMemberSpec() throws Exception {
+        DynamicFabric fabric = app.createAndManageChild(EntitySpec.create(DynamicFabric.class)
+                .configure(DynamicFabric.FIRST_MEMBER_SPEC,
+                        EntitySpec.create(BasicEntity.class).configure(TestEntity.CONF_NAME, "first"))
+                .configure(DynamicFabric.MEMBER_SPEC,
+                        EntitySpec.create(BasicEntity.class).configure(TestEntity.CONF_NAME, "non-first"))
+                .configure(DynamicFabric.UP_QUORUM_CHECK, QuorumCheck.QuorumChecks.alwaysTrue()));
+        List<Location> locs = ImmutableList.of(loc1, loc2, loc3);
+        fabric.start(locs);
+
+        EntityAsserts.assertAttributeEqualsEventually(fabric, Attributes.SERVICE_STATE_ACTUAL, Lifecycle.RUNNING);
+        assertTrue(fabric.getAttribute(Attributes.SERVICE_UP));
+
+        assertEquals(fabric.getMembers().size(), 3);
+
+        assertFirstAndNonFirstCounts(fabric.getMembers(), 1, 2);
+    }
+
     private Entity getChild(Entity entity, int childIndex) {
         return Iterables.get(entity.getChildren(), childIndex);
     }

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/5ed32b2e/core/src/test/java/org/apache/brooklyn/entity/group/DynamicRegionsFabricTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/brooklyn/entity/group/DynamicRegionsFabricTest.java b/core/src/test/java/org/apache/brooklyn/entity/group/DynamicRegionsFabricTest.java
index 5227c8d..b2ff9eb 100644
--- a/core/src/test/java/org/apache/brooklyn/entity/group/DynamicRegionsFabricTest.java
+++ b/core/src/test/java/org/apache/brooklyn/entity/group/DynamicRegionsFabricTest.java
@@ -29,13 +29,19 @@ import java.util.Set;
 import org.apache.brooklyn.api.entity.Entity;
 import org.apache.brooklyn.api.entity.EntitySpec;
 import org.apache.brooklyn.api.location.Location;
+import org.apache.brooklyn.api.location.LocationSpec;
+import org.apache.brooklyn.api.mgmt.LocationManager;
+import org.apache.brooklyn.core.entity.Attributes;
 import org.apache.brooklyn.core.entity.BrooklynConfigKeys;
+import org.apache.brooklyn.core.entity.EntityAsserts;
+import org.apache.brooklyn.core.entity.lifecycle.Lifecycle;
 import org.apache.brooklyn.core.location.SimulatedLocation;
 import org.apache.brooklyn.core.test.BrooklynAppUnitTestSupport;
 import org.apache.brooklyn.core.test.entity.TestApplication;
 import org.apache.brooklyn.core.test.entity.TestEntity;
 import org.apache.brooklyn.entity.stock.BasicEntity;
 import org.apache.brooklyn.util.collections.MutableSet;
+import org.apache.brooklyn.util.collections.QuorumCheck;
 import org.apache.brooklyn.util.exceptions.Exceptions;
 import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.Test;
@@ -46,19 +52,22 @@ import com.google.common.collect.Iterables;
 import com.google.common.collect.Lists;
 import com.google.common.collect.Sets;
 
-public class DynamicRegionsFabricTest extends BrooklynAppUnitTestSupport {
+public class DynamicRegionsFabricTest extends AbstractDynamicClusterOrFabricTest {
 
     DynamicRegionsFabric fabric;
     private Location loc1;
     private Location loc2;
-    
+    private Location loc3;
+
     @BeforeMethod(alwaysRun=true)
     @Override
     public void setUp() throws Exception {
         super.setUp();
-        loc1 = new SimulatedLocation();
-        loc2 = new SimulatedLocation();
-        
+        final LocationManager lm = mgmt.getLocationManager();
+        loc1 = lm.createLocation(LocationSpec.create(SimulatedLocation.class).configure("displayName", "newloc1"));
+        loc2 = lm.createLocation(LocationSpec.create(SimulatedLocation.class).configure("displayName", "newloc2"));
+        loc3 = lm.createLocation(LocationSpec.create(SimulatedLocation.class).configure("displayName", "newloc3"));
+
         fabric = app.createAndManageChild(EntitySpec.create(DynamicRegionsFabric.class)
                 .configure("memberSpec", EntitySpec.create(TestEntity.class)));
     }
@@ -240,7 +249,48 @@ public class DynamicRegionsFabricTest extends BrooklynAppUnitTestSupport {
             if (cause == null && !e.toString().contains("No entity found")) throw e;
         }
     }
-    
+
+    @Test
+    public void testDifferentFirstMemberSpec() throws Exception {
+        DynamicRegionsFabric fabric = app.createAndManageChild(EntitySpec.create(DynamicRegionsFabric.class)
+                .configure(DynamicRegionsFabric.FIRST_MEMBER_SPEC,
+                        EntitySpec.create(BasicEntity.class).configure(TestEntity.CONF_NAME, "first"))
+                .configure(DynamicRegionsFabric.MEMBER_SPEC,
+                        EntitySpec.create(BasicEntity.class).configure(TestEntity.CONF_NAME, "non-first"))
+                .configure(DynamicRegionsFabric.UP_QUORUM_CHECK, QuorumCheck.QuorumChecks.alwaysTrue()));
+        List<Location> locs = ImmutableList.of(loc1, loc2, loc3);
+        fabric.start(locs);
+
+        EntityAsserts.assertAttributeEqualsEventually(fabric, Attributes.SERVICE_STATE_ACTUAL, Lifecycle.RUNNING);
+        assertTrue(fabric.getAttribute(Attributes.SERVICE_UP));
+
+        assertEquals(fabric.getMembers().size(), 3);
+
+        assertFirstAndNonFirstCounts(fabric.getMembers(), 1, 2);
+
+        // and after re-size
+        fabric.addRegion("localhost:(name=newloc4)");
+        assertFirstAndNonFirstCounts(fabric.getMembers(), 1, 3);
+
+        // and re-size to 1
+        for(Entity r : Iterables.skip(ImmutableSet.copyOf(fabric.getChildren()), 1)) { // skip 'first', remove the remaining ones
+            fabric.removeRegion(r.getId());
+        }
+        assertFirstAndNonFirstCounts(fabric.getMembers(), 1, 0);
+
+        // and re-size to 0
+        for(Entity r : ImmutableSet.copyOf(fabric.getChildren())) {
+            fabric.removeRegion(r.getId());
+        }
+        assertFirstAndNonFirstCounts(fabric.getMembers(), 0, 0);
+
+        // and back to 3
+        fabric.addRegion("localhost:(name=newloc1)");
+        fabric.addRegion("localhost:(name=newloc2)");
+        fabric.addRegion("localhost:(name=newloc3)");
+        assertFirstAndNonFirstCounts(fabric.getMembers(), 1, 2);
+    }
+
     private List<Location> getLocationsOfChildren(DynamicRegionsFabric fabric) {
         return getLocationsOf(fabric.getChildren());
     }


[3/3] brooklyn-server git commit: This closes #721

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


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

Branch: refs/heads/master
Commit: 9ebc32c10cf662f43c431ca7f138407eedde469e
Parents: e25832b 5ed32b2
Author: Duncan Godwin <dr...@googlemail.com>
Authored: Tue Jun 20 10:04:41 2017 +0100
Committer: Duncan Godwin <dr...@googlemail.com>
Committed: Tue Jun 20 10:04:41 2017 +0100

----------------------------------------------------------------------
 .../brooklyn/entity/group/DynamicFabric.java    |  4 ++
 .../entity/group/DynamicFabricImpl.java         | 13 +++-
 .../AbstractDynamicClusterOrFabricTest.java     | 45 ++++++++++++++
 .../entity/group/DynamicClusterTest.java        | 16 +----
 .../entity/group/DynamicFabricTest.java         | 24 +++++++-
 .../entity/group/DynamicRegionsFabricTest.java  | 62 ++++++++++++++++++--
 6 files changed, 140 insertions(+), 24 deletions(-)
----------------------------------------------------------------------