brooklyn-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From neykov <...@git.apache.org>
Subject [GitHub] brooklyn-server pull request #295: Change conditional entity to reflect serv...
Date Thu, 11 Aug 2016 13:41:12 GMT
Github user neykov commented on a diff in the pull request:

    https://github.com/apache/brooklyn-server/pull/295#discussion_r74423357
  
    --- 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());
    +                if (Boolean.TRUE.equals(propagate)) {
    +                    if (sensors.isEmpty()) {
    +                        enrichers().add(Enrichers.builder().propagatingAllButUsualAnd().from(child).build());
    +                    } else {
    +                        enrichers().add(Enrichers.builder().propagating(sensors).from(child).build());
    +                    }
    +                }
    +            }
    +
    +            // Start child if create flag is set; otherwise just set service.isUp
    +            if (Boolean.TRUE.equals(create)) {
    +                Entities.invokeEffectorWithArgs(this, child, Startable.START, locations).getUnchecked();
    +            } else {
    +                sensors().set(Attributes.SERVICE_UP, true);
    --- End diff --
    
    Similar to the previous comment on `SERVICE_UP` propagation you could control the sensor
value by adding/removing values in the `notUp` map. `AbstractApplication` is a good example
of the approach.


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message