Search in sources :

Example 1 with LeaderElectionChangeEvent

use of com.netflix.titus.api.clustermembership.model.event.LeaderElectionChangeEvent 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 LeaderElectionChangeEvent

use of com.netflix.titus.api.clustermembership.model.event.LeaderElectionChangeEvent 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 LeaderElectionChangeEvent

use of com.netflix.titus.api.clustermembership.model.event.LeaderElectionChangeEvent in project titus-control-plane by Netflix.

the class DefaultClusterMembershipServiceTest method expectLocalLeadershipTransition.

private void expectLocalLeadershipTransition(ClusterMemberLeadershipState state) throws InterruptedException {
    LeaderElectionChangeEvent leadershipEvent = (LeaderElectionChangeEvent) eventSubscriber.takeNext(TIMEOUT);
    assertThat(leadershipEvent).isNotNull();
    assertThat(leadershipEvent.getLeadershipRevision().getCurrent().getLeadershipState()).isEqualTo(state);
    assertThat(service.getLocalLeadership().getCurrent().getLeadershipState()).isEqualTo(state);
}
Also used : LeaderElectionChangeEvent(com.netflix.titus.api.clustermembership.model.event.LeaderElectionChangeEvent)

Example 4 with LeaderElectionChangeEvent

use of com.netflix.titus.api.clustermembership.model.event.LeaderElectionChangeEvent in project titus-control-plane by Netflix.

the class AbstractKubeLeaderElectionExecutorTest method testLeaderElection.

@Test
public void testLeaderElection() {
    // Join first member
    MemberHolder member1 = new MemberHolder();
    joinLeaderElectionProcess(member1);
    awaitBeingLeader(member1);
    LeaderElectionChangeEvent leaderSelectedEvent = member1.takeNextEvent();
    assertThat(leaderSelectedEvent.getLeadershipRevision().getCurrent().getMemberId()).isEqualTo(member1.getMemberId());
    assertThat(leaderSelectedEvent.getChangeType()).isEqualTo(LeaderElectionChangeEvent.ChangeType.LeaderElected);
    // Join second member
    MemberHolder member2 = new MemberHolder();
    joinLeaderElectionProcess(member2);
    // Leave leader election process.
    member1.getExecutor().leaveLeaderElectionProcess();
    await().until(() -> {
        LeaderElectionChangeEvent event = member1.takeNextEvent();
        return event != null && event.getChangeType() == LeaderElectionChangeEvent.ChangeType.LeaderLost;
    });
    // Check that second member takes over leadership
    awaitBeingLeader(member2);
}
Also used : LeaderElectionChangeEvent(com.netflix.titus.api.clustermembership.model.event.LeaderElectionChangeEvent) Test(org.junit.Test)

Example 5 with LeaderElectionChangeEvent

use of com.netflix.titus.api.clustermembership.model.event.LeaderElectionChangeEvent in project titus-control-plane by Netflix.

the class KubeClusterMembershipConnectorTest method stopBeingLeader.

private void stopBeingLeader() throws InterruptedException {
    connector.leaveLeadershipGroup(false).block();
    LeaderElectionChangeEvent electionEvent = takeLeaderElectionEvent(LeaderElectionChangeEvent.ChangeType.LeaderLost);
    assertThat(electionEvent.getLeadershipRevision().getCurrent().getLeadershipState()).isEqualTo(ClusterMemberLeadershipState.Disabled);
    assertThat(connector.getLocalLeadershipRevision().getCurrent().getLeadershipState()).isEqualTo(ClusterMemberLeadershipState.Disabled);
}
Also used : LeaderElectionChangeEvent(com.netflix.titus.api.clustermembership.model.event.LeaderElectionChangeEvent)

Aggregations

LeaderElectionChangeEvent (com.netflix.titus.api.clustermembership.model.event.LeaderElectionChangeEvent)9 ClusterMemberLeadership (com.netflix.titus.api.clustermembership.model.ClusterMemberLeadership)3 ClusterMembershipEvent (com.netflix.titus.api.clustermembership.model.event.ClusterMembershipEvent)1 Test (org.junit.Test)1