Search in sources :

Example 1 with MasterState

use of com.netflix.titus.api.supervisor.model.MasterState in project titus-control-plane by Netflix.

the class LeaderElectionOrchestrator method updateLeaderElectionState.

private void updateLeaderElectionState(MasterInstance newMasterInstance) {
    MasterState state = newMasterInstance.getStatus().getState();
    stateFsmMetrics.transition(state);
    if (state == MasterState.NonLeader) {
        if (leaderElector.join()) {
            logger.info("Joined leader election process due to MasterInstance state update: {}", newMasterInstance);
        }
    } else if (state == MasterState.Inactive) {
        if (leaderElector.leaveIfNotLeader()) {
            logger.info("Left leader election process due to MasterInstance state update: {}", newMasterInstance);
        }
    }
}
Also used : MasterState(com.netflix.titus.api.supervisor.model.MasterState)

Example 2 with MasterState

use of com.netflix.titus.api.supervisor.model.MasterState in project titus-control-plane by Netflix.

the class LeaderElectionOrchestrator method processChange.

private Optional<MasterInstance> processChange(Object change, MasterInstance currentMaster) {
    MasterState currentState = currentMaster.getStatus().getState();
    // MasterInstance update
    if (change instanceof MasterInstance) {
        if (MasterState.isLeader(currentState)) {
            // If already a leader, ignore further updates
            return Optional.empty();
        }
        return Optional.of((MasterInstance) change);
    }
    // Leader election event
    if (change instanceof MasterState) {
        MasterState newState = (MasterState) change;
        if (!MasterState.isLeader(newState)) {
            titusRuntime.getCodeInvariants().inconsistent("Expected leader election state, but got: %s", newState);
            return Optional.empty();
        }
        if (!MasterState.isAfter(currentState, newState)) {
            titusRuntime.getCodeInvariants().inconsistent("Unexpected leader election state: current=%s, new=%s", currentState, newState);
            return Optional.empty();
        }
        MasterInstance newMasterInstance = currentMaster.toBuilder().withStatus(MasterStatus.newBuilder().withState(newState).withMessage("Leader activation status change").withTimestamp(titusRuntime.getClock().wallTime()).build()).withStatusHistory(CollectionsExt.copyAndAdd(currentMaster.getStatusHistory(), currentMaster.getStatus())).build();
        return Optional.of(newMasterInstance);
    }
    return Optional.empty();
}
Also used : MasterState(com.netflix.titus.api.supervisor.model.MasterState) MasterInstance(com.netflix.titus.api.supervisor.model.MasterInstance)

Example 3 with MasterState

use of com.netflix.titus.api.supervisor.model.MasterState in project titus-control-plane by Netflix.

the class DefaultLocalMasterInstanceResolver method refresh.

private Optional<MasterInstance> refresh(@Nullable MasterInstance previousMasterInstance, ReadinessStatus currentReadinessStatus) {
    MasterState newState;
    switch(currentReadinessStatus.getState()) {
        case NotReady:
            newState = MasterState.Starting;
            break;
        case Disabled:
            newState = MasterState.Inactive;
            break;
        case Enabled:
            newState = MasterState.NonLeader;
            break;
        default:
            logger.warn("Unrecognized master readiness state; assuming inactive: {}", currentReadinessStatus.getState());
            newState = MasterState.Inactive;
    }
    MasterStatus newStatus = MasterStatus.newBuilder().withState(newState).withMessage(currentReadinessStatus.getMessage()).withTimestamp(currentReadinessStatus.getTimestamp()).build();
    if (areDifferent(previousMasterInstance.getStatus(), newStatus)) {
        MasterInstance newMasterInstance = MasterInstanceFunctions.moveTo(previousMasterInstance, newStatus);
        logger.info("MasterInstance status change: {}", newMasterInstance);
        return Optional.of(newMasterInstance);
    }
    logger.debug("Refreshed master instance status not changed: status={}", newStatus);
    return Optional.empty();
}
Also used : MasterStatus(com.netflix.titus.api.supervisor.model.MasterStatus) MasterState(com.netflix.titus.api.supervisor.model.MasterState) MasterInstance(com.netflix.titus.api.supervisor.model.MasterInstance)

Aggregations

MasterState (com.netflix.titus.api.supervisor.model.MasterState)3 MasterInstance (com.netflix.titus.api.supervisor.model.MasterInstance)2 MasterStatus (com.netflix.titus.api.supervisor.model.MasterStatus)1