Search in sources :

Example 6 with Task

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);
}
Also used : Task(com.netflix.titus.api.jobmanager.model.job.Task) JobSnapshotTestUtil.newServiceTask(com.netflix.titus.runtime.connector.jobmanager.snapshot.JobSnapshotTestUtil.newServiceTask) Test(org.junit.Test)

Example 7 with Task

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);
}
Also used : Task(com.netflix.titus.api.jobmanager.model.job.Task) JobSnapshotTestUtil.newServiceTask(com.netflix.titus.runtime.connector.jobmanager.snapshot.JobSnapshotTestUtil.newServiceTask) ServiceJobExt(com.netflix.titus.api.jobmanager.model.job.ext.ServiceJobExt) Test(org.junit.Test)

Example 8 with Task

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)));
}
Also used : BatchJobTask(com.netflix.titus.api.jobmanager.model.job.BatchJobTask) Task(com.netflix.titus.api.jobmanager.model.job.Task) HashTreePMap(org.pcollections.HashTreePMap) PMap(org.pcollections.PMap) Job(com.netflix.titus.api.jobmanager.model.job.Job)

Example 9 with Task

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));
}
Also used : Task(com.netflix.titus.api.jobmanager.model.job.Task) ArrayList(java.util.ArrayList) Job(com.netflix.titus.api.jobmanager.model.job.Job) Map(java.util.Map) PMap(org.pcollections.PMap) Pair(com.netflix.titus.common.util.tuple.Pair) Test(org.junit.Test)

Example 10 with Task

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);
}
Also used : Task(com.netflix.titus.api.jobmanager.model.job.Task) ArrayList(java.util.ArrayList) PMap(org.pcollections.PMap) Job(com.netflix.titus.api.jobmanager.model.job.Job) Test(org.junit.Test)

Aggregations

Task (com.netflix.titus.api.jobmanager.model.job.Task)222 Test (org.junit.Test)98 ArrayList (java.util.ArrayList)63 List (java.util.List)62 Job (com.netflix.titus.api.jobmanager.model.job.Job)58 BatchJobTask (com.netflix.titus.api.jobmanager.model.job.BatchJobTask)45 TaskStatus (com.netflix.titus.api.jobmanager.model.job.TaskStatus)45 TaskState (com.netflix.titus.api.jobmanager.model.job.TaskState)42 TitusRuntime (com.netflix.titus.common.runtime.TitusRuntime)38 BatchJobExt (com.netflix.titus.api.jobmanager.model.job.ext.BatchJobExt)34 Pair (com.netflix.titus.common.util.tuple.Pair)32 V1Pod (io.kubernetes.client.openapi.models.V1Pod)32 V3JobOperations (com.netflix.titus.api.jobmanager.service.V3JobOperations)31 ServiceJobTask (com.netflix.titus.api.jobmanager.model.job.ServiceJobTask)29 Optional (java.util.Optional)27 Collections (java.util.Collections)26 Collectors (java.util.stream.Collectors)25 CallMetadata (com.netflix.titus.api.model.callmetadata.CallMetadata)24 HashMap (java.util.HashMap)24 TaskUpdateEvent (com.netflix.titus.api.jobmanager.model.job.event.TaskUpdateEvent)23