Package com.hubspot.singularity

Examples of com.hubspot.singularity.SingularityRequestWithState


      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));
View Full Code Here


  })
  public SingularityRequestParent cancelDeploy(
      @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,
      @ApiParam(required=false, value="The user which executes the delete request.") @QueryParam("user") Optional<String> user) {
    SingularityRequestWithState requestWithState = fetchRequestWithState(requestId);

    Optional<SingularityRequestDeployState> deployState = deployManager.getRequestDeployState(requestWithState.getRequest().getId());

    if (!deployState.isPresent() || !deployState.get().getPendingDeploy().isPresent() || !deployState.get().getPendingDeploy().get().getDeployId().equals(deployId)) {
      throw WebExceptions.badRequest("Request %s does not have a pending deploy %s", requestId, deployId);
    }
View Full Code Here

  }

  private SingularityCreateResult save(SingularityRequest request, RequestState state, RequestHistoryType eventType, Optional<String> user) {
    saveHistory(new SingularityRequestHistory(System.currentTimeMillis(), user, eventType, request));

    return save(getRequestPath(request.getId()), new SingularityRequestWithState(request, state), requestTranscoder);
  }
View Full Code Here

  @POST
  @Path("/request/{requestId}/bounce")
  @ApiOperation("Bounce a specific Singularity request. A bounce launches replacement task(s), and then kills the original task(s) if the replacement(s) are healthy.")
  public SingularityRequestParent bounce(@ApiParam("The request ID to bounce") @PathParam("requestId") String requestId,
                                         @ApiParam("Username of the person requesting the bounce") @QueryParam("user") Optional<String> user) {
    SingularityRequestWithState requestWithState = fetchRequestWithState(requestId);

    if (!requestWithState.getRequest().isLongRunning()) {
      throw WebExceptions.badRequest("Can not bounce a scheduled or one-off request (%s)", requestWithState);
    }

    checkRequestStateNotPaused(requestWithState, "bounce");
View Full Code Here

  @Path("/request/{requestId}/run")
  @ApiOperation("Schedule a Singularity request for immediate execution.")
  public SingularityRequestParent scheduleImmediately(@ApiParam("The request ID to run.") @PathParam("requestId") String requestId,
                                                      @ApiParam("Username of the person requesting the execution") @QueryParam("user") Optional<String> user,
                                                      @ApiParam("Additional command line arguments to append to the task") String commandLineArgs) {
    SingularityRequestWithState requestWithState = fetchRequestWithState(requestId);

    checkRequestStateNotPaused(requestWithState, "run now");

    Optional<String> maybeCmdLineArgs = Optional.absent();

    PendingType pendingType = null;

    if (requestWithState.getRequest().isScheduled()) {
      pendingType = PendingType.IMMEDIATE;
    } else if (requestWithState.getRequest().isOneOff()) {
      pendingType = PendingType.ONEOFF;
    } else {
      throw WebExceptions.badRequest("Can not request an immediate run of a non-scheduled / always running request (%s)", requestWithState.getRequest());
    }

    if (!Strings.isNullOrEmpty(commandLineArgs)) {
      maybeCmdLineArgs = Optional.of(commandLineArgs);
    }
View Full Code Here

  @Path("/request/{requestId}/pause")
  @ApiOperation("Pause a Singularity request.")
  public SingularityRequestParent pause(@ApiParam("The request ID to pause.") @PathParam("requestId") String requestId,
                                        @ApiParam("Username of the person requesting the pause.") @QueryParam("user") Optional<String> user,
                                        @ApiParam("Additional pause options.") Optional<SingularityPauseRequest> pauseRequest) {
    SingularityRequestWithState requestWithState = fetchRequestWithState(requestId);

    checkRequestStateNotPaused(requestWithState, "pause");

    Optional<Boolean> killTasks = Optional.absent();
    if (pauseRequest.isPresent()) {
      user = pauseRequest.get().getUser();
      killTasks = pauseRequest.get().getKillTasks();
    }

    mailer.sendRequestPausedMail(requestWithState.getRequest(), user);
    requestManager.pause(requestWithState.getRequest(), user);

    SingularityCreateResult result = requestManager.createCleanupRequest(new SingularityRequestCleanup(user, RequestCleanupType.PAUSING, System.currentTimeMillis(), killTasks, requestId));

    if (result != SingularityCreateResult.CREATED) {
      throw WebExceptions.conflict("A cleanup/pause request for %s failed to create because it was in state %s", requestId, result);
    }

    return fillEntireRequest(new SingularityRequestWithState(requestWithState.getRequest(), RequestState.PAUSED));
  }
View Full Code Here

  @POST
  @Path("/request/{requestId}/unpause")
  @ApiOperation("Unpause a Singularity request.")
  public SingularityRequestParent unpause(@ApiParam("The request ID to unpause.") @PathParam("requestId") String requestId,
                                          @ApiParam("Username of the person requesting the unpause") @QueryParam("user") Optional<String> user) {
    SingularityRequestWithState requestWithState = fetchRequestWithState(requestId);

    if (requestWithState.getState() != RequestState.PAUSED) {
      throw WebExceptions.conflict("Request %s is not in PAUSED state, it is in %s", requestId, requestWithState.getState());
    }

    mailer.sendRequestUnpausedMail(requestWithState.getRequest(), user);

    Optional<String> maybeDeployId = deployManager.getInUseDeployId(requestId);

    if (maybeDeployId.isPresent() && !requestWithState.getRequest().isOneOff()) {
      requestManager.addToPendingQueue(new SingularityPendingRequest(requestId, maybeDeployId.get(), System.currentTimeMillis(), Optional.<String> absent(), user, PendingType.UNPAUSED));
    }

    requestManager.unpause(requestWithState.getRequest(), user);

    return fillEntireRequest(new SingularityRequestWithState(requestWithState.getRequest(), RequestState.ACTIVE));
  }
View Full Code Here

    final SingularityDeployMarker pendingDeployMarker = pendingDeploy.getDeployMarker();

    final Optional<SingularityDeployMarker> cancelRequest = findCancel(cancelDeploys, pendingDeployMarker);

    final SingularityRequestWithState requestWithState = maybeRequestWithState.get();
    final SingularityRequest request = requestWithState.getRequest();

    final List<SingularityTaskId> requestTasks = taskManager.getTaskIdsForRequest(request.getId());
    final List<SingularityTaskId> activeTasks = taskManager.filterActiveTaskIds(requestTasks);

    final List<SingularityTaskId> inactiveDeployMatchingTasks = SingularityTaskId.matchingAndNotIn(requestTasks, pendingDeployMarker.getRequestId(), pendingDeployMarker.getDeployId(), activeTasks);
View Full Code Here

TOP

Related Classes of com.hubspot.singularity.SingularityRequestWithState

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.