use of com.wordnik.swagger.annotations.ApiResponses in project Singularity by HubSpot.
the class TaskResource method postTaskMetadata.
@POST
@Path("/task/{taskId}/metadata")
@ApiOperation(value = "Post metadata about a task that will be persisted along with it and displayed in the UI")
@ApiResponses({ @ApiResponse(code = 400, message = "Invalid metadata object or doesn't match allowed types"), @ApiResponse(code = 404, message = "Task doesn't exist"), @ApiResponse(code = 409, message = "Metadata with this type/timestamp already existed") })
@Consumes({ MediaType.APPLICATION_JSON })
public void postTaskMetadata(@Auth SingularityUser user, @PathParam("taskId") String taskId, final SingularityTaskMetadataRequest taskMetadataRequest) {
SingularityTaskId taskIdObj = getTaskIdFromStr(taskId);
authorizationHelper.checkForAuthorizationByTaskId(taskId, user, SingularityAuthorizationScope.WRITE);
validator.checkActionEnabled(SingularityAction.ADD_METADATA);
WebExceptions.checkBadRequest(taskMetadataRequest.getTitle().length() < taskMetadataConfiguration.getMaxMetadataTitleLength(), "Task metadata title too long, must be less than %s bytes", taskMetadataConfiguration.getMaxMetadataTitleLength());
int messageLength = taskMetadataRequest.getMessage().isPresent() ? taskMetadataRequest.getMessage().get().length() : 0;
WebExceptions.checkBadRequest(!taskMetadataRequest.getMessage().isPresent() || messageLength < taskMetadataConfiguration.getMaxMetadataMessageLength(), "Task metadata message too long, must be less than %s bytes", taskMetadataConfiguration.getMaxMetadataMessageLength());
if (taskMetadataConfiguration.getAllowedMetadataTypes().isPresent()) {
WebExceptions.checkBadRequest(taskMetadataConfiguration.getAllowedMetadataTypes().get().contains(taskMetadataRequest.getType()), "%s is not one of the allowed metadata types %s", taskMetadataRequest.getType(), taskMetadataConfiguration.getAllowedMetadataTypes().get());
}
WebExceptions.checkNotFound(taskManager.taskExistsInZk(taskIdObj), "Task %s not found in ZooKeeper (can not save metadata to tasks which have been persisted", taskIdObj);
final SingularityTaskMetadata taskMetadata = new SingularityTaskMetadata(taskIdObj, System.currentTimeMillis(), taskMetadataRequest.getType(), taskMetadataRequest.getTitle(), taskMetadataRequest.getMessage(), user.getEmail(), taskMetadataRequest.getLevel());
SingularityCreateResult result = taskManager.saveTaskMetadata(taskMetadata);
WebExceptions.checkConflict(result == SingularityCreateResult.CREATED, "Task metadata conficted with existing metadata for %s at %s", taskMetadata.getType(), taskMetadata.getTimestamp());
}
use of com.wordnik.swagger.annotations.ApiResponses in project fabric8 by jboss-fuse.
the class CustomerService method updateCustomer.
/**
* Using HTTP PUT, we can can upload the XML representation of a customer object. This operation will be mapped
* to the method below and the XML representation will get unmarshaled into a real Customer object using JAXB.
* <p/>
* The method itself just updates the customer object in our local data map and afterwards uses the Reponse class to
* build the appropriate HTTP response: either OK if the update succeeded (translates to HTTP Status 200/OK) or not
* modified if the method failed to update a customer object (translates to HTTP Status 304/Not Modified).
* <p/>
* Note how this method is using the same @Path value as our next method - the HTTP method used will determine which
* method is being invoked.
*/
@PUT
@Path("/customers/")
@Consumes({ "application/xml", "application/json" })
@ApiOperation(value = "Update an existing Customer")
@ApiResponses(value = { @ApiResponse(code = 500, message = "Invalid ID supplied"), @ApiResponse(code = 204, message = "Customer not found") })
public Response updateCustomer(@ApiParam(value = "Customer object that needs to be updated", required = true) Customer customer) {
LOG.info("Invoking updateCustomer, Customer name is: {}", customer.getName());
Customer c = customers.get(customer.getId());
Response r;
if (c != null) {
customers.put(customer.getId(), customer);
r = Response.ok().build();
} else {
r = Response.notModified().build();
}
return r;
}
use of com.wordnik.swagger.annotations.ApiResponses in project fabric8 by jboss-fuse.
the class CustomerService method deleteCustomer.
/**
* This method is mapped to an HTTP DELETE of 'http://localhost:8181/cxf/crm/customerservice/customers/{id}'. The value for
* {id} will be passed to this message as a parameter, using the @PathParam annotation.
* <p/>
* The method uses the Response class to create the HTTP response: either HTTP Status 200/OK if the customer object was
* successfully removed from the local data map or a HTTP Status 304/Not Modified if it failed to remove the object.
*/
@DELETE
@Path("/customers/{id}/")
@ApiOperation(value = "Delete Customer")
@ApiResponses(value = { @ApiResponse(code = 500, message = "Invalid ID supplied"), @ApiResponse(code = 204, message = "Customer not found") })
public Response deleteCustomer(@ApiParam(value = "ID of Customer to delete", required = true) @PathParam("id") String id) {
LOG.info("Invoking deleteCustomer, Customer id is: {}", id);
long idNumber = Long.parseLong(id);
Customer c = customers.get(idNumber);
Response r;
if (c != null) {
r = Response.ok().build();
customers.remove(idNumber);
} else {
r = Response.notModified().build();
}
return r;
}
use of com.wordnik.swagger.annotations.ApiResponses in project Singularity by HubSpot.
the class RequestResource method scheduleImmediately.
@POST
@Path("/request/{requestId}/run")
@Consumes({ MediaType.APPLICATION_JSON })
@ApiOperation(value = "Schedule a one-off or scheduled Singularity request for immediate or delayed execution.", response = SingularityRequestParent.class)
@ApiResponses({ @ApiResponse(code = 400, message = "Singularity Request is not scheduled or one-off") })
public SingularityPendingRequestParent scheduleImmediately(@Auth SingularityUser user, @ApiParam("The request ID to run") @PathParam("requestId") String requestId, SingularityRunNowRequest runNowRequest) {
final Optional<SingularityRunNowRequest> maybeRunNowRequest = Optional.fromNullable(runNowRequest);
SingularityRequestWithState requestWithState = fetchRequestWithState(requestId, user);
authorizationHelper.checkForAuthorization(requestWithState.getRequest(), user, SingularityAuthorizationScope.WRITE);
checkConflict(requestWithState.getState() != RequestState.PAUSED, "Request %s is paused. Unable to run now (it must be manually unpaused first)", requestWithState.getRequest().getId());
final SingularityPendingRequest pendingRequest = validator.checkRunNowRequest(getAndCheckDeployId(requestId), user.getEmail(), requestWithState.getRequest(), maybeRunNowRequest, taskManager.getActiveTaskIdsForRequest(requestId), taskManager.getPendingTaskIdsForRequest(requestId));
SingularityCreateResult result = requestManager.addToPendingQueue(pendingRequest);
checkConflict(result != SingularityCreateResult.EXISTED, "%s is already pending, please try again soon", requestId);
return SingularityPendingRequestParent.fromSingularityRequestParent(fillEntireRequest(requestWithState), pendingRequest);
}
use of com.wordnik.swagger.annotations.ApiResponses in project Singularity by HubSpot.
the class RequestResource method checkAuthForGroupsUpdate.
@POST
@Path("/request/{requestId}/groups/auth-check")
@ApiOperation(value = "Check authorization for updating the group, readOnlyGroups, and readWriteGroups for a SingularityReques, without commiting the change")
@ApiResponses({ @ApiResponse(code = 200, message = "User is authorized to make these changes"), @ApiResponse(code = 401, message = "User is not authorized to make these updates") })
public Response checkAuthForGroupsUpdate(@Auth SingularityUser user, @PathParam("requestId") String requestId, @ApiParam("Updated groups") SingularityUpdateGroupsRequest updateGroupsRequest) {
Optional<SingularityRequestWithState> maybeOldRequestWithState = requestManager.getRequest(requestId, false);
if (!maybeOldRequestWithState.isPresent()) {
authorizationHelper.checkForAuthorization(user, Sets.union(updateGroupsRequest.getGroup().asSet(), updateGroupsRequest.getReadWriteGroups()), updateGroupsRequest.getReadOnlyGroups(), SingularityAuthorizationScope.WRITE, Optional.absent());
return Response.ok().build();
}
SingularityRequestWithState oldRequestWithState = maybeOldRequestWithState.get();
authorizationHelper.checkForAuthorization(oldRequestWithState.getRequest(), user, SingularityAuthorizationScope.WRITE);
SingularityRequest newRequest = oldRequestWithState.getRequest().toBuilder().setGroup(updateGroupsRequest.getGroup()).setReadWriteGroups(Optional.of(updateGroupsRequest.getReadWriteGroups())).setReadOnlyGroups(Optional.of(updateGroupsRequest.getReadOnlyGroups())).build();
authorizationHelper.checkForAuthorizedChanges(newRequest, oldRequestWithState.getRequest(), user);
return Response.ok().build();
}
Aggregations