Search in sources :

Example 6 with ContainerHealthStatus

use of com.netflix.titus.api.containerhealth.model.ContainerHealthStatus 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

ContainerHealthStatus (com.netflix.titus.api.containerhealth.model.ContainerHealthStatus)6 ContainerHealthState (com.netflix.titus.api.containerhealth.model.ContainerHealthState)2 ContainerHealthSnapshotEvent (com.netflix.titus.api.containerhealth.model.event.ContainerHealthSnapshotEvent)2 ContainerHealthService (com.netflix.titus.api.containerhealth.service.ContainerHealthService)2 Job (com.netflix.titus.api.jobmanager.model.job.Job)2 Task (com.netflix.titus.api.jobmanager.model.job.Task)2 Pair (com.netflix.titus.common.util.tuple.Pair)2 ArrayList (java.util.ArrayList)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 CacheRefreshedEvent (com.netflix.discovery.CacheRefreshedEvent)1 ContainerHealthEvent (com.netflix.titus.api.containerhealth.model.event.ContainerHealthEvent)1 EvictionQuota (com.netflix.titus.api.eviction.model.EvictionQuota)1 JobFunctions (com.netflix.titus.api.jobmanager.model.job.JobFunctions)1 TaskState (com.netflix.titus.api.jobmanager.model.job.TaskState)1 AvailabilityPercentageLimitDisruptionBudgetPolicy (com.netflix.titus.api.jobmanager.model.job.disruptionbudget.AvailabilityPercentageLimitDisruptionBudgetPolicy)1 UnhealthyTasksLimitDisruptionBudgetPolicy (com.netflix.titus.api.jobmanager.model.job.disruptionbudget.UnhealthyTasksLimitDisruptionBudgetPolicy)1 JobManagerException (com.netflix.titus.api.jobmanager.service.JobManagerException)1 V3JobOperations (com.netflix.titus.api.jobmanager.service.V3JobOperations)1 Reference (com.netflix.titus.api.model.reference.Reference)1 StringExt.startWithLowercase (com.netflix.titus.common.util.StringExt.startWithLowercase)1