use of com.hubspot.singularity.SingularityRequestCleanup in project Singularity by HubSpot.
the class SingularityCleaner method cleanupRequestIfNoRemainingTasks.
private void cleanupRequestIfNoRemainingTasks(SingularityTaskCleanup cleanupTask, List<String> taskIdsForDeletedRequest, boolean isRequestDeleting) {
String requestId = cleanupTask.getTaskId().getRequestId();
taskIdsForDeletedRequest.remove(cleanupTask.getTaskId().getId());
if (taskIdsForDeletedRequest.isEmpty() && isRequestDeleting) {
LOG.warn("All tasks for requestId {} are now killed, re-enqueueing request cleanup", requestId);
requestManager.createCleanupRequest(new SingularityRequestCleanup(cleanupTask.getUser(), RequestCleanupType.DELETING, System.currentTimeMillis(), Optional.of(Boolean.TRUE), cleanupTask.getRemoveFromLoadBalancer(), requestId, Optional.absent(), Optional.absent(), cleanupTask.getMessage(), Optional.absent(), Optional.absent()));
}
}
use of com.hubspot.singularity.SingularityRequestCleanup in project Singularity by HubSpot.
the class RequestManager method startDeletingRequest.
public void startDeletingRequest(SingularityRequest request, Optional<Boolean> removeFromLoadBalancer, Optional<String> user, Optional<String> actionId, Optional<String> message) {
final long now = System.currentTimeMillis();
// delete it no matter if the delete request already exists.
createCleanupRequest(new SingularityRequestCleanup(user, RequestCleanupType.DELETING, now, Optional.of(Boolean.TRUE), removeFromLoadBalancer, request.getId(), Optional.<String>absent(), Optional.<Boolean>absent(), message, actionId, Optional.<SingularityShellCommand>absent()));
markDeleting(request, System.currentTimeMillis(), user, message);
LOG.info("Request {} enqueued for deletion by {} - {}", request.getId(), user, message);
}
use of com.hubspot.singularity.SingularityRequestCleanup in project Singularity by HubSpot.
the class RequestResource method pause.
public SingularityRequestParent pause(String requestId, Optional<SingularityPauseRequest> pauseRequest, SingularityUser user) {
SingularityRequestWithState requestWithState = fetchRequestWithState(requestId, user);
authorizationHelper.checkForAuthorization(requestWithState.getRequest(), user, SingularityAuthorizationScope.WRITE);
checkConflict(requestWithState.getState() != RequestState.PAUSED, "Request %s is paused. Unable to pause (it must be manually unpaused first)", requestWithState.getRequest().getId());
Optional<Boolean> killTasks = Optional.absent();
Optional<String> message = Optional.absent();
Optional<String> actionId = Optional.absent();
Optional<SingularityShellCommand> runBeforeKill = Optional.absent();
if (pauseRequest.isPresent()) {
killTasks = pauseRequest.get().getKillTasks();
message = pauseRequest.get().getMessage();
if (pauseRequest.get().getRunShellCommandBeforeKill().isPresent()) {
validator.checkValidShellCommand(pauseRequest.get().getRunShellCommandBeforeKill().get());
runBeforeKill = pauseRequest.get().getRunShellCommandBeforeKill();
}
if (pauseRequest.get().getDurationMillis().isPresent() && !actionId.isPresent()) {
actionId = Optional.of(UUID.randomUUID().toString());
}
}
final long now = System.currentTimeMillis();
Optional<Boolean> removeFromLoadBalancer = Optional.absent();
SingularityCreateResult result = requestManager.createCleanupRequest(new SingularityRequestCleanup(user.getEmail(), RequestCleanupType.PAUSING, now, killTasks, removeFromLoadBalancer, requestId, Optional.<String>absent(), Optional.<Boolean>absent(), message, actionId, runBeforeKill));
checkConflict(result == SingularityCreateResult.CREATED, "%s is already pausing - try again soon", requestId, result);
mailer.sendRequestPausedMail(requestWithState.getRequest(), pauseRequest, user.getEmail());
requestManager.pause(requestWithState.getRequest(), now, user.getEmail(), message);
if (pauseRequest.isPresent() && pauseRequest.get().getDurationMillis().isPresent()) {
requestManager.saveExpiringObject(new SingularityExpiringPause(requestId, user.getEmail(), System.currentTimeMillis(), pauseRequest.get(), actionId.get()));
}
return fillEntireRequest(new SingularityRequestWithState(requestWithState.getRequest(), RequestState.PAUSED, now));
}
Aggregations