Search in sources :

Example 1 with QuotaTracker

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

the class JobQuotaController method consume.

@Override
public ConsumptionResult consume(String taskId) {
    if (isLegacy()) {
        return LEGACY;
    }
    Reference taskReference = Reference.task(taskId);
    StringBuilder rejectionResponseBuilder = new StringBuilder("MissingQuotas[");
    // Check quota trackers first
    boolean noQuota = false;
    for (QuotaTracker tracker : quotaTrackers) {
        EvictionQuota quotaStatus = tracker.getQuota(taskReference);
        if (quotaStatus.getQuota() <= 0) {
            noQuota = true;
            rejectionResponseBuilder.append(tracker.getClass().getSimpleName()).append('=').append(quotaStatus.getMessage()).append(", ");
        }
    }
    if (noQuota) {
        rejectionResponseBuilder.setLength(rejectionResponseBuilder.length() - 2);
        return ConsumptionResult.rejected(rejectionResponseBuilder.append(']').toString());
    }
    // Now controllers
    for (int i = 0; i < quotaControllers.size(); i++) {
        QuotaController<Job<?>> controller = quotaControllers.get(i);
        ConsumptionResult result = controller.consume(taskId);
        if (!result.isApproved()) {
            for (int j = 0; j < i; j++) {
                quotaControllers.get(j).giveBackConsumedQuota(taskId);
            }
            rejectionResponseBuilder.append(controller.getClass().getSimpleName()).append('=').append(result.getRejectionReason().orElse("no quota"));
            return ConsumptionResult.rejected(rejectionResponseBuilder.append(']').toString());
        }
    }
    return ConsumptionResult.approved();
}
Also used : TimeWindowQuotaTracker(com.netflix.titus.master.eviction.service.quota.TimeWindowQuotaTracker) QuotaTracker(com.netflix.titus.master.eviction.service.quota.QuotaTracker) EvictionQuota(com.netflix.titus.api.eviction.model.EvictionQuota) ConsumptionResult(com.netflix.titus.master.eviction.service.quota.ConsumptionResult) Reference(com.netflix.titus.api.model.reference.Reference) Job(com.netflix.titus.api.jobmanager.model.job.Job)

Example 2 with QuotaTracker

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

the class JobQuotaController method buildQuotaTrackers.

@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;
}
Also used : TimeWindowQuotaTracker(com.netflix.titus.master.eviction.service.quota.TimeWindowQuotaTracker) QuotaTracker(com.netflix.titus.master.eviction.service.quota.QuotaTracker) 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) DisruptionBudget(com.netflix.titus.api.jobmanager.model.job.disruptionbudget.DisruptionBudget) ArrayList(java.util.ArrayList) TimeWindowQuotaTracker(com.netflix.titus.master.eviction.service.quota.TimeWindowQuotaTracker) UnhealthyTasksLimitDisruptionBudgetPolicy(com.netflix.titus.api.jobmanager.model.job.disruptionbudget.UnhealthyTasksLimitDisruptionBudgetPolicy) AvailabilityPercentageLimitDisruptionBudgetPolicy(com.netflix.titus.api.jobmanager.model.job.disruptionbudget.AvailabilityPercentageLimitDisruptionBudgetPolicy) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Aggregations

QuotaTracker (com.netflix.titus.master.eviction.service.quota.QuotaTracker)2 TimeWindowQuotaTracker (com.netflix.titus.master.eviction.service.quota.TimeWindowQuotaTracker)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 EvictionQuota (com.netflix.titus.api.eviction.model.EvictionQuota)1 Job (com.netflix.titus.api.jobmanager.model.job.Job)1 AvailabilityPercentageLimitDisruptionBudgetPolicy (com.netflix.titus.api.jobmanager.model.job.disruptionbudget.AvailabilityPercentageLimitDisruptionBudgetPolicy)1 DisruptionBudget (com.netflix.titus.api.jobmanager.model.job.disruptionbudget.DisruptionBudget)1 DisruptionBudgetPolicy (com.netflix.titus.api.jobmanager.model.job.disruptionbudget.DisruptionBudgetPolicy)1 RelocationLimitDisruptionBudgetPolicy (com.netflix.titus.api.jobmanager.model.job.disruptionbudget.RelocationLimitDisruptionBudgetPolicy)1 UnhealthyTasksLimitDisruptionBudgetPolicy (com.netflix.titus.api.jobmanager.model.job.disruptionbudget.UnhealthyTasksLimitDisruptionBudgetPolicy)1 Reference (com.netflix.titus.api.model.reference.Reference)1 ConsumptionResult (com.netflix.titus.master.eviction.service.quota.ConsumptionResult)1 ArrayList (java.util.ArrayList)1