use of com.netflix.titus.api.containerhealth.model.ContainerHealthStatus in project titus-control-plane by Netflix.
the class ContainerHealthAsserts method assertContainerHealthSnapshot.
@SafeVarargs
public static void assertContainerHealthSnapshot(ContainerHealthEvent event, Predicate<ContainerHealthStatus>... predicates) {
assertThat(event).isInstanceOf(ContainerHealthSnapshotEvent.class);
ContainerHealthSnapshotEvent snapshotEvent = (ContainerHealthSnapshotEvent) event;
List<ContainerHealthStatus> snapshotEvents = snapshotEvent.getSnapshot();
assertThat(snapshotEvents).describedAs("Expecting %s events, but got %s", predicates.length, snapshotEvents.size()).hasSize(predicates.length);
for (int i = 0; i < snapshotEvents.size(); i++) {
if (!predicates[i].test(snapshotEvents.get(i))) {
fail("Event %s does not match its predicate: event=%s", i, snapshotEvents.get(i));
}
}
}
use of com.netflix.titus.api.containerhealth.model.ContainerHealthStatus in project titus-control-plane by Netflix.
the class UnhealthyTasksLimitTracker method countHealthy.
private Pair<Integer, String> countHealthy() {
List<Task> tasks;
try {
tasks = jobOperations.getTasks(job.getId());
} catch (JobManagerException e) {
return Pair.of(0, "job not found");
}
int healthy = 0;
Map<String, String> notStartedOrUnhealthyTasks = new HashMap<>();
for (Task task : tasks) {
if (task.getStatus().getState() == TaskState.Started) {
Optional<ContainerHealthStatus> statusOpt = containerHealthService.findHealthStatus(task.getId());
if (statusOpt.isPresent() && statusOpt.get().getState() == ContainerHealthState.Healthy) {
healthy++;
} else {
String report = statusOpt.map(status -> startWithLowercase(status.getState().name()) + '(' + status.getReason() + ')').orElse("health not found");
notStartedOrUnhealthyTasks.put(task.getId(), report);
}
} else {
notStartedOrUnhealthyTasks.put(task.getId(), String.format("Not started (current task state=%s)", task.getStatus().getState()));
}
}
if (!notStartedOrUnhealthyTasks.isEmpty()) {
StringBuilder builder = new StringBuilder("not started and healthy: ");
builder.append("total=").append(notStartedOrUnhealthyTasks.size());
builder.append(", tasks=[");
int counter = 0;
for (Map.Entry<String, String> entry : notStartedOrUnhealthyTasks.entrySet()) {
builder.append(entry.getKey()).append('=').append(entry.getValue());
counter++;
if (counter < notStartedOrUnhealthyTasks.size()) {
builder.append(", ");
} else {
builder.append("]");
}
if (counter >= TASK_ID_REPORT_LIMIT && counter < notStartedOrUnhealthyTasks.size()) {
builder.append(",... dropped ").append(notStartedOrUnhealthyTasks.size() - counter).append(" tasks]");
}
}
return Pair.of(healthy, builder.toString());
}
return Pair.of(healthy, healthy > minimumHealthyCount ? "" : String.format("not enough healthy containers: healthy=%s, minimum=%s", healthy, minimumHealthyCount));
}
use of com.netflix.titus.api.containerhealth.model.ContainerHealthStatus in project titus-control-plane by Netflix.
the class AggregatingContainerHealthService method takeStatusOfTaskWithHealthProviders.
private ContainerHealthStatus takeStatusOfTaskWithHealthProviders(Task task, Set<String> enabledServices) {
ContainerHealthStatus current = null;
for (String name : enabledServices) {
ContainerHealthService healthService = healthServices.get(name);
ContainerHealthStatus newStatus;
if (healthService != null) {
newStatus = healthService.findHealthStatus(task.getId()).orElseGet(() -> ContainerHealthStatus.newBuilder().withTaskId(task.getId()).withState(ContainerHealthState.Unknown).withReason("not known to: " + name).withTimestamp(clock.wallTime()).build());
} else {
newStatus = ContainerHealthStatus.newBuilder().withTaskId(task.getId()).withState(ContainerHealthState.Unknown).withReason("unknown container health provider set: " + name).withTimestamp(clock.wallTime()).build();
}
current = current == null ? newStatus : ContainerHealthFunctions.merge(current, newStatus);
}
return current;
}
use of com.netflix.titus.api.containerhealth.model.ContainerHealthStatus in project titus-control-plane by Netflix.
the class AggregatingContainerHealthService method handleNewState.
private Flux<ContainerHealthEvent> handleNewState(Job<?> job, Task task, ConcurrentMap<String, ContainerHealthState> emittedStates) {
ContainerHealthStatus newStatus = takeStatusOf(job, task);
ContainerHealthState previousState = emittedStates.get(task.getId());
ContainerHealthState newState = newStatus.getState();
if (newState == previousState) {
return Flux.empty();
}
if (newState == ContainerHealthState.Terminated) {
emittedStates.remove(task.getId());
} else {
emittedStates.put(task.getId(), newState);
}
return Flux.just(ContainerHealthEvent.healthChanged(newStatus));
}
use of com.netflix.titus.api.containerhealth.model.ContainerHealthStatus in project titus-control-plane by Netflix.
the class AggregatingContainerHealthService method buildCurrentSnapshot.
private ContainerHealthSnapshotEvent buildCurrentSnapshot() {
List<ContainerHealthStatus> snapshot = new ArrayList<>();
jobOperations.getJobsAndTasks().forEach(p -> {
Job job = p.getLeft();
p.getRight().forEach(task -> {
if (task.getStatus().getState() == TaskState.Finished) {
snapshot.add(ContainerHealthStatus.terminated(task.getId(), titusRuntime.getClock().wallTime()));
} else {
snapshot.add(takeStatusOf(job, task));
}
});
});
return new ContainerHealthSnapshotEvent(snapshot);
}
Aggregations