use of com.netflix.titus.api.health.HealthStatus 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());
});
}
Aggregations