fix the problem in the previous test where failure in custom start behaviour in applications does not cause an app to go on fire
Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/4e0be7f6 Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/4e0be7f6 Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/4e0be7f6 Branch: refs/heads/master Commit: 4e0be7f696325adad0389aac3b756c043cb268d9 Parents: 1bbe475 Author: Alex Heneveld <alex.henev...@cloudsoftcorp.com> Authored: Wed Feb 22 17:23:02 2017 +0000 Committer: Alex Heneveld <alex.henev...@cloudsoftcorp.com> Committed: Wed Feb 22 17:26:20 2017 +0000 ---------------------------------------------------------------------- .../core/entity/AbstractApplication.java | 51 +++++++++++++++----- 1 file changed, 38 insertions(+), 13 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/4e0be7f6/core/src/main/java/org/apache/brooklyn/core/entity/AbstractApplication.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/brooklyn/core/entity/AbstractApplication.java b/core/src/main/java/org/apache/brooklyn/core/entity/AbstractApplication.java index 857635d..55b0c27 100644 --- a/core/src/main/java/org/apache/brooklyn/core/entity/AbstractApplication.java +++ b/core/src/main/java/org/apache/brooklyn/core/entity/AbstractApplication.java @@ -147,24 +147,35 @@ public abstract class AbstractApplication extends AbstractEntity implements Star Collection<? extends Location> locationsToUse = locations==null ? ImmutableSet.<Location>of() : locations; ServiceProblemsLogic.clearProblemsIndicator(this, START); ServiceStateLogic.ServiceNotUpLogic.updateNotUpIndicator(this, Attributes.SERVICE_STATE_ACTUAL, "Application starting"); + ServiceStateLogic.ServiceNotUpLogic.clearNotUpIndicator(this, START.getName()); setExpectedStateAndRecordLifecycleEvent(Lifecycle.STARTING); try { - preStart(locationsToUse); - - // Opportunity to block startup until other dependent components are available - Object val = config().get(START_LATCH); - if (val != null) log.debug("{} finished waiting for start-latch; continuing...", this); - - doStart(locationsToUse); - postStart(locationsToUse); - + try { + + preStart(locationsToUse); + + // Opportunity to block startup until other dependent components are available + Object val = config().get(START_LATCH); + if (val != null) log.debug("{} finished waiting for start-latch; continuing...", this); + + doStart(locationsToUse); + postStart(locationsToUse); + + } catch (ProblemStartingChildrenException e) { + throw Exceptions.propagate(e); + } catch (Exception e) { + // should remember problems, apart from those that happened starting children + // fixed bug introduced by the fix in dacf18b831e1e5e1383d662a873643a3c3cabac6 + // where failures in special code at application root don't cause app to go on fire + ServiceStateLogic.ServiceNotUpLogic.updateNotUpIndicator(this, START.getName(), Exceptions.collapseText(e)); + throw Exceptions.propagate(e); + } + } catch (Exception e) { - // TODO should probably remember these problems then clear? if so, do it here ... or on all effectors? - // ServiceProblemsLogic.updateProblemsIndicator(this, START, e); - recordApplicationEvent(Lifecycle.ON_FIRE); // no need to log here; the effector invocation should do that throw Exceptions.propagate(e); + } finally { ServiceStateLogic.ServiceNotUpLogic.clearNotUpIndicator(this, Attributes.SERVICE_STATE_ACTUAL); ServiceStateLogic.setExpectedState(this, Lifecycle.RUNNING); @@ -180,9 +191,23 @@ public abstract class AbstractApplication extends AbstractEntity implements Star } protected void doStart(Collection<? extends Location> locations) { - StartableMethods.start(this, locations); + doStartChildren(locations); + } + + protected void doStartChildren(Collection<? extends Location> locations) { + try { + StartableMethods.start(this, locations); + } catch (Exception e) { + Exceptions.propagateIfFatal(e); + throw new ProblemStartingChildrenException(e); + } } + private static class ProblemStartingChildrenException extends RuntimeException { + private static final long serialVersionUID = 7710856289284536803L; + private ProblemStartingChildrenException(Exception cause) { super(cause); } + } + /** * Default is no-op. Subclasses can override. * */