Search in sources :

Example 1 with ClusterMemberLeadership

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;
}
Also used : ClusterMemberLeadership(com.netflix.titus.api.clustermembership.model.ClusterMemberLeadership) LeaderElectionChangeEvent(com.netflix.titus.api.clustermembership.model.event.LeaderElectionChangeEvent)

Example 2 with ClusterMemberLeadership

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();
}
Also used : ClusterMemberLeadership(com.netflix.titus.api.clustermembership.model.ClusterMemberLeadership) LeaderElectionChangeEvent(com.netflix.titus.api.clustermembership.model.event.LeaderElectionChangeEvent)

Example 3 with ClusterMemberLeadership

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);
}
Also used : ClusterMemberLeadership(com.netflix.titus.api.clustermembership.model.ClusterMemberLeadership) Test(org.junit.Test)

Example 4 with ClusterMemberLeadership

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);
}
Also used : ClusterMemberLeadership(com.netflix.titus.api.clustermembership.model.ClusterMemberLeadership) LeaderElectionChangeEvent(com.netflix.titus.api.clustermembership.model.event.LeaderElectionChangeEvent)

Example 5 with ClusterMemberLeadership

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;
}
Also used : ClusterMembershipRevision(com.netflix.titus.api.clustermembership.model.ClusterMembershipRevision) ClusterMemberLeadership(com.netflix.titus.api.clustermembership.model.ClusterMemberLeadership)

Aggregations

ClusterMemberLeadership (com.netflix.titus.api.clustermembership.model.ClusterMemberLeadership)7 LeaderElectionChangeEvent (com.netflix.titus.api.clustermembership.model.event.LeaderElectionChangeEvent)3 ClusterMembershipRevision (com.netflix.titus.api.clustermembership.model.ClusterMembershipRevision)2 Preconditions (com.google.common.base.Preconditions)1 Stopwatch (com.google.common.base.Stopwatch)1 ClusterMember (com.netflix.titus.api.clustermembership.model.ClusterMember)1 ClusterMemberAddress (com.netflix.titus.api.clustermembership.model.ClusterMemberAddress)1 ClusterMembershipSnapshot (com.netflix.titus.api.clustermembership.model.ClusterMembershipSnapshot)1 ScheduleReference (com.netflix.titus.common.framework.scheduler.ScheduleReference)1 ScheduleDescriptor (com.netflix.titus.common.framework.scheduler.model.ScheduleDescriptor)1 TitusRuntime (com.netflix.titus.common.runtime.TitusRuntime)1 CollectionsExt (com.netflix.titus.common.util.CollectionsExt)1 Retryers (com.netflix.titus.common.util.retry.Retryers)1 ReactorExt (com.netflix.titus.common.util.rx.ReactorExt)1 Duration (java.time.Duration)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1