You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by al...@apache.org on 2014/07/28 16:21:52 UTC

[1/4] git commit: DynamicFabric: add existing children as members

Repository: incubator-brooklyn
Updated Branches:
  refs/heads/master 7997893f2 -> f03d82c4f


DynamicFabric: add existing children as members


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

Branch: refs/heads/master
Commit: 35f267fe7c4a21d4afefc68a5f97caca1e04dfba
Parents: fede962
Author: Aled Sage <al...@gmail.com>
Authored: Mon Jul 21 14:31:23 2014 +0100
Committer: Aled Sage <al...@gmail.com>
Committed: Mon Jul 21 14:31:37 2014 +0100

----------------------------------------------------------------------
 core/src/main/java/brooklyn/entity/group/DynamicFabricImpl.java | 4 +++-
 core/src/test/java/brooklyn/entity/group/DynamicFabricTest.java | 3 +++
 2 files changed, 6 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/35f267fe/core/src/main/java/brooklyn/entity/group/DynamicFabricImpl.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/entity/group/DynamicFabricImpl.java b/core/src/main/java/brooklyn/entity/group/DynamicFabricImpl.java
index 72b868a..a72f77f 100644
--- a/core/src/main/java/brooklyn/entity/group/DynamicFabricImpl.java
+++ b/core/src/main/java/brooklyn/entity/group/DynamicFabricImpl.java
@@ -23,6 +23,7 @@ import static brooklyn.util.GroovyJavaMethods.truth;
 
 import java.util.Arrays;
 import java.util.Collection;
+import java.util.List;
 import java.util.Map;
 import java.util.concurrent.ExecutionException;
 
@@ -113,7 +114,7 @@ public class DynamicFabricImpl extends AbstractGroupImpl implements DynamicFabri
         Preconditions.checkArgument(locations.size() >= 1, "One or more location must be supplied");
         addLocations(locations);
         
-        MutableList<Location> newLocations = MutableList.copyOf(locations);
+        List<Location> newLocations = MutableList.copyOf(locations);
         if (newLocations.isEmpty()) newLocations.addAll(getLocations());
         int locIndex = 0;
         
@@ -125,6 +126,7 @@ public class DynamicFabricImpl extends AbstractGroupImpl implements DynamicFabri
             // if they have no locations yet
             for (Entity child: getChildren()) {
                 if (child instanceof Startable) {
+                    addMember(child);
                     Location it = null;
                     if (child.getLocations().isEmpty())
                         // give him any of these locations if he has none, allowing round robin here

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/35f267fe/core/src/test/java/brooklyn/entity/group/DynamicFabricTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/brooklyn/entity/group/DynamicFabricTest.java b/core/src/test/java/brooklyn/entity/group/DynamicFabricTest.java
index ea024b6..84cb13c 100644
--- a/core/src/test/java/brooklyn/entity/group/DynamicFabricTest.java
+++ b/core/src/test/java/brooklyn/entity/group/DynamicFabricTest.java
@@ -420,6 +420,7 @@ public class DynamicFabricTest extends BrooklynAppUnitTestSupport {
 
         // Expect only these existing children
         Asserts.assertEqualsIgnoringOrder(fabric.getChildren(), existingChildren);
+        Asserts.assertEqualsIgnoringOrder(fabric.getMembers(), existingChildren);
 
         // Expect one location per existing child
         List<Location> remainingLocs = MutableList.copyOf(locs);
@@ -445,6 +446,7 @@ public class DynamicFabricTest extends BrooklynAppUnitTestSupport {
 
         // Expect only these existing children
         Asserts.assertEqualsIgnoringOrder(fabric.getChildren(), existingChildren);
+        Asserts.assertEqualsIgnoringOrder(fabric.getMembers(), existingChildren);
 
         // Expect one location per existing child (round-robin)
         // Expect one location per existing child
@@ -470,6 +472,7 @@ public class DynamicFabricTest extends BrooklynAppUnitTestSupport {
         // Expect three children: the existing one, and one per other location
         assertEquals(fabric.getChildren().size(), 3, "children="+fabric.getChildren());
         assertTrue(fabric.getChildren().contains(existingChild), "children="+fabric.getChildren()+"; existingChild="+existingChild);
+        Asserts.assertEqualsIgnoringOrder(fabric.getMembers(), fabric.getChildren());
 
         List<Location> remainingLocs = MutableList.<Location>builder().addAll(locs).build();
         for (Entity child : fabric.getChildren()) {


[2/4] git commit: Improve DynamicFabric test coverage

Posted by al...@apache.org.
Improve DynamicFabric test coverage

- for when fabric has existing children


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

Branch: refs/heads/master
Commit: fede9621588ddf2a60cb58015db4cc00ab60deaa
Parents: e315de3
Author: Aled Sage <al...@gmail.com>
Authored: Mon Jul 21 14:21:30 2014 +0100
Committer: Aled Sage <al...@gmail.com>
Committed: Mon Jul 21 14:31:37 2014 +0100

----------------------------------------------------------------------
 .../entity/group/DynamicFabricTest.java         | 75 ++++++++++++++++++++
 1 file changed, 75 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/fede9621/core/src/test/java/brooklyn/entity/group/DynamicFabricTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/brooklyn/entity/group/DynamicFabricTest.java b/core/src/test/java/brooklyn/entity/group/DynamicFabricTest.java
index 85f032c..ea024b6 100644
--- a/core/src/test/java/brooklyn/entity/group/DynamicFabricTest.java
+++ b/core/src/test/java/brooklyn/entity/group/DynamicFabricTest.java
@@ -53,6 +53,7 @@ import brooklyn.test.Asserts;
 import brooklyn.test.TestUtils;
 import brooklyn.test.entity.BlockingEntity;
 import brooklyn.test.entity.TestEntity;
+import brooklyn.util.collections.MutableList;
 import brooklyn.util.collections.MutableMap;
 import brooklyn.util.repeat.Repeater;
 
@@ -404,6 +405,80 @@ public class DynamicFabricTest extends BrooklynAppUnitTestSupport {
         assertEquals(((TestEntity)getMember(child, 1)).getConfigureProperties().get("fromFabric"), null);
 	}
 
+    @Test
+    public void testExistingChildrenStarted() throws Exception {
+        List<Location> locs = ImmutableList.of(loc1, loc2, loc3);
+        
+        DynamicFabric fabric = app.createAndManageChild(EntitySpec.create(DynamicFabric.class)
+            .configure(DynamicFabric.MEMBER_SPEC, EntitySpec.create(TestEntity.class)));
+        
+        List<TestEntity> existingChildren = Lists.newArrayList();
+        for (int i = 0; i < 3; i++) {
+            existingChildren.add(fabric.addChild(EntitySpec.create(TestEntity.class)));
+        }
+        app.start(locs);
+
+        // Expect only these existing children
+        Asserts.assertEqualsIgnoringOrder(fabric.getChildren(), existingChildren);
+
+        // Expect one location per existing child
+        List<Location> remainingLocs = MutableList.copyOf(locs);
+        for (Entity existingChild : existingChildren) {
+            Collection<Location> childLocs = existingChild.getLocations();
+            assertEquals(childLocs.size(), 1, "childLocs="+childLocs);
+            assertTrue(remainingLocs.removeAll(childLocs));
+        }
+    }
+
+    @Test
+    public void testExistingChildrenStartedRoundRobiningAcrossLocations() throws Exception {
+        List<Location> locs = ImmutableList.of(loc1, loc2);
+        
+        DynamicFabric fabric = app.createAndManageChild(EntitySpec.create(DynamicFabric.class)
+            .configure(DynamicFabric.MEMBER_SPEC, EntitySpec.create(TestEntity.class)));
+        
+        List<TestEntity> existingChildren = Lists.newArrayList();
+        for (int i = 0; i < 4; i++) {
+            existingChildren.add(fabric.addChild(EntitySpec.create(TestEntity.class)));
+        }
+        app.start(locs);
+
+        // Expect only these existing children
+        Asserts.assertEqualsIgnoringOrder(fabric.getChildren(), existingChildren);
+
+        // Expect one location per existing child (round-robin)
+        // Expect one location per existing child
+        List<Location> remainingLocs = MutableList.<Location>builder().addAll(locs).addAll(locs).build();
+        for (Entity existingChild : existingChildren) {
+            Collection<Location> childLocs = existingChild.getLocations();
+            assertEquals(childLocs.size(), 1, "childLocs="+childLocs);
+            assertTrue(remainingLocs.remove(Iterables.get(childLocs, 0)), "childLocs="+childLocs+"; remainingLocs="+remainingLocs+"; allLocs="+locs);
+        }
+    }
+
+    @Test
+    public void testExistingChildrenToppedUpWhenNewMembersIfMoreLocations() throws Exception {
+        List<Location> locs = ImmutableList.of(loc1, loc2, loc3);
+        
+        DynamicFabric fabric = app.createAndManageChild(EntitySpec.create(DynamicFabric.class)
+            .configure(DynamicFabric.MEMBER_SPEC, EntitySpec.create(TestEntity.class)));
+        
+        TestEntity existingChild = fabric.addChild(EntitySpec.create(TestEntity.class));
+        
+        app.start(locs);
+
+        // Expect three children: the existing one, and one per other location
+        assertEquals(fabric.getChildren().size(), 3, "children="+fabric.getChildren());
+        assertTrue(fabric.getChildren().contains(existingChild), "children="+fabric.getChildren()+"; existingChild="+existingChild);
+
+        List<Location> remainingLocs = MutableList.<Location>builder().addAll(locs).build();
+        for (Entity child : fabric.getChildren()) {
+            Collection<Location> childLocs = child.getLocations();
+            assertEquals(childLocs.size(), 1, "childLocs="+childLocs);
+            assertTrue(remainingLocs.remove(Iterables.get(childLocs, 0)), "childLocs="+childLocs+"; remainingLocs="+remainingLocs+"; allLocs="+locs);
+        }
+    }
+
 	private Entity getGrandchild(Entity entity, int childIndex, int grandchildIndex) {
         Entity child = getChild(entity, childIndex);
         return Iterables.get(child.getChildren(), grandchildIndex);


[3/4] git commit: Adds EntitySpec.groups and EntitySpec.members

Posted by al...@apache.org.
Adds EntitySpec.groups and EntitySpec.members

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

Branch: refs/heads/master
Commit: 406702291832cc21b9cc820d5d78920933f8233d
Parents: 35f267f
Author: Aled Sage <al...@gmail.com>
Authored: Mon Jul 21 14:48:07 2014 +0100
Committer: Aled Sage <al...@gmail.com>
Committed: Mon Jul 21 14:48:07 2014 +0100

----------------------------------------------------------------------
 .../brooklyn/entity/proxying/EntitySpec.java    | 39 +++++++++++++++++++-
 .../entity/proxying/InternalEntityFactory.java  | 12 ++++++
 .../brooklyn/entity/basic/EntitySpecTest.java   | 22 +++++++++++
 3 files changed, 72 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/40670229/api/src/main/java/brooklyn/entity/proxying/EntitySpec.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/brooklyn/entity/proxying/EntitySpec.java b/api/src/main/java/brooklyn/entity/proxying/EntitySpec.java
index 1ea5fb6..aad0d28 100644
--- a/api/src/main/java/brooklyn/entity/proxying/EntitySpec.java
+++ b/api/src/main/java/brooklyn/entity/proxying/EntitySpec.java
@@ -35,6 +35,7 @@ import org.slf4j.LoggerFactory;
 import brooklyn.config.ConfigKey;
 import brooklyn.config.ConfigKey.HasConfigKey;
 import brooklyn.entity.Entity;
+import brooklyn.entity.Group;
 import brooklyn.location.Location;
 import brooklyn.management.Task;
 import brooklyn.policy.Enricher;
@@ -116,7 +117,9 @@ public class EntitySpec<T extends Entity> implements Serializable {
                 .enricherSpecs(spec.getEnricherSpecs())
                 .enrichers(spec.getEnrichers())
                 .addInitializers(spec.getInitializers())
-                .children(spec.getChildren());
+                .children(spec.getChildren())
+                .members(spec.getMembers())
+                .groups(spec.getGroups());
         
         if (spec.getParent() != null) result.parent(spec.getParent());
         if (spec.getImplementation() != null) result.impl(spec.getImplementation());
@@ -143,6 +146,8 @@ public class EntitySpec<T extends Entity> implements Serializable {
     private final Set<Class<?>> additionalInterfaces = Sets.newLinkedHashSet();
     private final List<EntityInitializer> entityInitializers = Lists.newArrayList();
     private final List<EntitySpec<?>> children = Lists.newArrayList();
+    private final List<Entity> members = Lists.newArrayList();
+    private final List<Group> groups = Lists.newArrayList();
     private volatile boolean immutable;
     
     public EntitySpec(Class<T> type) {
@@ -198,6 +203,14 @@ public class EntitySpec<T extends Entity> implements Serializable {
         return children;
     }
     
+    public List<Entity> getMembers() {
+        return members;
+    }
+    
+    public List<Group> getGroups() {
+        return groups;
+    }
+    
     /**
      * @return The entity's parent
      */
@@ -310,6 +323,30 @@ public class EntitySpec<T extends Entity> implements Serializable {
         return this;
     }
 
+    public EntitySpec<T> members(Iterable<? extends Entity> members) {
+        checkMutable();
+        Iterables.addAll(this.members, members);
+        return this;
+    }
+
+    public EntitySpec<T> member(Entity member) {
+        checkMutable();
+        members.add(member);
+        return this;
+    }
+
+    public EntitySpec<T> groups(Iterable<? extends Group> groups) {
+        checkMutable();
+        Iterables.addAll(this.groups, groups);
+        return this;
+    }
+
+    public EntitySpec<T> group(Group group) {
+        checkMutable();
+        groups.add(group);
+        return this;
+    }
+
     public EntitySpec<T> parent(Entity val) {
         checkMutable();
         parent = checkNotNull(val, "parent");

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/40670229/core/src/main/java/brooklyn/entity/proxying/InternalEntityFactory.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/entity/proxying/InternalEntityFactory.java b/core/src/main/java/brooklyn/entity/proxying/InternalEntityFactory.java
index df73423..d6a31fb 100644
--- a/core/src/main/java/brooklyn/entity/proxying/InternalEntityFactory.java
+++ b/core/src/main/java/brooklyn/entity/proxying/InternalEntityFactory.java
@@ -29,6 +29,7 @@ import org.slf4j.LoggerFactory;
 
 import brooklyn.config.ConfigKey;
 import brooklyn.entity.Entity;
+import brooklyn.entity.Group;
 import brooklyn.entity.basic.AbstractEntity;
 import brooklyn.entity.basic.BrooklynTaskTags;
 import brooklyn.entity.basic.EntityInternal;
@@ -220,6 +221,17 @@ public class InternalEntityFactory {
                 entity.addChild(child);
             }
             
+            for (Entity member: spec.getMembers()) {
+                if (!(entity instanceof Group)) {
+                    throw new IllegalStateException("Entity "+entity+" must be a group to add members "+spec.getMembers());
+                }
+                ((Group)entity).addMember(member);
+            }
+
+            for (Group group : spec.getGroups()) {
+                group.addMember(entity);
+            }
+
             return entity;
             
         } catch (Exception e) {

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/40670229/core/src/test/java/brooklyn/entity/basic/EntitySpecTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/brooklyn/entity/basic/EntitySpecTest.java b/core/src/test/java/brooklyn/entity/basic/EntitySpecTest.java
index 8550231..403441c 100644
--- a/core/src/test/java/brooklyn/entity/basic/EntitySpecTest.java
+++ b/core/src/test/java/brooklyn/entity/basic/EntitySpecTest.java
@@ -35,9 +35,11 @@ import brooklyn.policy.EnricherSpec;
 import brooklyn.policy.Policy;
 import brooklyn.policy.PolicySpec;
 import brooklyn.policy.basic.AbstractPolicy;
+import brooklyn.test.Asserts;
 import brooklyn.test.entity.TestEntity;
 import brooklyn.util.flags.SetFromFlag;
 
+import com.google.common.collect.ImmutableSet;
 import com.google.common.collect.Iterables;
 
 public class EntitySpecTest extends BrooklynAppUnitTestSupport {
@@ -123,6 +125,26 @@ public class EntitySpecTest extends BrooklynAppUnitTestSupport {
         assertEquals(Iterables.getOnlyElement(entity.getEnrichers()), enricher);
     }
     
+    @Test
+    public void testAddsMembers() throws Exception {
+        entity = app.createAndManageChild(EntitySpec.create(TestEntity.class));
+        BasicGroup group = app.createAndManageChild(EntitySpec.create(BasicGroup.class)
+                .member(entity));
+        
+        Asserts.assertEqualsIgnoringOrder(group.getMembers(), ImmutableSet.of(entity));
+        Asserts.assertEqualsIgnoringOrder(entity.getGroups(), ImmutableSet.of(group));
+    }
+    
+    @Test
+    public void testAddsGroups() throws Exception {
+        BasicGroup group = app.createAndManageChild(EntitySpec.create(BasicGroup.class));
+        entity = app.createAndManageChild(EntitySpec.create(TestEntity.class)
+                .group(group));
+        
+        Asserts.assertEqualsIgnoringOrder(group.getMembers(), ImmutableSet.of(entity));
+        Asserts.assertEqualsIgnoringOrder(entity.getGroups(), ImmutableSet.of(group));
+    }
+    
     public static class MyPolicy extends AbstractPolicy {
         public static final BasicConfigKey<String> CONF1 = new BasicConfigKey<String>(String.class, "testpolicy.conf1", "my descr, conf1", "defaultval1");
         public static final BasicConfigKey<Integer> CONF2 = new BasicConfigKey<Integer>(Integer.class, "testpolicy.conf2", "my descr, conf2", 2);


[4/4] git commit: This closes #82

Posted by al...@apache.org.
This closes #82


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

Branch: refs/heads/master
Commit: f03d82c4f9aa166bbed058f0f63cb300ad892194
Parents: 7997893 4067022
Author: Aled Sage <al...@gmail.com>
Authored: Mon Jul 28 15:21:33 2014 +0100
Committer: Aled Sage <al...@gmail.com>
Committed: Mon Jul 28 15:21:33 2014 +0100

----------------------------------------------------------------------
 .../brooklyn/entity/proxying/EntitySpec.java    | 39 +++++++++-
 .../entity/group/DynamicFabricImpl.java         |  4 +-
 .../entity/proxying/InternalEntityFactory.java  | 12 +++
 .../brooklyn/entity/basic/EntitySpecTest.java   | 22 ++++++
 .../entity/group/DynamicFabricTest.java         | 78 ++++++++++++++++++++
 5 files changed, 153 insertions(+), 2 deletions(-)
----------------------------------------------------------------------