Search in sources :

Example 1 with OrderDirection

use of com.hubspot.singularity.OrderDirection in project Singularity by HubSpot.

the class HistoryResource method getRecentCommandLineArgs.

@GET
@Path("/request/{requestId}/command-line-args")
@ApiOperation("Get a list of recently used command line args for an on-demand or scheduled request")
public Set<List<String>> getRecentCommandLineArgs(@Auth SingularityUser user, @ApiParam("Request ID to look up") @PathParam("requestId") String requestId, @ApiParam("Max number of recent args to return") @QueryParam("count") Optional<Integer> count) {
    authorizationHelper.checkForAuthorizationByRequestId(requestId, user, SingularityAuthorizationScope.READ);
    final int argCount = count.or(DEFAULT_ARGS_HISTORY_COUNT);
    List<SingularityTaskIdHistory> historiesToCheck = taskHistoryHelper.getBlendedHistory(new SingularityTaskHistoryQuery(Optional.of(requestId), Optional.<String>absent(), Optional.<String>absent(), Optional.<String>absent(), Optional.<ExtendedTaskState>absent(), Optional.<Long>absent(), Optional.<Long>absent(), Optional.<Long>absent(), Optional.<Long>absent(), Optional.<OrderDirection>absent()), 0, argCount);
    Collections.sort(historiesToCheck);
    Set<List<String>> args = new HashSet<>();
    for (SingularityTaskIdHistory taskIdHistory : historiesToCheck) {
        Optional<SingularityTask> maybeTask = taskHistoryHelper.getTask(taskIdHistory.getTaskId());
        if (maybeTask.isPresent() && maybeTask.get().getTaskRequest().getPendingTask().getCmdLineArgsList().isPresent()) {
            List<String> taskArgs = maybeTask.get().getTaskRequest().getPendingTask().getCmdLineArgsList().get();
            if (!taskArgs.isEmpty()) {
                args.add(maybeTask.get().getTaskRequest().getPendingTask().getCmdLineArgsList().get());
            }
        }
    }
    return args;
}
Also used : ExtendedTaskState(com.hubspot.singularity.ExtendedTaskState) SingularityTask(com.hubspot.singularity.SingularityTask) SingularityTaskHistoryQuery(com.hubspot.singularity.SingularityTaskHistoryQuery) List(java.util.List) SingularityTaskIdHistory(com.hubspot.singularity.SingularityTaskIdHistory) OrderDirection(com.hubspot.singularity.OrderDirection) HashSet(java.util.HashSet) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET) ApiOperation(com.wordnik.swagger.annotations.ApiOperation)

Aggregations

ExtendedTaskState (com.hubspot.singularity.ExtendedTaskState)1 OrderDirection (com.hubspot.singularity.OrderDirection)1 SingularityTask (com.hubspot.singularity.SingularityTask)1 SingularityTaskHistoryQuery (com.hubspot.singularity.SingularityTaskHistoryQuery)1 SingularityTaskIdHistory (com.hubspot.singularity.SingularityTaskIdHistory)1 ApiOperation (com.wordnik.swagger.annotations.ApiOperation)1 HashSet (java.util.HashSet)1 List (java.util.List)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1