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);
}
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();
}
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);
}
Aggregations