You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@brooklyn.apache.org by grkvlt <gi...@git.apache.org> on 2016/08/10 20:02:24 UTC

[GitHub] brooklyn-server pull request #295: Change conditional entity to reflect serv...

GitHub user grkvlt opened a pull request:

    https://github.com/apache/brooklyn-server/pull/295

    Change conditional entity to reflect service state of optional child

    Adds an enricher that propagates `service.isUp` from the child entity, if one is created. This allows other entities to use the `service.isUp` sensor of the `ConditionalEntity` as a latch, without needing to know the identity (or even presence) of the child. A configuration setting enables propagation of other sensors from the child.

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/grkvlt/brooklyn-server conditional-entity-startup

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/brooklyn-server/pull/295.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #295
    
----

----


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

[GitHub] brooklyn-server pull request #295: Change conditional entity to reflect serv...

Posted by neykov <gi...@git.apache.org>.
Github user neykov commented on a diff in the pull request:

    https://github.com/apache/brooklyn-server/pull/295#discussion_r74420188
  
    --- 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();
    --- End diff --
    
    Why did you have to pass locations explicitly, won't it pick them from the parent by default? What if there's a location embedded in the spec?


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

[GitHub] brooklyn-server issue #295: Change conditional entity to reflect service sta...

Posted by neykov <gi...@git.apache.org>.
Github user neykov commented on the issue:

    https://github.com/apache/brooklyn-server/pull/295
  
    LGTM, could improve `SERVICE_UP` handling by following the `AbstractApplication` example.


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

[GitHub] brooklyn-server pull request #295: Change conditional entity to reflect serv...

Posted by neykov <gi...@git.apache.org>.
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.
---

[GitHub] brooklyn-server pull request #295: Change conditional entity to reflect serv...

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

[GitHub] brooklyn-server pull request #295: Change conditional entity to reflect serv...

Posted by neykov <gi...@git.apache.org>.
Github user neykov commented on a diff in the pull request:

    https://github.com/apache/brooklyn-server/pull/295#discussion_r74420374
  
    --- 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
    --- End diff --
    
    Typo propagateion


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

[GitHub] brooklyn-server issue #295: Change conditional entity to reflect service sta...

Posted by grkvlt <gi...@git.apache.org>.
Github user grkvlt commented on the issue:

    https://github.com/apache/brooklyn-server/pull/295
  
    @neykov I added the enricher you suggested, it looks like a better way of doing things, thanks


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

[GitHub] brooklyn-server pull request #295: Change conditional entity to reflect serv...

Posted by asfgit <gi...@git.apache.org>.
Github user asfgit closed the pull request at:

    https://github.com/apache/brooklyn-server/pull/295


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