use of com.netflix.titus.api.eviction.model.EvictionQuota in project titus-control-plane by Netflix.
the class JobQuotaController method getMinSubQuota.
private EvictionQuota getMinSubQuota(Reference reference) {
EvictionQuota minTrackers = getMinSubQuota(quotaTrackers, reference);
EvictionQuota minControllers = getMinSubQuota(quotaControllers, reference);
return minTrackers.getQuota() <= minControllers.getQuota() ? minTrackers : minControllers;
}
use of com.netflix.titus.api.eviction.model.EvictionQuota 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.eviction.model.EvictionQuota in project titus-control-plane by Netflix.
the class TaskRelocationLimitController method getTaskQuota.
private EvictionQuota getTaskQuota(Reference taskReference) {
String taskId = taskReference.getName();
EvictionQuota.Builder quotaBuilder = EvictionQuota.newBuilder().withReference(taskReference);
Optional<Pair<Job<?>, Task>> jobTaskOpt = jobOperations.findTaskById(taskId);
if (!jobTaskOpt.isPresent()) {
return quotaBuilder.withQuota(0).withMessage("Task not found").build();
}
Task task = jobTaskOpt.get().getRight();
int counter = task.getEvictionResubmitNumber();
if (counter < perTaskLimit) {
return quotaBuilder.withQuota(1).withMessage("Per task limit is %s, and restart count is %s", perTaskLimit, counter).build();
}
return quotaBuilder.withQuota(0).withMessage(taskLimitExceeded.getRejectionReason().get()).build();
}
use of com.netflix.titus.api.eviction.model.EvictionQuota in project titus-control-plane by Netflix.
the class TaskRelocationLimitController method getJobQuota.
private EvictionQuota getJobQuota(Reference jobReference) {
EvictionQuota.Builder quotaBuilder = EvictionQuota.newBuilder().withReference(jobReference);
List<Task> tasks;
try {
tasks = jobOperations.getTasks(job.getId());
} catch (JobManagerException e) {
return quotaBuilder.withQuota(0).withMessage("Internal error: %s", e.getMessage()).build();
}
int quota = 0;
for (Task task : tasks) {
if (task.getEvictionResubmitNumber() < perTaskLimit) {
quota++;
}
}
return quota > 0 ? quotaBuilder.withQuota(quota).withMessage("Per task limit is %s", perTaskLimit).build() : quotaBuilder.withQuota(0).withMessage("Each task of the job reached its maximum eviction limit %s", perTaskLimit).build();
}
Aggregations