Search in sources :

Example 51 with Task

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

the class JobQuotaControllerTest method testMergeTaskRelocationLimitController.

@Test
public void testMergeTaskRelocationLimitController() {
    // First version
    Job<BatchJobExt> job = newBatchJob(10, budget(perTaskRelocationLimitPolicy(1), unlimitedRate(), Collections.emptyList()));
    scheduleJob(job, 10);
    List<QuotaController<Job<?>>> controllers = buildQuotaControllers(job, jobOperations, SelfJobDisruptionBudgetResolver.getInstance(), titusRuntime);
    TaskRelocationLimitController controller = (TaskRelocationLimitController) controllers.get(0);
    Task task = jobOperations.getTasks(job.getId()).get(0);
    assertThat(controller.consume(task.getId()).isApproved()).isTrue();
    jobComponentStub.killTask(task, false, false, V3JobOperations.Trigger.Eviction);
    assertThat(controller.consume(task.getId()).isApproved()).isFalse();
    Task replacement1 = jobComponentStub.getJobOperations().getTasks().stream().filter(t -> t.getOriginalId().equals(task.getId())).findFirst().get();
    jobComponentStub.moveTaskToState(replacement1, TaskState.Started);
    // Change job descriptor and consume some quota
    Job<BatchJobExt> updatedJob = jobComponentStub.changeJob(exceptPolicy(job, perTaskRelocationLimitPolicy(3)));
    List<QuotaController<Job<?>>> merged = mergeQuotaControllers(controllers, updatedJob, jobOperations, SelfJobDisruptionBudgetResolver.getInstance(), titusRuntime);
    TaskRelocationLimitController updatedController = (TaskRelocationLimitController) merged.get(0);
    // Evict replacement 1
    assertThat(updatedController.consume(replacement1.getId()).isApproved()).isTrue();
    jobComponentStub.killTask(replacement1, false, false, V3JobOperations.Trigger.Eviction);
    Task replacement2 = jobComponentStub.getJobOperations().getTasks().stream().filter(t -> t.getOriginalId().equals(task.getId())).findFirst().get();
    jobComponentStub.moveTaskToState(replacement2, TaskState.Started);
    // Evict replacement 2
    assertThat(updatedController.consume(replacement2.getId()).isApproved()).isTrue();
    jobComponentStub.killTask(replacement2, false, false, V3JobOperations.Trigger.Eviction);
    Task replacement3 = jobComponentStub.getJobOperations().getTasks().stream().filter(t -> t.getOriginalId().equals(task.getId())).findFirst().get();
    jobComponentStub.moveTaskToState(replacement3, TaskState.Started);
    assertThat(updatedController.consume(replacement3.getId()).isApproved()).isFalse();
}
Also used : Task(com.netflix.titus.api.jobmanager.model.job.Task) QuotaController(com.netflix.titus.master.eviction.service.quota.QuotaController) BatchJobExt(com.netflix.titus.api.jobmanager.model.job.ext.BatchJobExt) Test(org.junit.Test)

Example 52 with Task

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

the class JobQuotaControllerTest method testUpdate.

@Test
public void testUpdate() {
    Job<BatchJobExt> job = newBatchJob(10, budget(perTaskRelocationLimitPolicy(2), hourlyRatePercentage(20), Collections.emptyList()));
    com.netflix.titus.api.model.reference.Reference jobReference = com.netflix.titus.api.model.reference.Reference.job(job.getId());
    scheduleJob(job, 10);
    JobQuotaController jobController = new JobQuotaController(job, jobOperations, SelfJobDisruptionBudgetResolver.getInstance(), containerHealthService, titusRuntime);
    assertThat(jobController.getQuota(jobReference).getQuota()).isEqualTo(2);
    // Evict task 1
    Task task = jobOperations.getTasks(job.getId()).get(0);
    assertThat(jobController.consume(task.getId()).isApproved()).isTrue();
    jobComponentStub.killTask(task, false, false, V3JobOperations.Trigger.Eviction);
    Task replacement1 = jobComponentStub.getJobOperations().getTasks().stream().filter(t -> t.getOriginalId().equals(task.getId())).findFirst().get();
    // Evict replacement 1
    assertThat(jobController.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(jobController.consume(replacement2.getId()).isApproved()).isFalse();
    assertThat(jobController.getQuota(jobReference).getQuota()).isEqualTo(0);
    // Now bump up the limit by 1
    Job<BatchJobExt> updatedJob = jobComponentStub.changeJob(exceptBudget(job, budget(perTaskRelocationLimitPolicy(3), hourlyRatePercentage(80), Collections.emptyList())));
    JobQuotaController updatedController = jobController.update(updatedJob);
    // Evict replacement 2
    assertThat(updatedController.consume(replacement2.getId()).isApproved()).isTrue();
    jobComponentStub.moveTaskToState(replacement2, TaskState.Started);
    jobComponentStub.killTask(replacement2, false, false, V3JobOperations.Trigger.Eviction);
    Task replacement3 = jobComponentStub.getJobOperations().getTasks().stream().filter(t -> t.getOriginalId().equals(task.getId())).findFirst().get();
    assertThat(updatedController.consume(replacement3.getId()).isApproved()).isFalse();
    // 3 task killed out of 8 allowed in an hour
    assertThat(updatedController.getQuota(jobReference).getQuota()).isEqualTo(5);
    // Now increase job size
    Job<BatchJobExt> scaledJob = jobComponentStub.changeJob(JobFunctions.changeBatchJobSize(updatedJob, 20));
    jobComponentStub.createDesiredTasks(scaledJob);
    JobQuotaController updatedController2 = jobController.update(scaledJob);
    // 3 task kills out of 16 allowed in an hour
    assertThat(updatedController2.getQuota(jobReference).getQuota()).isEqualTo(13);
}
Also used : Task(com.netflix.titus.api.jobmanager.model.job.Task) BatchJobExt(com.netflix.titus.api.jobmanager.model.job.ext.BatchJobExt) Test(org.junit.Test)

Example 53 with Task

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

the class JobQuotaControllerTest method testSelfManagedJobUsesInternalDisruptionBudget.

@Test
public void testSelfManagedJobUsesInternalDisruptionBudget() {
    Job<BatchJobExt> job = newBatchJob(10, budget(selfManagedPolicy(1_000), unlimitedRate(), Collections.emptyList()));
    com.netflix.titus.api.model.reference.Reference jobReference = com.netflix.titus.api.model.reference.Reference.job(job.getId());
    scheduleJob(job, 10);
    EffectiveJobDisruptionBudgetResolver budgetResolver = j -> budget(perTaskRelocationLimitPolicy(100), hourlyRatePercentage(5), singletonList(officeHourTimeWindow()));
    JobQuotaController jobController = new JobQuotaController(job, jobOperations, budgetResolver, containerHealthService, titusRuntime);
    assertThat(jobController.getQuota(jobReference).getQuota()).isEqualTo(1);
    Task task = jobOperations.getTasks(job.getId()).get(0);
    assertThat(jobController.consume(task.getId()).isApproved()).isTrue();
    assertThat(jobController.getQuota(jobReference).getQuota()).isEqualTo(0);
    ConsumptionResult failure = jobController.consume(task.getId());
    assertThat(failure.isApproved()).isFalse();
    assertThat(failure.getRejectionReason().get()).contains("JobPercentagePerHourRelocationRateController");
}
Also used : DisruptionBudgetGenerator.numberOfHealthyPolicy(com.netflix.titus.testkit.model.eviction.DisruptionBudgetGenerator.numberOfHealthyPolicy) DisruptionBudgetGenerator.unlimitedRate(com.netflix.titus.testkit.model.eviction.DisruptionBudgetGenerator.unlimitedRate) ConsumptionResult(com.netflix.titus.master.eviction.service.quota.ConsumptionResult) DisruptionBudgetGenerator.exceptBudget(com.netflix.titus.testkit.model.eviction.DisruptionBudgetGenerator.exceptBudget) DisruptionBudgetGenerator.percentageOfHealthyPolicy(com.netflix.titus.testkit.model.eviction.DisruptionBudgetGenerator.percentageOfHealthyPolicy) Task(com.netflix.titus.api.jobmanager.model.job.Task) DisruptionBudgetGenerator.budget(com.netflix.titus.testkit.model.eviction.DisruptionBudgetGenerator.budget) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) DisruptionBudgetGenerator.exceptRate(com.netflix.titus.testkit.model.eviction.DisruptionBudgetGenerator.exceptRate) TimeWindowQuotaTracker(com.netflix.titus.master.eviction.service.quota.TimeWindowQuotaTracker) DisruptionBudgetGenerator.newBatchJob(com.netflix.titus.testkit.model.eviction.DisruptionBudgetGenerator.newBatchJob) JobQuotaController.buildQuotaControllers(com.netflix.titus.master.eviction.service.quota.job.JobQuotaController.buildQuotaControllers) DisruptionBudgetGenerator.hourlyRatePercentage(com.netflix.titus.testkit.model.eviction.DisruptionBudgetGenerator.hourlyRatePercentage) Collections.singletonList(java.util.Collections.singletonList) DisruptionBudgetGenerator.perTaskRelocationLimitPolicy(com.netflix.titus.testkit.model.eviction.DisruptionBudgetGenerator.perTaskRelocationLimitPolicy) TitusRuntimes(com.netflix.titus.common.runtime.TitusRuntimes) QuotaTracker(com.netflix.titus.master.eviction.service.quota.QuotaTracker) JobQuotaController.buildQuotaTrackers(com.netflix.titus.master.eviction.service.quota.job.JobQuotaController.buildQuotaTrackers) BatchJobExt(com.netflix.titus.api.jobmanager.model.job.ext.BatchJobExt) QuotaController(com.netflix.titus.master.eviction.service.quota.QuotaController) DisruptionBudgetGenerator.exceptPolicy(com.netflix.titus.testkit.model.eviction.DisruptionBudgetGenerator.exceptPolicy) DisruptionBudgetGenerator.selfManagedPolicy(com.netflix.titus.testkit.model.eviction.DisruptionBudgetGenerator.selfManagedPolicy) Clocks(com.netflix.titus.common.util.time.Clocks) Job(com.netflix.titus.api.jobmanager.model.job.Job) DisruptionBudgetGenerator.officeHourTimeWindow(com.netflix.titus.testkit.model.eviction.DisruptionBudgetGenerator.officeHourTimeWindow) Set(java.util.Set) JobFunctions(com.netflix.titus.api.jobmanager.model.job.JobFunctions) Test(org.junit.Test) Collectors(java.util.stream.Collectors) TaskState(com.netflix.titus.api.jobmanager.model.job.TaskState) List(java.util.List) V3JobOperations(com.netflix.titus.api.jobmanager.service.V3JobOperations) Stream(java.util.stream.Stream) DayOfWeek(java.time.DayOfWeek) JobComponentStub(com.netflix.titus.testkit.model.job.JobComponentStub) TitusRuntime(com.netflix.titus.common.runtime.TitusRuntime) TestClock(com.netflix.titus.common.util.time.TestClock) DisruptionBudgetGenerator.ratePerInterval(com.netflix.titus.testkit.model.eviction.DisruptionBudgetGenerator.ratePerInterval) ContainerHealthService(com.netflix.titus.api.containerhealth.service.ContainerHealthService) Collections(java.util.Collections) JobQuotaController.mergeQuotaControllers(com.netflix.titus.master.eviction.service.quota.job.JobQuotaController.mergeQuotaControllers) Task(com.netflix.titus.api.jobmanager.model.job.Task) ConsumptionResult(com.netflix.titus.master.eviction.service.quota.ConsumptionResult) BatchJobExt(com.netflix.titus.api.jobmanager.model.job.ext.BatchJobExt) Test(org.junit.Test)

Example 54 with Task

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

the class JobQuotaControllerTest method testConsume.

@Test
public void testConsume() {
    Job<BatchJobExt> job = newBatchJob(10, budget(percentageOfHealthyPolicy(80.0), hourlyRatePercentage(20), Collections.emptyList()));
    com.netflix.titus.api.model.reference.Reference jobReference = com.netflix.titus.api.model.reference.Reference.job(job.getId());
    scheduleJob(job, 10);
    JobQuotaController jobController = new JobQuotaController(job, jobOperations, SelfJobDisruptionBudgetResolver.getInstance(), containerHealthService, titusRuntime);
    assertThat(jobController.getQuota(jobReference).getQuota()).isEqualTo(2);
    Task task = jobOperations.getTasks(job.getId()).get(0);
    assertThat(jobController.consume(task.getId()).isApproved()).isTrue();
    assertThat(jobController.consume(task.getId()).isApproved()).isTrue();
    assertThat(jobController.getQuota(jobReference).getQuota()).isEqualTo(0);
    ConsumptionResult failure = jobController.consume(task.getId());
    assertThat(failure.isApproved()).isFalse();
    assertThat(failure.getRejectionReason().get()).contains("JobPercentagePerHourRelocationRateController");
}
Also used : Task(com.netflix.titus.api.jobmanager.model.job.Task) ConsumptionResult(com.netflix.titus.master.eviction.service.quota.ConsumptionResult) BatchJobExt(com.netflix.titus.api.jobmanager.model.job.ext.BatchJobExt) Test(org.junit.Test)

Example 55 with Task

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

the class JobQuotaControllerTest method testMergePercentagePerHourDisruptionBudgetRateQuotaController.

@Test
public void testMergePercentagePerHourDisruptionBudgetRateQuotaController() {
    // First version
    Job<BatchJobExt> job = newBatchJob(10, budget(perTaskRelocationLimitPolicy(3), hourlyRatePercentage(50), Collections.emptyList()));
    com.netflix.titus.api.model.reference.Reference jobReference = com.netflix.titus.api.model.reference.Reference.job(job.getId());
    scheduleJob(job, 10);
    List<QuotaController<Job<?>>> controllers = buildQuotaControllers(job, jobOperations, SelfJobDisruptionBudgetResolver.getInstance(), titusRuntime);
    JobPercentagePerHourRelocationRateController controller = (JobPercentagePerHourRelocationRateController) controllers.get(0);
    Task task = jobOperations.getTasks(job.getId()).get(0);
    assertThat(controller.consume(task.getId()).isApproved()).isTrue();
    assertThat(controller.getQuota(jobReference).getQuota()).isEqualTo(4);
    // Change job descriptor and consume some quota
    Job<BatchJobExt> updatedJob = jobComponentStub.changeJob(exceptRate(job, hourlyRatePercentage(80)));
    List<QuotaController<Job<?>>> merged = mergeQuotaControllers(controllers, updatedJob, jobOperations, SelfJobDisruptionBudgetResolver.getInstance(), titusRuntime);
    JobPercentagePerHourRelocationRateController updatedController = (JobPercentagePerHourRelocationRateController) merged.get(0);
    assertThat(updatedController.getQuota(jobReference).getQuota()).isEqualTo(7);
}
Also used : Task(com.netflix.titus.api.jobmanager.model.job.Task) QuotaController(com.netflix.titus.master.eviction.service.quota.QuotaController) BatchJobExt(com.netflix.titus.api.jobmanager.model.job.ext.BatchJobExt) Test(org.junit.Test)

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