Search in sources :

Example 41 with ApiResponses

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());
}
Also used : SingularityTaskMetadata(com.hubspot.singularity.SingularityTaskMetadata) SingularityCreateResult(com.hubspot.singularity.SingularityCreateResult) SingularityTaskId(com.hubspot.singularity.SingularityTaskId) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) ApiOperation(com.wordnik.swagger.annotations.ApiOperation) ApiResponses(com.wordnik.swagger.annotations.ApiResponses)

Example 42 with ApiResponses

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;
}
Also used : Response(javax.ws.rs.core.Response) ApiResponse(com.wordnik.swagger.annotations.ApiResponse) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) ApiOperation(com.wordnik.swagger.annotations.ApiOperation) PUT(javax.ws.rs.PUT) ApiResponses(com.wordnik.swagger.annotations.ApiResponses)

Example 43 with ApiResponses

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;
}
Also used : Response(javax.ws.rs.core.Response) ApiResponse(com.wordnik.swagger.annotations.ApiResponse) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) ApiOperation(com.wordnik.swagger.annotations.ApiOperation) ApiResponses(com.wordnik.swagger.annotations.ApiResponses)

Example 44 with ApiResponses

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);
}
Also used : SingularityRunNowRequest(com.hubspot.singularity.api.SingularityRunNowRequest) SingularityPendingRequest(com.hubspot.singularity.SingularityPendingRequest) SingularityRequestWithState(com.hubspot.singularity.SingularityRequestWithState) SingularityCreateResult(com.hubspot.singularity.SingularityCreateResult) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) ApiOperation(com.wordnik.swagger.annotations.ApiOperation) ApiResponses(com.wordnik.swagger.annotations.ApiResponses)

Example 45 with ApiResponses

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();
}
Also used : SingularityRequestWithState(com.hubspot.singularity.SingularityRequestWithState) SingularityRequest(com.hubspot.singularity.SingularityRequest) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) ApiOperation(com.wordnik.swagger.annotations.ApiOperation) ApiResponses(com.wordnik.swagger.annotations.ApiResponses)

Aggregations

ApiResponses (com.wordnik.swagger.annotations.ApiResponses)47 ApiOperation (com.wordnik.swagger.annotations.ApiOperation)44 Path (javax.ws.rs.Path)21 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)19 Produces (javax.ws.rs.Produces)17 POST (javax.ws.rs.POST)14 RestProcessResult (com.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult)13 IOException (java.io.IOException)10 User (com.serotonin.m2m2.vo.User)9 Consumes (javax.ws.rs.Consumes)9 GET (javax.ws.rs.GET)9 ArrayList (java.util.ArrayList)8 WebApplicationException (javax.ws.rs.WebApplicationException)8 CertificateEncodingException (java.security.cert.CertificateEncodingException)6 GluuSAMLTrustRelationship (org.gluu.oxtrust.model.GluuSAMLTrustRelationship)6 BaseMappingException (org.gluu.persist.exception.mapping.BaseMappingException)6 TranslatableMessage (com.serotonin.m2m2.i18n.TranslatableMessage)5 ResponseEntity (org.springframework.http.ResponseEntity)5 SingularityRequestWithState (com.hubspot.singularity.SingularityRequestWithState)4 InvalidRQLRestException (com.infiniteautomation.mango.rest.v2.exception.InvalidRQLRestException)4