use of com.hubspot.singularity.SingularityTaskShellCommandRequestId in project Singularity by HubSpot.
the class SingularityPriorityKillPoller method runActionOnPoll.
@Override
public void runActionOnPoll() {
if (!priorityManager.checkPriorityKillExists()) {
LOG.trace("No priority freeze to process.");
return;
}
final Optional<SingularityPriorityFreezeParent> maybePriorityFreeze = priorityManager.getActivePriorityFreeze();
if (!maybePriorityFreeze.isPresent() || !maybePriorityFreeze.get().getPriorityFreeze().isKillTasks()) {
LOG.trace("Priority freeze does not exist.");
priorityManager.clearPriorityKill();
return;
}
LOG.info("Handling priority freeze {}", maybePriorityFreeze.get());
final long now = System.currentTimeMillis();
int cancelledPendingTaskCount = 0;
int killedTaskCount = 0;
try {
final double minPriorityLevel = maybePriorityFreeze.get().getPriorityFreeze().getMinimumPriorityLevel();
// map request ID to priority level
final Map<String, Double> requestIdToTaskPriority = new HashMap<>();
for (SingularityRequestWithState requestWithState : requestManager.getRequests()) {
requestIdToTaskPriority.put(requestWithState.getRequest().getId(), priorityManager.getTaskPriorityLevelForRequest(requestWithState.getRequest()));
}
// kill active tasks below minimum priority level
for (SingularityTaskId taskId : taskManager.getActiveTaskIds()) {
if (!requestIdToTaskPriority.containsKey(taskId.getRequestId())) {
LOG.trace("Unable to lookup priority level for task {}, skipping...", taskId);
continue;
}
final double taskPriorityLevel = requestIdToTaskPriority.get(taskId.getRequestId());
if (taskPriorityLevel < minPriorityLevel) {
LOG.info("Killing active task {} since priority level {} is less than {}", taskId.getId(), taskPriorityLevel, minPriorityLevel);
taskManager.createTaskCleanup(new SingularityTaskCleanup(maybePriorityFreeze.get().getUser(), TaskCleanupType.PRIORITY_KILL, now, taskId, maybePriorityFreeze.get().getPriorityFreeze().getMessage(), maybePriorityFreeze.get().getPriorityFreeze().getActionId(), Optional.<SingularityTaskShellCommandRequestId>empty()));
killedTaskCount++;
}
}
} finally {
priorityManager.clearPriorityKill();
LOG.info("Finished killing active tasks for priority freeze {} in {} for {} active tasks, {} pending tasks", maybePriorityFreeze, JavaUtils.duration(now), killedTaskCount, cancelledPendingTaskCount);
}
}
Aggregations