@Test public void testBuildQuotaTrackers() { testBuildQuotaTrackers( scheduleJob( newBatchJob(10, budget(percentageOfHealthyPolicy(80.0), hourlyRatePercentage(5), Collections.emptyList())), 10 ), SelfJobDisruptionBudgetResolver.getInstance(), UnhealthyTasksLimitTracker.class ); testBuildQuotaTrackers( scheduleJob( newBatchJob(10, budget(percentageOfHealthyPolicy(80.0), hourlyRatePercentage(5), singletonList(officeHourTimeWindow()))), 10 ), SelfJobDisruptionBudgetResolver.getInstance(), UnhealthyTasksLimitTracker.class, TimeWindowQuotaTracker.class ); testBuildQuotaTrackers( scheduleJob( newBatchJob(10, budget(numberOfHealthyPolicy(2), hourlyRatePercentage(5), singletonList(officeHourTimeWindow()))), 10 ), SelfJobDisruptionBudgetResolver.getInstance(), UnhealthyTasksLimitTracker.class, TimeWindowQuotaTracker.class ); testBuildQuotaTrackers( scheduleJob( newBatchJob(10, budget(selfManagedPolicy(10_000), unlimitedRate(), Collections.emptyList())), 10 ), job -> budget(perTaskRelocationLimitPolicy(100), hourlyRatePercentage(5), singletonList(officeHourTimeWindow())), TimeWindowQuotaTracker.class ); }
@VisibleForTesting static List<QuotaTracker> buildQuotaTrackers(Job<?> job, V3JobOperations jobOperations, EffectiveJobDisruptionBudgetResolver effectiveDisruptionBudgetResolver, ContainerHealthService containerHealthService, TitusRuntime titusRuntime) { List<QuotaTracker> quotaTrackers = new ArrayList<>(); DisruptionBudget effectiveBudget = effectiveDisruptionBudgetResolver.resolve(job); if (!effectiveBudget.getTimeWindows().isEmpty()) { quotaTrackers.add(new TimeWindowQuotaTracker(effectiveBudget.getTimeWindows(), titusRuntime)); } DisruptionBudgetPolicy policy = effectiveBudget.getDisruptionBudgetPolicy(); if (policy instanceof AvailabilityPercentageLimitDisruptionBudgetPolicy) { quotaTrackers.add(UnhealthyTasksLimitTracker.percentageLimit(job, (AvailabilityPercentageLimitDisruptionBudgetPolicy) policy, jobOperations, containerHealthService)); } else if (policy instanceof UnhealthyTasksLimitDisruptionBudgetPolicy) { quotaTrackers.add(UnhealthyTasksLimitTracker.absoluteLimit(job, (UnhealthyTasksLimitDisruptionBudgetPolicy) policy, jobOperations, containerHealthService)); } return quotaTrackers; }
JobQuotaController implements QuotaController<Job<?>> { @VisibleForTesting static List<QuotaTracker> buildQuotaTrackers(Job<?> job, V3JobOperations jobOperations, EffectiveJobDisruptionBudgetResolver effectiveDisruptionBudgetResolver, ContainerHealthService containerHealthService, TitusRuntime titusRuntime) { List<QuotaTracker> quotaTrackers = new ArrayList<>(); DisruptionBudget effectiveBudget = effectiveDisruptionBudgetResolver.resolve(job); if (!effectiveBudget.getTimeWindows().isEmpty()) { quotaTrackers.add(new TimeWindowQuotaTracker(effectiveBudget.getTimeWindows(), titusRuntime)); } DisruptionBudgetPolicy policy = effectiveBudget.getDisruptionBudgetPolicy(); if (policy instanceof AvailabilityPercentageLimitDisruptionBudgetPolicy) { quotaTrackers.add(UnhealthyTasksLimitTracker.percentageLimit(job, (AvailabilityPercentageLimitDisruptionBudgetPolicy) policy, jobOperations, containerHealthService)); } else if (policy instanceof UnhealthyTasksLimitDisruptionBudgetPolicy) { quotaTrackers.add(UnhealthyTasksLimitTracker.absoluteLimit(job, (UnhealthyTasksLimitDisruptionBudgetPolicy) policy, jobOperations, containerHealthService)); } return quotaTrackers; } }
JobQuotaController implements QuotaController<Job<?>> { @VisibleForTesting static List<QuotaTracker> buildQuotaTrackers(Job<?> job, V3JobOperations jobOperations, EffectiveJobDisruptionBudgetResolver effectiveDisruptionBudgetResolver, ContainerHealthService containerHealthService, TitusRuntime titusRuntime) { List<QuotaTracker> quotaTrackers = new ArrayList<>(); DisruptionBudget effectiveBudget = effectiveDisruptionBudgetResolver.resolve(job); if (!effectiveBudget.getTimeWindows().isEmpty()) { quotaTrackers.add(new TimeWindowQuotaTracker(effectiveBudget.getTimeWindows(), titusRuntime)); } DisruptionBudgetPolicy policy = effectiveBudget.getDisruptionBudgetPolicy(); if (policy instanceof AvailabilityPercentageLimitDisruptionBudgetPolicy) { quotaTrackers.add(UnhealthyTasksLimitTracker.percentageLimit(job, (AvailabilityPercentageLimitDisruptionBudgetPolicy) policy, jobOperations, containerHealthService)); } else if (policy instanceof UnhealthyTasksLimitDisruptionBudgetPolicy) { quotaTrackers.add(UnhealthyTasksLimitTracker.absoluteLimit(job, (UnhealthyTasksLimitDisruptionBudgetPolicy) policy, jobOperations, containerHealthService)); } return quotaTrackers; } 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<QuotaTracker> buildQuotaTrackers(Job<?> job, V3JobOperations jobOperations, EffectiveJobDisruptionBudgetResolver effectiveDisruptionBudgetResolver, ContainerHealthService containerHealthService, TitusRuntime titusRuntime) { List<QuotaTracker> quotaTrackers = new ArrayList<>(); DisruptionBudget effectiveBudget = effectiveDisruptionBudgetResolver.resolve(job); if (!effectiveBudget.getTimeWindows().isEmpty()) { quotaTrackers.add(new TimeWindowQuotaTracker(effectiveBudget.getTimeWindows(), titusRuntime)); } DisruptionBudgetPolicy policy = effectiveBudget.getDisruptionBudgetPolicy(); if (policy instanceof AvailabilityPercentageLimitDisruptionBudgetPolicy) { quotaTrackers.add(UnhealthyTasksLimitTracker.percentageLimit(job, (AvailabilityPercentageLimitDisruptionBudgetPolicy) policy, jobOperations, containerHealthService)); } else if (policy instanceof UnhealthyTasksLimitDisruptionBudgetPolicy) { quotaTrackers.add(UnhealthyTasksLimitTracker.absoluteLimit(job, (UnhealthyTasksLimitDisruptionBudgetPolicy) policy, jobOperations, containerHealthService)); } return quotaTrackers; } 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<QuotaTracker> buildQuotaTrackers(Job<?> job, V3JobOperations jobOperations, EffectiveJobDisruptionBudgetResolver effectiveDisruptionBudgetResolver, ContainerHealthService containerHealthService, TitusRuntime titusRuntime) { List<QuotaTracker> quotaTrackers = new ArrayList<>(); DisruptionBudget effectiveBudget = effectiveDisruptionBudgetResolver.resolve(job); if (!effectiveBudget.getTimeWindows().isEmpty()) { quotaTrackers.add(new TimeWindowQuotaTracker(effectiveBudget.getTimeWindows(), titusRuntime)); } DisruptionBudgetPolicy policy = effectiveBudget.getDisruptionBudgetPolicy(); if (policy instanceof AvailabilityPercentageLimitDisruptionBudgetPolicy) { quotaTrackers.add(UnhealthyTasksLimitTracker.percentageLimit(job, (AvailabilityPercentageLimitDisruptionBudgetPolicy) policy, jobOperations, containerHealthService)); } else if (policy instanceof UnhealthyTasksLimitDisruptionBudgetPolicy) { quotaTrackers.add(UnhealthyTasksLimitTracker.absoluteLimit(job, (UnhealthyTasksLimitDisruptionBudgetPolicy) policy, jobOperations, containerHealthService)); } return quotaTrackers; } 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);  }