@SuppressWarnings({ "unchecked", "rawtypes" }) @Override public Void apply(Entity input) { for (Map.Entry<AttributeSensor<?>,Object> entry : values.entrySet()) { AttributeSensor sensor = entry.getKey(); Object value = entry.getValue(); if (value==Entities.UNCHANGED) { // nothing } else if (value==Entities.REMOVE) { ((EntityInternal)input).sensors().remove(sensor); } else { value = TypeCoercions.coerce(value, sensor.getTypeToken()); ((EntityInternal)input).sensors().set(sensor, value); } } return null; } }
@Override public void delete(String application, String entityToken, String sensorName) { final Entity entity = brooklyn().getEntity(application, entityToken); if (!Entitlements.isEntitled(mgmt().getEntitlementManager(), Entitlements.MODIFY_ENTITY, entity)) { throw WebResourceUtils.forbidden("User '%s' is not authorized to modify entity '%s'", Entitlements.getEntitlementContext().user(), entity); } AttributeSensor<?> sensor = findSensor(entity, sensorName); if (log.isDebugEnabled()) log.debug("REST user "+Entitlements.getEntitlementContext()+" deleting sensor "+sensorName); ((EntityInternal)entity).sensors().remove(sensor); }
entity().sensors().set(INTERNAL_PROVISIONED_MACHINE, machine); } finally { entity().sensors().remove(AttributesInternal.INTERNAL_PROVISIONING_TASK_STATE);
entity().sensors().remove(AttributesInternal.INTERNAL_TERMINATION_TASK_STATE);
@Override protected <T> void emit(Sensor<T> sensor, Object val) { checkState(entity != null, "entity must first be set"); if (val == Entities.UNCHANGED) { return; } if (val == Entities.REMOVE) { ((EntityInternal)entity).sensors().remove((AttributeSensor<T>) sensor); return; } T newVal = TypeCoercions.coerce(val, sensor.getTypeToken()); Maybe<T> published = Maybe.of(newVal); if (sensor instanceof AttributeSensor) { AttributeSensor<T> attribute = (AttributeSensor<T>)sensor; if (Boolean.TRUE.equals(suppressDuplicates)) { DeduplicatingAttributeModifier<T> modifier = DeduplicatingAttributeModifier.create(newVal); entity.sensors().modify(attribute, modifier); published = modifier.getLastValue(); } else { entity.sensors().set(attribute, newVal); } } else { entity.sensors().emit(sensor, newVal); } if (published!=null && published.isPresent()) { highlightActionPublishSensor(sensor, published.get()); } }
@Override protected void instanceRebind(AbstractBrooklynObject instance) { Preconditions.checkState(instance == entity, "Expected %s and %s to match, but different objects", instance, entity); Lifecycle expectedState = ServiceStateLogic.getExpectedState(entity); boolean isAsync = (entity instanceof AsyncStartable); if ((!isAsync && expectedState == Lifecycle.STARTING) || expectedState == Lifecycle.STOPPING) { // If we were previously "starting" or "stopping", then those tasks will have been // aborted. We don't want to continue showing that state (e.g. the web-console would // then show the it as in-progress with the "spinning" icon). // Therefore we set the entity as on-fire, and add the indicator that says why. markTransitioningEntityOnFireOnRebind(entity, expectedState); } // Clear the provisioning/termination task-state; the task will have been aborted, so wrong to keep this state. entity.sensors().remove(AttributesInternal.INTERNAL_PROVISIONING_TASK_STATE); entity.sensors().remove(AttributesInternal.INTERNAL_TERMINATION_TASK_STATE); super.instanceRebind(instance); }