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();
}
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;
}
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);
}
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()));
}
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());
}
Aggregations