Search in sources :

Example 6 with SingularityShellCommand

use of com.hubspot.singularity.SingularityShellCommand 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 7 with SingularityShellCommand

use of com.hubspot.singularity.SingularityShellCommand 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

SingularityShellCommand (com.hubspot.singularity.SingularityShellCommand)7 SingularityRequestCleanup (com.hubspot.singularity.SingularityRequestCleanup)5 Test (org.junit.Test)4 ByteString (com.google.protobuf.ByteString)2 SingularityRequestWithState (com.hubspot.singularity.SingularityRequestWithState)2 SingularityTask (com.hubspot.singularity.SingularityTask)2 SingularityTaskShellCommandRequestId (com.hubspot.singularity.SingularityTaskShellCommandRequestId)2 SingularityTaskShellCommandUpdate (com.hubspot.singularity.SingularityTaskShellCommandUpdate)2 SingularityBounceRequest (com.hubspot.singularity.api.SingularityBounceRequest)2 SingularityCreateResult (com.hubspot.singularity.SingularityCreateResult)1 SingularityRequest (com.hubspot.singularity.SingularityRequest)1 SingularityTaskCleanup (com.hubspot.singularity.SingularityTaskCleanup)1 SingularityTaskHealthcheckResult (com.hubspot.singularity.SingularityTaskHealthcheckResult)1 SingularityTaskId (com.hubspot.singularity.SingularityTaskId)1 SingularityTaskShellCommandRequest (com.hubspot.singularity.SingularityTaskShellCommandRequest)1 SingularityExpiringBounce (com.hubspot.singularity.expiring.SingularityExpiringBounce)1 SingularityExpiringPause (com.hubspot.singularity.expiring.SingularityExpiringPause)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 WebApplicationException (javax.ws.rs.WebApplicationException)1