use of com.hubspot.singularity.SingularityPriorityFreezeParent in project Singularity by HubSpot.
the class SingularityMesosTaskPrioritizer method removeTasksAffectedByPriorityFreeze.
public void removeTasksAffectedByPriorityFreeze(List<SingularityTaskRequest> taskRequests) {
final Optional<SingularityPriorityFreezeParent> maybePriorityFreeze = priorityManager.getActivePriorityFreeze();
if (maybePriorityFreeze.isPresent()) {
final ListIterator<SingularityTaskRequest> iterator = taskRequests.listIterator();
while (iterator.hasNext()) {
final SingularityTaskRequest taskRequest = iterator.next();
final double taskPriorityLevel = priorityManager.getTaskPriorityLevelForRequest(taskRequest.getRequest());
if (taskPriorityLevel < maybePriorityFreeze.get().getPriorityFreeze().getMinimumPriorityLevel()) {
LOG.trace("Skipping scheduled task {} because taskPriorityLevel ({}) is less than active priority freeze ({})", taskRequest.getPendingTask().getPendingTaskId(), taskPriorityLevel, maybePriorityFreeze.get().getPriorityFreeze().getMinimumPriorityLevel());
iterator.remove();
}
}
}
}
use of com.hubspot.singularity.SingularityPriorityFreezeParent in project Singularity by HubSpot.
the class PriorityResource method createPriorityFreeze.
@POST
@Path("/freeze")
@ApiOperation(value = "Stop scheduling tasks below a certain priority level.", response = SingularityPriorityFreezeParent.class)
@ApiResponses({ @ApiResponse(code = 200, message = "The priority freeze request was accepted."), @ApiResponse(code = 400, message = "There was a validation error with the priority freeze request.") })
public SingularityPriorityFreezeParent createPriorityFreeze(@Auth SingularityUser user, SingularityPriorityFreeze priorityFreezeRequest) {
authorizationHelper.checkAdminAuthorization(user);
priorityFreezeRequest = singularityValidator.checkSingularityPriorityFreeze(priorityFreezeRequest);
final SingularityPriorityFreezeParent priorityFreezeRequestParent = new SingularityPriorityFreezeParent(priorityFreezeRequest, System.currentTimeMillis(), user.getEmail());
priorityManager.createPriorityFreeze(priorityFreezeRequestParent);
if (priorityFreezeRequest.isKillTasks()) {
priorityManager.setPriorityKill();
}
return priorityFreezeRequestParent;
}
use of com.hubspot.singularity.SingularityPriorityFreezeParent 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>absent()));
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);
}
}
use of com.hubspot.singularity.SingularityPriorityFreezeParent in project Singularity by HubSpot.
the class SingularitySchedulerTest method testPriorityFreezeDoesntLaunchTasks.
@Test
public void testPriorityFreezeDoesntLaunchTasks() {
// deploy lowPriorityRequest (affected by priority freeze)
final SingularityRequest lowPriorityRequest = new SingularityRequestBuilder("lowPriorityRequest", RequestType.ON_DEMAND).setTaskPriorityLevel(Optional.of(.25)).build();
saveRequest(lowPriorityRequest);
deployResource.deploy(new SingularityDeployRequest(new SingularityDeployBuilder(lowPriorityRequest.getId(), "d1").setCommand(Optional.of("cmd")).build(), Optional.absent(), Optional.absent()), singularityUser);
// deploy medium priority request (NOT affected by priority freeze)
final SingularityRequest mediumPriorityRequest = new SingularityRequestBuilder("mediumPriorityRequest", RequestType.ON_DEMAND).setTaskPriorityLevel(Optional.of(.5)).build();
saveRequest(mediumPriorityRequest);
deployResource.deploy(new SingularityDeployRequest(new SingularityDeployBuilder(mediumPriorityRequest.getId(), "d2").setCommand(Optional.of("cmd")).build(), Optional.absent(), Optional.absent()), singularityUser);
// create priority freeze
priorityManager.createPriorityFreeze(new SingularityPriorityFreezeParent(new SingularityPriorityFreeze(0.3, true, Optional.<String>absent(), Optional.<String>absent()), System.currentTimeMillis(), Optional.<String>absent()));
// launch both tasks
requestResource.scheduleImmediately(singularityUser, lowPriorityRequest.getId());
requestResource.scheduleImmediately(singularityUser, mediumPriorityRequest.getId());
// drain pending queue
scheduler.drainPendingQueue();
resourceOffers();
// assert that lowPriorityRequest has a pending task
Assert.assertEquals(1, taskManager.getPendingTaskIds().size());
Assert.assertEquals(lowPriorityRequest.getId(), taskManager.getPendingTaskIds().get(0).getRequestId());
// assert that only mediumPriorityRequest has an active task
Assert.assertEquals(0, taskManager.getActiveTaskIdsForRequest(lowPriorityRequest.getId()).size());
Assert.assertEquals(1, taskManager.getActiveTaskIdsForRequest(mediumPriorityRequest.getId()).size());
// delete priority freeze
Assert.assertEquals(SingularityDeleteResult.DELETED, priorityManager.deleteActivePriorityFreeze());
// drain pending
scheduler.drainPendingQueue();
resourceOffers();
// check that both requests have active tasks
Assert.assertEquals(1, taskManager.getActiveTaskIdsForRequest(lowPriorityRequest.getId()).size());
Assert.assertEquals(1, taskManager.getActiveTaskIdsForRequest(mediumPriorityRequest.getId()).size());
}
Aggregations