Search in sources :

Example 6 with ApiResponses

use of com.wordnik.swagger.annotations.ApiResponses in project oxTrust by GluuFederation.

the class TrustRelationshipWebService method setMetadata.

@POST
@Path("/set_metadata/{inum}")
@Consumes({ MediaType.APPLICATION_XML, MediaType.TEXT_PLAIN })
@Produces(MediaType.TEXT_PLAIN)
@ApiResponses(value = { @ApiResponse(code = 200, message = "OK"), @ApiResponse(code = 500, message = "Server error") })
public void setMetadata(@PathParam("inum") String trustRelationshipInum, String metadata, @Context HttpServletResponse response) {
    try {
        GluuSAMLTrustRelationship trustRelationship = trustService.getRelationshipByInum(trustRelationshipInum);
        String metadataFileName = trustRelationship.getSpMetaDataFN();
        if (StringHelper.isEmpty(metadataFileName)) {
            // Generate new file name
            metadataFileName = shibboleth3ConfService.getSpNewMetadataFileName(trustRelationshipInum);
        }
        shibboleth3ConfService.saveSpMetadataFile(metadataFileName, metadata.getBytes("UTF8"));
        trustRelationship.setSpMetaDataFN(metadataFileName);
        trustRelationship.setSpMetaDataSourceType(GluuMetadataSourceType.FILE);
        trustService.updateTrustRelationship(trustRelationship);
    } catch (Exception e) {
        logger.error("addMetadata() Exception", e);
        try {
            response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "INTERNAL SERVER ERROR");
        } catch (Exception ex) {
        }
    }
}
Also used : GluuSAMLTrustRelationship(org.gluu.oxtrust.model.GluuSAMLTrustRelationship) CertificateEncodingException(java.security.cert.CertificateEncodingException) BaseMappingException(org.gluu.persist.exception.mapping.BaseMappingException) IOException(java.io.IOException) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) ApiResponses(com.wordnik.swagger.annotations.ApiResponses)

Example 7 with ApiResponses

use of com.wordnik.swagger.annotations.ApiResponses in project Singularity by HubSpot.

the class TaskResource method runShellCommand.

@POST
@Path("/task/{taskId}/command")
@ApiOperation(value = "Run a configured shell command against the given task")
@ApiResponses({ @ApiResponse(code = 400, message = "Given shell command option doesn't exist"), @ApiResponse(code = 403, message = "Given shell command doesn't exist") })
@Consumes({ MediaType.APPLICATION_JSON })
public SingularityTaskShellCommandRequest runShellCommand(@Auth SingularityUser user, @PathParam("taskId") String taskId, final SingularityShellCommand shellCommand) {
    SingularityTaskId taskIdObj = getTaskIdFromStr(taskId);
    authorizationHelper.checkForAuthorizationByTaskId(taskId, user, SingularityAuthorizationScope.WRITE);
    validator.checkActionEnabled(SingularityAction.RUN_SHELL_COMMAND);
    if (!taskManager.isActiveTask(taskId)) {
        throw WebExceptions.badRequest("%s is not an active task, can't run %s on it", taskId, shellCommand.getName());
    }
    return startShellCommand(taskIdObj, shellCommand, user);
}
Also used : 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 8 with ApiResponses

use of com.wordnik.swagger.annotations.ApiResponses in project Singularity by HubSpot.

the class TaskTrackerResource method getTaskStateByRunId.

@GET
@Path("/run/{requestId}/{runId}")
@ApiOperation(value = "Get the current state of a task by taskId whether it is pending, active, or inactive")
@ApiResponses({ @ApiResponse(code = 404, message = "Task with this runId does not exist") })
public Optional<SingularityTaskState> getTaskStateByRunId(@Auth SingularityUser user, @PathParam("requestId") String requestId, @PathParam("runId") String runId) {
    authorizationHelper.checkForAuthorizationByRequestId(requestId, user, SingularityAuthorizationScope.READ);
    // Check if it's active or inactive
    Optional<SingularityTaskId> maybeTaskId = taskManager.getTaskByRunId(requestId, runId);
    if (maybeTaskId.isPresent()) {
        Optional<SingularityTaskState> maybeTaskState = getTaskStateFromId(maybeTaskId.get());
        if (maybeTaskState.isPresent()) {
            return maybeTaskState;
        }
    } else {
        Optional<SingularityTaskHistory> maybeTaskHistory = historyManager.getTaskHistoryByRunId(requestId, runId);
        if (maybeTaskHistory.isPresent()) {
            return Optional.of(SingularityTaskState.fromTaskHistory(maybeTaskHistory.get()));
        }
    }
    // Check if it's pending
    for (SingularityPendingTask pendingTask : taskManager.getPendingTasksForRequest(requestId)) {
        if (pendingTask.getRunId().isPresent() && pendingTask.getRunId().get().equals(runId)) {
            return Optional.of(new SingularityTaskState(Optional.absent(), pendingTask.getPendingTaskId(), pendingTask.getRunId(), Optional.absent(), Collections.emptyList(), true));
        }
    }
    for (SingularityPendingRequest pendingRequest : requestManager.getPendingRequests()) {
        if (pendingRequest.getRequestId().equals(requestId) && pendingRequest.getRunId().isPresent() && pendingRequest.getRunId().get().equals(runId)) {
            return Optional.of(new SingularityTaskState(Optional.absent(), Optional.absent(), pendingRequest.getRunId(), Optional.absent(), Collections.emptyList(), true));
        }
    }
    return Optional.absent();
}
Also used : SingularityTaskState(com.hubspot.singularity.SingularityTaskState) SingularityPendingRequest(com.hubspot.singularity.SingularityPendingRequest) SingularityPendingTask(com.hubspot.singularity.SingularityPendingTask) SingularityTaskHistory(com.hubspot.singularity.SingularityTaskHistory) SingularityTaskId(com.hubspot.singularity.SingularityTaskId) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET) ApiOperation(com.wordnik.swagger.annotations.ApiOperation) ApiResponses(com.wordnik.swagger.annotations.ApiResponses)

Example 9 with ApiResponses

use of com.wordnik.swagger.annotations.ApiResponses in project Singularity by HubSpot.

the class PriorityResource method createPriorityFreeze.

@POST
@Path("/freeze")
@ApiOperation(value = "Stop scheduling tasks below a certain priority level.", response = SingularityPriorityFreezeParent.class)
@ApiResponses({ @ApiResponse(code = 200, message = "The priority freeze request was accepted."), @ApiResponse(code = 400, message = "There was a validation error with the priority freeze request.") })
public SingularityPriorityFreezeParent createPriorityFreeze(@Auth SingularityUser user, SingularityPriorityFreeze priorityFreezeRequest) {
    authorizationHelper.checkAdminAuthorization(user);
    priorityFreezeRequest = singularityValidator.checkSingularityPriorityFreeze(priorityFreezeRequest);
    final SingularityPriorityFreezeParent priorityFreezeRequestParent = new SingularityPriorityFreezeParent(priorityFreezeRequest, System.currentTimeMillis(), user.getEmail());
    priorityManager.createPriorityFreeze(priorityFreezeRequestParent);
    if (priorityFreezeRequest.isKillTasks()) {
        priorityManager.setPriorityKill();
    }
    return priorityFreezeRequestParent;
}
Also used : SingularityPriorityFreezeParent(com.hubspot.singularity.SingularityPriorityFreezeParent) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) ApiOperation(com.wordnik.swagger.annotations.ApiOperation) ApiResponses(com.wordnik.swagger.annotations.ApiResponses)

Example 10 with ApiResponses

use of com.wordnik.swagger.annotations.ApiResponses in project Singularity by HubSpot.

the class PriorityResource method deleteActivePriorityFreeze.

@DELETE
@Path("/freeze")
@ApiOperation("Stops the active priority freeze.")
@ApiResponses({ @ApiResponse(code = 202, message = "The active priority freeze was deleted."), @ApiResponse(code = 400, message = "There was no active priority freeze to delete.") })
public void deleteActivePriorityFreeze(@Auth SingularityUser user) {
    authorizationHelper.checkAdminAuthorization(user);
    final SingularityDeleteResult deleteResult = priorityManager.deleteActivePriorityFreeze();
    checkBadRequest(deleteResult == SingularityDeleteResult.DELETED, "No active priority freeze to delete.");
    priorityManager.clearPriorityKill();
}
Also used : SingularityDeleteResult(com.hubspot.singularity.SingularityDeleteResult) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) 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