use of com.netflix.titus.api.jobmanager.model.job.ext.BatchJobExt 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);
}
use of com.netflix.titus.api.jobmanager.model.job.ext.BatchJobExt 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");
}
use of com.netflix.titus.api.jobmanager.model.job.ext.BatchJobExt 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");
}
use of com.netflix.titus.api.jobmanager.model.job.ext.BatchJobExt 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);
}
use of com.netflix.titus.api.jobmanager.model.job.ext.BatchJobExt 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);
}
Aggregations