use of io.swagger.v3.oas.annotations.Hidden in project Singularity by HubSpot.
the class HistoryResource method getTaskHistoryForRequestWithMetadata.
@GET
@Path("/request/{requestId}/tasks/withmetadata")
@Operation(summary = "Retrieve the history count for all inactive tasks of a specific request")
public SingularityPaginatedResponse<SingularityTaskIdHistory> getTaskHistoryForRequestWithMetadata(@Parameter(hidden = true) @Auth SingularityUser user, @Parameter(required = true, description = "Request ID to match") @PathParam("requestId") String requestId, @Parameter(description = "Optional deploy ID to match") @QueryParam("deployId") Optional<String> deployId, @Parameter(description = "Optional runId to match") @QueryParam("runId") Optional<String> runId, @Parameter(description = "Optional host to match") @QueryParam("host") Optional<String> host, @Parameter(description = "Optional last task status to match") @QueryParam("lastTaskStatus") Optional<ExtendedTaskState> lastTaskStatus, @Parameter(description = "Optionally match only tasks started before") @QueryParam("startedBefore") Optional<Long> startedBefore, @Parameter(description = "Optionally match only tasks started after") @QueryParam("startedAfter") Optional<Long> startedAfter, @Parameter(description = "Optionally match tasks last updated before") @QueryParam("updatedBefore") Optional<Long> updatedBefore, @Parameter(description = "Optionally match tasks last updated after") @QueryParam("updatedAfter") Optional<Long> updatedAfter, @Parameter(description = "Sort direction") @QueryParam("orderDirection") Optional<OrderDirection> orderDirection, @Parameter(description = "Maximum number of items to return") @QueryParam("count") Integer count, @Parameter(description = "Which page of items to view") @QueryParam("page") Integer page, @Parameter(description = "Skip checking zookeeper, items that have not been persisted yet may not appear") @QueryParam("skipZk") @DefaultValue("true") boolean skipZk) {
authorizationHelper.checkForAuthorizationByRequestId(requestId, user, SingularityAuthorizationScope.READ);
final Optional<Integer> dataCount = taskHistoryHelper.getBlendedHistoryCount(new SingularityTaskHistoryQuery(Optional.of(requestId), deployId, runId, host, lastTaskStatus, startedBefore, startedAfter, updatedBefore, updatedAfter, orderDirection), skipZk);
final int limitCount = getLimitCount(count);
final List<SingularityTaskIdHistory> data = this.getTaskHistoryForRequest(user, requestId, deployId, runId, host, lastTaskStatus, startedBefore, startedAfter, updatedBefore, updatedAfter, orderDirection, count, page, skipZk);
final Optional<Integer> pageCount = getPageCount(dataCount, limitCount);
return new SingularityPaginatedResponse<>(dataCount, pageCount, Optional.ofNullable(page), data);
}
use of io.swagger.v3.oas.annotations.Hidden in project Singularity by HubSpot.
the class SandboxResource method read.
@GET
@Path("/{taskId}/read")
@Operation(summary = "Retrieve part of the contents of a file in a specific task's sandbox", responses = { @ApiResponse(responseCode = "404", description = "An agent, task, or file with the specified id was not found") })
public MesosFileChunkObject read(@Parameter(hidden = true) @Auth SingularityUser user, @Parameter(required = true, description = "The task ID of the sandbox to read from") @PathParam("taskId") String taskId, @Parameter(required = true, description = "The path to the file to be read") @QueryParam("path") String path, @Parameter(description = "Optional string to grep for") @QueryParam("grep") Optional<String> grep, @Parameter(description = "Byte offset to start reading from") @QueryParam("offset") Optional<Long> offset, @Parameter(description = "Maximum number of bytes to read") @QueryParam("length") Optional<Long> length) {
authorizationHelper.checkForAuthorizationByTaskId(taskId, user, SingularityAuthorizationScope.READ);
final SingularityTaskHistory history = checkHistory(taskId, user);
checkBadRequest(!Strings.isNullOrEmpty(path), "Must specify 'path'");
final String hostname = history.getTask().getHostname();
final String fullPath = new File(history.getDirectory().get(), path).toString();
try {
final Optional<MesosFileChunkObject> maybeChunk = sandboxManager.read(hostname, fullPath, offset, length);
checkNotFound(maybeChunk.isPresent(), "File %s does not exist for task ID %s", fullPath, taskId);
if (grep.isPresent() && !Strings.isNullOrEmpty(grep.get())) {
final Pattern grepPattern = Pattern.compile(grep.get());
final StringBuilder strBuilder = new StringBuilder(maybeChunk.get().getData().length());
for (String line : Splitter.on("\n").split(maybeChunk.get().getData())) {
if (grepPattern.matcher(line).find()) {
strBuilder.append(line);
strBuilder.append("\n");
}
}
return new MesosFileChunkObject(strBuilder.toString(), maybeChunk.get().getOffset(), Optional.of(maybeChunk.get().getOffset() + maybeChunk.get().getData().length()));
}
return maybeChunk.get();
} catch (AgentNotFoundException snfe) {
throw notFound("Slave @ %s was not found, it is probably offline", hostname);
}
}
use of io.swagger.v3.oas.annotations.Hidden 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.Hidden in project Singularity by HubSpot.
the class TaskResource method getShellCommandHisotry.
@GET
@Path("/task/{taskId}/command")
@Operation(summary = "Retrieve a list of shell commands that have run for a task")
public List<SingularityTaskShellCommandHistory> getShellCommandHisotry(@Parameter(hidden = true) @Auth SingularityUser user, @Parameter(required = true, description = "Id of the task") @PathParam("taskId") String taskId) {
authorizationHelper.checkForAuthorizationByTaskId(taskId, user, SingularityAuthorizationScope.READ);
SingularityTaskId taskIdObj = getTaskIdFromStr(taskId);
return taskManager.getTaskShellCommandHistory(taskIdObj);
}
use of io.swagger.v3.oas.annotations.Hidden 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);
}
Aggregations