Search in sources :

Example 16 with TaskRelocationPlan

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

the class DefaultDeschedulerServiceTest method testAllExpectedJobMigrationsAreFound.

@Test
public void testAllExpectedJobMigrationsAreFound() {
    List<Task> tasksOfJob1 = jobOperations.getTasks("job1");
    dataGenerator.place("active1", tasksOfJob1.get(0), tasksOfJob1.get(1));
    dataGenerator.place("removable1", tasksOfJob1.get(2), tasksOfJob1.get(3));
    dataGenerator.setQuota("job1", 2);
    List<Task> tasksOfJob2 = jobOperations.getTasks("job2");
    dataGenerator.place("active1", tasksOfJob2.get(0), tasksOfJob2.get(1));
    dataGenerator.place("removable1", tasksOfJob2.get(2), tasksOfJob2.get(3));
    dataGenerator.setQuota("job2", 2);
    dataGenerator.addJobAttribute("jobImmediate", RelocationAttributes.RELOCATION_REQUIRED_BY_IMMEDIATELY, "" + (clock.wallTime() + 1));
    Task taskImmediate = jobOperations.getTasks("jobImmediate").get(0);
    dataGenerator.place("active1", taskImmediate);
    List<DeschedulingResult> results = deschedulerService.deschedule(Collections.emptyMap());
    assertThat(results).hasSize(5);
    for (DeschedulingResult result : results) {
        boolean isImmediateJobMigration = result.getTask().getId().equals(taskImmediate.getId());
        if (isImmediateJobMigration) {
            assertThat(result.getAgentInstance().getServerGroupId()).isEqualTo("active1");
        } else {
            assertThat(result.getAgentInstance().getServerGroupId()).isEqualTo("removable1");
        }
        TaskRelocationPlan plan = result.getTaskRelocationPlan();
        if (plan.getTaskId().startsWith("jobImmediate")) {
            assertThat(plan.getReason()).isEqualTo(TaskRelocationReason.TaskMigration);
        } else {
            assertThat(plan.getReason()).isEqualTo(TaskRelocationReason.AgentEvacuation);
        }
        if (isImmediateJobMigration) {
            assertThat(plan.getReasonMessage()).containsSequence("Job marked for immediate eviction");
        } else {
            assertThat(plan.getReasonMessage()).isEqualTo("Enough quota to migrate the task (no migration delay configured)");
        }
    }
}
Also used : Task(com.netflix.titus.api.jobmanager.model.job.Task) ServiceJobTask(com.netflix.titus.api.jobmanager.model.job.ServiceJobTask) DeschedulingResult(com.netflix.titus.supplementary.relocation.model.DeschedulingResult) TaskRelocationPlan(com.netflix.titus.api.relocation.model.TaskRelocationPlan) Test(org.junit.Test)

Example 17 with TaskRelocationPlan

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

the class MustBeRelocatedSelfManagedTaskCollectorStep method collectTasksThatMustBeRelocated.

public Map<String, TaskRelocationPlan> collectTasksThatMustBeRelocated() {
    Stopwatch stopwatch = Stopwatch.createStarted();
    try {
        Map<String, TaskRelocationPlan> result = buildRelocationPlans();
        metrics.onSuccess(result.size(), stopwatch.elapsed(TimeUnit.MILLISECONDS));
        logger.debug("Step results: {}", result);
        return result;
    } catch (Exception e) {
        logger.error("Step processing error", e);
        metrics.onError(stopwatch.elapsed(TimeUnit.MILLISECONDS));
        throw e;
    }
}
Also used : Stopwatch(com.google.common.base.Stopwatch) TaskRelocationPlan(com.netflix.titus.api.relocation.model.TaskRelocationPlan)

Example 18 with TaskRelocationPlan

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

the class MustBeRelocatedSelfManagedTaskCollectorStep method buildSelfManagedRelocationPlan.

/**
 * Relocation plans today are limited to self managed polices.
 */
private TaskRelocationPlan buildSelfManagedRelocationPlan(Job<?> job, Task task, String reason) {
    long now = clock.wallTime();
    SelfManagedDisruptionBudgetPolicy selfManaged = (SelfManagedDisruptionBudgetPolicy) job.getJobDescriptor().getDisruptionBudget().getDisruptionBudgetPolicy();
    TaskRelocationPlan relocationPlan = TaskRelocationPlan.newBuilder().withTaskId(task.getId()).withReason(TaskRelocationReason.SelfManagedMigration).withReasonMessage(reason).withDecisionTime(now).withRelocationTime(now + selfManaged.getRelocationTimeMs()).build();
    TaskRelocationPlan previous = lastResult.get(task.getId());
    boolean keepPrevious = previous != null && (areEqualExceptRelocationTime(previous, relocationPlan) || previous.getRelocationTime() < relocationPlan.getRelocationTime());
    return keepPrevious ? previous : relocationPlan;
}
Also used : SelfManagedDisruptionBudgetPolicy(com.netflix.titus.api.jobmanager.model.job.disruptionbudget.SelfManagedDisruptionBudgetPolicy) TaskRelocationPlan(com.netflix.titus.api.relocation.model.TaskRelocationPlan)

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