use of com.netflix.titus.api.jobmanager.model.job.Task in project titus-control-plane by Netflix.
the class CachedServiceJobTest method testUpdateFinishedTask.
@Test
public void testUpdateFinishedTask() {
PCollectionJobSnapshot initialSnapshot = initialSnapshot(2, true);
CachedJob cached1 = CollectionsExt.first(initialSnapshot.cachedJobsById.values());
Task someTask = CollectionsExt.first(cached1.getTasks().values());
Task updatedTask = someTask.toBuilder().withStatus(TaskStatus.newBuilder().withState(TaskState.Finished).build()).build();
// In archive mode we do not remove finished tasks immediately
PCollectionJobSnapshot snapshot2 = (PCollectionJobSnapshot) cached1.updateTask(initialSnapshot, updatedTask).orElse(null);
CachedJob cached2 = CollectionsExt.first(snapshot2.cachedJobsById.values());
assertThat(cached2.getTasks()).hasSize(2);
assertThat(cached2.getTasks().get(updatedTask.getId()).getStatus().getState()).isEqualTo(TaskState.Finished);
// Now remove it explicitly
PCollectionJobSnapshot snapshot3 = (PCollectionJobSnapshot) cached1.removeTask(initialSnapshot, updatedTask).orElse(null);
CachedJob cached3 = CollectionsExt.first(snapshot3.cachedJobsById.values());
assertThat(cached3.getTasks()).hasSize(1);
}
use of com.netflix.titus.api.jobmanager.model.job.Task in project titus-control-plane by Netflix.
the class CachedServiceJobTest method testAddTask.
@Test
public void testAddTask() {
PCollectionJobSnapshot initialSnapshot = initialSnapshot(2, false);
// Empty
CachedJob cached1 = CollectionsExt.first(initialSnapshot.cachedJobsById.values());
assertThat(cached1.getTasks()).hasSize(2);
// One task
Task extraTask = newServiceTask((Job<ServiceJobExt>) cached1.getJob(), 3);
PCollectionJobSnapshot withThreeTasks = (PCollectionJobSnapshot) cached1.updateTask(initialSnapshot, extraTask).orElse(null);
CachedJob cached2 = CollectionsExt.first(withThreeTasks.cachedJobsById.values());
assertThat(cached2.getTasks()).hasSize(3);
assertThat(cached2.getTasks()).containsValue(extraTask);
}
use of com.netflix.titus.api.jobmanager.model.job.Task in project titus-control-plane by Netflix.
the class JobSnapshotPerf method updateTask.
private void updateTask() {
int idx = random.nextInt(jobAndTasks.size());
Pair<Job<?>, PMap<String, Task>> toUpdate = this.jobAndTasks.get(idx);
Job<?> job = toUpdate.getLeft();
PMap<String, Task> tasks = toUpdate.getRight();
int taskIdx = random.nextInt(tasks.size());
Task taskToUpdate = new ArrayList<>(tasks.values()).get(taskIdx);
Task updatedTask = taskToUpdate.toBuilder().withVersion(Version.newBuilder().withTimestamp(System.currentTimeMillis()).build()).build();
snapshot.updateTask(updatedTask, false).ifPresent(newSnapshot -> this.snapshot = newSnapshot);
// Clean local map
jobAndTasks = jobAndTasks.with(idx, Pair.of(job, tasks.plus(updatedTask.getId(), updatedTask)));
}
use of com.netflix.titus.api.jobmanager.model.job.Task in project titus-control-plane by Netflix.
the class JobSnapshotTest method testJobAndTaskUpdate.
@Test
public void testJobAndTaskUpdate() {
Pair<Job<?>, Map<String, Task>> pair1 = (Pair) newServiceJobWithTasks(1, 2, 1_000);
Pair<Job<?>, Map<String, Task>> pair2 = (Pair) newBatchJobWithTasks(2, 2);
Job<?> job1 = pair1.getLeft();
Job<?> job2 = pair2.getLeft();
List<Task> tasks1 = new ArrayList<>(pair1.getRight().values());
List<Task> tasks2 = new ArrayList<>(pair2.getRight().values());
JobSnapshot initial = newSnapshot(factory, pair1);
// Add job2
JobSnapshot updated = initial.updateJob(job2).orElse(null);
assertThat(updated).isNotNull();
assertThat(updated.getJobMap()).containsValues(job1, job2);
// Add tasks of job2
updated = updated.updateTask(tasks2.get(0), false).orElse(null);
assertThat(updated).isNotNull();
updated = updated.updateTask(tasks2.get(1), false).orElse(null);
assertThat(updated).isNotNull();
assertThat(updated.getTasks(job2.getId()).values()).containsAll(tasks2);
assertThat(updated.getTaskMap()).hasSize(4);
// Modify job1
Job<?> updatedJob = job1.toBuilder().withVersion(Version.newBuilder().withTimestamp(123).build()).build();
updated = updated.updateJob(updatedJob).orElse(null);
assertThat(updated).isNotNull();
assertThat(updated.getJobMap()).containsValues(updatedJob, job2);
// Modify task (job1)
Task updatedTask = tasks1.get(0).toBuilder().withVersion(Version.newBuilder().withTimestamp(123).build()).build();
updated = updated.updateTask(updatedTask, false).orElse(null);
assertThat(updated).isNotNull();
assertThat(updated.getTasks(job1.getId())).hasSize(2);
assertThat(updated.getTasks(job1.getId()).values()).contains(tasks1.get(1)).contains(updatedTask);
assertThat(updated.getTaskMap()).hasSize(4);
assertThat(updated.getTaskMap().get(updatedTask.getId())).isEqualTo(updatedTask);
// Remove task (job1)
updated = updated.updateTask(updatedTask.toBuilder().withStatus(TaskStatus.newBuilder().withState(TaskState.Finished).build()).build(), false).orElse(null);
assertThat(updated).isNotNull();
assertThat(updated.getTasks(job1.getId()).values()).containsExactly(tasks1.get(1));
assertThat(updated.getTaskMap()).hasSize(3);
// Remove job1
updated = updated.updateJob(updatedJob.toBuilder().withStatus(JobStatus.newBuilder().withState(JobState.Finished).build()).build()).orElse(null);
assertThat(updated).isNotNull();
assertThat(updated.getJobMap()).hasSize(1).containsEntry(job2.getId(), job2);
assertThat(updated.getTasks(job2.getId()).values()).containsAll(tasks2);
assertThat(updated.getTaskMap()).hasSize(2).containsValues(tasks2.get(0), tasks2.get(1));
}
use of com.netflix.titus.api.jobmanager.model.job.Task in project titus-control-plane by Netflix.
the class JobSnapshotTest method testMovedTask.
@Test
public void testMovedTask() {
Pair<Job<ServiceJobExt>, PMap<String, Task>> pair1 = newServiceJobWithTasks(1, 2, 1_000);
Pair<Job<ServiceJobExt>, PMap<String, Task>> pair2 = newServiceJobWithTasks(2, 0, 1_000);
Job<?> job1 = pair1.getLeft();
Job<?> job2 = pair2.getLeft();
List<Task> tasks1 = new ArrayList<>(pair1.getRight().values());
JobSnapshot initial = newSnapshot(factory, (Pair) pair1, (Pair) pair2);
Task movedTask = tasks1.get(0).toBuilder().withJobId(job2.getId()).withTaskContext(Collections.singletonMap(TaskAttributes.TASK_ATTRIBUTES_MOVED_FROM_JOB, job1.getId())).build();
JobSnapshot updated = initial.updateTask(movedTask, true).orElse(null);
assertThat(updated).isNotNull();
assertThat(updated.getJobMap()).hasSize(2).containsValues(job1, job2);
assertThat(updated.getTaskMap()).containsValues(movedTask, tasks1.get(1));
assertThat(updated.getTasks(job1.getId()).values()).containsExactly(tasks1.get(1));
assertThat(updated.getTasks(job2.getId()).values()).containsExactly(movedTask);
}
Aggregations