@Override public void onManagementStopped() { super.onManagementStopped(); if (getManagementContext().isRunning()) { recordApplicationEvent(Lifecycle.DESTROYED); } }
protected 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 recording application event '"+state+"' for "+this, e); } } } }
@Override public String toString() { return "JmxFeed["+(getManagementContext()!=null&&getManagementContext().isRunning()?getJmxUri():"mgmt-not-running")+"]"; } }
public static boolean isManaged(Location loc) { ManagementContext mgmt = ((LocationInternal)loc).getManagementContext(); return (mgmt != null) && mgmt.isRunning() && mgmt.getLocationManager().isManaged(loc); }
public static boolean isManaged(Entity e) { return ((EntityInternal)e).getManagementSupport().isDeployed() && ((EntityInternal)e).getManagementContext().isRunning(); }
/** Returns a string describing the problem if mgmt is null or not running; returns absent if no problems */ public static Maybe<String> getProblemMessageIfServerNotRunning(ManagementContext mgmt) { if (mgmt==null) return Maybe.of("no management context available"); if (!mgmt.isRunning()) return Maybe.of("server no longer running"); if (!mgmt.isStartupComplete()) return Maybe.of("server not in required startup-completed state"); return Maybe.absent(); }
@Override @AfterMethod(alwaysRun=true) public void tearDown() throws Exception { List<Exception> exceptions = Lists.newArrayList(); for (ManagementContext mgmt : mgmts) { try { if (mgmt.isRunning()) Entities.destroyAll(mgmt); } catch (Exception e) { LOG.warn("Error destroying management context", e); exceptions.add(e); } } mgmts.clear(); origManagementContext = null; newManagementContext = null; origApp = null; newApp = null; super.tearDown(); if (exceptions.size() > 0) { throw new CompoundRuntimeException("Error in tearDown of "+getClass(), exceptions); } }
private void checkEntitiesHealthy(TestApplication app, TestEntity entity) { Assert.assertNotNull(app.getManagementContext()); Assert.assertTrue( app.getManagementContext().isRunning() ); Assert.assertNotNull(entity.getManagementContext()); Assert.assertNotNull( ((EntityInternal)app.getChildren().iterator().next()).getManagementContext() ); Assert.assertTrue( ((EntityInternal)app.getChildren().iterator().next()).getManagementSupport().isDeployed()); Assert.assertTrue( ((EntityInternal)app.getChildren().iterator().next()).getManagementContext() instanceof LocalManagementContext ); }
@Override public synchronized void run() { if (effector == null) return; if (!(isRunning() && getManagementContext().isRunning())) return; try { ConfigBag bag = ResolvingConfigBag.newInstanceExtending(getManagementContext(), config().getBag()); Map<String, Object> args = EntityInitializers.resolve(bag, EFFECTOR_ARGUMENTS); LOG.debug("{}: Resolving arguments for {}: {}", new Object[] { this, effector.getName(), Iterables.toString(args.keySet()) }); Map<String, Object> resolved = (Map) Tasks.resolving(args, Object.class) .deep(true) .context(entity) .get(); LOG.debug("{}: Invoking effector on {}, {}({})", new Object[] { this, entity, effector.getName(), resolved }); Object result = entity.invoke(effector, resolved).getUnchecked(); LOG.debug("{}: Effector {} returned {}", new Object[] { this, effector.getName(), result }); } catch (RuntimeInterruptedException rie) { // Gracefully stop Thread.currentThread().interrupt(); } catch (Throwable t) { LOG.warn("{}: Exception running {}: {}", new Object[] { this, effector.getName(), t.getMessage() }); Exceptions.propagate(t); } }
@Override public synchronized void run() { try { super.run(); } finally { if (isRunning() && getManagementContext().isRunning()) { Duration period = config().get(PERIOD); String time = config().get(TIME); if (time == null || time.equalsIgnoreCase(NOW) || time.equalsIgnoreCase(IMMEDIATELY)) { schedule(period); } else { Duration wait = getWaitUntil(time); schedule(wait.upperBound(period)); } } } } }
@Override @AfterMethod(alwaysRun=true) public void tearDown() throws Exception { try { List<Exception> exceptions = Lists.newArrayList(); for (ManagementContext mgmt : mgmts) { try { if (mgmt.isRunning()) Entities.destroyAll(mgmt); } catch (Exception e) { LOG.warn("Error destroying management context", e); exceptions.add(e); } } super.tearDown(); if (exceptions.size() > 0) { throw new CompoundRuntimeException("Error in tearDown of "+getClass(), exceptions); } } finally { mgmts.clear(); origManagementContext = null; newManagementContext = null; origApp = null; newApp = null; RecordingSshTool.clear(); RecordingWinRmTool.clear(); } }
@AfterMethod(alwaysRun=true) public void tearDown() throws Exception { if (executor != null) executor.shutdownNow(); if (app != null) Entities.destroyAll(app.getManagementContext()); if (mgmt != null && mgmt.isRunning()) Entities.destroyAll(mgmt); if (exampleEntity != null && exampleEntity.getApplication() != null) Entities.destroyAll(exampleEntity.getApplication().getManagementContext()); if (filesToDelete != null) { for (File file : filesToDelete) { file.delete(); } } app = null; }
/** * A cut-down start, which just does the web-apps (intended as a read-only view). It assumes * that a fully initialised management context will have been registered. */ @Override public BrooklynLauncher start() { if (started) throw new IllegalStateException("Cannot start() or launch() multiple times"); started = true; if (getManagementContext() == null || !getManagementContext().isRunning()) { throw new IllegalStateException("Management context must be set, and running"); } startingUp(); markStartupComplete(); initBrooklynNode(); return this; } }
@Override public boolean isShuttingDown() { if (!Entitlements.isEntitled(mgmt().getEntitlementManager(), Entitlements.SERVER_STATUS, null)) throw WebResourceUtils.forbidden("User '%s' is not authorized for this operation", Entitlements.getEntitlementContext().user()); Maybe<ManagementContext> mm = mgmtMaybe(); return !mm.isAbsent() && mm.get().isStartupComplete() && !mm.get().isRunning(); }
@Override public boolean isUp() { if (!Entitlements.isEntitled(mgmt().getEntitlementManager(), Entitlements.SERVER_STATUS, null)) throw WebResourceUtils.forbidden("User '%s' is not authorized for this operation", Entitlements.getEntitlementContext().user()); Maybe<ManagementContext> mm = mgmtMaybe(); return !mm.isAbsent() && mm.get().isStartupComplete() && mm.get().isRunning(); }
public void onManagementStopped() { this.managed = false; if (getManagementContext().isRunning()) { BrooklynStorage storage = ((ManagementContextInternal)getManagementContext()).getStorage(); storage.remove(getId()+"-parent"); storage.remove(getId()+"-children"); storage.remove(getId()+"-creationTime"); storage.remove(getId()+"-hostGeoInfo"); storage.remove(getId()+"-displayName"); storage.remove(getId()+"-config"); } }
/** * Invoked by {@link EntityManagementSupport} when this entity is fully unmanaged. * <p> * Note that the activies possible here (when unmanaged) are limited, * and that this event may be caused by either a brooklyn node itself being demoted * (so the entity is managed elsewhere) or by a controlled shutdown. */ public void onManagementStopped() { if (getManagementContext().isRunning()) { BrooklynStorage storage = ((ManagementContextInternal)getManagementContext()).getStorage(); storage.remove(getId()+"-parent"); storage.remove(getId()+"-groups"); storage.remove(getId()+"-children"); storage.remove(getId()+"-locations"); storage.remove(getId()+"-creationTime"); storage.remove(getId()+"-displayName"); storage.remove(getId()+"-config"); storage.remove(getId()+"-attributes"); } }