use of com.netflix.titus.api.jobmanager.model.job.Task in project titus-control-plane by Netflix.
the class CachedBatchJob method newBatchInstance.
public static CachedJob newBatchInstance(Job<BatchJobExt> job, PMap<String, Task> tasks, TitusRuntime titusRuntime) {
int size = job.getJobDescriptor().getExtensions().getSize();
PVector<Task> tasksByIndex = TreePVector.empty();
for (int i = 0; i < size; i++) {
tasksByIndex = tasksByIndex.plus(null);
}
for (Task task : tasks.values()) {
int index = indexOf(task, size, titusRuntime);
if (index >= 0) {
tasksByIndex = tasksByIndex.with(index, task);
}
}
return new CachedBatchJob(job, tasks, tasksByIndex, titusRuntime);
}
use of com.netflix.titus.api.jobmanager.model.job.Task in project titus-control-plane by Netflix.
the class CachedBatchJob method updateTask.
@Override
public Optional<JobSnapshot> updateTask(PCollectionJobSnapshot snapshot, Task task) {
int index = indexOf(task, tasksByIndex.size(), titusRuntime);
if (index < 0) {
return Optional.empty();
}
Task current = tasksByIndex.get(index);
if (current == null) {
CachedBatchJob update = new CachedBatchJob(job, tasks.plus(task.getId(), task), tasksByIndex.with(index, task), titusRuntime);
return Optional.ofNullable(snapshot.newSnapshot(snapshot.cachedJobsById.plus(job.getId(), update), snapshot.jobsById, snapshot.taskById.plus(task.getId(), task)));
}
// This task collides with another one
if (task.getVersion().getTimestamp() < current.getVersion().getTimestamp()) {
// It is an earlier version. Ignore it.
titusRuntime.getCodeInvariants().inconsistent("Received earlier version of a task: current=%s, received=%s", current.getVersion().getTimestamp(), task.getVersion().getTimestamp());
return Optional.empty();
}
// Replace the old version.
CachedBatchJob update = new CachedBatchJob(job, tasks.minus(current.getId()).plus(task.getId(), task), tasksByIndex.with(index, task), titusRuntime);
return Optional.of(snapshot.newSnapshot(snapshot.cachedJobsById.plus(job.getId(), update), snapshot.jobsById, snapshot.taskById.minus(current.getId()).plus(task.getId(), task)));
}
use of com.netflix.titus.api.jobmanager.model.job.Task in project titus-control-plane by Netflix.
the class CachedBatchJobWithOneTask method newBatchInstance.
public static CachedJob newBatchInstance(Job<BatchJobExt> job, PMap<String, Task> tasks, TitusRuntime titusRuntime) {
int size = job.getJobDescriptor().getExtensions().getSize();
Preconditions.checkState(size == 1, "Expected batch job of size 1");
Task task = null;
if (tasks.size() == 1) {
task = CollectionsExt.first(tasks.values());
} else if (tasks.size() > 1) {
// We have to find the latest version.
for (Task next : tasks.values()) {
if (task == null) {
task = next;
} else if (task.getVersion().getTimestamp() < next.getVersion().getTimestamp()) {
task = next;
}
}
}
return new CachedBatchJobWithOneTask(job, task, titusRuntime);
}
use of com.netflix.titus.api.jobmanager.model.job.Task in project titus-control-plane by Netflix.
the class CachedServiceJob method updateTask.
@Override
public Optional<JobSnapshot> updateTask(PCollectionJobSnapshot snapshot, Task updatedTask) {
String taskId = updatedTask.getId();
Task currentTaskVersion = tasks.get(taskId);
if (!archiveMode && updatedTask.getStatus().getState() == TaskState.Finished) {
if (currentTaskVersion == null) {
return Optional.empty();
}
return removeTask(snapshot, updatedTask);
}
if (currentTaskVersion == null) {
CachedServiceJob update = new CachedServiceJob(job, tasks.plus(taskId, updatedTask), archiveMode, titusRuntime);
return Optional.ofNullable(snapshot.newSnapshot(snapshot.cachedJobsById.plus(job.getId(), update), snapshot.jobsById, snapshot.taskById.plus(taskId, updatedTask)));
}
// This task collides with another one
if (updatedTask.getVersion().getTimestamp() < currentTaskVersion.getVersion().getTimestamp()) {
// It is an earlier version. Ignore it.
titusRuntime.getCodeInvariants().inconsistent("Received earlier version of a task: current=%s, received=%s", currentTaskVersion.getVersion().getTimestamp(), updatedTask.getVersion().getTimestamp());
return Optional.empty();
}
CachedServiceJob update = new CachedServiceJob(job, tasks.plus(taskId, updatedTask), archiveMode, titusRuntime);
return Optional.ofNullable(snapshot.newSnapshot(snapshot.cachedJobsById.plus(job.getId(), update), snapshot.jobsById, snapshot.taskById.plus(taskId, updatedTask)));
}
use of com.netflix.titus.api.jobmanager.model.job.Task in project titus-control-plane by Netflix.
the class JobComponentStub method createJobAndTasks.
public Pair<Job, List<Task>> createJobAndTasks(String templateId) {
Job job = createJob(templateId);
List<Task> tasks = createDesiredTasks(job);
return Pair.of(job, tasks);
}
Aggregations