recursively(e, new Predicate<EntityInternal>() { @Override public boolean apply(EntityInternal it) { if (shouldSkipUnmanagement(it)) return false; allEntities.add(it); it.getManagementSupport().onManagementStopping(info); return true; } });
/** returns false if deleted, throws exception if invalid state, otherwise true. * okay if entity is not yet managed (but not if entity is no longer managed). */ protected boolean checkCanSubscribe(Entity producer) { if (destroyed.get()) return false; if (producer==null) throw new IllegalStateException(this+" given a null target for subscription"); if (entity==null) throw new IllegalStateException(this+" cannot subscribe to "+producer+" because it is not associated to an entity"); if (((EntityInternal)entity).getManagementSupport().isNoLongerManaged()) throw new IllegalStateException(this+" cannot subscribe to "+producer+" because the associated entity "+entity+" is no longer managed"); return true; }
protected boolean checkCanSubscribe() { if (destroyed.get()) return false; if (entity==null) throw new IllegalStateException(this+" cannot subscribe because it is not associated to an entity"); if (((EntityInternal)entity).getManagementSupport().isNoLongerManaged()) throw new IllegalStateException(this+" cannot subscribe because the associated entity "+entity+" is no longer managed"); return true; }
/** as {@link EntityManagerInternal#isReadOnly(Entity)} */ @Beta public static Boolean isReadOnly(Entity e) { return ((EntityInternal)e).getManagementSupport().isReadOnly(); }
/** returns one of three log levels depending on the read-only status of the entity; * unknown should only be the case very early in the management cycle */ public static LoggingLevel levelDependingIfReadOnly(Entity entity, LoggingLevel levelIfWriting, LoggingLevel levelIfReadOnly, LoggingLevel levelIfUnknown) { if (entity==null) return levelIfUnknown; Boolean ro = ((EntityInternal)entity).getManagementSupport().isReadOnlyRaw(); if (ro==null) return levelIfUnknown; if (ro) return levelIfReadOnly; return levelIfWriting; }
public static boolean isNoLongerManaged(Entity e) { return ((EntityInternal)e).getManagementSupport().isNoLongerManaged(); }
protected boolean isConnected() { // TODO Default impl will result in multiple logs for same error if becomes unreachable // (e.g. if ssh gets NoRouteToHostException, then every AttributePollHandler for that // feed will log.warn - so if polling for 10 sensors/attributes will get 10 log messages). // Would be nice if reduced this logging duplication. // (You can reduce it by providing a better 'isConnected' implementation of course.) return isRunning() && entity!=null && !((EntityInternal)entity).getManagementSupport().isNoLongerManaged(); }
public static boolean isManaged(Entity e) { return ((EntityInternal)e).getManagementSupport().isDeployed() && ((EntityInternal)e).getManagementContext().isRunning(); }
public static void unmanage(Entity entity) { if (((EntityInternal)entity).getManagementSupport().isDeployed()) { ((EntityInternal)entity).getManagementContext().getEntityManager().unmanage(entity); } }
protected void setActualState(Maybe<Lifecycle> state) { if (log.isTraceEnabled()) log.trace("{} setting actual state {}", this, state); if (((EntityInternal)entity).getManagementSupport().isNoLongerManaged()) { // won't catch everything, but catches some BrooklynLogging.log(log, BrooklynLogging.levelDebugOrTraceIfReadOnly(entity), entity+" is no longer managed when told to set actual state to "+state+"; suppressing"); return; } Object newVal = (state.isAbsent() ? Entities.UNCHANGED : (state.get() == null ? Entities.REMOVE : state.get())); emit(SERVICE_STATE_ACTUAL, newVal); }
@Override protected void postLocalEvaluate(ConfigKey<?> key, BrooklynObject bo, Maybe<?> rawValue, Maybe<?> resolvedValue) { // TEMPORARY CODE // We're notifying of config-changed because currently persistence needs to know when the // attributeWhenReady is complete (so it can persist the result). // Long term, we'll just persist tasks properly so the call to onConfigChanged will go! if (rawValue.isPresent() && (rawValue.get() instanceof Task)) { ((EntityInternal)bo).getManagementSupport().getEntityChangeListener().onConfigChanged(key); } }
((EntityInternal)entity).getManagementSupport().setReadOnly( rebindContext.isReadOnly(entity) ); rebindContext.registerEntity(entityId, entity);
public static <T> Task<T> invokeEffectorAsync(Entity entity, Effector<T> eff, Map<String,?> parameters) { String name = eff.getName(); if (log.isDebugEnabled()) log.debug("Invoking-async effector {} on {}", new Object[] { name, entity }); if (log.isTraceEnabled()) log.trace("Invoking-async effector {} on {} with args {}", new Object[] { name, entity, Sanitizer.sanitize(parameters) }); EntityManagementSupport mgmtSupport = ((EntityInternal)entity).getManagementSupport(); if (!mgmtSupport.isDeployed()) { mgmtSupport.attemptLegacyAutodeployment(name); } ManagementContextInternal mgmtContext = (ManagementContextInternal) ((EntityInternal)entity).getManagementContext(); // FIXME seems brittle to have the listeners in the Utils method; better to move into the context.invokeEff // (or whatever the last mile before invoking the effector is - though currently there is not such a canonical place!) mgmtSupport.getEntityChangeListener().onEffectorStarting(eff, parameters); try { return mgmtContext.invokeEffector(entity, eff, parameters); } finally { // FIXME this is really Effector submitted mgmtSupport.getEntityChangeListener().onEffectorCompleted(eff); } }
protected boolean isMaster() { if (isMaster!=null) return isMaster; ManagementContext mgmt = ((EntityInternal)delegate).getManagementContext(); ManagementTransitionMode mode = ((EntityManagerInternal)mgmt.getEntityManager()).getLastManagementTransitionMode(delegate.getId()); Boolean ro = ((EntityInternal)delegate).getManagementSupport().isReadOnlyRaw(); if (mode==null || ro==null) { // not configured yet return false; } boolean isMasterX = !mode.isReadOnly(); if (isMasterX != !ro) { LOG.warn("Inconsistent read-only state for "+delegate+" (possibly rebinding); " + "management thinks "+isMasterX+" but entity thinks "+!ro); return false; } isMaster = isMasterX; return isMasterX; }
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 ); }
public void attemptLegacyAutodeployment(String effectorName) { synchronized (this) { if (managementContext != null) { log.warn("Autodeployment suggested but not required for " + entity + "." + effectorName); return; } if (entity instanceof Application) { log.warn("Autodeployment with new management context triggered for " + entity + "." + effectorName + " -- will not be supported in future. Explicit manage call required."); if (initialManagementContext != null) { initialManagementContext.getEntityManager().manage(entity); } else { Entities.startManagement(entity); } return; } } if ("start".equals(effectorName)) { Entity e=entity; if (e.getParent()!=null && ((EntityInternal)e.getParent()).getManagementSupport().isDeployed()) { log.warn("Autodeployment in parent's management context triggered for "+entity+"."+effectorName+" -- will not be supported in future. Explicit manage call required."); ((EntityInternal)e.getParent()).getManagementContext().getEntityManager().manage(entity); return; } } log.warn("Autodeployment not available for "+entity+"."+effectorName); }
/** * Invokes a method effector so that its progress is tracked. For internal use only, when we know the effector is backed by a method which is local. */ public static <T> T invokeMethodEffector(Entity entity, Effector<T> eff, Map<String,?> args) { Object[] parametersArray = EffectorUtils.prepareArgsForEffector(eff, args); String name = eff.getName(); try { if (log.isDebugEnabled()) log.debug("Invoking effector {} on {}", new Object[] {name, entity}); if (log.isTraceEnabled()) log.trace("Invoking effector {} on {} with args {}", new Object[] {name, entity, Sanitizer.sanitize(args)}); EntityManagementSupport mgmtSupport = ((EntityInternal)entity).getManagementSupport(); if (!mgmtSupport.isDeployed()) { mgmtSupport.attemptLegacyAutodeployment(name); } ManagementContextInternal mgmtContext = (ManagementContextInternal) ((EntityInternal) entity).getManagementContext(); mgmtSupport.getEntityChangeListener().onEffectorStarting(eff, parametersArray); try { return mgmtContext.invokeEffectorMethodSync(entity, eff, args); } finally { mgmtSupport.getEntityChangeListener().onEffectorCompleted(eff); } } catch (Exception e) { throw handleEffectorException(entity, eff, e); } }
if (anEntity!=null && !((EntityInternal)anEntity).getManagementSupport().isReadOnly()) {
@Test public void testRebindParentSimple() throws Exception { TestEntity c1 = origApp.addChild(EntitySpec.create(TestEntity.class)); AbstractEntity origAppr = Entities.deproxy(origApp); doPartialRebindOfIds(origApp.getId()); BrooklynObject app2 = origManagementContext.lookup(origApp.getId()); AbstractEntity app2r = Entities.deproxy((Entity)app2); Assert.assertTrue(app2 == origApp, "Proxy instance should be the same: "+app2+" / "+origApp); Assert.assertFalse(app2r == origAppr, "Real instance should NOT be the same: "+app2r+" / "+origAppr); Assert.assertTrue(c1.getManagementSupport().isDeployed()); // check that child of parent is not a new unmanaged entity Entity c1b = origApp.getChildren().iterator().next(); Assert.assertTrue(c1.getManagementSupport().isDeployed()); Assert.assertTrue( ((EntityInternal)c1b).getManagementSupport().isDeployed(), "Not deployed: "+c1b ); }
/** clears all managed items from the management context; same items destroyed as in the course of a rebind cycle */ protected void clearManagedItems(ManagementTransitionMode mode) { // start with the root applications for (Application app: managementContext.getApplications()) { if (((EntityInternal)app).getManagementSupport().isDeployed()) { ((LocalEntityManager)((EntityInternal)app).getManagementContext().getEntityManager()).unmanage(app, mode); } } // for active management, call above will remove recursively at present, // but for read-only, and if we stop recursively, go through them all for (Entity entity: managementContext.getEntityManager().getEntities()) { ((LocalEntityManager)managementContext.getEntityManager()).unmanage(entity, mode); } // again, for locations, call unmanage on parents first for (Location loc: managementContext.getLocationManager().getLocations()) { if (loc.getParent()==null) ((LocationManagerInternal)managementContext.getLocationManager()).unmanage(loc, mode); } for (Location loc: managementContext.getLocationManager().getLocations()) { ((LocationManagerInternal)managementContext.getLocationManager()).unmanage(loc, mode); } ((BasicBrooklynCatalog)managementContext.getCatalog()).reset(CatalogDto.newEmptyInstance("<reset-by-ha-status-change>")); }