use of com.netflix.titus.api.clustermembership.model.ClusterMemberLeadership in project titus-control-plane by Netflix.
the class KubeClusterMembershipConnectorTest method electSiblingAsLeader.
private ClusterMemberLeadership electSiblingAsLeader() throws InterruptedException {
ClusterMemberLeadership sibling = ClusterMemberLeadership.newBuilder().withMemberId("sibling1").withLeadershipState(ClusterMemberLeadershipState.Leader).build();
kubeExecutors.emitLeadershipEvent(ClusterMembershipEvent.leaderElected(ClusterMembershipRevision.<ClusterMemberLeadership>newBuilder().withCurrent(sibling).build()));
LeaderElectionChangeEvent electionEvent = takeLeaderElectionEvent(LeaderElectionChangeEvent.ChangeType.LeaderElected);
assertThat(electionEvent.getLeadershipRevision().getCurrent().getLeadershipState()).isEqualTo(ClusterMemberLeadershipState.Leader);
return sibling;
}
use of com.netflix.titus.api.clustermembership.model.ClusterMemberLeadership in project titus-control-plane by Netflix.
the class KubeClusterState method setLeaveLeaderElection.
public KubeClusterState setLeaveLeaderElection() {
ClusterMembershipRevision<ClusterMemberLeadership> revision = ClusterMembershipRevision.<ClusterMemberLeadership>newBuilder().withCurrent(ClusterMemberLeadership.newBuilder().withMemberId(localMemberId).withLeadershipState(ClusterMemberLeadershipState.Disabled).build()).build();
LeaderElectionChangeEvent event = localLeader ? LeaderElectionChangeEvent.leaderLost(revision) : LeaderElectionChangeEvent.localLeftElection(revision);
return toBuilder().withInLeaderElectionProcess(false).withLocalMemberLeadershipRevision(revision).withEvent(event).build();
}
use of com.netflix.titus.api.clustermembership.model.ClusterMemberLeadership in project titus-control-plane by Netflix.
the class KubeClusterMembershipConnectorTest method testDiscoveryOfSiblingLeader.
@Test
public void testDiscoveryOfSiblingLeader() throws InterruptedException {
ClusterMemberLeadership sibling = electSiblingAsLeader();
ClusterMembershipRevision<ClusterMemberLeadership> leader = connector.findCurrentLeader().orElseThrow(() -> new IllegalStateException("Leader not found"));
assertThat(leader.getCurrent()).isEqualTo(sibling);
}
use of com.netflix.titus.api.clustermembership.model.ClusterMemberLeadership in project titus-control-plane by Netflix.
the class KubeClusterMembershipConnectorTest method electLocalAsLeader.
private void electLocalAsLeader() throws InterruptedException {
kubeExecutors.emitLeadershipEvent(ClusterMembershipEvent.leaderElected(ClusterMembershipRevision.<ClusterMemberLeadership>newBuilder().withCurrent(ClusterMemberLeadership.newBuilder().withMemberId(LOCAL_MEMBER_UNREGISTERED.getMemberId()).withLeadershipState(ClusterMemberLeadershipState.Leader).build()).build()));
LeaderElectionChangeEvent electionEvent = takeLeaderElectionEvent(LeaderElectionChangeEvent.ChangeType.LeaderElected);
assertThat(electionEvent.getLeadershipRevision().getCurrent().getLeadershipState()).isEqualTo(ClusterMemberLeadershipState.Leader);
}
use of com.netflix.titus.api.clustermembership.model.ClusterMemberLeadership in project titus-control-plane by Netflix.
the class MultiNodeClusterMemberResolver method report.
private void report(ClusterMembershipSnapshot newSnapshot) {
if (lastReportedSnapshot == null) {
newSnapshot.getMemberRevisions().forEach((memberId, revision) -> {
logger.info("Discovered new cluster member: id={}, addresses={}", memberId, revision.getCurrent().getClusterMemberAddresses());
});
if (newSnapshot.getLeaderRevision().isPresent()) {
logger.info("Cluster leader is {}", newSnapshot.getLeaderRevision().get().getCurrent().getMemberId());
} else {
logger.info("No leader yet");
}
} else {
Map<String, ClusterMembershipRevision<ClusterMember>> previousRevisions = lastReportedSnapshot.getMemberRevisions();
newSnapshot.getMemberRevisions().forEach((memberId, revision) -> {
if (!previousRevisions.containsKey(memberId)) {
logger.info("Discovered new cluster member: id={}, addresses={}", memberId, revision.getCurrent().getClusterMemberAddresses());
}
});
lastReportedSnapshot.getMemberRevisions().forEach((memberId, previousRevision) -> {
if (!newSnapshot.getMemberRevisions().containsKey(memberId)) {
logger.info("Removed cluster member: {}", memberId);
}
});
if (lastReportedSnapshot.getLeaderRevision().isPresent()) {
ClusterMemberLeadership previousLeader = lastReportedSnapshot.getLeaderRevision().get().getCurrent();
if (newSnapshot.getLeaderRevision().isPresent()) {
ClusterMemberLeadership newLeader = newSnapshot.getLeaderRevision().get().getCurrent();
if (!newLeader.getMemberId().equals(previousLeader.getMemberId())) {
logger.info("Leader changed from {} to {}", previousLeader.getMemberId(), newLeader.getMemberId());
}
} else {
logger.info("{} is no longer leader, and no new leader is re-elected yet", previousLeader.getMemberId());
}
} else if (newSnapshot.getLeaderRevision().isPresent()) {
logger.info("Cluster leader is {}", newSnapshot.getLeaderRevision().get().getCurrent().getMemberId());
}
}
metrics.updateConnectedMembers(memberResolversByIpAddress);
metrics.updateSnapshot(newSnapshot);
this.lastReportedSnapshot = newSnapshot;
}
Aggregations