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);
}
}
}
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();
}
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();
}
Aggregations