use of com.hubspot.singularity.SingularityTaskHistoryQuery in project Singularity by HubSpot.
the class RequestHelper method getMostRecentTask.
public Optional<SingularityTaskIdHistory> getMostRecentTask(SingularityRequest request) {
List<SingularityTaskId> activeTaskIds = taskManager.getActiveTaskIdsForRequest(request.getId());
if (!activeTaskIds.isEmpty()) {
SingularityTaskId lastTaskId = activeTaskIds.get(0);
List<SingularityTaskHistoryUpdate> historyUpdates = taskManager.getTaskHistoryUpdates(lastTaskId);
if (!historyUpdates.isEmpty()) {
SingularityTaskHistoryUpdate lastUpdate = historyUpdates.get(historyUpdates.size() - 1);
return Optional.of(new SingularityTaskIdHistory(lastTaskId, lastUpdate.getTimestamp(), Optional.of(lastUpdate.getTaskState()), // runId not currently provided here, grabbing the full task data for this is a more expensive call
Optional.absent()));
}
}
List<SingularityTaskIdHistory> maybeRecentTasks = taskHistoryHelper.getBlendedHistory(new SingularityTaskHistoryQuery(request.getId()), 0, 1);
if (!maybeRecentTasks.isEmpty()) {
return Optional.of(maybeRecentTasks.get(0));
}
return Optional.absent();
}
use of com.hubspot.singularity.SingularityTaskHistoryQuery in project Singularity by HubSpot.
the class HistoryResource method getTaskHistory.
@GET
@Path("/tasks")
@ApiOperation("Retrieve the history sorted by startedAt for all inactive tasks.")
public List<SingularityTaskIdHistory> getTaskHistory(@Auth SingularityUser user, @ApiParam("Optional Request ID to match") @QueryParam("requestId") Optional<String> requestId, @ApiParam("Optional deploy ID to match") @QueryParam("deployId") Optional<String> deployId, @ApiParam("Optional runId to match") @QueryParam("runId") Optional<String> runId, @ApiParam("Optional host to match") @QueryParam("host") Optional<String> host, @ApiParam("Optional last task status to match") @QueryParam("lastTaskStatus") Optional<ExtendedTaskState> lastTaskStatus, @ApiParam("Optionally match only tasks started before") @QueryParam("startedBefore") Optional<Long> startedBefore, @ApiParam("Optionally match only tasks started after") @QueryParam("startedAfter") Optional<Long> startedAfter, @ApiParam("Optionally match tasks last updated before") @QueryParam("updatedBefore") Optional<Long> updatedBefore, @ApiParam("Optionally match tasks last updated after") @QueryParam("updatedAfter") Optional<Long> updatedAfter, @ApiParam("Sort direction") @QueryParam("orderDirection") Optional<OrderDirection> orderDirection, @ApiParam("Maximum number of items to return") @QueryParam("count") Integer count, @ApiParam("Which page of items to view") @QueryParam("page") Integer page) {
if (requestId.isPresent()) {
authorizationHelper.checkForAuthorizationByRequestId(requestId.get(), user, SingularityAuthorizationScope.READ);
} else {
authorizationHelper.checkAdminAuthorization(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);
}
use of com.hubspot.singularity.SingularityTaskHistoryQuery in project Singularity by HubSpot.
the class HistoryResource method getTaskHistoryForRequestWithMetadata.
@GET
@Path("/request/{requestId}/tasks/withmetadata")
@ApiOperation("Retrieve the history count for all inactive tasks of a specific request.")
public SingularityPaginatedResponse<SingularityTaskIdHistory> getTaskHistoryForRequestWithMetadata(@Auth SingularityUser user, @ApiParam("Request ID to match") @PathParam("requestId") String requestId, @ApiParam("Optional deploy ID to match") @QueryParam("deployId") Optional<String> deployId, @ApiParam("Optional runId to match") @QueryParam("runId") Optional<String> runId, @ApiParam("Optional host to match") @QueryParam("host") Optional<String> host, @ApiParam("Optional last task status to match") @QueryParam("lastTaskStatus") Optional<ExtendedTaskState> lastTaskStatus, @ApiParam("Optionally match only tasks started before") @QueryParam("startedBefore") Optional<Long> startedBefore, @ApiParam("Optionally match only tasks started after") @QueryParam("startedAfter") Optional<Long> startedAfter, @ApiParam("Optionally match tasks last updated before") @QueryParam("updatedBefore") Optional<Long> updatedBefore, @ApiParam("Optionally match tasks last updated after") @QueryParam("updatedAfter") Optional<Long> updatedAfter, @ApiParam("Sort direction") @QueryParam("orderDirection") Optional<OrderDirection> orderDirection, @ApiParam("Maximum number of items to return") @QueryParam("count") Integer count, @ApiParam("Which page of items to view") @QueryParam("page") Integer page) {
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));
final int limitCount = getLimitCount(count);
final List<SingularityTaskIdHistory> data = this.getTaskHistoryForRequest(user, requestId, deployId, runId, host, lastTaskStatus, startedBefore, startedAfter, updatedBefore, updatedAfter, orderDirection, count, page);
final Optional<Integer> pageCount = getPageCount(dataCount, limitCount);
return new SingularityPaginatedResponse<>(dataCount, pageCount, Optional.fromNullable(page), data);
}
use of com.hubspot.singularity.SingularityTaskHistoryQuery in project Singularity by HubSpot.
the class HistoryResource method getTaskHistoryForRequest.
@GET
@Path("/request/{requestId}/tasks")
@ApiOperation("Retrieve the history sorted by startedAt for all inactive tasks of a specific request.")
public List<SingularityTaskIdHistory> getTaskHistoryForRequest(@Auth SingularityUser user, @ApiParam("Request ID to match") @PathParam("requestId") String requestId, @ApiParam("Optional deploy ID to match") @QueryParam("deployId") Optional<String> deployId, @ApiParam("Optional runId to match") @QueryParam("runId") Optional<String> runId, @ApiParam("Optional host to match") @QueryParam("host") Optional<String> host, @ApiParam("Optional last task status to match") @QueryParam("lastTaskStatus") Optional<ExtendedTaskState> lastTaskStatus, @ApiParam("Optionally match only tasks started before") @QueryParam("startedBefore") Optional<Long> startedBefore, @ApiParam("Optionally match only tasks started after") @QueryParam("startedAfter") Optional<Long> startedAfter, @ApiParam("Optionally match tasks last updated before") @QueryParam("updatedBefore") Optional<Long> updatedBefore, @ApiParam("Optionally match tasks last updated after") @QueryParam("updatedAfter") Optional<Long> updatedAfter, @ApiParam("Sort direction") @QueryParam("orderDirection") Optional<OrderDirection> orderDirection, @ApiParam("Maximum number of items to return") @QueryParam("count") Integer count, @ApiParam("Which page of items to view") @QueryParam("page") Integer page) {
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);
}
use of com.hubspot.singularity.SingularityTaskHistoryQuery 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;
}
Aggregations