Search in sources :

Example 36 with SingularityRequestWithState

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

the class DeployResource method cancelDeploy.

@DELETE
@Path("/deploy/{deployId}/request/{requestId}")
@ApiOperation(value = "Cancel a pending deployment (best effort - the deploy may still succeed or fail)", response = SingularityRequestParent.class)
@ApiResponses({ @ApiResponse(code = 400, message = "Deploy is not in the pending state pending or is not not present") })
public SingularityRequestParent cancelDeploy(@Auth SingularityUser user, @ApiParam(required = true, value = "The Singularity Request Id from which the deployment is removed.") @PathParam("requestId") String requestId, @ApiParam(required = true, value = "The Singularity Deploy Id that should be removed.") @PathParam("deployId") String deployId) {
    SingularityRequestWithState requestWithState = fetchRequestWithState(requestId, user);
    authorizationHelper.checkForAuthorization(requestWithState.getRequest(), user, SingularityAuthorizationScope.WRITE);
    validator.checkActionEnabled(SingularityAction.CANCEL_DEPLOY);
    Optional<SingularityRequestDeployState> deployState = deployManager.getRequestDeployState(requestWithState.getRequest().getId());
    checkBadRequest(deployState.isPresent() && deployState.get().getPendingDeploy().isPresent() && deployState.get().getPendingDeploy().get().getDeployId().equals(deployId), "Request %s does not have a pending deploy %s", requestId, deployId);
    deployManager.createCancelDeployRequest(new SingularityDeployMarker(requestId, deployId, System.currentTimeMillis(), user.getEmail(), Optional.<String>absent()));
    return fillEntireRequest(requestWithState);
}
Also used : SingularityDeployMarker(com.hubspot.singularity.SingularityDeployMarker) SingularityRequestWithState(com.hubspot.singularity.SingularityRequestWithState) SingularityRequestDeployState(com.hubspot.singularity.SingularityRequestDeployState) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) ApiOperation(com.wordnik.swagger.annotations.ApiOperation) ApiResponses(com.wordnik.swagger.annotations.ApiResponses)

Example 37 with SingularityRequestWithState

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

the class SingularityStartup method enqueueHealthAndNewTaskChecks.

private void enqueueHealthAndNewTaskChecks() {
    final long start = System.currentTimeMillis();
    final List<SingularityTask> activeTasks = taskManager.getActiveTasks();
    final Map<SingularityTaskId, SingularityTask> activeTaskMap = Maps.uniqueIndex(activeTasks, SingularityTaskIdHolder.getTaskIdFunction());
    final Map<SingularityTaskId, List<SingularityTaskHistoryUpdate>> taskUpdates = taskManager.getTaskHistoryUpdates(activeTaskMap.keySet());
    final Map<SingularityDeployKey, SingularityPendingDeploy> pendingDeploys = Maps.uniqueIndex(deployManager.getPendingDeploys(), SingularityDeployKey.FROM_PENDING_TO_DEPLOY_KEY);
    final Map<String, SingularityRequestWithState> idToRequest = Maps.uniqueIndex(requestManager.getRequests(), SingularityRequestWithState.REQUEST_STATE_TO_REQUEST_ID);
    requestManager.getActiveRequests();
    int enqueuedNewTaskChecks = 0;
    int enqueuedHealthchecks = 0;
    for (Map.Entry<SingularityTaskId, SingularityTask> entry : activeTaskMap.entrySet()) {
        SingularityTaskId taskId = entry.getKey();
        SingularityTask task = entry.getValue();
        SimplifiedTaskState simplifiedTaskState = SingularityTaskHistoryUpdate.getCurrentState(taskUpdates.get(taskId));
        if (simplifiedTaskState != SimplifiedTaskState.DONE) {
            SingularityDeployKey deployKey = new SingularityDeployKey(taskId.getRequestId(), taskId.getDeployId());
            Optional<SingularityPendingDeploy> pendingDeploy = Optional.fromNullable(pendingDeploys.get(deployKey));
            Optional<SingularityRequestWithState> request = Optional.fromNullable(idToRequest.get(taskId.getRequestId()));
            if (!pendingDeploy.isPresent()) {
                newTaskChecker.enqueueNewTaskCheck(task, request, healthchecker);
                enqueuedNewTaskChecks++;
            }
            if (simplifiedTaskState == SimplifiedTaskState.RUNNING) {
                if (healthchecker.enqueueHealthcheck(task, pendingDeploy, request)) {
                    enqueuedHealthchecks++;
                }
            }
        }
    }
    LOG.info("Enqueued {} health checks and {} new task checks (out of {} active tasks) in {}", enqueuedHealthchecks, enqueuedNewTaskChecks, activeTasks.size(), JavaUtils.duration(start));
}
Also used : SingularityDeployKey(com.hubspot.singularity.SingularityDeployKey) SingularityTask(com.hubspot.singularity.SingularityTask) SingularityPendingDeploy(com.hubspot.singularity.SingularityPendingDeploy) SingularityRequestWithState(com.hubspot.singularity.SingularityRequestWithState) List(java.util.List) SimplifiedTaskState(com.hubspot.singularity.SingularityTaskHistoryUpdate.SimplifiedTaskState) SingularityTaskId(com.hubspot.singularity.SingularityTaskId) Map(java.util.Map)

Aggregations

SingularityRequestWithState (com.hubspot.singularity.SingularityRequestWithState)37 SingularityRequest (com.hubspot.singularity.SingularityRequest)16 SingularityTaskId (com.hubspot.singularity.SingularityTaskId)11 SingularityPendingDeploy (com.hubspot.singularity.SingularityPendingDeploy)9 SingularityPendingRequest (com.hubspot.singularity.SingularityPendingRequest)7 SingularityRequestDeployState (com.hubspot.singularity.SingularityRequestDeployState)7 ArrayList (java.util.ArrayList)7 SingularityDeploy (com.hubspot.singularity.SingularityDeploy)6 SingularityCreateResult (com.hubspot.singularity.SingularityCreateResult)5 SingularityDeployKey (com.hubspot.singularity.SingularityDeployKey)5 SingularityPendingTaskId (com.hubspot.singularity.SingularityPendingTaskId)5 ApiOperation (com.wordnik.swagger.annotations.ApiOperation)5 Path (javax.ws.rs.Path)5 RequestState (com.hubspot.singularity.RequestState)4 SingularityDeployMarker (com.hubspot.singularity.SingularityDeployMarker)4 SingularityRequestCleanup (com.hubspot.singularity.SingularityRequestCleanup)4 SingularityRequestHistory (com.hubspot.singularity.SingularityRequestHistory)4 SingularityBounceRequest (com.hubspot.singularity.api.SingularityBounceRequest)4 ApiResponses (com.wordnik.swagger.annotations.ApiResponses)4 List (java.util.List)4