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

    https://github.com/apache/brooklyn-server/pull/295#discussion_r74423092
  
    --- Diff: 
core/src/main/java/org/apache/brooklyn/entity/stock/ConditionalEntityImpl.java 
---
    @@ -19,25 +19,72 @@
     package org.apache.brooklyn.entity.stock;
     
     import java.util.Collection;
    +import java.util.Set;
    +
    +import org.slf4j.Logger;
    +import org.slf4j.LoggerFactory;
     
     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.sensor.AttributeSensor;
    +import org.apache.brooklyn.core.entity.Attributes;
    +import org.apache.brooklyn.core.entity.Entities;
    +import org.apache.brooklyn.core.entity.lifecycle.Lifecycle;
    +import org.apache.brooklyn.core.entity.lifecycle.ServiceStateLogic;
    +import org.apache.brooklyn.core.entity.trait.Startable;
    +import org.apache.brooklyn.core.location.Locations;
    +import org.apache.brooklyn.enricher.stock.Enrichers;
    +import org.apache.brooklyn.util.collections.MutableSet;
    +import org.apache.brooklyn.util.exceptions.Exceptions;
     
     public class ConditionalEntityImpl extends BasicStartableImpl implements 
ConditionalEntity {
     
    +    private static final Logger LOG = 
LoggerFactory.getLogger(BasicStartableImpl.class);
    +
         @Override
         public void start(Collection<? extends Location> locations) {
    -        Entity child = sensors().get(CONDITIONAL_ENTITY);
    -        EntitySpec<?> spec = config().get(CONDITIONAL_ENTITY_SPEC);
    -        Boolean create = config().get(CREATE_CONDITIONAL_ENTITY);
    -
    -        // Child not yet created; Entity spec is present; Create flag is 
true
    -        if (child == null && spec != null && Boolean.TRUE.equals(create)) {
    -            Entity created = addChild(EntitySpec.create(spec));
    -            sensors().set(CONDITIONAL_ENTITY, created);
    +        try {
    +            ServiceStateLogic.setExpectedState(this, Lifecycle.STARTING);
    +
    +            Entity child = sensors().get(CONDITIONAL_ENTITY);
    +            EntitySpec<?> spec = config().get(CONDITIONAL_ENTITY_SPEC);
    +            Boolean create = config().get(CREATE_CONDITIONAL_ENTITY);
    +            Boolean propagate = 
config().get(PROPAGATE_CONDITIONAL_ENTITY_SENSORS);
    +            Set<AttributeSensor<?>> sensors = 
MutableSet.copyOf(config().get(CONDITIONAL_ENTITY_SENSOR_LIST));
    +
    +            addLocations(locations);
    +            locations = Locations.getLocationsCheckingAncestors(locations, 
this);
    +            LOG.info("Starting entity "+this+" at "+locations);
    +
    +            // Child not yet created; Entity spec is present; Create flag 
is true
    +            if (child == null && spec != null && 
Boolean.TRUE.equals(create)) {
    +                child = addChild(EntitySpec.create(spec));
    +                sensors().set(CONDITIONAL_ENTITY, child);
    +
    +                // Add enrichers for sensor propagateion
    +                
enrichers().add(Enrichers.builder().propagating(Startable.SERVICE_UP).from(child).build());
    --- End diff --
    
    This approach to propagating the `SERVICE_UP` sensor could in theory 
conflict with the logic which updates it based on the 
`service.notUp.indicators` key. Suggest using instead:
    ```
            enrichers().add(ServiceStateLogic.newEnricherFromChildrenUp()
                    .suppressDuplicates(true)
                    
.configure(ComputeServiceIndicatorsFromChildrenAndMembers.UP_QUORUM_CHECK, 
QuorumCheck.QuorumChecks.all()));
    ```
    
    It will add an entry to the `notUp` map if there are any problems with the 
children and update `state.isUp` correspondingly.
    
    If you would like additionally to propagate the running state (i.e. wait 
for children startup) could replace the above with
    ```
            enrichers().add(ServiceStateLogic.newEnricherFromChildren()
                    .suppressDuplicates(true)
                    
.configure(ComputeServiceIndicatorsFromChildrenAndMembers.UP_QUORUM_CHECK, 
QuorumCheck.QuorumChecks.all()));
    ```
    



---
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