@Test public void testBuildQuotaControllers() { testBuildQuotaControllers( scheduleJob( newBatchJob(10, budget(perTaskRelocationLimitPolicy(3), unlimitedRate(), Collections.emptyList())), 10 ), SelfJobDisruptionBudgetResolver.getInstance(), TaskRelocationLimitController.class ); testBuildQuotaControllers( scheduleJob( newBatchJob(10, budget(perTaskRelocationLimitPolicy(3), hourlyRatePercentage(5), Collections.emptyList())), 10 ), SelfJobDisruptionBudgetResolver.getInstance(), JobPercentagePerHourRelocationRateController.class, TaskRelocationLimitController.class ); testBuildQuotaControllers( scheduleJob( newBatchJob(10, budget(perTaskRelocationLimitPolicy(3), ratePerInterval(60_000, 5), Collections.emptyList())), 10 ), SelfJobDisruptionBudgetResolver.getInstance(), RatePerIntervalRateController.class, TaskRelocationLimitController.class ); testBuildQuotaControllers( scheduleJob( newBatchJob(10, budget(selfManagedPolicy(10_000), unlimitedRate(), Collections.emptyList())), 10 ), job -> budget(perTaskRelocationLimitPolicy(100), hourlyRatePercentage(5), singletonList(officeHourTimeWindow())), TaskRelocationLimitController.class, JobPercentagePerHourRelocationRateController.class ); }
@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; }
JobQuotaController implements QuotaController<Job<?>> { @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; } }
JobQuotaController implements QuotaController<Job<?>> { @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; } JobQuotaController(Job<?> job,
                              V3JobOperations jobOperations,
                              EffectiveJobDisruptionBudgetResolver effectiveDisruptionBudgetResolver,
                              ContainerHealthService containerHealthService,
                              TitusRuntime titusRuntime); private  JobQuotaController(Job<?> newJob,
                               V3JobOperations jobOperations,
                               EffectiveJobDisruptionBudgetResolver effectiveDisruptionBudgetResolver,
                               ContainerHealthService containerHealthService,
                               JobQuotaController previousJobQuotaController,
                               TitusRuntime titusRuntime); }
JobQuotaController implements QuotaController<Job<?>> { @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; } JobQuotaController(Job<?> job,
                              V3JobOperations jobOperations,
                              EffectiveJobDisruptionBudgetResolver effectiveDisruptionBudgetResolver,
                              ContainerHealthService containerHealthService,
                              TitusRuntime titusRuntime); private  JobQuotaController(Job<?> newJob,
                               V3JobOperations jobOperations,
                               EffectiveJobDisruptionBudgetResolver effectiveDisruptionBudgetResolver,
                               ContainerHealthService containerHealthService,
                               JobQuotaController previousJobQuotaController,
                               TitusRuntime titusRuntime); Job<?> getJob(); @Override EvictionQuota getQuota(Reference reference); @Override ConsumptionResult consume(String taskId); @Override void giveBackConsumedQuota(String taskId); @Override JobQuotaController update(Job<?> updatedJob); }
JobQuotaController implements QuotaController<Job<?>> { @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; } JobQuotaController(Job<?> job,
                              V3JobOperations jobOperations,
                              EffectiveJobDisruptionBudgetResolver effectiveDisruptionBudgetResolver,
                              ContainerHealthService containerHealthService,
                              TitusRuntime titusRuntime); private  JobQuotaController(Job<?> newJob,
                               V3JobOperations jobOperations,
                               EffectiveJobDisruptionBudgetResolver effectiveDisruptionBudgetResolver,
                               ContainerHealthService containerHealthService,
                               JobQuotaController previousJobQuotaController,
                               TitusRuntime titusRuntime); Job<?> getJob(); @Override EvictionQuota getQuota(Reference reference); @Override ConsumptionResult consume(String taskId); @Override void giveBackConsumedQuota(String taskId); @Override JobQuotaController update(Job<?> updatedJob);  }