Add new first cluster member attributes
Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/d2d78e43 Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/d2d78e43 Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/d2d78e43 Branch: refs/heads/master Commit: d2d78e43262f42a33b77dadee8b54917399d6608 Parents: c6d148d Author: Andrew Kennedy <[email protected]> Authored: Mon Aug 25 19:32:02 2014 +0100 Committer: Andrew Kennedy <[email protected]> Committed: Sat Aug 30 17:23:47 2014 +0100 ---------------------------------------------------------------------- .../brooklyn/entity/group/DynamicCluster.java | 14 +++++++++++ .../entity/group/DynamicClusterImpl.java | 25 ++++++++++++++++++-- 2 files changed, 37 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/d2d78e43/core/src/main/java/brooklyn/entity/group/DynamicCluster.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/brooklyn/entity/group/DynamicCluster.java b/core/src/main/java/brooklyn/entity/group/DynamicCluster.java index f51a9ef..bf46ebb 100644 --- a/core/src/main/java/brooklyn/entity/group/DynamicCluster.java +++ b/core/src/main/java/brooklyn/entity/group/DynamicCluster.java @@ -166,6 +166,18 @@ public interface DynamicCluster extends AbstractGroup, Cluster, MemberReplaceabl new TypeToken<Set<Location>>() {}, "dynamiccluster.failedSubLocations", "Sub locations that seem to have failed"); + AttributeSensor<Boolean> CLUSTER_MEMBER = Sensors.newBooleanSensor( + "cluster.member", "Set on an entity if it is a member of a cluster"); + + AttributeSensor<Boolean> FIRST_MEMBER = Sensors.newBooleanSensor( + "cluster.first", "Set on an entity if it is the first member of a cluster"); + + AttributeSensor<Entity> FIRST = Sensors.newSensor(Entity.class, + "cluster.first.entity", "The first member of the cluster"); + + AttributeSensor<Entity> CLUSTER = Sensors.newSensor(Entity.class, + "cluster.entity", "The cluster an entity is a member of"); + /** * Changes the cluster size by the given number. * @@ -187,4 +199,6 @@ public interface DynamicCluster extends AbstractGroup, Cluster, MemberReplaceabl /** @deprecated since 0.7.0; use {@link #setMemberSpec(EntitySpec)} */ @Deprecated void setFactory(EntityFactory<?> factory); + + Entity addNode(Location loc, Map<?,?> extraFlags); } http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/d2d78e43/core/src/main/java/brooklyn/entity/group/DynamicClusterImpl.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/brooklyn/entity/group/DynamicClusterImpl.java b/core/src/main/java/brooklyn/entity/group/DynamicClusterImpl.java index 553d453..d0e273f 100644 --- a/core/src/main/java/brooklyn/entity/group/DynamicClusterImpl.java +++ b/core/src/main/java/brooklyn/entity/group/DynamicClusterImpl.java @@ -34,12 +34,14 @@ import javax.annotation.Nullable; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import brooklyn.config.render.RendererHints; import brooklyn.entity.Entity; import brooklyn.entity.basic.AbstractGroupImpl; -import brooklyn.entity.basic.Attributes; +import brooklyn.entity.basic.DelegateEntity; import brooklyn.entity.basic.Entities; import brooklyn.entity.basic.EntityFactory; import brooklyn.entity.basic.EntityFactoryForLocation; +import brooklyn.entity.basic.EntityLocal; import brooklyn.entity.basic.Lifecycle; import brooklyn.entity.basic.QuorumCheck.QuorumChecks; import brooklyn.entity.basic.ServiceStateLogic; @@ -112,6 +114,12 @@ public class DynamicClusterImpl extends AbstractGroupImpl implements DynamicClus }); } + static { + RendererHints.register(FIRST, new RendererHints.NamedActionWithUrl("Open", DelegateEntity.EntityUrl.entityUrl())); + RendererHints.register(CLUSTER, new RendererHints.NamedActionWithUrl("Open", DelegateEntity.EntityUrl.entityUrl())); + } + + private static final Logger LOG = LoggerFactory.getLogger(DynamicClusterImpl.class); /** @@ -710,7 +718,8 @@ public class DynamicClusterImpl extends AbstractGroupImpl implements DynamicClus return getConfig(CUSTOM_CHILD_FLAGS); } - protected Entity addNode(Location loc, Map<?,?> extraFlags) { + @Override + public Entity addNode(Location loc, Map<?,?> extraFlags) { Map<?,?> createFlags = MutableMap.builder() .putAll(getCustomChildFlags()) .putAll(extraFlags) @@ -720,6 +729,18 @@ public class DynamicClusterImpl extends AbstractGroupImpl implements DynamicClus } Entity entity = createNode(loc, createFlags); + + ((EntityLocal) entity).setAttribute(CLUSTER_MEMBER, true); + ((EntityLocal) entity).setAttribute(CLUSTER, this); + synchronized (this) { + if (getAttribute(FIRST) == null) { + setAttribute(FIRST, entity); + ((EntityLocal) entity).setAttribute(FIRST_MEMBER, true); + } else { + ((EntityLocal) entity).setAttribute(FIRST_MEMBER, false); + } + } + Entities.manage(entity); addMember(entity); return entity;
