Search in sources :

Example 1 with ContainerHealthEvent

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

the class EurekaContainerHealthServiceTest method testBadSubscriberIsolation.

@Test
public void testBadSubscriberIsolation() {
    jobManagerStub.moveTaskToState(taskId1, TaskState.Started);
    eurekaServer.register(newInstanceInfo(taskId1, InstanceStatus.UP));
    // First event / one subscriber
    TitusRxSubscriber<ContainerHealthEvent> subscriber1 = new TitusRxSubscriber<>();
    healthService.events(false).subscribe(subscriber1);
    eurekaServer.triggerCacheRefreshUpdate();
    // Add bad subscriber
    Disposable subscription2 = healthService.events(false).subscribe(next -> {
        throw new RuntimeException("simulated error");
    }, e -> {
        throw new RuntimeException("simulated error");
    }, () -> {
        throw new RuntimeException("simulated error");
    });
    // Event 2
    registerAndRefresh(InstanceStatus.DOWN);
    assertThat(subscription2.isDisposed()).isTrue();
    // Event 3
    registerAndRefresh(InstanceStatus.UP);
    assertThat(subscriber1.isDisposed()).isFalse();
    assertThat(subscriber1.getAllItems()).hasSize(3);
}
Also used : Disposable(reactor.core.Disposable) TitusRxSubscriber(com.netflix.titus.testkit.rx.TitusRxSubscriber) ContainerHealthAsserts.assertContainerHealthEvent(com.netflix.titus.testkit.junit.asserts.ContainerHealthAsserts.assertContainerHealthEvent) ContainerHealthEvent(com.netflix.titus.api.containerhealth.model.event.ContainerHealthEvent) Test(org.junit.Test)

Example 2 with ContainerHealthEvent

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

the class AggregatingContainerHealthServiceTest method testBadSubscriberIsIsolated.

@Test
public void testBadSubscriberIsIsolated() {
    // First event / one subscriber
    TitusRxSubscriber<ContainerHealthEvent> goodSubscriber = new TitusRxSubscriber<>();
    healthService.events(false).subscribe(goodSubscriber);
    // Add bad subscriber
    Disposable badSubscriber = healthService.events(false).subscribe(next -> {
        throw new RuntimeException("simulated error");
    }, e -> {
        throw new RuntimeException("simulated error");
    }, () -> {
        throw new RuntimeException("simulated error");
    });
    downstream1.makeHealthy(taskId1);
    assertThat(goodSubscriber.isOpen()).isTrue();
    assertThat(badSubscriber.isDisposed()).isTrue();
}
Also used : Disposable(reactor.core.Disposable) TitusRxSubscriber(com.netflix.titus.testkit.rx.TitusRxSubscriber) ContainerHealthAsserts.assertContainerHealthEvent(com.netflix.titus.testkit.junit.asserts.ContainerHealthAsserts.assertContainerHealthEvent) ContainerHealthEvent(com.netflix.titus.api.containerhealth.model.event.ContainerHealthEvent) Test(org.junit.Test)

Example 3 with ContainerHealthEvent

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

the class EurekaContainerHealthService method handleEurekaEvent.

private Flux<ContainerHealthEvent> handleEurekaEvent(EurekaEvent event, ConcurrentMap<String, ContainerHealthEvent> state) {
    if (!(event instanceof CacheRefreshedEvent)) {
        return Flux.empty();
    }
    List<Pair<Job, List<Task>>> allJobsAndTasks = jobOperations.getJobsAndTasks();
    List<Task> allTasks = new ArrayList<>();
    List<ContainerHealthEvent> events = new ArrayList<>();
    allJobsAndTasks.forEach(jobAndTasks -> {
        jobAndTasks.getRight().forEach(task -> {
            handleTaskStateUpdate(jobAndTasks.getLeft(), task, state).ifPresent(events::add);
            allTasks.add(task);
        });
    });
    // Cleanup, in case we have stale entries.
    Set<String> unknownTaskIds = CollectionsExt.copyAndRemove(state.keySet(), allTasks.stream().map(Task::getId).collect(Collectors.toSet()));
    unknownTaskIds.forEach(taskId -> {
        state.remove(taskId);
        // Assume the task was terminated.
        ContainerHealthStatus terminatedStatus = ContainerHealthStatus.newBuilder().withTaskId(taskId).withTimestamp(titusRuntime.getClock().wallTime()).withState(ContainerHealthState.Terminated).withReason("terminated").build();
        events.add(ContainerHealthUpdateEvent.healthChanged(terminatedStatus));
    });
    return Flux.fromIterable(events);
}
Also used : Task(com.netflix.titus.api.jobmanager.model.job.Task) ContainerHealthStatus(com.netflix.titus.api.containerhealth.model.ContainerHealthStatus) ArrayList(java.util.ArrayList) ContainerHealthEvent(com.netflix.titus.api.containerhealth.model.event.ContainerHealthEvent) CacheRefreshedEvent(com.netflix.discovery.CacheRefreshedEvent) Pair(com.netflix.titus.common.util.tuple.Pair)

Aggregations

ContainerHealthEvent (com.netflix.titus.api.containerhealth.model.event.ContainerHealthEvent)3 ContainerHealthAsserts.assertContainerHealthEvent (com.netflix.titus.testkit.junit.asserts.ContainerHealthAsserts.assertContainerHealthEvent)2 TitusRxSubscriber (com.netflix.titus.testkit.rx.TitusRxSubscriber)2 Test (org.junit.Test)2 Disposable (reactor.core.Disposable)2 CacheRefreshedEvent (com.netflix.discovery.CacheRefreshedEvent)1 ContainerHealthStatus (com.netflix.titus.api.containerhealth.model.ContainerHealthStatus)1 Task (com.netflix.titus.api.jobmanager.model.job.Task)1 Pair (com.netflix.titus.common.util.tuple.Pair)1 ArrayList (java.util.ArrayList)1