Search in sources :

Example 96 with ApiResponse

use of io.swagger.v3.oas.models.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();
}
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) Operation(io.swagger.v3.oas.annotations.Operation)

Example 97 with ApiResponse

use of io.swagger.v3.oas.models.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);
}
Also used : SingularityTaskId(com.hubspot.singularity.SingularityTaskId) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Operation(io.swagger.v3.oas.annotations.Operation)

Example 98 with ApiResponse

use of io.swagger.v3.oas.models.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());
}
Also used : SingularityTask(com.hubspot.singularity.SingularityTask) MesosTaskMonitorObject(com.hubspot.mesos.json.MesosTaskMonitorObject) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET) Operation(io.swagger.v3.oas.annotations.Operation)

Example 99 with ApiResponse

use of io.swagger.v3.oas.models.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();
}
Also used : SingularityDeleteResult(com.hubspot.singularity.SingularityDeleteResult) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) Operation(io.swagger.v3.oas.annotations.Operation)

Example 100 with ApiResponse

use of io.swagger.v3.oas.models.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;
}
Also used : SingularityPriorityFreezeParent(com.hubspot.singularity.SingularityPriorityFreezeParent) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Operation(io.swagger.v3.oas.annotations.Operation)

Aggregations

Operation (io.swagger.v3.oas.annotations.Operation)113 ApiResponses (io.swagger.v3.oas.annotations.responses.ApiResponses)99 ApiResponse (io.swagger.v3.oas.models.responses.ApiResponse)84 Test (org.testng.annotations.Test)53 Operation (io.swagger.v3.oas.models.Operation)50 ProtectedApi (org.gluu.oxtrust.service.filter.ProtectedApi)48 OpenAPI (io.swagger.v3.oas.models.OpenAPI)47 ApiResponses (io.swagger.v3.oas.models.responses.ApiResponses)43 PathItem (io.swagger.v3.oas.models.PathItem)39 Schema (io.swagger.v3.oas.models.media.Schema)38 MediaType (io.swagger.v3.oas.models.media.MediaType)31 Path (javax.ws.rs.Path)30 ObjectSchema (io.swagger.v3.oas.models.media.ObjectSchema)29 IntegerSchema (io.swagger.v3.oas.models.media.IntegerSchema)27 StringSchema (io.swagger.v3.oas.models.media.StringSchema)27 ArraySchema (io.swagger.v3.oas.models.media.ArraySchema)25 Content (io.swagger.v3.oas.models.media.Content)25 ArrayList (java.util.ArrayList)24 Components (io.swagger.v3.oas.models.Components)19 Parameter (io.swagger.v3.oas.models.parameters.Parameter)18