Java Code Examples for org.apache.brooklyn.core.entity.lifecycle.Lifecycle#ON_FIRE

The following examples show how to use org.apache.brooklyn.core.entity.lifecycle.Lifecycle#ON_FIRE . 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: DynamicClusterTest.java    From brooklyn-server with Apache License 2.0 6 votes vote down vote up
/** This can be sensitive to order, e.g. if TestEntity set expected RUNNING before setting SERVICE_UP, 
 * there would be a point when TestEntity is ON_FIRE.
 * <p>
 * There can also be issues if a cluster is resizing from/to 0 while in a RUNNING state.
 * To correct that, use {@link ServiceStateLogic#newEnricherFromChildrenUp()}.
 */
@Test
public void testResizeFromZeroToOneDoesNotGoThroughFailing() throws Exception {
    final DynamicCluster cluster = app.createAndManageChild(EntitySpec.create(DynamicCluster.class)
        .configure(DynamicCluster.MEMBER_SPEC, EntitySpec.create(TestEntity.class))
        .configure(DynamicCluster.INITIAL_SIZE, 1));
    
    RecordingSensorEventListener<Lifecycle> r = new RecordingSensorEventListener<>();
    app.subscriptions().subscribe(cluster, Attributes.SERVICE_STATE_ACTUAL, r);

    cluster.start(ImmutableList.of(loc));
    EntityAsserts.assertAttributeEqualsEventually(cluster, Attributes.SERVICE_STATE_ACTUAL, Lifecycle.RUNNING);
    for (SensorEvent<Lifecycle> evt: r.getEvents()) {
        if (evt.getValue()==Lifecycle.ON_FIRE)
            Assert.fail("Should not have published " + Lifecycle.ON_FIRE + " during normal start up: " + r.getEvents());
    }
}
 
Example 2
Source File: CassandraFabricImpl.java    From brooklyn-library with Apache License 2.0 5 votes vote down vote up
public boolean isViableSeed(Entity member) {
    // TODO remove duplication from CassandraClusterImpl.SeedTracker.isViableSeed
    boolean managed = Entities.isManaged(member);
    String hostname = member.getAttribute(Attributes.HOSTNAME);
    boolean serviceUp = Boolean.TRUE.equals(member.getAttribute(Attributes.SERVICE_UP));
    Lifecycle serviceState = member.getAttribute(Attributes.SERVICE_STATE_ACTUAL);
    boolean hasFailed = !managed || (serviceState == Lifecycle.ON_FIRE) || (serviceState == Lifecycle.RUNNING && !serviceUp) || (serviceState == Lifecycle.STOPPED);
    boolean result = (hostname != null && !hasFailed);
    if (log.isTraceEnabled()) log.trace("Node {} in Fabric {}: viableSeed={}; hostname={}; serviceUp={}; serviceState={}; hasFailed={}", new Object[] {member, CassandraFabricImpl.this, result, hostname, serviceUp, serviceState, hasFailed});
    return result;
}
 
Example 3
Source File: CassandraDatacenterImpl.java    From brooklyn-library with Apache License 2.0 5 votes vote down vote up
public boolean isViableSeed(Entity member) {
    // TODO would be good to reuse the better logic in ServiceFailureDetector
    // (e.g. if that didn't just emit a notification but set a sensor as well?)
    boolean managed = Entities.isManaged(member);
    String hostname = member.getAttribute(Attributes.HOSTNAME);
    boolean serviceUp = Boolean.TRUE.equals(member.getAttribute(Attributes.SERVICE_UP));
    Lifecycle serviceState = member.getAttribute(Attributes.SERVICE_STATE_ACTUAL);
    boolean hasFailed = !managed || (serviceState == Lifecycle.ON_FIRE) || (serviceState == Lifecycle.RUNNING && !serviceUp) || (serviceState == Lifecycle.STOPPED);
    boolean result = (hostname != null && !hasFailed);
    if (log.isTraceEnabled()) log.trace("Node {} in Cluster {}: viableSeed={}; hostname={}; serviceUp={}; serviceState={}; hasFailed={}", new Object[] {member, this, result, hostname, serviceUp, serviceState, hasFailed});
    return result;
}
 
Example 4
Source File: AsyncApplicationImpl.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@Override
protected void onUpdated() {
    if (entity == null || !isRunning() || !Entities.isManaged(entity)) {
        // e.g. invoked during setup or entity has become unmanaged; just ignore
        BrooklynLogging.log(LOG, BrooklynLogging.levelDebugOrTraceIfReadOnly(entity),
            "Ignoring {} onUpdated when entity is not in valid state ({})", this, entity);
        return;
    }

    Lifecycle.Transition oldExpectedStateTransition = entity.sensors().get(Attributes.SERVICE_STATE_EXPECTED);
    Lifecycle oldExpectedState = (oldExpectedStateTransition != null) ? oldExpectedStateTransition.getState() : null;
    
    ValueAndReason<Boolean> newServiceUp = computeServiceUp(oldExpectedState);
    ValueAndReason<Lifecycle> newServiceState = computeServiceState(oldExpectedState);
    Lifecycle newExpectedState = computeExpectedState(oldExpectedState, newServiceState.val);

    emit(Attributes.SERVICE_STATE_ACTUAL, newServiceState.val);
    emit(Attributes.SERVICE_UP, newServiceUp.val);
    
    if (Boolean.TRUE.equals(newServiceUp.val)) {
        clearMapSensorEntry(entity, Attributes.SERVICE_NOT_UP_INDICATORS, DEFAULT_UNIQUE_TAG);
    } else {
        updateMapSensorEntry(entity, Attributes.SERVICE_NOT_UP_INDICATORS, DEFAULT_UNIQUE_TAG, newServiceUp.reason);
    }
    if (newServiceState.val != null && newServiceState.val == Lifecycle.ON_FIRE) {
        updateMapSensorEntry(entity, Attributes.SERVICE_PROBLEMS, DEFAULT_UNIQUE_TAG, newServiceState.reason);
    } else {
        clearMapSensorEntry(entity, Attributes.SERVICE_PROBLEMS, DEFAULT_UNIQUE_TAG);
    }
    
    if (oldExpectedState != newExpectedState) {
        // TODO could check no-one else has changed expectedState (e.g. by calling "stop")
        // TODO do we need to subscribe to our own serviceStateExpected, in case someone calls stop?
        getEntity().setExpectedStateAndRecordLifecycleEvent(newExpectedState);
    }
}
 
Example 5
Source File: AsyncApplicationImpl.java    From brooklyn-server with Apache License 2.0 4 votes vote down vote up
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);

}