public static boolean isExpectedState(Entity entity, Lifecycle state) { return getExpectedState(entity)==state; }
@Override public void rebind() { //SERVICE_STATE_ACTUAL might be ON_FIRE due to a temporary condition (problems map non-empty) //Only if the expected state is ON_FIRE then the entity has permanently failed. Lifecycle expectedState = ServiceStateLogic.getExpectedState(this); if (expectedState == null || expectedState != Lifecycle.RUNNING) { LOG.warn("On rebind of {}, not calling software process rebind hooks because expected state is {}", this, expectedState); return; } Lifecycle actualState = ServiceStateLogic.getActualState(this); if (actualState == null || actualState != Lifecycle.RUNNING) { LOG.warn("Rebinding entity {}, even though actual state is {}. Expected state is {}", new Object[] { this, actualState, expectedState }); } // e.g. rebinding to a running instance // FIXME What if location not set? LOG.info("Rebind {} connecting to pre-running service", this); MachineLocation machine = getMachineOrNull(); if (machine != null) { initDriver(machine); driver.rebind(); LOG.debug("On rebind of {}, re-created driver {}", this, driver); } else { LOG.info("On rebind of {}, no MachineLocation found (with locations {}) so not generating driver", this, getLocations()); } callRebindHooks(); }
@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); }
assertEquals(ServiceStateLogic.getExpectedState(entity), Lifecycle.STOPPING); EntityAsserts.assertAttributeEquals(entity, Attributes.SERVICE_STATE_ACTUAL, Lifecycle.STOPPING); assertEquals(ServiceStateLogic.getExpectedState(entity), Lifecycle.STOPPED); EntityAsserts.assertAttributeEquals(entity, Attributes.SERVICE_STATE_ACTUAL, Lifecycle.STOPPED); Asserts.succeedsContinually(new Runnable() {