Search in sources :

Example 1 with Reference

use of com.netflix.titus.api.model.reference.Reference 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 Reference

use of com.netflix.titus.api.model.reference.Reference 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);
}
Also used : Task(com.netflix.titus.api.jobmanager.model.job.Task) Reference(com.netflix.titus.api.model.reference.Reference) BatchJobExt(com.netflix.titus.api.jobmanager.model.job.ext.BatchJobExt) Test(org.junit.Test)

Example 3 with Reference

use of com.netflix.titus.api.model.reference.Reference in project titus-control-plane by Netflix.

the class TaskRelocationLimitControllerTest method testQuota.

@Test
public void testQuota() {
    Job<BatchJobExt> job = createBatchJob(2);
    Task task = jobOperations.getTasks(job.getId()).get(0);
    Reference jobReference = Reference.job(job.getId());
    Reference taskReference = Reference.task(task.getId());
    TaskRelocationLimitController quotaController = new TaskRelocationLimitController(job, jobOperations, SelfJobDisruptionBudgetResolver.getInstance());
    assertThat(quotaController.getQuota(jobReference).getQuota()).isEqualTo(10);
    assertThat(quotaController.getQuota(taskReference).getQuota()).isEqualTo(1);
    // Now consume quotas for the first task
    assertThat(quotaController.consume(task.getId()).isApproved()).isTrue();
    assertThat(quotaController.getQuota(taskReference).getQuota()).isEqualTo(1);
    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(quotaController.consume(replacement1.getId()).isApproved()).isTrue();
    assertThat(quotaController.getQuota(jobReference).getQuota()).isEqualTo(10);
    assertThat(quotaController.getQuota(taskReference).getQuota()).isEqualTo(0);
    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(quotaController.consume(replacement2.getId()).isApproved()).isFalse();
    assertThat(quotaController.getQuota(jobReference).getQuota()).isEqualTo(9);
}
Also used : Task(com.netflix.titus.api.jobmanager.model.job.Task) Reference(com.netflix.titus.api.model.reference.Reference) BatchJobExt(com.netflix.titus.api.jobmanager.model.job.ext.BatchJobExt) Test(org.junit.Test)

Example 4 with Reference

use of com.netflix.titus.api.model.reference.Reference in project titus-control-plane by Netflix.

the class UnhealthyTasksLimitTrackerTest method testPercentageBasedQuotaWithOneTaskJob.

@Test
public void testPercentageBasedQuotaWithOneTaskJob() {
    Job<BatchJobExt> job = newBatchJobWithPercentageLimit(1, 95);
    UnhealthyTasksLimitTracker tracker = UnhealthyTasksLimitTracker.percentageLimit(job, (AvailabilityPercentageLimitDisruptionBudgetPolicy) job.getJobDescriptor().getDisruptionBudget().getDisruptionBudgetPolicy(), jobOperations, jobComponentStub.getContainerHealthService());
    Reference jobReference = Reference.job(job.getId());
    // No tasks are started yet
    assertThat(tracker.getQuota(jobReference).getQuota()).isEqualTo(1);
    // Start task
    jobOperations.getTasks().forEach(task -> jobComponentStub.moveTaskToState(task, TaskState.Started));
    assertThat(tracker.getQuota(jobReference).getQuota()).isEqualTo(1);
    // Now make one unhealthy. As this is the only task in the job, it should be possible to move it
    jobComponentStub.changeContainerHealth(jobOperations.getTasks().get(0).getId(), ContainerHealthState.Unhealthy);
    assertThat(tracker.getQuota(jobReference).getQuota()).isEqualTo(1);
}
Also used : Reference(com.netflix.titus.api.model.reference.Reference) BatchJobExt(com.netflix.titus.api.jobmanager.model.job.ext.BatchJobExt) Test(org.junit.Test)

Aggregations

Reference (com.netflix.titus.api.model.reference.Reference)4 BatchJobExt (com.netflix.titus.api.jobmanager.model.job.ext.BatchJobExt)3 Test (org.junit.Test)3 Task (com.netflix.titus.api.jobmanager.model.job.Task)2 EvictionQuota (com.netflix.titus.api.eviction.model.EvictionQuota)1 Job (com.netflix.titus.api.jobmanager.model.job.Job)1 ConsumptionResult (com.netflix.titus.master.eviction.service.quota.ConsumptionResult)1 QuotaTracker (com.netflix.titus.master.eviction.service.quota.QuotaTracker)1 TimeWindowQuotaTracker (com.netflix.titus.master.eviction.service.quota.TimeWindowQuotaTracker)1