use of com.netflix.titus.api.jobmanager.model.job.Task in project titus-control-plane by Netflix.
the class ObserveJobsSubscription method createJobsSnapshot.
private List<JobChangeNotification> createJobsSnapshot(Predicate<Pair<Job<?>, List<Task>>> jobsPredicate, Predicate<Pair<com.netflix.titus.api.jobmanager.model.job.Job<?>, com.netflix.titus.api.jobmanager.model.job.Task>> tasksPredicate) {
long now = titusRuntime.getClock().wallTime();
List<JobChangeNotification> snapshot = new ArrayList<>();
// Generics casting issue
List allJobsAndTasksRaw = context.getJobOperations().getJobsAndTasks();
List<Pair<com.netflix.titus.api.jobmanager.model.job.Job<?>, List<com.netflix.titus.api.jobmanager.model.job.Task>>> allJobsAndTasks = allJobsAndTasksRaw;
allJobsAndTasks.forEach(pair -> {
com.netflix.titus.api.jobmanager.model.job.Job<?> job = pair.getLeft();
List<com.netflix.titus.api.jobmanager.model.job.Task> tasks = pair.getRight();
if (jobsPredicate.test(pair)) {
snapshot.add(context.toJobChangeNotification(job, now));
}
tasks.forEach(task -> {
if (tasksPredicate.test(Pair.of(job, task))) {
snapshot.add(context.toJobChangeNotification(task, now));
}
});
});
return snapshot;
}
use of com.netflix.titus.api.jobmanager.model.job.Task in project titus-control-plane by Netflix.
the class TaskRelocationLimitController method getTaskQuota.
private EvictionQuota getTaskQuota(Reference taskReference) {
String taskId = taskReference.getName();
EvictionQuota.Builder quotaBuilder = EvictionQuota.newBuilder().withReference(taskReference);
Optional<Pair<Job<?>, Task>> jobTaskOpt = jobOperations.findTaskById(taskId);
if (!jobTaskOpt.isPresent()) {
return quotaBuilder.withQuota(0).withMessage("Task not found").build();
}
Task task = jobTaskOpt.get().getRight();
int counter = task.getEvictionResubmitNumber();
if (counter < perTaskLimit) {
return quotaBuilder.withQuota(1).withMessage("Per task limit is %s, and restart count is %s", perTaskLimit, counter).build();
}
return quotaBuilder.withQuota(0).withMessage(taskLimitExceeded.getRejectionReason().get()).build();
}
use of com.netflix.titus.api.jobmanager.model.job.Task in project titus-control-plane by Netflix.
the class TaskRelocationLimitController method getJobQuota.
private EvictionQuota getJobQuota(Reference jobReference) {
EvictionQuota.Builder quotaBuilder = EvictionQuota.newBuilder().withReference(jobReference);
List<Task> tasks;
try {
tasks = jobOperations.getTasks(job.getId());
} catch (JobManagerException e) {
return quotaBuilder.withQuota(0).withMessage("Internal error: %s", e.getMessage()).build();
}
int quota = 0;
for (Task task : tasks) {
if (task.getEvictionResubmitNumber() < perTaskLimit) {
quota++;
}
}
return quota > 0 ? quotaBuilder.withQuota(quota).withMessage("Per task limit is %s", perTaskLimit).build() : quotaBuilder.withQuota(0).withMessage("Each task of the job reached its maximum eviction limit %s", perTaskLimit).build();
}
use of com.netflix.titus.api.jobmanager.model.job.Task in project titus-control-plane by Netflix.
the class TaskRelocationLimitController method consume.
@Override
public ConsumptionResult consume(String taskId) {
Optional<Pair<Job<?>, Task>> jobTaskPair = jobOperations.findTaskById(taskId);
if (!jobTaskPair.isPresent()) {
return TASK_NOT_FOUND;
}
Task task = jobTaskPair.get().getRight();
int counter = task.getEvictionResubmitNumber();
if (counter >= perTaskLimit) {
return taskLimitExceeded;
}
return ConsumptionResult.approved();
}
use of com.netflix.titus.api.jobmanager.model.job.Task 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));
}
Aggregations