Github user neykov commented on a diff in the pull request:

    https://github.com/apache/incubator-brooklyn/pull/782#discussion_r36010043
  
    --- Diff: 
software/nosql/src/main/java/brooklyn/entity/nosql/redis/RedisClusterImpl.java 
---
    @@ -20,49 +20,73 @@
     
     import java.util.Collection;
     
    +import brooklyn.enricher.Enrichers;
     import brooklyn.entity.Entity;
     import brooklyn.entity.basic.AbstractEntity;
     import brooklyn.entity.basic.Entities;
     import brooklyn.entity.group.DynamicCluster;
     import brooklyn.entity.proxying.EntitySpec;
     import brooklyn.entity.trait.Startable;
    +import brooklyn.event.AttributeSensor;
    +import brooklyn.event.basic.Sensors;
     import brooklyn.location.Location;
     
    +import com.google.common.collect.ImmutableList;
    +import com.google.common.collect.ImmutableMap;
    +
     public class RedisClusterImpl extends AbstractEntity implements 
RedisCluster {
     
    -    protected RedisStore master;
    -    protected DynamicCluster slaves;
    +    private AttributeSensor<RedisStore> MASTER = 
Sensors.newSensor(RedisStore.class, "redis.master");
    +    private AttributeSensor<DynamicCluster> SLAVES = 
Sensors.newSensor(DynamicCluster.class, "redis.slaves");
     
         public RedisClusterImpl() {
         }
     
         @Override
         public RedisStore getMaster() {
    -        return master;
    +        return getAttribute(MASTER);
         }
         
         @Override
         public DynamicCluster getSlaves() {
    -        return slaves;
    +        return getAttribute(SLAVES);
         }
         
         @Override
         public void start(Collection<? extends Location> locations) {
    -        master = addChild(EntitySpec.create(RedisStore.class));
    +        RedisStore master = getMaster();
    +        if (master == null) {
    +            master = addChild(EntitySpec.create(RedisStore.class));
    +            setAttribute(MASTER, master);
    +        }
    +
             Entities.manage(master);
    -        master.start(locations);
    +        master.invoke(RedisStore.START, ImmutableMap.<String, 
Object>of("locations", ImmutableList.copyOf(locations))).blockUntilEnded();
     
    -        slaves = addChild(EntitySpec.create(DynamicCluster.class)
    -                .configure(DynamicCluster.MEMBER_SPEC, 
EntitySpec.create(RedisSlave.class).configure(RedisSlave.MASTER, master)));
    -        slaves.start(locations);
    +        DynamicCluster slaves = getSlaves();
    +        if (slaves == null) {
    +            slaves = addChild(EntitySpec.create(DynamicCluster.class)
    +                    .configure(DynamicCluster.MEMBER_SPEC, 
EntitySpec.create(RedisSlave.class).configure(RedisSlave.MASTER, master)));
    +            setAttribute(SLAVES, slaves);
    +        }
    +        
    +        slaves.invoke(DynamicCluster.START, ImmutableMap.<String, 
Object>of("locations", ImmutableList.copyOf(locations))).blockUntilEnded();
     
             setAttribute(Startable.SERVICE_UP, calculateServiceUp());
    +
    +        addEnricher(Enrichers.builder()
    +                .propagating(RedisStore.HOSTNAME, RedisStore.ADDRESS, 
RedisStore.SUBNET_HOSTNAME, RedisStore.SUBNET_ADDRESS, RedisStore.REDIS_PORT)
    +                .from(master)
    +                .build());
         }
     
         @Override
         public void stop() {
    -        if (slaves != null) slaves.stop();
    -        if (master != null) master.stop();
    +        DynamicCluster slaves = getSlaves();
    +        RedisStore master = getMaster(); 
    +        
    +        if (slaves != null) slaves.invoke(DynamicCluster.STOP, 
ImmutableMap.<String, Object>of()).blockUntilEnded();
    --- End diff --
    
    Same here, you could invoke both effectors and then check for the return 
value.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

Reply via email to