Search in sources :

Example 1 with Task

use of com.netflix.titus.api.jobmanager.model.job.Task in project titus-control-plane by Netflix.

the class JobStoreFitAction method handleDuplicatedEni.

private <T> T handleDuplicatedEni(T result, boolean storeOnly) {
    if (!(result instanceof Task)) {
        return result;
    }
    Task task = (Task) result;
    if (task.getTwoLevelResources().isEmpty()) {
        return result;
    }
    TwoLevelResource original = task.getTwoLevelResources().get(0);
    synchronized (twoLevelResourceAssignments) {
        // Store current assignment
        ConcurrentMap<Integer, TwoLevelResource> agentAssignments = twoLevelResourceAssignments.computeIfAbsent(task.getTaskContext().getOrDefault(TaskAttributes.TASK_ATTRIBUTES_AGENT_HOST, "DEFAULT"), k -> new ConcurrentHashMap<>());
        agentAssignments.put(original.getIndex(), original);
        if (storeOnly) {
            return result;
        }
        // Find another assignment on the same agent with different resource value
        Optional<Task> taskOverride = agentAssignments.values().stream().filter(a -> !a.getValue().equals(original.getValue())).findFirst().map(match -> {
            TwoLevelResource override = original.toBuilder().withIndex(match.getIndex()).build();
            return task.toBuilder().withTwoLevelResources(override).build();
        });
        return (T) taskOverride.orElse(task);
    }
}
Also used : Task(com.netflix.titus.api.jobmanager.model.job.Task) TwoLevelResource(com.netflix.titus.api.jobmanager.model.job.TwoLevelResource)

Example 2 with Task

use of com.netflix.titus.api.jobmanager.model.job.Task in project titus-control-plane by Netflix.

the class GrpcJobReplicatorEventStreamTest method testCacheTaskRemove.

@Test
public void testCacheTaskRemove() {
    Pair<Job, List<Task>> pair = jobServiceStub.createJobAndTasks(SERVICE_JOB);
    List<Task> tasks = pair.getRight();
    Task task = tasks.get(0);
    newConnectVerifier().assertNext(next -> assertThat(next.getSnapshot().getTasks().get(0).getStatus().getState()).isEqualTo(TaskState.Accepted)).then(() -> jobServiceStub.moveTaskToState(task, TaskState.Finished)).assertNext(next -> assertThat(next.getSnapshot().getTaskMap()).hasSize(tasks.size() - 1)).thenCancel().verify();
}
Also used : BatchJobTask(com.netflix.titus.api.jobmanager.model.job.BatchJobTask) Task(com.netflix.titus.api.jobmanager.model.job.Task) ArrayList(java.util.ArrayList) List(java.util.List) Job(com.netflix.titus.api.jobmanager.model.job.Job) Test(org.junit.Test)

Example 3 with Task

use of com.netflix.titus.api.jobmanager.model.job.Task in project titus-control-plane by Netflix.

the class GrpcJobReplicatorEventStreamTest method testCacheTaskUpdate.

@Test
public void testCacheTaskUpdate() {
    Pair<Job, List<Task>> pair = jobServiceStub.createJobAndTasks(BATCH_JOB);
    Task task = pair.getRight().get(0);
    newConnectVerifier().assertNext(next -> assertThat(next.getSnapshot().getTasks().get(0).getStatus().getState()).isEqualTo(TaskState.Accepted)).then(() -> jobServiceStub.moveTaskToState(task, TaskState.Launched)).assertNext(next -> assertThat(next.getSnapshot().getTasks().get(0).getStatus().getState()).isEqualTo(TaskState.Launched)).thenCancel().verify();
}
Also used : BatchJobTask(com.netflix.titus.api.jobmanager.model.job.BatchJobTask) Task(com.netflix.titus.api.jobmanager.model.job.Task) ArrayList(java.util.ArrayList) List(java.util.List) Job(com.netflix.titus.api.jobmanager.model.job.Job) Test(org.junit.Test)

Example 4 with Task

use of com.netflix.titus.api.jobmanager.model.job.Task in project titus-control-plane by Netflix.

the class CachedBatchJobTest method initialSnapshot.

/**
 * Create a snapshot with a single job and size == taskCount. Create up to tasksCreated tasks, leaving
 * the remaining slots empty.
 */
private Triple<PCollectionJobSnapshot, Map<Integer, Task>, Map<Integer, Task>> initialSnapshot(int taskCount, int tasksCreated) {
    Pair<Job<BatchJobExt>, PMap<String, Task>> jobAndTasks = newBatchJobWithTasks(0, taskCount);
    Job<BatchJobExt> job = jobAndTasks.getLeft();
    Map<Integer, Task> tasksByIndex = new HashMap<>();
    Map<String, Task> tasks = new HashMap<>(jobAndTasks.getRight());
    Map<Integer, Task> skipped = new HashMap<>();
    Iterator<Task> it = tasks.values().iterator();
    while (it.hasNext()) {
        Task task = it.next();
        int index = CachedBatchJob.indexOf(task, taskCount, titusRuntime);
        if (index >= tasksCreated) {
            it.remove();
            skipped.put(index, task);
        } else {
            tasksByIndex.put(index, task);
        }
    }
    PCollectionJobSnapshot snapshot = PCollectionJobSnapshot.newInstance("test", Collections.singletonMap(job.getId(), job), Collections.singletonMap(job.getId(), tasks), false, false, error -> {
        throw new IllegalStateException(error);
    }, titusRuntime);
    return Triple.of(snapshot, tasksByIndex, skipped);
}
Also used : Task(com.netflix.titus.api.jobmanager.model.job.Task) HashMap(java.util.HashMap) BatchJobExt(com.netflix.titus.api.jobmanager.model.job.ext.BatchJobExt) PMap(org.pcollections.PMap) Job(com.netflix.titus.api.jobmanager.model.job.Job)

Example 5 with Task

use of com.netflix.titus.api.jobmanager.model.job.Task in project titus-control-plane by Netflix.

the class CachedBatchJobWithOneTaskTest method testUpdateTask.

@Test
public void testUpdateTask() {
    Pair<PCollectionJobSnapshot, Task> initial = initialSnapshot(true);
    PCollectionJobSnapshot initialSnapshot = initial.getLeft();
    Task task = initial.getRight();
    Task task0Updated = task.toBuilder().withStatus(TaskStatus.newBuilder().withState(TaskState.Started).build()).build();
    CachedJob cached1 = CollectionsExt.first(initialSnapshot.cachedJobsById.values());
    PCollectionJobSnapshot snapshot2 = (PCollectionJobSnapshot) cached1.updateTask(initialSnapshot, task0Updated).orElse(null);
    CachedJob cached2 = CollectionsExt.first(snapshot2.cachedJobsById.values());
    assertThat(cached2.getTasks()).hasSize(1);
    assertThat(cached2.getTasks().get(task0Updated.getId())).isEqualTo(task0Updated);
}
Also used : Task(com.netflix.titus.api.jobmanager.model.job.Task) 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