Search in sources :

Example 21 with Task

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

Example 22 with Task

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

Example 23 with 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);
}
Also used : Task(com.netflix.titus.api.jobmanager.model.job.Task)

Example 24 with Task

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

Example 25 with Task

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

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