org.zodiac.actuate.kubernetes.leader.LeaderInfoContributor Maven / Gradle / Ivy
package org.zodiac.actuate.kubernetes.leader;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import org.springframework.boot.actuate.info.Info.Builder;
import org.springframework.boot.actuate.info.InfoContributor;
import org.springframework.integration.leader.Candidate;
import org.zodic.kubernetes.leader.Leader;
import org.zodic.kubernetes.leader.LeadershipController;
public class LeaderInfoContributor implements InfoContributor {
private final LeadershipController leadershipController;
private final Candidate candidate;
public LeaderInfoContributor(LeadershipController leadershipController, Candidate candidate) {
this.leadershipController = leadershipController;
this.candidate = candidate;
}
@Override
public void contribute(Builder builder) {
Map details = new HashMap<>();
Optional leader = leadershipController.getLocalLeader();
if (leader.isPresent()) {
Leader l = leader.get();
details.put("leaderId", l.getId());
details.put("role", l.getRole());
details.put("isLeader", l.isCandidate(candidate));
} else {
details.put("leaderId", "Unknown");
}
builder.withDetail("leaderElection", details);
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy