Search in sources :

Example 1 with QuotaController

use of com.netflix.titus.master.eviction.service.quota.QuotaController in project titus-control-plane by Netflix.

the class JobQuotaController method mergeQuotaControllers.

@VisibleForTesting
static List<QuotaController<Job<?>>> mergeQuotaControllers(List<QuotaController<Job<?>>> previousControllers, Job<?> job, V3JobOperations jobOperations, EffectiveJobDisruptionBudgetResolver effectiveDisruptionBudgetResolver, TitusRuntime titusRuntime) {
    List<QuotaController<Job<?>>> quotaControllers = new ArrayList<>();
    DisruptionBudget effectiveBudget = effectiveDisruptionBudgetResolver.resolve(job);
    if (effectiveBudget.getDisruptionBudgetRate() instanceof PercentagePerHourDisruptionBudgetRate) {
        QuotaController<Job<?>> newController = mergeQuotaController(job, previousControllers, JobPercentagePerHourRelocationRateController.class, () -> JobPercentagePerHourRelocationRateController.newJobPercentagePerHourRelocationRateController(job, effectiveDisruptionBudgetResolver, titusRuntime));
        quotaControllers.add(newController);
    } else if (effectiveBudget.getDisruptionBudgetRate() instanceof RatePercentagePerIntervalDisruptionBudgetRate) {
        QuotaController<Job<?>> newController = mergeQuotaController(job, previousControllers, JobPercentagePerIntervalRateController.class, () -> JobPercentagePerIntervalRateController.newJobPercentagePerIntervalRateController(job, effectiveDisruptionBudgetResolver, titusRuntime));
        quotaControllers.add(newController);
    } else if (effectiveBudget.getDisruptionBudgetRate() instanceof RatePerIntervalDisruptionBudgetRate) {
        QuotaController<Job<?>> newController = mergeQuotaController(job, previousControllers, RatePerIntervalRateController.class, () -> RatePerIntervalRateController.newRatePerIntervalRateController(job, effectiveDisruptionBudgetResolver, titusRuntime));
        quotaControllers.add(newController);
    }
    DisruptionBudgetPolicy policy = effectiveBudget.getDisruptionBudgetPolicy();
    if (policy instanceof RelocationLimitDisruptionBudgetPolicy) {
        QuotaController<Job<?>> newController = mergeQuotaController(job, previousControllers, TaskRelocationLimitController.class, () -> new TaskRelocationLimitController(job, jobOperations, effectiveDisruptionBudgetResolver));
        quotaControllers.add(newController);
    }
    return quotaControllers;
}
Also used : PercentagePerHourDisruptionBudgetRate(com.netflix.titus.api.jobmanager.model.job.disruptionbudget.PercentagePerHourDisruptionBudgetRate) RatePerIntervalDisruptionBudgetRate(com.netflix.titus.api.jobmanager.model.job.disruptionbudget.RatePerIntervalDisruptionBudgetRate) UnhealthyTasksLimitDisruptionBudgetPolicy(com.netflix.titus.api.jobmanager.model.job.disruptionbudget.UnhealthyTasksLimitDisruptionBudgetPolicy) RelocationLimitDisruptionBudgetPolicy(com.netflix.titus.api.jobmanager.model.job.disruptionbudget.RelocationLimitDisruptionBudgetPolicy) DisruptionBudgetPolicy(com.netflix.titus.api.jobmanager.model.job.disruptionbudget.DisruptionBudgetPolicy) AvailabilityPercentageLimitDisruptionBudgetPolicy(com.netflix.titus.api.jobmanager.model.job.disruptionbudget.AvailabilityPercentageLimitDisruptionBudgetPolicy) QuotaController(com.netflix.titus.master.eviction.service.quota.QuotaController) DisruptionBudget(com.netflix.titus.api.jobmanager.model.job.disruptionbudget.DisruptionBudget) ArrayList(java.util.ArrayList) RelocationLimitDisruptionBudgetPolicy(com.netflix.titus.api.jobmanager.model.job.disruptionbudget.RelocationLimitDisruptionBudgetPolicy) RatePercentagePerIntervalDisruptionBudgetRate(com.netflix.titus.api.jobmanager.model.job.disruptionbudget.RatePercentagePerIntervalDisruptionBudgetRate) Job(com.netflix.titus.api.jobmanager.model.job.Job) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 2 with QuotaController

use of com.netflix.titus.master.eviction.service.quota.QuotaController 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 3 with QuotaController

use of com.netflix.titus.master.eviction.service.quota.QuotaController 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)

Example 4 with QuotaController

use of com.netflix.titus.master.eviction.service.quota.QuotaController in project titus-control-plane by Netflix.

the class JobQuotaController method buildQuotaControllers.

@VisibleForTesting
static List<QuotaController<Job<?>>> buildQuotaControllers(Job<?> job, V3JobOperations jobOperations, EffectiveJobDisruptionBudgetResolver effectiveDisruptionBudgetResolver, TitusRuntime titusRuntime) {
    List<QuotaController<Job<?>>> quotaControllers = new ArrayList<>();
    DisruptionBudget effectiveBudget = effectiveDisruptionBudgetResolver.resolve(job);
    if (effectiveBudget.getDisruptionBudgetRate() instanceof PercentagePerHourDisruptionBudgetRate) {
        quotaControllers.add(JobPercentagePerHourRelocationRateController.newJobPercentagePerHourRelocationRateController(job, effectiveDisruptionBudgetResolver, titusRuntime));
    } else if (effectiveBudget.getDisruptionBudgetRate() instanceof RatePercentagePerIntervalDisruptionBudgetRate) {
        quotaControllers.add(JobPercentagePerIntervalRateController.newJobPercentagePerIntervalRateController(job, effectiveDisruptionBudgetResolver, titusRuntime));
    } else if (effectiveBudget.getDisruptionBudgetRate() instanceof RatePerIntervalDisruptionBudgetRate) {
        quotaControllers.add(RatePerIntervalRateController.newRatePerIntervalRateController(job, effectiveDisruptionBudgetResolver, titusRuntime));
    }
    DisruptionBudgetPolicy policy = effectiveBudget.getDisruptionBudgetPolicy();
    if (policy instanceof RelocationLimitDisruptionBudgetPolicy) {
        quotaControllers.add(new TaskRelocationLimitController(job, jobOperations, effectiveDisruptionBudgetResolver));
    }
    return quotaControllers;
}
Also used : PercentagePerHourDisruptionBudgetRate(com.netflix.titus.api.jobmanager.model.job.disruptionbudget.PercentagePerHourDisruptionBudgetRate) RatePerIntervalDisruptionBudgetRate(com.netflix.titus.api.jobmanager.model.job.disruptionbudget.RatePerIntervalDisruptionBudgetRate) RelocationLimitDisruptionBudgetPolicy(com.netflix.titus.api.jobmanager.model.job.disruptionbudget.RelocationLimitDisruptionBudgetPolicy) UnhealthyTasksLimitDisruptionBudgetPolicy(com.netflix.titus.api.jobmanager.model.job.disruptionbudget.UnhealthyTasksLimitDisruptionBudgetPolicy) RelocationLimitDisruptionBudgetPolicy(com.netflix.titus.api.jobmanager.model.job.disruptionbudget.RelocationLimitDisruptionBudgetPolicy) DisruptionBudgetPolicy(com.netflix.titus.api.jobmanager.model.job.disruptionbudget.DisruptionBudgetPolicy) AvailabilityPercentageLimitDisruptionBudgetPolicy(com.netflix.titus.api.jobmanager.model.job.disruptionbudget.AvailabilityPercentageLimitDisruptionBudgetPolicy) QuotaController(com.netflix.titus.master.eviction.service.quota.QuotaController) RatePercentagePerIntervalDisruptionBudgetRate(com.netflix.titus.api.jobmanager.model.job.disruptionbudget.RatePercentagePerIntervalDisruptionBudgetRate) DisruptionBudget(com.netflix.titus.api.jobmanager.model.job.disruptionbudget.DisruptionBudget) ArrayList(java.util.ArrayList) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 5 with QuotaController

use of com.netflix.titus.master.eviction.service.quota.QuotaController in project titus-control-plane by Netflix.

the class JobQuotaControllerTest method testMergeRatePerIntervalDisruptionBudgetRateQuotaController.

@Test
public void testMergeRatePerIntervalDisruptionBudgetRateQuotaController() {
    // First version
    Job<BatchJobExt> job = newBatchJob(10, budget(perTaskRelocationLimitPolicy(3), ratePerInterval(60_000, 5), 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);
    RatePerIntervalRateController controller = (RatePerIntervalRateController) 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, ratePerInterval(30_000, 5)));
    List<QuotaController<Job<?>>> merged = mergeQuotaControllers(controllers, updatedJob, jobOperations, SelfJobDisruptionBudgetResolver.getInstance(), titusRuntime);
    RatePerIntervalRateController updatedController = (RatePerIntervalRateController) merged.get(0);
    assertThat(updatedController.getQuota(jobReference).getQuota()).isEqualTo(4);
}
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

QuotaController (com.netflix.titus.master.eviction.service.quota.QuotaController)5 Task (com.netflix.titus.api.jobmanager.model.job.Task)3 BatchJobExt (com.netflix.titus.api.jobmanager.model.job.ext.BatchJobExt)3 Test (org.junit.Test)3 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 AvailabilityPercentageLimitDisruptionBudgetPolicy (com.netflix.titus.api.jobmanager.model.job.disruptionbudget.AvailabilityPercentageLimitDisruptionBudgetPolicy)2 DisruptionBudget (com.netflix.titus.api.jobmanager.model.job.disruptionbudget.DisruptionBudget)2 DisruptionBudgetPolicy (com.netflix.titus.api.jobmanager.model.job.disruptionbudget.DisruptionBudgetPolicy)2 PercentagePerHourDisruptionBudgetRate (com.netflix.titus.api.jobmanager.model.job.disruptionbudget.PercentagePerHourDisruptionBudgetRate)2 RatePerIntervalDisruptionBudgetRate (com.netflix.titus.api.jobmanager.model.job.disruptionbudget.RatePerIntervalDisruptionBudgetRate)2 RatePercentagePerIntervalDisruptionBudgetRate (com.netflix.titus.api.jobmanager.model.job.disruptionbudget.RatePercentagePerIntervalDisruptionBudgetRate)2 RelocationLimitDisruptionBudgetPolicy (com.netflix.titus.api.jobmanager.model.job.disruptionbudget.RelocationLimitDisruptionBudgetPolicy)2 UnhealthyTasksLimitDisruptionBudgetPolicy (com.netflix.titus.api.jobmanager.model.job.disruptionbudget.UnhealthyTasksLimitDisruptionBudgetPolicy)2 ArrayList (java.util.ArrayList)2 Job (com.netflix.titus.api.jobmanager.model.job.Job)1