Java Code Examples for org.apache.brooklyn.core.entity.lifecycle.Lifecycle#STARTING
The following examples show how to use
org.apache.brooklyn.core.entity.lifecycle.Lifecycle#STARTING .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AsyncApplicationImpl.java From brooklyn-server with Apache License 2.0 | 6 votes |
protected Lifecycle computeExpectedState(Lifecycle oldExpectedState, Lifecycle newActualState) { if (oldExpectedState != Lifecycle.STARTING) { return oldExpectedState; } // Are any of our children still starting? Map<Entity, Lifecycle> values = getValues(SERVICE_STATE_ACTUAL); boolean childIsStarting = values.containsValue(Lifecycle.STARTING) || values.containsValue(Lifecycle.CREATED) || values.containsValue(null); if (!childIsStarting) { // We only transition to expected=RUNNING if all our children are no longer starting. // When actual=running, this matters if quorum != all; // When actual=on_fire, this matters for recovering. return Lifecycle.RUNNING; } return oldExpectedState; }
Example 2
Source File: EntityAdjuncts.java From brooklyn-server with Apache License 2.0 | 6 votes |
@Beta public static Lifecycle inferAdjunctStatus(EntityAdjunct a) { if (a.isRunning()) return Lifecycle.RUNNING; if (a.isDestroyed()) return Lifecycle.DESTROYED; // adjuncts don't currently support an "error" state; though that would be useful! if (a instanceof Policy) { if (((Policy)a).isSuspended()) return Lifecycle.STOPPED; return Lifecycle.CREATED; } if (a instanceof Feed) { if (((Feed)a).isSuspended()) return Lifecycle.STOPPED; if (((Feed)a).isActivated()) return Lifecycle.STARTING; return Lifecycle.CREATED; } // Enricher doesn't support suspend so if not running or destroyed then // it is just created return Lifecycle.CREATED; }
Example 3
Source File: BasicEntityRebindSupport.java From brooklyn-server with Apache License 2.0 | 6 votes |
@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); }
Example 4
Source File: JMSBrokerImpl.java From brooklyn-library with Apache License 2.0 | 5 votes |
public void checkStartingOrRunning() { Lifecycle state = getAttribute(SERVICE_STATE_ACTUAL); if (getAttribute(SERVICE_STATE_ACTUAL) == Lifecycle.RUNNING) return; if (getAttribute(SERVICE_STATE_ACTUAL) == Lifecycle.STARTING) return; // TODO this check may be redundant or even inappropriate throw new IllegalStateException("Cannot run against "+this+" in state "+state); }
Example 5
Source File: SoftwareProcessImpl.java From brooklyn-server with Apache License 2.0 | 5 votes |
protected void onUpdated() { Boolean up = entity.getAttribute(SERVICE_UP); Lifecycle state = entity.getAttribute(SERVICE_STATE_ACTUAL); if (up == null || up) { entity.sensors().set(ServiceStateLogic.SERVICE_NOT_UP_DIAGNOSTICS, ImmutableMap.<String, Object>of()); } else if (state == null || state == Lifecycle.CREATED || state == Lifecycle.STARTING) { // not yet started; do nothing } else if (state == Lifecycle.STOPPING || state == Lifecycle.STOPPED || state == Lifecycle.DESTROYED) { // stopping/stopped, so expect not to be up; get rid of the diagnostics. entity.sensors().set(ServiceStateLogic.SERVICE_NOT_UP_DIAGNOSTICS, ImmutableMap.<String, Object>of()); } else { ((SoftwareProcess)entity).populateServiceNotUpDiagnostics(); } }
Example 6
Source File: DoNothingSoftwareProcessImpl.java From brooklyn-server with Apache License 2.0 | 5 votes |
@Override protected void connectSensors() { super.connectSensors(); if (getAttribute(SERVICE_STATE_ACTUAL) == Lifecycle.STARTING) { sensors().set(SERVICE_UP, true); } }
Example 7
Source File: EntityAsyncTest.java From brooklyn-server with Apache License 2.0 | 5 votes |
@Override public void onCallback(boolean success) { if (success) { ServiceStateLogic.ServiceNotUpLogic.clearNotUpIndicator(this, START.getName()); } else { ServiceStateLogic.ServiceNotUpLogic.updateNotUpIndicator(this, START.getName(), "callback reported failure"); } Transition expectedState = sensors().get(Attributes.SERVICE_STATE_EXPECTED); if (expectedState != null && expectedState.getState() == Lifecycle.STARTING) { ServiceStateLogic.setExpectedState(this, Lifecycle.RUNNING); } }
Example 8
Source File: SoftwareProcessRebindNotRunningEntityTest.java From brooklyn-server with Apache License 2.0 | 4 votes |
protected void assertMarkedAsVmLost(Entity entity, Lifecycle previousState) throws Exception { String expectedReason = "VM " + (previousState == Lifecycle.STARTING ? "provisioning" : "termination") + " may have been in-progress and now lost, because tasks aborted on shutdown"; assertNotUpIndicatorIncludesEventually(entity, "VM may be lost on rebind", expectedReason); }
Example 9
Source File: AsyncApplicationImpl.java From brooklyn-server with Apache License 2.0 | 4 votes |
/** * Count the entities that are up versus not up. Compare this with the quorum required. */ protected ValueAndReason<Boolean> computeServiceUp(Lifecycle expectedState) { boolean ignoreNull = getConfig(IGNORE_ENTITIES_WITH_SERVICE_UP_NULL); Set<Lifecycle> ignoredStates; if (expectedState == Lifecycle.STARTING) { ignoredStates = getConfig(ENTITY_IGNORED_STATES_ON_STARTING); } else { ignoredStates = getConfig(ENTITY_IGNORED_STATES_ON_OTHERS); } Map<Entity, Boolean> values = getValues(SERVICE_UP); List<Entity> violators = MutableList.of(); int entries = 0; int numUp = 0; for (Map.Entry<Entity, Boolean> entry : values.entrySet()) { Lifecycle entityState = entry.getKey().getAttribute(SERVICE_STATE_ACTUAL); if (ignoreNull && entry.getValue()==null) { continue; } if (ignoredStates.contains(entityState)) { continue; } entries++; if (Boolean.TRUE.equals(entry.getValue())) { numUp++; } else { violators.add(entry.getKey()); } } QuorumCheck qc = getRequiredConfig(UP_QUORUM_CHECK); if (qc.isQuorate(numUp, violators.size()+numUp)) { // quorate return new ValueAndReason<>(Boolean.TRUE, "quorate"); } String reason; if (values.isEmpty()) { reason = "No entities present"; } else if (entries == 0) { reason = "No entities (in correct state) publishing service up"; } else if (violators.isEmpty()) { reason = "Not enough entities"; } else if (violators.size() == 1) { reason = violators.get(0)+" is not up"; } else if (violators.size() == entries) { reason = "None of the entities are up"; } else { reason = violators.size()+" entities are not up, including "+violators.get(0); } return new ValueAndReason<>(Boolean.FALSE, reason); }
Example 10
Source File: AsyncApplicationImpl.java From brooklyn-server with Apache License 2.0 | 4 votes |
protected ValueAndReason<Lifecycle> computeServiceState(Lifecycle expectedState) { if (expectedState != null && (expectedState != Lifecycle.STARTING && expectedState != Lifecycle.RUNNING)) { return new ValueAndReason<>(expectedState, "expected state "+expectedState); } Set<Lifecycle> ignoredStates; if (expectedState == Lifecycle.STARTING) { ignoredStates = getConfig(ENTITY_IGNORED_STATES_ON_STARTING); } else { ignoredStates = getConfig(ENTITY_IGNORED_STATES_ON_OTHERS); } Set<Lifecycle> transitionStates; if (expectedState == Lifecycle.STARTING) { transitionStates = getConfig(ENTITY_TRANSITION_STATES_ON_STARTING); } else { transitionStates = ImmutableSet.of(); } Map<Entity, Lifecycle> values = getValues(SERVICE_STATE_ACTUAL); List<Entity> violators = MutableList.of(); int entries = 0; int numRunning = 0; int numTransitioning = 0; for (Map.Entry<Entity,Lifecycle> entry : values.entrySet()) { if (ignoredStates.contains(entry.getValue())) { continue; } entries++; if (entry.getValue() == Lifecycle.RUNNING) { numRunning++; } else if (transitionStates.contains(entry.getValue())) { numTransitioning++; } else { violators.add(entry.getKey()); } } QuorumCheck qc = getConfig(RUNNING_QUORUM_CHECK); if (qc.isQuorate(numRunning, violators.size()+numRunning+numTransitioning)) { // quorate return new ValueAndReason<Lifecycle>(Lifecycle.RUNNING, "quorate"); } boolean canEverBeQuorate = qc.isQuorate(numRunning+numTransitioning, violators.size()+numRunning+numTransitioning); if (expectedState == Lifecycle.STARTING && canEverBeQuorate) { // quorate return new ValueAndReason<Lifecycle>(Lifecycle.STARTING, "not yet quorate"); } String reason; if (values.isEmpty()) { reason = "No entities present"; } else if (entries == 0) { reason = "No entities in interesting states"; } else if (violators.isEmpty()) { reason = "Not enough entities"; } else if (violators.size() == 1) { reason = violators.get(0)+" is not healthy"; } else if (violators.size() == entries) { reason = "None of the entities are healthy"; } else { reason = violators.size()+" entities are not healthy, including "+violators.get(0); } return new ValueAndReason<>(Lifecycle.ON_FIRE, reason); }
Example 11
Source File: AttributePollHandler.java From brooklyn-server with Apache License 2.0 | 4 votes |
protected boolean isTransitioningOrStopped() { if (entity==null) return false; Transition expected = entity.getAttribute(Attributes.SERVICE_STATE_EXPECTED); if (expected==null) return false; return (expected.getState()==Lifecycle.STARTING || expected.getState()==Lifecycle.STOPPING || expected.getState()==Lifecycle.STOPPED); }