Search in sources :

Example 11 with TaskRelocationPlan

use of com.netflix.titus.api.relocation.model.TaskRelocationPlan in project titus-control-plane by Netflix.

the class MustBeRelocatedSelfManagedTaskCollectorStepTest method testOriginalPlanIsReturnedOnEachInvocation.

@Test
public void testOriginalPlanIsReturnedOnEachInvocation() {
    Job<BatchJobExt> job = TestDataFactory.newBatchJob("job1", 1, newSelfManagedDisruptionBudget(1_000));
    relocationConnectorStubs.addJob(job);
    Task task = jobOperations.getTasks().get(0);
    relocationConnectorStubs.place(TestDataFactory.REMOVABLE_INSTANCE_GROUP_ID, task);
    Map<String, TaskRelocationPlan> firstResult = step.collectTasksThatMustBeRelocated();
    assertThat(firstResult).hasSize(1);
    TaskRelocationPlan first = firstResult.get(task.getId());
    ((TestClock) titusRuntime.getClock()).advanceTime(1, TimeUnit.SECONDS);
    Map<String, TaskRelocationPlan> secondResult = step.collectTasksThatMustBeRelocated();
    assertThat(secondResult).hasSize(1);
    TaskRelocationPlan second = secondResult.get(task.getId());
    assertThat(first).isEqualTo(second);
}
Also used : TestClock(com.netflix.titus.common.util.time.TestClock) Task(com.netflix.titus.api.jobmanager.model.job.Task) BatchJobExt(com.netflix.titus.api.jobmanager.model.job.ext.BatchJobExt) TaskRelocationPlan(com.netflix.titus.api.relocation.model.TaskRelocationPlan) AbstractTaskRelocationTest(com.netflix.titus.supplementary.relocation.AbstractTaskRelocationTest) Test(org.junit.Test)

Example 12 with TaskRelocationPlan

use of com.netflix.titus.api.relocation.model.TaskRelocationPlan in project titus-control-plane by Netflix.

the class MustBeRelocatedTaskStoreUpdateStepTest method testCreateOrUpdate.

@Test
public void testCreateOrUpdate() {
    when(store.getAllTaskRelocationPlans()).thenReturn(Mono.just(Collections.emptyMap()));
    MustBeRelocatedTaskStoreUpdateStep step = new MustBeRelocatedTaskStoreUpdateStep(configuration, store, transactionLog, titusRuntime);
    Job<BatchJobExt> job = TestDataFactory.newBatchJob("job1", 1, newSelfManagedDisruptionBudget(1_000));
    relocationConnectorStubs.addJob(job);
    relocationConnectorStubs.place(TestDataFactory.REMOVABLE_INSTANCE_GROUP_ID, jobOperations.getTasks().get(0));
    when(store.createOrUpdateTaskRelocationPlans(anyList())).thenReturn(Mono.just(Collections.singletonMap("task1", Optional.empty())));
    TaskRelocationPlan taskRelocationPlan = oneMigrationPlan();
    Map<String, TaskRelocationPlan> storeResult = step.persistChangesInStore(Collections.singletonMap(taskRelocationPlan.getTaskId(), taskRelocationPlan));
    assertThat(storeResult).hasSize(1);
    verify(store, times(1)).createOrUpdateTaskRelocationPlans(Collections.singletonList(taskRelocationPlan));
    // No try again with the same data, and make sure no store update is executed
    Map<String, TaskRelocationPlan> storeResultRepeated = step.persistChangesInStore(Collections.singletonMap(taskRelocationPlan.getTaskId(), taskRelocationPlan));
    assertThat(storeResultRepeated).hasSize(1);
    verify(store, times(1)).createOrUpdateTaskRelocationPlans(Collections.singletonList(taskRelocationPlan));
}
Also used : BatchJobExt(com.netflix.titus.api.jobmanager.model.job.ext.BatchJobExt) TaskRelocationPlan(com.netflix.titus.api.relocation.model.TaskRelocationPlan) AbstractTaskRelocationTest(com.netflix.titus.supplementary.relocation.AbstractTaskRelocationTest) Test(org.junit.Test)

Example 13 with TaskRelocationPlan

use of com.netflix.titus.api.relocation.model.TaskRelocationPlan in project titus-control-plane by Netflix.

the class MustBeRelocatedTaskStoreUpdateStepTest method testRemove.

@Test
public void testRemove() {
    TaskRelocationPlan taskRelocationPlan = oneMigrationPlan();
    when(store.getAllTaskRelocationPlans()).thenReturn(Mono.just(Collections.singletonMap(taskRelocationPlan.getTaskId(), taskRelocationPlan)));
    MustBeRelocatedTaskStoreUpdateStep step = new MustBeRelocatedTaskStoreUpdateStep(configuration, store, transactionLog, titusRuntime);
    when(store.removeTaskRelocationPlans(Collections.singleton(taskRelocationPlan.getTaskId()))).thenReturn(Mono.just(Collections.singletonMap("task1", Optional.empty())));
    step.persistChangesInStore(Collections.emptyMap());
    verify(store, times(1)).removeTaskRelocationPlans(Collections.singleton(taskRelocationPlan.getTaskId()));
    // No try again with the same data, and make sure no store update is executed
    step.persistChangesInStore(Collections.emptyMap());
    verify(store, times(1)).removeTaskRelocationPlans(Collections.singleton(taskRelocationPlan.getTaskId()));
}
Also used : TaskRelocationPlan(com.netflix.titus.api.relocation.model.TaskRelocationPlan) AbstractTaskRelocationTest(com.netflix.titus.supplementary.relocation.AbstractTaskRelocationTest) Test(org.junit.Test)

Example 14 with TaskRelocationPlan

use of com.netflix.titus.api.relocation.model.TaskRelocationPlan in project titus-control-plane by Netflix.

the class TaskEvictionStepTest method testSuccessfulEviction.

@Test
public void testSuccessfulEviction() {
    Job<BatchJobExt> job = TestDataFactory.newBatchJob("job1", 1, newSelfManagedDisruptionBudget(1_000));
    relocationConnectorStubs.addJob(job);
    relocationConnectorStubs.setQuota("job1", 1);
    Task task = jobOperations.getTasks().get(0);
    relocationConnectorStubs.place(TestDataFactory.REMOVABLE_INSTANCE_GROUP_ID, task);
    TaskRelocationPlan taskRelocationPlan = oneMigrationPlan().toBuilder().withTaskId(task.getId()).build();
    Map<String, TaskRelocationStatus> result = step.evict(Collections.singletonMap(task.getId(), taskRelocationPlan));
    assertThat(result).hasSize(1);
    TaskRelocationStatus relocationStatus = result.get(task.getId());
    assertThat(relocationStatus.getTaskId()).isEqualTo(task.getId());
    assertThat(relocationStatus.getStatusCode()).isEqualTo(TaskRelocationStatus.STATUS_CODE_TERMINATED);
    assertThat(relocationStatus.getTaskRelocationPlan()).isEqualTo(taskRelocationPlan);
}
Also used : Task(com.netflix.titus.api.jobmanager.model.job.Task) BatchJobExt(com.netflix.titus.api.jobmanager.model.job.ext.BatchJobExt) TaskRelocationStatus(com.netflix.titus.api.relocation.model.TaskRelocationStatus) TaskRelocationPlan(com.netflix.titus.api.relocation.model.TaskRelocationPlan) AbstractTaskRelocationTest(com.netflix.titus.supplementary.relocation.AbstractTaskRelocationTest) Test(org.junit.Test)

Example 15 with TaskRelocationPlan

use of com.netflix.titus.api.relocation.model.TaskRelocationPlan in project titus-control-plane by Netflix.

the class TaskMigrationDeschedulerTest method testSelfMigrationAfterDeadline.

@Test
public void testSelfMigrationAfterDeadline() {
    Task job1Task0 = jobOperations.getTasks("job1").get(0);
    relocationConnectorStubs.place("removable1", job1Task0);
    relocationConnectorStubs.setQuota("job1", 1);
    TaskRelocationPlan job1Task0Plan = TaskRelocationPlan.newBuilder().withTaskId(job1Task0.getId()).withRelocationTime(clock.wallTime() - 1).build();
    Optional<Pair<TitusNode, List<Task>>> results = newDescheduler(Collections.singletonMap(job1Task0.getId(), job1Task0Plan)).nextBestMatch();
    assertThat(results).isNotEmpty();
}
Also used : Task(com.netflix.titus.api.jobmanager.model.job.Task) TaskRelocationPlan(com.netflix.titus.api.relocation.model.TaskRelocationPlan) Pair(com.netflix.titus.common.util.tuple.Pair) Test(org.junit.Test)

Aggregations

TaskRelocationPlan (com.netflix.titus.api.relocation.model.TaskRelocationPlan)18 Task (com.netflix.titus.api.jobmanager.model.job.Task)10 Test (org.junit.Test)10 Optional (java.util.Optional)5 Job (com.netflix.titus.api.jobmanager.model.job.Job)4 TitusRuntime (com.netflix.titus.common.runtime.TitusRuntime)4 Pair (com.netflix.titus.common.util.tuple.Pair)4 AbstractTaskRelocationTest (com.netflix.titus.supplementary.relocation.AbstractTaskRelocationTest)4 TitusNode (com.netflix.titus.supplementary.relocation.connector.TitusNode)4 DeschedulingResult (com.netflix.titus.supplementary.relocation.model.DeschedulingResult)4 HashMap (java.util.HashMap)4 ReadOnlyEvictionOperations (com.netflix.titus.api.eviction.service.ReadOnlyEvictionOperations)3 BatchJobExt (com.netflix.titus.api.jobmanager.model.job.ext.BatchJobExt)3 ReadOnlyJobOperations (com.netflix.titus.api.jobmanager.service.ReadOnlyJobOperations)3 TaskRelocationReason (com.netflix.titus.api.relocation.model.TaskRelocationPlan.TaskRelocationReason)3 TaskRelocationStatus (com.netflix.titus.api.relocation.model.TaskRelocationStatus)3 Clock (com.netflix.titus.common.util.time.Clock)3 List (java.util.List)3 Map (java.util.Map)3 Collectors (java.util.stream.Collectors)3