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);
}
}
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();
}
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();
}
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);
}
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);
}
Aggregations