/** * Default start will start all Startable children (child.start(Collection<? extends Location>)), * calling preStart(locations) first and postStart(locations) afterwards. */ @Override public void start(Collection<? extends Location> locations) { this.addLocations(locations); setAttribute(Attributes.SERVICE_STATE, Lifecycle.STARTING); recordApplicationEvent(Lifecycle.STARTING); try { preStart(locations); StartableMethods.start(this, locations); postStart(locations); } catch (Exception e) { setAttribute(Attributes.SERVICE_STATE, Lifecycle.ON_FIRE); recordApplicationEvent(Lifecycle.ON_FIRE); // no need to log here; the effector invocation should do that throw Exceptions.propagate(e); } setAttribute(SERVICE_UP, true); setAttribute(Attributes.SERVICE_STATE, Lifecycle.RUNNING); deployed = true; recordApplicationEvent(Lifecycle.RUNNING); log.info("Started application " + this); }
@Override public Application getApplication() { if (application!=null) { if (application.getId().equals(getId())) return (Application) getProxyIfAvailable(); return application; } if (getParent()==null) return (Application)getProxyIfAvailable(); return getParent().getApplication(); }
@Override protected synchronized void setApplication(Application app) { if (app.getId().equals(getId())) { application = getProxy()!=null ? (Application)getProxy() : app; } else { application = app; // Alex, Mar 2013: added some checks; // i *think* these conditions should not happen, // and so should throw but don't want to break things (yet) if (getParent()==null) { log.warn("Setting application of "+this+" to "+app+", but "+this+" is not parented"); } else if (getParent().getApplicationId().equals(app.getParent())) { log.warn("Setting application of "+this+" to "+app+", but parent "+getParent()+" has different app "+getParent().getApplication()); } } super.setApplication(app); }
log.info("Stopping application " + this); setAttribute(SERVICE_UP, false); setAttribute(Attributes.SERVICE_STATE, Lifecycle.STOPPING); recordApplicationEvent(Lifecycle.STOPPING); try { StartableMethods.stop(this); } catch (Exception e) { setAttribute(Attributes.SERVICE_STATE, Lifecycle.ON_FIRE); recordApplicationEvent(Lifecycle.ON_FIRE); log.warn("Error stopping application " + this + " (rethrowing): "+e); throw Exceptions.propagate(e); setAttribute(Attributes.SERVICE_STATE, Lifecycle.STOPPED); recordApplicationEvent(Lifecycle.STOPPED); getEntityManager().unmanage(this);
private void recordApplicationEvent(Lifecycle state) { try { ((ManagementContextInternal)getManagementContext()).getUsageManager().recordApplicationEvent(this, state); } catch (RuntimeInterruptedException e) { throw e; } catch (RuntimeException e) { if (getManagementContext().isRunning()) { log.warn("Problem storing application event "+state+" for "+this, e); } } } }
@Override public void onManagementStopped() { super.onManagementStopped(); recordApplicationEvent(Lifecycle.DESTROYED); }
/** Launches the web console on the given port, and a Brooklyn application, with a single command. * For readability and flexibility, clients may prefer the {@link #newLauncher()} builder-style syntax. * * @deprecated in 0.5; use newInstance().webconsolePort(port).shutdownOnExit(shutdownApp).webconsole(startWebConsole).application(app).start() */ @Deprecated public static ManagementContext manage(final AbstractApplication app, int port, boolean shutdownApp, boolean startWebConsole) { // Locate the management context Entities.startManagement(app); LocalManagementContext context = (LocalManagementContext) app.getManagementContext(); if (startWebConsole) { try { new BrooklynWebServer(context, port).start(); } catch (Exception e) { LOG.warn("Failed to start Brooklyn web-console", e); } } if (shutdownApp) Entities.invokeStopOnShutdown(app); return context; }