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) {
}
}
}
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);
}
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();
}
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;
}
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();
}
Aggregations