Search in sources :

Example 46 with SingularityPendingRequest

use of com.hubspot.singularity.SingularityPendingRequest in project Singularity by HubSpot.

the class SingularityUsageTest method scheduleTask.

protected void scheduleTask(String rqid, double requiredCpus, double requiredMemoryMb, int instances) {
    Resources rs = new Resources(requiredCpus, requiredMemoryMb, 0);
    SingularityRequest rq = new SingularityRequestBuilder(rqid, RequestType.WORKER).setInstances(Optional.of(instances)).build();
    SingularityDeploy dp = new SingularityDeployBuilder(rq.getId(), "deployId1").setCommand(Optional.of("sleep 100")).setResources(Optional.of(rs)).build();
    SingularityDeployMarker marker = new SingularityDeployMarker(dp.getRequestId(), dp.getId(), System.currentTimeMillis(), Optional.empty(), Optional.empty());
    SingularityPendingRequest pending = new SingularityPendingRequest(rq.getId(), dp.getId(), System.currentTimeMillis(), Optional.empty(), SingularityPendingRequest.PendingType.UPDATED_REQUEST, Optional.empty(), Optional.empty());
    saveRequest(rq);
    deployManager.saveDeploy(rq, marker, dp);
    deployManager.deletePendingDeploy(marker.getRequestId());
    deployManager.saveDeployResult(marker, Optional.of(dp), new SingularityDeployResult(DeployState.SUCCEEDED));
    deployManager.saveNewRequestDeployState(new SingularityRequestDeployState(marker.getRequestId(), Optional.of(marker), Optional.empty()));
    requestManager.addToPendingQueue(pending);
    scheduler.drainPendingQueue();
}
Also used : SingularityRequestBuilder(com.hubspot.singularity.SingularityRequestBuilder) SingularityPendingRequest(com.hubspot.singularity.SingularityPendingRequest) SingularityDeployMarker(com.hubspot.singularity.SingularityDeployMarker) SingularityDeployResult(com.hubspot.singularity.SingularityDeployResult) SingularityRequest(com.hubspot.singularity.SingularityRequest) SingularityDeployBuilder(com.hubspot.singularity.SingularityDeployBuilder) Resources(com.hubspot.mesos.Resources) SingularityRequestDeployState(com.hubspot.singularity.SingularityRequestDeployState) SingularityDeploy(com.hubspot.singularity.SingularityDeploy)

Example 47 with SingularityPendingRequest

use of com.hubspot.singularity.SingularityPendingRequest in project Singularity by HubSpot.

the class RequestManager method addToPendingQueue.

public SingularityCreateResult addToPendingQueue(SingularityPendingRequest pendingRequest) {
    SingularityCreateResult result = create(getPendingPath(pendingRequest), pendingRequest, pendingRequestTranscoder);
    if (result == SingularityCreateResult.EXISTED) {
        Optional<SingularityPendingRequest> existingPendingRequest = getPendingRequest(pendingRequest.getRequestId(), pendingRequest.getDeployId());
        if (!existingPendingRequest.isPresent() || (existingPendingRequest.get().getPendingType() == PendingType.STARTUP)) {
            // Fresh pending requests take priority over STARTUP-type pending requests (or if the pending request we originally found is gone, we'll go ahead and do the write now)
            set(getPendingPath(pendingRequest), pendingRequest, pendingRequestTranscoder);
            LOG.info("{} added to pending queue, overwriting an existing SingularityPendingRequest of type STARTUP. Previous pending request was {}", existingPendingRequest, result);
            return result;
        }
    }
    LOG.info("{} added to pending queue with result: {}", pendingRequest, result);
    return result;
}
Also used : SingularityPendingRequest(com.hubspot.singularity.SingularityPendingRequest) SingularityCreateResult(com.hubspot.singularity.SingularityCreateResult)

Example 48 with SingularityPendingRequest

use of com.hubspot.singularity.SingularityPendingRequest in project Singularity by HubSpot.

the class RequestResource method exitCooldown.

public SingularityRequestParent exitCooldown(String requestId, Optional<SingularityExitCooldownRequest> exitCooldownRequest, SingularityUser user) {
    final SingularityRequestWithState requestWithState = fetchRequestWithState(requestId, user);
    authorizationHelper.checkForAuthorization(requestWithState.getRequest(), user, SingularityAuthorizationScope.WRITE);
    checkConflict(requestWithState.getState() == RequestState.SYSTEM_COOLDOWN, "Request %s is not in SYSTEM_COOLDOWN state, it is in %s", requestId, requestWithState.getState());
    final Optional<String> maybeDeployId = deployManager.getInUseDeployId(requestId);
    final long now = System.currentTimeMillis();
    Optional<String> message = Optional.empty();
    Optional<Boolean> skipHealthchecks = Optional.empty();
    if (exitCooldownRequest.isPresent()) {
        message = exitCooldownRequest.get().getMessage();
        skipHealthchecks = exitCooldownRequest.get().getSkipHealthchecks();
    }
    requestManager.exitCooldown(requestWithState.getRequest(), now, Optional.of(user.getId()), message);
    if (maybeDeployId.isPresent() && !requestWithState.getRequest().isOneOff()) {
        requestManager.addToPendingQueue(new SingularityPendingRequest(requestId, maybeDeployId.get(), now, Optional.of(user.getId()), PendingType.IMMEDIATE, skipHealthchecks, message));
    }
    return fillEntireRequest(requestWithState);
}
Also used : SingularityPendingRequest(com.hubspot.singularity.SingularityPendingRequest) SingularityRequestWithState(com.hubspot.singularity.SingularityRequestWithState)

Example 49 with SingularityPendingRequest

use of com.hubspot.singularity.SingularityPendingRequest in project Singularity by HubSpot.

the class SingularityStartup method checkActiveRequest.

private void checkActiveRequest(SingularityRequestWithState requestWithState, Map<SingularityDeployKey, SingularityPendingTaskId> deployKeyToPendingTaskId, final long timestamp) {
    final SingularityRequest request = requestWithState.getRequest();
    if (request.getRequestType() == RequestType.ON_DEMAND || request.getRequestType() == RequestType.RUN_ONCE) {
        // There's no situation where we'd want to schedule an On Demand or Run Once request at startup, so don't even bother with them.
        return;
    }
    Optional<SingularityRequestDeployState> requestDeployState = deployManager.getRequestDeployState(request.getId());
    if (!requestDeployState.isPresent() || !requestDeployState.get().getActiveDeploy().isPresent()) {
        LOG.debug("No active deploy for {} - not scheduling on startup", request.getId());
        return;
    }
    final String activeDeployId = requestDeployState.get().getActiveDeploy().get().getDeployId();
    if (request.isScheduled()) {
        SingularityDeployKey deployKey = new SingularityDeployKey(request.getId(), activeDeployId);
        SingularityPendingTaskId pendingTaskId = deployKeyToPendingTaskId.get(deployKey);
        if (pendingTaskId != null && pendingTaskId.getCreatedAt() >= requestWithState.getTimestamp()) {
            LOG.info("Not rescheduling {} because {} is newer than {}", request.getId(), pendingTaskId, requestWithState.getTimestamp());
            return;
        }
    }
    requestManager.addToPendingQueue(new SingularityPendingRequest(request.getId(), activeDeployId, timestamp, Optional.<String>empty(), PendingType.STARTUP, Optional.<Boolean>empty(), Optional.<String>empty()));
}
Also used : SingularityDeployKey(com.hubspot.singularity.SingularityDeployKey) SingularityPendingRequest(com.hubspot.singularity.SingularityPendingRequest) SingularityRequest(com.hubspot.singularity.SingularityRequest) SingularityPendingTaskId(com.hubspot.singularity.SingularityPendingTaskId) SingularityRequestDeployState(com.hubspot.singularity.SingularityRequestDeployState)

Example 50 with SingularityPendingRequest

use of com.hubspot.singularity.SingularityPendingRequest in project Singularity by HubSpot.

the class ValidatorTest method whenRunNowIfRunIdSetItWillBePropagated.

@Test
public void whenRunNowIfRunIdSetItWillBePropagated() {
    String deployID = "deploy";
    Optional<String> userEmail = Optional.empty();
    SingularityRequest request = new SingularityRequestBuilder("request2", RequestType.ON_DEMAND).build();
    Optional<SingularityRunNowRequest> runNowRequest = Optional.of(runNowRequest("runId"));
    SingularityPendingRequest pendingRequest = validator.checkRunNowRequest(deployID, userEmail, request, runNowRequest, 0, 0);
    Assertions.assertEquals("runId", pendingRequest.getRunId().get());
}
Also used : SingularityRunNowRequest(com.hubspot.singularity.api.SingularityRunNowRequest) SingularityRequestBuilder(com.hubspot.singularity.SingularityRequestBuilder) SingularityPendingRequest(com.hubspot.singularity.SingularityPendingRequest) SingularityRequest(com.hubspot.singularity.SingularityRequest) Test(org.junit.jupiter.api.Test)

Aggregations

SingularityPendingRequest (com.hubspot.singularity.SingularityPendingRequest)53 Test (org.junit.jupiter.api.Test)18 SingularityRequest (com.hubspot.singularity.SingularityRequest)12 SingularityRequestWithState (com.hubspot.singularity.SingularityRequestWithState)11 SingularityTask (com.hubspot.singularity.SingularityTask)9 SingularityTaskId (com.hubspot.singularity.SingularityTaskId)9 SingularityCreateResult (com.hubspot.singularity.SingularityCreateResult)8 SingularityTaskCleanup (com.hubspot.singularity.SingularityTaskCleanup)8 SingularityRunNowRequest (com.hubspot.singularity.api.SingularityRunNowRequest)8 ArrayList (java.util.ArrayList)8 List (java.util.List)8 SingularityDeploy (com.hubspot.singularity.SingularityDeploy)7 SingularityPendingDeploy (com.hubspot.singularity.SingularityPendingDeploy)7 SingularityPendingTask (com.hubspot.singularity.SingularityPendingTask)7 SingularityRequestDeployState (com.hubspot.singularity.SingularityRequestDeployState)7 Resources (com.hubspot.mesos.Resources)6 SingularityDeployKey (com.hubspot.singularity.SingularityDeployKey)6 SingularityDeployProgress (com.hubspot.singularity.SingularityDeployProgress)6 PendingType (com.hubspot.singularity.SingularityPendingRequest.PendingType)6 SingularityRequestBuilder (com.hubspot.singularity.SingularityRequestBuilder)6