Exemplo n.º 1
0
  @POST
  @Consumes({MediaType.APPLICATION_JSON})
  @ApiOperation(
      value = "Create or update a Singularity Request",
      response = SingularityRequestParent.class)
  @ApiResponses({
    @ApiResponse(code = 400, message = "Request object is invalid"),
    @ApiResponse(code = 409, message = "Request object is being cleaned. Try again shortly"),
  })
  public SingularityRequestParent submit(
      @ApiParam("The Singularity request to create or update") SingularityRequest request,
      @ApiParam("Username of the person requesting to create or update") @QueryParam("user")
          Optional<String> user) {
    checkNotNullBadRequest(request.getId(), "Request must have an id");
    checkConflict(
        !requestManager.cleanupRequestExists(request.getId()),
        "Request %s is currently cleaning. Try again after a few moments",
        request.getId());

    Optional<SingularityRequestWithState> maybeOldRequestWithState =
        requestManager.getRequest(request.getId());
    Optional<SingularityRequest> maybeOldRequest =
        maybeOldRequestWithState.isPresent()
            ? Optional.of(maybeOldRequestWithState.get().getRequest())
            : Optional.<SingularityRequest>absent();

    SingularityRequestDeployHolder deployHolder = getDeployHolder(request.getId());

    SingularityRequest newRequest =
        validator.checkSingularityRequest(
            request,
            maybeOldRequest,
            deployHolder.getActiveDeploy(),
            deployHolder.getPendingDeploy());

    checkConflict(
        maybeOldRequest.isPresent() || !requestManager.cleanupRequestExists(request.getId()),
        "Request %s is currently cleaning. Try again after a few moments",
        request.getId());

    final long now = System.currentTimeMillis();

    requestManager.activate(
        newRequest,
        maybeOldRequest.isPresent() ? RequestHistoryType.UPDATED : RequestHistoryType.CREATED,
        now,
        user);

    checkReschedule(newRequest, maybeOldRequest, now);

    return fillEntireRequest(fetchRequestWithState(request.getId()));
  }
Exemplo n.º 2
0
  @PUT
  @Path("/request/{requestId}/instances")
  @ApiOperation(
      value = "Scale the number of instances up or down for a specific Request",
      response = SingularityRequest.class)
  @ApiResponses({
    @ApiResponse(code = 400, message = "Posted object did not match Request ID"),
    @ApiResponse(code = 404, message = "No Request with that ID"),
  })
  public SingularityRequest updateInstances(
      @ApiParam("The Request ID to scale") @PathParam("requestId") String requestId,
      @ApiParam("Username of the person requesting the scale") @QueryParam("user")
          Optional<String> user,
      @ApiParam("Object to hold number of instances to request")
          SingularityRequestInstances newInstances) {

    checkBadRequest(
        requestId != null && newInstances.getId() != null && requestId.equals(newInstances.getId()),
        "Update for request instance must pass a matching non-null requestId in path (%s) and object (%s)",
        requestId,
        newInstances.getId());
    checkConflict(
        !requestManager.cleanupRequestExists(requestId),
        "Request %s is currently cleaning. Try again after a few moments",
        requestId);

    SingularityRequest oldRequest = fetchRequest(requestId);
    Optional<SingularityRequest> maybeOldRequest = Optional.of(oldRequest);

    SingularityRequestDeployHolder deployHolder = getDeployHolder(newInstances.getId());
    SingularityRequest newRequest =
        oldRequest.toBuilder().setInstances(newInstances.getInstances()).build();

    validator.checkSingularityRequest(
        newRequest,
        maybeOldRequest,
        deployHolder.getActiveDeploy(),
        deployHolder.getPendingDeploy());

    final long now = System.currentTimeMillis();

    requestManager.update(newRequest, now, user);

    checkReschedule(newRequest, maybeOldRequest, now);

    return newRequest;
  }