use of com.netflix.titus.api.clustermembership.model.ClusterMemberLeadershipState in project titus-control-plane by Netflix.
the class DefaultClusterMembershipService method clusterStateEvaluator.
private Mono<Void> clusterStateEvaluator(ExecutionContext context) {
return Mono.defer(() -> {
ClusterMember localMember = connector.getLocalClusterMemberRevision().getCurrent();
ClusterMemberLeadershipState localLeadershipState = connector.getLocalLeadershipRevision().getCurrent().getLeadershipState();
HealthStatus health = healthIndicator.health();
// Explicitly disabled
if (!configuration.isLeaderElectionEnabled() || !localMember.isEnabled()) {
if (localLeadershipState == ClusterMemberLeadershipState.NonLeader) {
logger.info("Local member excluded from the leader election. Leaving the leader election process");
return connector.leaveLeadershipGroup(true).flatMap(success -> success ? connector.register(current -> toInactive(current, "Marked by a user as disabled")).ignoreElement().cast(Void.class) : Mono.empty());
}
if (localLeadershipState == ClusterMemberLeadershipState.Disabled && localMember.isActive()) {
return connector.register(current -> toInactive(current, "Marked by a user as disabled")).ignoreElement().cast(Void.class);
}
return Mono.empty();
}
// Re-enable if healthy
if (health.getHealthState() == HealthState.Healthy) {
if (localLeadershipState == ClusterMemberLeadershipState.Disabled) {
logger.info("Re-enabling local member which is in the disabled state");
return connector.joinLeadershipGroup().then(connector.register(this::toActive).ignoreElement().cast(Void.class));
}
if (!localMember.isActive()) {
return connector.register(this::toActive).ignoreElement().cast(Void.class);
}
return Mono.empty();
}
// Disable if unhealthy (and not the leader)
if (localLeadershipState != ClusterMemberLeadershipState.Disabled && localLeadershipState != ClusterMemberLeadershipState.Leader) {
logger.info("Disabling local member as it is unhealthy: {}", health);
return connector.leaveLeadershipGroup(true).flatMap(success -> success ? connector.register(current -> toInactive(current, "Unhealthy: " + health)).ignoreElement().cast(Void.class) : Mono.empty());
}
if (localLeadershipState == ClusterMemberLeadershipState.Disabled && localMember.isActive()) {
return connector.register(current -> toInactive(current, "Unhealthy: " + health)).ignoreElement().cast(Void.class);
}
return Mono.empty();
}).doOnError(error -> {
logger.info("Cluster membership health evaluation error: {}", error.getMessage());
logger.debug("Stack trace", error);
}).doOnTerminate(() -> {
metrics.updateLocal(connector.getLocalLeadershipRevision().getCurrent().getLeadershipState(), healthIndicator.health());
metrics.updateSiblings(connector.getClusterMemberSiblings());
});
}
use of com.netflix.titus.api.clustermembership.model.ClusterMemberLeadershipState in project titus-control-plane by Netflix.
the class ClusterMembershipConnectorStub method leaveLeadershipGroup.
@Override
public Mono<Boolean> leaveLeadershipGroup(boolean onlyNonLeader) {
return Mono.defer(() -> {
ClusterMemberLeadershipState state = localLeadershipRevision.getCurrent().getLeadershipState();
if (state == ClusterMemberLeadershipState.Disabled) {
return Mono.just(true);
}
if (onlyNonLeader && state == ClusterMemberLeadershipState.Leader) {
return Mono.just(false);
}
this.localLeadershipRevision = newLocalLeadershipState(ClusterMemberLeadershipState.Disabled);
emitEvent(ClusterMembershipEvent.localLeftElection(localLeadershipRevision));
return Mono.just(true);
});
}
use of com.netflix.titus.api.clustermembership.model.ClusterMemberLeadershipState in project titus-control-plane by Netflix.
the class ClusterMembershipConnectorStub method joinLeadershipGroup.
@Override
public Mono<Void> joinLeadershipGroup() {
return Mono.defer(() -> {
ClusterMemberLeadershipState state = localLeadershipRevision.getCurrent().getLeadershipState();
if (state == ClusterMemberLeadershipState.Disabled) {
this.localLeadershipRevision = newLocalLeadershipState(ClusterMemberLeadershipState.NonLeader);
}
emitEvent(ClusterMembershipEvent.localJoinedElection(localLeadershipRevision));
return Mono.empty();
});
}
Aggregations