use of io.swagger.v3.oas.annotations.responses.ApiResponse in project Singularity by HubSpot.
the class TaskTrackerResource method getTaskStateByRunId.
@GET
@Path("/run/{requestId}/{runId}")
@Operation(summary = "Get the current state of a task by taskId whether it is pending, active, or inactive", responses = { @ApiResponse(responseCode = "404", description = "Task with this runId does not exist") })
public Optional<SingularityTaskState> getTaskStateByRunId(@Parameter(hidden = true) @Auth SingularityUser user, @Parameter(required = true, description = "the request id to search for tasks") @PathParam("requestId") String requestId, @Parameter(required = true, description = "the run id to search for") @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, false)) {
if (pendingTask.getRunId().isPresent() && pendingTask.getRunId().get().equals(runId)) {
return Optional.of(new SingularityTaskState(Optional.empty(), pendingTask.getPendingTaskId(), pendingTask.getRunId(), Optional.empty(), 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.empty(), Optional.empty(), pendingRequest.getRunId(), Optional.empty(), Collections.emptyList(), true));
}
}
return Optional.empty();
}
use of io.swagger.v3.oas.annotations.responses.ApiResponse in project Singularity by HubSpot.
the class TaskResource method runShellCommand.
@POST
@Path("/task/{taskId}/command")
@Operation(summary = "Run a configured shell command against the given task", responses = { @ApiResponse(responseCode = "400", description = "Given shell command option doesn't exist"), @ApiResponse(responseCode = "403", description = "Given shell command doesn't exist") })
@Consumes({ MediaType.APPLICATION_JSON })
public SingularityTaskShellCommandRequest runShellCommand(@Parameter(hidden = true) @Auth SingularityUser user, @Parameter(required = true, description = "Id of the task") @PathParam("taskId") String taskId, @RequestBody(required = true, description = "Object describing the command to be run") final SingularityShellCommand shellCommand) {
SingularityTaskId taskIdObj = getTaskIdFromStr(taskId);
authorizationHelper.checkForAuthorizationByTaskId(taskId, user, SingularityAuthorizationScope.WRITE, SingularityUserFacingAction.RUN_SHELL_COMMAND);
validator.checkActionEnabled(SingularityAction.RUN_SHELL_COMMAND);
if (!taskManager.isActiveTask(taskIdObj)) {
throw badRequest("%s is not an active task, can't run %s on it", taskId, shellCommand.getName());
}
return startShellCommand(taskIdObj, shellCommand, user);
}
use of io.swagger.v3.oas.annotations.responses.ApiResponse in project Singularity by HubSpot.
the class TaskResource method getTaskStatistics.
@GET
@Path("/task/{taskId}/statistics")
@Operation(summary = "Retrieve resource usage statistics about a specific active task", responses = { @ApiResponse(responseCode = "404", description = "A task with this id, or agent and executor with matching statistics was not found") })
public MesosTaskStatisticsObject getTaskStatistics(@Parameter(hidden = true) @Auth SingularityUser user, @Parameter(description = "Id of the task") @PathParam("taskId") String taskId) {
SingularityTask task = checkActiveTask(taskId, SingularityAuthorizationScope.READ, user);
String executorIdToMatch = null;
if (task.getMesosTask().hasExecutor()) {
executorIdToMatch = task.getMesosTask().getExecutor().getExecutorId().getValue();
} else {
executorIdToMatch = taskId;
}
for (MesosTaskMonitorObject taskMonitor : mesosClient.getSlaveResourceUsage(task.getHostname())) {
if (taskMonitor.getExecutorId().equals(executorIdToMatch)) {
return taskMonitor.getStatistics();
}
}
throw notFound("Couldn't find executor %s for %s on agent %s", executorIdToMatch, taskId, task.getHostname());
}
use of io.swagger.v3.oas.annotations.responses.ApiResponse in project Singularity by HubSpot.
the class PriorityResource method deleteActivePriorityFreeze.
@DELETE
@Path("/freeze")
@Operation(summary = "Stops the active priority freeze", responses = { @ApiResponse(responseCode = "202", description = "The active priority freeze was deleted"), @ApiResponse(responseCode = "400", description = "There was no active priority freeze to delete") })
public void deleteActivePriorityFreeze(@Parameter(hidden = true) @Auth SingularityUser user) {
authorizationHelper.checkAdminAuthorization(user);
final SingularityDeleteResult deleteResult = priorityManager.deleteActivePriorityFreeze();
checkBadRequest(deleteResult == SingularityDeleteResult.DELETED, "No active priority freeze to delete.");
priorityManager.clearPriorityKill();
}
use of io.swagger.v3.oas.annotations.responses.ApiResponse in project Singularity by HubSpot.
the class PriorityResource method createPriorityFreeze.
@POST
@Path("/freeze")
@Operation(summary = "Stop scheduling tasks below a certain priority level", responses = { @ApiResponse(responseCode = "200", description = "The priority freeze request was accepted"), @ApiResponse(responseCode = "400", description = "There was a validation error with the priority freeze request") })
public SingularityPriorityFreezeParent createPriorityFreeze(@Parameter(hidden = true) @Auth SingularityUser user, @RequestBody(description = "the new priority freeze to create") 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;
}
Aggregations