Repository: incubator-brooklyn Updated Branches: refs/heads/master 56e8c3989 -> 0efc1e351
BasicStartableImpl sets expected lifecycle states Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/614cbb27 Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/614cbb27 Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/614cbb27 Branch: refs/heads/master Commit: 614cbb27acac4051e8314524751b731d9a7fa60e Parents: 846143c Author: Sam Corbett <[email protected]> Authored: Mon Jul 20 19:25:59 2015 +0100 Committer: Sam Corbett <[email protected]> Committed: Thu Aug 6 16:01:55 2015 +0100 ---------------------------------------------------------------------- .../entity/basic/BasicStartableImpl.java | 58 +++++++++++++------- 1 file changed, 37 insertions(+), 21 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/614cbb27/core/src/main/java/brooklyn/entity/basic/BasicStartableImpl.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/brooklyn/entity/basic/BasicStartableImpl.java b/core/src/main/java/brooklyn/entity/basic/BasicStartableImpl.java index 1e42490..0f92141 100644 --- a/core/src/main/java/brooklyn/entity/basic/BasicStartableImpl.java +++ b/core/src/main/java/brooklyn/entity/basic/BasicStartableImpl.java @@ -30,6 +30,7 @@ import brooklyn.entity.trait.Startable; import brooklyn.entity.trait.StartableMethods; import brooklyn.location.Location; import brooklyn.management.Task; +import brooklyn.util.exceptions.Exceptions; import com.google.common.base.Predicates; import com.google.common.collect.Iterables; @@ -38,38 +39,53 @@ import com.google.common.collect.Lists; public class BasicStartableImpl extends AbstractEntity implements BasicStartable { private static final Logger log = LoggerFactory.getLogger(BasicStartableImpl.class); - - public BasicStartableImpl() { - super(); - } @Override public void start(Collection<? extends Location> locations) { log.info("Starting entity "+this+" at "+locations); - addLocations(locations); - - // essentially does StartableMethods.start(this, locations), - // but optionally filters locations for each child - - brooklyn.location.basic.Locations.LocationsFilter filter = getConfig(LOCATIONS_FILTER); - Iterable<Entity> startables = filterStartableManagedEntities(getChildren()); - if (startables == null || Iterables.isEmpty(startables)) return; + try { + ServiceStateLogic.setExpectedState(this, Lifecycle.STARTING); + + addLocations(locations); - List<Task<?>> tasks = Lists.newArrayList(); - for (final Entity entity : startables) { - Collection<? extends Location> l2 = locations; - if (filter!=null) { - l2 = filter.filterForContext(new ArrayList<Location>(locations), entity); - log.debug("Child "+entity+" of "+this+" being started in filtered location list: "+l2); + // essentially does StartableMethods.start(this, locations), + // but optionally filters locations for each child + + brooklyn.location.basic.Locations.LocationsFilter filter = getConfig(LOCATIONS_FILTER); + Iterable<Entity> startables = filterStartableManagedEntities(getChildren()); + if (!Iterables.isEmpty(startables)) { + List<Task<?>> tasks = Lists.newArrayListWithCapacity(Iterables.size(startables)); + for (final Entity entity : startables) { + Collection<? extends Location> l2 = locations; + if (filter != null) { + l2 = filter.filterForContext(new ArrayList<Location>(locations), entity); + log.debug("Child " + entity + " of " + this + " being started in filtered location list: " + l2); + } + tasks.add(Entities.invokeEffectorWithArgs(this, entity, Startable.START, l2)); + } + for (Task<?> t : tasks) { + t.getUnchecked(); + } } - tasks.add( Entities.invokeEffectorWithArgs(this, entity, Startable.START, l2) ); + setAttribute(Attributes.SERVICE_UP, true); + ServiceStateLogic.setExpectedState(this, Lifecycle.RUNNING); + } catch (Throwable t) { + ServiceStateLogic.setExpectedState(this, Lifecycle.ON_FIRE); + throw Exceptions.propagate(t); } - for (Task<?> t: tasks) t.getUnchecked(); } @Override public void stop() { - StartableMethods.stop(this); + ServiceStateLogic.setExpectedState(this, Lifecycle.STOPPING); + setAttribute(SERVICE_UP, false); + try { + StartableMethods.stop(this); + ServiceStateLogic.setExpectedState(this, Lifecycle.STOPPED); + } catch (Exception e) { + ServiceStateLogic.setExpectedState(this, Lifecycle.ON_FIRE); + throw Exceptions.propagate(e); + } } @Override
