Search in sources :

Example 11 with ClusterMembershipSnapshot

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

the class SingleClusterMemberResolverTest method testInitialState.

@Test(timeout = 30_000)
public void testInitialState() {
    assertThat(resolver.isHealthy()).isTrue();
    assertThat(resolver.getAddress()).isEqualTo(ADDRESS);
    ClusterMembershipSnapshot snapshotEvent = resolver.resolve().blockFirst(TIMEOUT);
    assertThat(snapshotEvent).isNotNull();
    assertThat(snapshotEvent.getMemberRevisions()).hasSize(3);
    assertThat(snapshotEvent.getLeaderRevision()).isNotEmpty();
}
Also used : ClusterMembershipSnapshot(com.netflix.titus.api.clustermembership.model.ClusterMembershipSnapshot) Test(org.junit.Test)

Example 12 with ClusterMembershipSnapshot

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

the class SingleClusterMemberResolverTest method testElectedLeaderSetInSnapshot.

@Test
public void testElectedLeaderSetInSnapshot() {
    Iterator<ClusterMembershipSnapshot> eventIt = resolver.resolve().toIterable().iterator();
    ClusterMembershipSnapshot leadElectedEvent = eventIt.next();
    assertThat(leadElectedEvent.getLeaderRevision()).isNotEmpty();
}
Also used : ClusterMembershipSnapshot(com.netflix.titus.api.clustermembership.model.ClusterMembershipSnapshot) Test(org.junit.Test)

Example 13 with ClusterMembershipSnapshot

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

the class SingleClusterMemberResolverTest method testMemberRemoval.

@Test(timeout = 30_000)
public void testMemberRemoval() {
    Iterator<ClusterMembershipSnapshot> eventIt = subscribeAndDiscardFirstSnapshot();
    serviceStub.removeMember(MEMBER_2);
    ClusterMembershipSnapshot update = eventIt.next();
    assertThat(update.getMemberRevisions()).hasSize(2);
    assertThat(update.getMemberRevisions()).doesNotContainKey(MEMBER_2.getCurrent().getMemberId());
}
Also used : ClusterMembershipSnapshot(com.netflix.titus.api.clustermembership.model.ClusterMembershipSnapshot) Test(org.junit.Test)

Example 14 with ClusterMembershipSnapshot

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

the class SingleClusterMemberResolverTest method testReconnectOnStreamOnComplete.

@Test(timeout = 30_000)
public void testReconnectOnStreamOnComplete() {
    Iterator<ClusterMembershipSnapshot> eventIt = subscribeAndDiscardFirstSnapshot();
    serviceStub.completeEventStream();
    ClusterMembershipSnapshot newSnapshot = eventIt.next();
    assertThat(newSnapshot).isNotNull();
    assertThat(newSnapshot.getMemberRevisions()).hasSize(3);
}
Also used : ClusterMembershipSnapshot(com.netflix.titus.api.clustermembership.model.ClusterMembershipSnapshot) Test(org.junit.Test)

Example 15 with ClusterMembershipSnapshot

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

the class MultiNodeClusterMemberResolver method buildSnapshot.

private ClusterMembershipSnapshot buildSnapshot() {
    if (memberResolversByIpAddress.isEmpty()) {
        return ClusterMembershipSnapshot.empty();
    }
    List<ClusterMembershipSnapshot> healthySnapshots = findHealthySnapshots();
    ClusterMembershipSnapshot.Builder builder = ClusterMembershipSnapshot.newBuilder();
    Map<String, List<ClusterMembershipRevision<ClusterMember>>> grouped = healthySnapshots.stream().flatMap(snapshot -> snapshot.getMemberRevisions().values().stream()).collect(Collectors.groupingBy(m -> m.getCurrent().getMemberId()));
    List<ClusterMembershipRevision<ClusterMember>> recentRevisions = grouped.values().stream().map(this::findBestMemberRevision).collect(Collectors.toList());
    builder.withMemberRevisions(recentRevisions);
    // Find leader
    Optional<ClusterMembershipRevision<ClusterMemberLeadership>> recentLeader = Optional.empty();
    for (ClusterMembershipSnapshot snapshot : healthySnapshots) {
        if (snapshot.getLeaderRevision().isPresent()) {
            if (recentLeader.isPresent()) {
                if (recentLeader.get().getRevision() < snapshot.getLeaderRevision().get().getRevision()) {
                    recentLeader = snapshot.getLeaderRevision();
                }
            } else {
                recentLeader = snapshot.getLeaderRevision();
            }
        }
    }
    recentLeader.ifPresent(builder::withLeaderRevision);
    // Choose latest version of each
    long minStaleness = healthySnapshots.stream().mapToLong(ClusterMembershipSnapshot::getStalenessMs).min().orElse(0);
    builder.withStalenessMs(minStaleness);
    return builder.build();
}
Also used : Stopwatch(com.google.common.base.Stopwatch) CollectionsExt(com.netflix.titus.common.util.CollectionsExt) LoggerFactory(org.slf4j.LoggerFactory) ClusterMembershipSnapshot(com.netflix.titus.api.clustermembership.model.ClusterMembershipSnapshot) HashMap(java.util.HashMap) ReactorExt(com.netflix.titus.common.util.rx.ReactorExt) Function(java.util.function.Function) Supplier(java.util.function.Supplier) ConcurrentMap(java.util.concurrent.ConcurrentMap) ScheduleReference(com.netflix.titus.common.framework.scheduler.ScheduleReference) ClusterMemberAddress(com.netflix.titus.api.clustermembership.model.ClusterMemberAddress) Duration(java.time.Duration) Map(java.util.Map) ClusterMember(com.netflix.titus.api.clustermembership.model.ClusterMember) ClusterMembershipRevision(com.netflix.titus.api.clustermembership.model.ClusterMembershipRevision) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) Retryers(com.netflix.titus.common.util.retry.Retryers) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ClusterMemberLeadership(com.netflix.titus.api.clustermembership.model.ClusterMemberLeadership) Set(java.util.Set) Collectors(java.util.stream.Collectors) ReplayProcessor(reactor.core.publisher.ReplayProcessor) TimeUnit(java.util.concurrent.TimeUnit) Flux(reactor.core.publisher.Flux) List(java.util.List) ScheduleDescriptor(com.netflix.titus.common.framework.scheduler.model.ScheduleDescriptor) Optional(java.util.Optional) Preconditions(com.google.common.base.Preconditions) TitusRuntime(com.netflix.titus.common.runtime.TitusRuntime) ClusterMembershipRevision(com.netflix.titus.api.clustermembership.model.ClusterMembershipRevision) ClusterMembershipSnapshot(com.netflix.titus.api.clustermembership.model.ClusterMembershipSnapshot) ClusterMember(com.netflix.titus.api.clustermembership.model.ClusterMember) List(java.util.List)

Aggregations

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