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();
}
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);
}
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);
}
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);
}
Aggregations