throw WebExceptions.badRequest("DeployRequest must have a deploy object with a non-null requestId");
}
final String requestId = deployRequest.getDeploy().getRequestId();
SingularityRequestWithState requestWithState = fetchRequestWithState(requestId);
SingularityRequest request = requestWithState.getRequest();
if (!deployRequest.getUnpauseOnSuccessfulDeploy().isPresent() || !deployRequest.getUnpauseOnSuccessfulDeploy().get().booleanValue()) {
checkRequestStateNotPaused(requestWithState, "deploy");
}
validator.checkDeploy(request, deployRequest.getDeploy());
SingularityDeployMarker deployMarker = new SingularityDeployMarker(requestId, deployRequest.getDeploy().getId(), System.currentTimeMillis(), deployRequest.getUser());
SingularityPendingDeploy pendingDeployObj = new SingularityPendingDeploy(deployMarker, Optional.<SingularityLoadBalancerUpdate> absent(), DeployState.WAITING);
if (deployManager.createPendingDeploy(pendingDeployObj) == SingularityCreateResult.EXISTED) {
throw WebExceptions.conflict("Pending deploy already in progress for %s - cancel it or wait for it to complete (%s)", requestId, deployManager.getPendingDeploy(requestId).orNull());
}
deployManager.saveDeploy(request, deployMarker, deployRequest.getDeploy());
if (requestWithState.getState() == RequestState.PAUSED) {
requestManager.deployToUnpause(request, deployRequest.getUser());
}
if (request.isDeployable()) {
requestManager.addToPendingQueue(new SingularityPendingRequest(requestId, deployMarker.getDeployId(), System.currentTimeMillis(), Optional.<String> absent(), deployRequest.getUser(), PendingType.NEW_DEPLOY));