Search in sources :

Example 6 with SingularityRequestCleanup

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()));
    }
}
Also used : SingularityRequestCleanup(com.hubspot.singularity.SingularityRequestCleanup)

Example 7 with SingularityRequestCleanup

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);
}
Also used : SingularityRequestCleanup(com.hubspot.singularity.SingularityRequestCleanup) SingularityShellCommand(com.hubspot.singularity.SingularityShellCommand)

Example 8 with SingularityRequestCleanup

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));
}
Also used : SingularityRequestCleanup(com.hubspot.singularity.SingularityRequestCleanup) SingularityExpiringPause(com.hubspot.singularity.expiring.SingularityExpiringPause) SingularityShellCommand(com.hubspot.singularity.SingularityShellCommand) SingularityRequestWithState(com.hubspot.singularity.SingularityRequestWithState) SingularityCreateResult(com.hubspot.singularity.SingularityCreateResult)

Aggregations

SingularityRequestCleanup (com.hubspot.singularity.SingularityRequestCleanup)8 SingularityShellCommand (com.hubspot.singularity.SingularityShellCommand)5 SingularityCreateResult (com.hubspot.singularity.SingularityCreateResult)2 SingularityRequestWithState (com.hubspot.singularity.SingularityRequestWithState)2 SingularityBounceRequest (com.hubspot.singularity.api.SingularityBounceRequest)2 SingularityExpiringBounce (com.hubspot.singularity.expiring.SingularityExpiringBounce)2 Test (org.junit.Test)2 SingularityPendingRequest (com.hubspot.singularity.SingularityPendingRequest)1 SingularityRequest (com.hubspot.singularity.SingularityRequest)1 SingularityTask (com.hubspot.singularity.SingularityTask)1 SingularityTaskHealthcheckResult (com.hubspot.singularity.SingularityTaskHealthcheckResult)1 SingularityExpiringPause (com.hubspot.singularity.expiring.SingularityExpiringPause)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1