Search in sources :

Example 26 with Hidden

use of io.swagger.v3.oas.annotations.Hidden in project Singularity by HubSpot.

the class SandboxResource method browse.

@GET
@Path("/{taskId}/browse")
@Operation(summary = "Retrieve information about a specific task's sandbox", responses = { @ApiResponse(responseCode = "404", description = "An agent or task with the specified id was not found") })
public SingularitySandbox browse(@Parameter(hidden = true) @Auth SingularityUser user, @Parameter(required = true, description = "The task ID to browse") @PathParam("taskId") String taskId, @Parameter(required = true, description = "The path to browse from") @QueryParam("path") String path) {
    authorizationHelper.checkForAuthorizationByTaskId(taskId, user, SingularityAuthorizationScope.READ);
    // Remove all trailing slashes from the path
    if (path != null) {
        path = path.replaceAll("\\/+$", "");
    }
    final String currentDirectory = getCurrentDirectory(taskId, path);
    final SingularityTaskHistory history = checkHistory(taskId, user);
    final String hostname = history.getTask().getHostname();
    final String pathToRoot = history.getDirectory().get();
    final String fullPath = new File(pathToRoot, currentDirectory).toString();
    final int substringTruncationLength = currentDirectory.length() == 0 ? pathToRoot.length() + 1 : pathToRoot.length() + currentDirectory.length() + 2;
    try {
        Collection<MesosFileObject> mesosFiles = sandboxManager.browse(hostname, fullPath);
        List<SingularitySandboxFile> sandboxFiles = Lists.newArrayList(Iterables.transform(mesosFiles, new Function<MesosFileObject, SingularitySandboxFile>() {

            @Override
            public SingularitySandboxFile apply(MesosFileObject input) {
                return new SingularitySandboxFile(input.getPath().substring(substringTruncationLength), input.getMtime(), input.getSize(), input.getMode());
            }
        }));
        return new SingularitySandbox(sandboxFiles, pathToRoot, currentDirectory, hostname);
    } catch (AgentNotFoundException snfe) {
        throw notFound("Slave @ %s was not found, it is probably offline", hostname);
    }
}
Also used : SingularitySandbox(com.hubspot.singularity.SingularitySandbox) SingularitySandboxFile(com.hubspot.singularity.SingularitySandboxFile) Function(com.google.common.base.Function) MesosFileObject(com.hubspot.mesos.json.MesosFileObject) SingularityTaskHistory(com.hubspot.singularity.SingularityTaskHistory) AgentNotFoundException(com.hubspot.singularity.data.SandboxManager.AgentNotFoundException) File(java.io.File) SingularitySandboxFile(com.hubspot.singularity.SingularitySandboxFile) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET) Operation(io.swagger.v3.oas.annotations.Operation)

Example 27 with Hidden

use of io.swagger.v3.oas.annotations.Hidden in project Singularity by HubSpot.

the class HistoryResource method getInactiveDeployTasks.

@GET
@Path("/request/{requestId}/deploy/{deployId}/tasks/inactive")
@Operation(summary = "Retrieve the task history for a specific deploy")
public List<SingularityTaskIdHistory> getInactiveDeployTasks(@Parameter(hidden = true) @Auth SingularityUser user, @Parameter(required = true, description = "Request ID for deploy") @PathParam("requestId") String requestId, @Parameter(required = true, description = "Deploy ID") @PathParam("deployId") String deployId, @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 Integer limitCount = getLimitCount(count);
    final Integer limitStart = getLimitStart(limitCount, page);
    SingularityDeployKey key = new SingularityDeployKey(requestId, deployId);
    return deployTaskHistoryHelper.getBlendedHistory(key, limitStart, limitCount, skipZk);
}
Also used : SingularityDeployKey(com.hubspot.singularity.SingularityDeployKey) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET) Operation(io.swagger.v3.oas.annotations.Operation)

Example 28 with Hidden

use of io.swagger.v3.oas.annotations.Hidden in project Singularity by HubSpot.

the class HistoryResource method getRequestHistoryForRequestWithMetadata.

@GET
@Path("/request/{requestId}/requests/withmetadata")
@Operation(summary = "Get request history for a single request")
public SingularityPaginatedResponse<SingularityRequestHistory> getRequestHistoryForRequestWithMetadata(@Parameter(hidden = true) @Auth SingularityUser user, @Parameter(required = true, description = "Request ID to look up") @PathParam("requestId") String requestId, @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);
    SingularityRequestHistoryQuery requestHistoryQuery = new SingularityRequestHistoryQuery(requestId, Optional.empty(), Optional.empty(), Optional.empty());
    final Optional<Integer> dataCount = requestHistoryHelper.getBlendedHistoryCount(requestHistoryQuery, skipZk);
    final Integer limitCount = getLimitCount(count);
    final Integer limitStart = getLimitStart(limitCount, page);
    final List<SingularityRequestHistory> data = requestHistoryHelper.getBlendedHistory(requestHistoryQuery, limitStart, limitCount, skipZk);
    final Optional<Integer> pageCount = getPageCount(dataCount, limitCount);
    return new SingularityPaginatedResponse<>(dataCount, pageCount, Optional.ofNullable(page), data);
}
Also used : SingularityRequestHistory(com.hubspot.singularity.SingularityRequestHistory) SingularityRequestHistoryQuery(com.hubspot.singularity.SingularityRequestHistoryQuery) SingularityPaginatedResponse(com.hubspot.singularity.SingularityPaginatedResponse) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET) Operation(io.swagger.v3.oas.annotations.Operation)

Example 29 with Hidden

use of io.swagger.v3.oas.annotations.Hidden in project Singularity by HubSpot.

the class HistoryResource method getTaskHistory.

@GET
@Path("/tasks")
@Operation(summary = "Retrieve the history sorted by startedAt for all inactive tasks")
public List<SingularityTaskIdHistory> getTaskHistory(@Parameter(hidden = true) @Auth SingularityUser user, @Parameter(description = "Optional Request ID to match") @QueryParam("requestId") Optional<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) {
    if (requestId.isPresent()) {
        authorizationHelper.checkForAuthorizationByRequestId(requestId.get(), user, SingularityAuthorizationScope.READ);
    } else {
        authorizationHelper.checkGlobalReadAuthorization(user);
    }
    final Integer limitCount = getLimitCount(count);
    final Integer limitStart = getLimitStart(limitCount, page);
    return taskHistoryHelper.getBlendedHistory(new SingularityTaskHistoryQuery(requestId, deployId, runId, host, lastTaskStatus, startedBefore, startedAfter, updatedBefore, updatedAfter, orderDirection), limitStart, limitCount, skipZk);
}
Also used : SingularityTaskHistoryQuery(com.hubspot.singularity.SingularityTaskHistoryQuery) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET) Operation(io.swagger.v3.oas.annotations.Operation)

Example 30 with Hidden

use of io.swagger.v3.oas.annotations.Hidden in project Singularity by HubSpot.

the class HistoryResource method getTaskHistoryForRequest.

@GET
@Path("/request/{requestId}/tasks")
@Operation(summary = "Retrieve the history sorted by startedAt for all inactive tasks of a specific request")
public List<SingularityTaskIdHistory> getTaskHistoryForRequest(@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("false") boolean skipZk) {
    authorizationHelper.checkForAuthorizationByRequestId(requestId, user, SingularityAuthorizationScope.READ);
    final Integer limitCount = getLimitCount(count);
    final Integer limitStart = getLimitStart(limitCount, page);
    return taskHistoryHelper.getBlendedHistory(new SingularityTaskHistoryQuery(Optional.of(requestId), deployId, runId, host, lastTaskStatus, startedBefore, startedAfter, updatedBefore, updatedAfter, orderDirection), limitStart, limitCount, skipZk);
}
Also used : SingularityTaskHistoryQuery(com.hubspot.singularity.SingularityTaskHistoryQuery) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET) Operation(io.swagger.v3.oas.annotations.Operation)

Aggregations

Operation (io.swagger.v3.oas.annotations.Operation)29 Path (javax.ws.rs.Path)25 GET (javax.ws.rs.GET)21 POST (javax.ws.rs.POST)6 SingularityTaskHistoryQuery (com.hubspot.singularity.SingularityTaskHistoryQuery)5 SingularityTaskId (com.hubspot.singularity.SingularityTaskId)5 List (java.util.List)4 Consumes (javax.ws.rs.Consumes)4 Produces (javax.ws.rs.Produces)4 SingularityPaginatedResponse (com.hubspot.singularity.SingularityPaginatedResponse)3 SingularityRequestWithState (com.hubspot.singularity.SingularityRequestWithState)3 SingularityTaskIdHistory (com.hubspot.singularity.SingularityTaskIdHistory)3 Schema (io.swagger.v3.oas.models.media.Schema)3 BeanDescription (com.fasterxml.jackson.databind.BeanDescription)2 AnnotatedMethod (com.fasterxml.jackson.databind.introspect.AnnotatedMethod)2 SingularityTaskHistory (com.hubspot.singularity.SingularityTaskHistory)2 Hidden (io.swagger.v3.oas.annotations.Hidden)2 GenericOpenApiContext (io.swagger.v3.oas.integration.GenericOpenApiContext)2 OpenAPIConfiguration (io.swagger.v3.oas.integration.api.OpenAPIConfiguration)2 OpenApiContext (io.swagger.v3.oas.integration.api.OpenApiContext)2