Search in sources :

Example 56 with Task

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

the class TaskRelocationLimitControllerTest method testJobUpdate.

@Test
public void testJobUpdate() {
    Job<BatchJobExt> job = createBatchJob(1);
    Task task = jobOperations.getTasks(job.getId()).get(0);
    Reference jobReference = Reference.job(job.getId());
    // Consume in first instance of the controller
    TaskRelocationLimitController firstController = new TaskRelocationLimitController(job, jobOperations, SelfJobDisruptionBudgetResolver.getInstance());
    assertThat(firstController.consume(task.getId()).isApproved()).isTrue();
    jobComponentStub.moveTaskToState(task, TaskState.Started);
    jobComponentStub.killTask(task, false, false, V3JobOperations.Trigger.Eviction);
    Task replacement1 = jobComponentStub.getJobOperations().getTasks().stream().filter(t -> t.getOriginalId().equals(task.getId())).findFirst().get();
    assertThat(firstController.consume(replacement1.getId()).isApproved()).isFalse();
    // Update
    Job<BatchJobExt> updatedJob = exceptPolicy(changeBatchJobSize(job, 20), perTaskRelocationLimitPolicy(2));
    jobComponentStub.changeJob(updatedJob);
    jobComponentStub.createDesiredTasks(updatedJob);
    TaskRelocationLimitController updatedController = firstController.update(updatedJob);
    assertThat(updatedController.getQuota(jobReference).getQuota()).isEqualTo(20);
    // Consume again, after limit increase
    assertThat(updatedController.consume(replacement1.getId()).isApproved()).isTrue();
    jobComponentStub.moveTaskToState(replacement1, TaskState.Started);
    jobComponentStub.killTask(replacement1, false, false, V3JobOperations.Trigger.Eviction);
    Task replacement2 = jobComponentStub.getJobOperations().getTasks().stream().filter(t -> t.getOriginalId().equals(task.getId())).findFirst().get();
    assertThat(updatedController.consume(replacement2.getId()).isApproved()).isFalse();
    assertThat(updatedController.getQuota(jobReference).getQuota()).isEqualTo(19);
}
Also used : Task(com.netflix.titus.api.jobmanager.model.job.Task) Reference(com.netflix.titus.api.model.reference.Reference) BatchJobExt(com.netflix.titus.api.jobmanager.model.job.ext.BatchJobExt) Test(org.junit.Test)

Example 57 with Task

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

the class TaskScenarioBuilder method expectTaskOnAgent.

public TaskScenarioBuilder expectTaskOnAgent() {
    Task task = getTask();
    logger.info("[{}] Expecting task {} on agent", discoverActiveTest(), task.getId());
    kubeCluster.schedule();
    expectStateAndReasonUpdateSkipOther(TaskStatus.TaskState.Launched, "SCHEDULED");
    kubeCluster.moveToStartInitiatedState(task.getId());
    return this;
}
Also used : Task(com.netflix.titus.api.jobmanager.model.job.Task)

Example 58 with Task

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

the class TaskScenarioBuilder method expectAllTasksInKube.

public TaskScenarioBuilder expectAllTasksInKube() {
    Task task = getTask();
    logger.info("[{}] Expecting task {} Kube", discoverActiveTest(), task.getId());
    try {
        await().timeout(TIMEOUT_MS, TimeUnit.MILLISECONDS).until(() -> kubeCluster.getPods().containsKey(task.getId()));
    } catch (Exception e) {
        throw e;
    }
    return this;
}
Also used : Task(com.netflix.titus.api.jobmanager.model.job.Task)

Example 59 with Task

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

the class TaskScenarioBuilder method assertTaskUpdate.

public TaskScenarioBuilder assertTaskUpdate(Consumer<Task> assertFun) {
    Task task = expectTaskUpdate(update -> true, update -> true, "N/A");
    assertFun.accept(task);
    return this;
}
Also used : Task(com.netflix.titus.api.jobmanager.model.job.Task)

Example 60 with Task

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

the class TaskScenarioBuilder method completeKillInitiated.

public TaskScenarioBuilder completeKillInitiated() {
    Task task = getTask();
    Preconditions.checkState(task.getStatus().getState() == TaskState.KillInitiated, "Expected task in KillInitiated state");
    kubeCluster.moveToFinishedSuccess(task.getId());
    return this;
}
Also used : Task(com.netflix.titus.api.jobmanager.model.job.Task)

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