use of com.hubspot.singularity.SingularityTaskIdHistory 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.SingularityTaskIdHistory in project Singularity by HubSpot.
the class BlendedHistoryHelper method getTaskHistoriesFor.
public List<SingularityTaskIdHistory> getTaskHistoriesFor(TaskManager taskManager, Collection<SingularityTaskId> taskIds) {
Map<SingularityTaskId, SingularityTask> tasks = taskManager.getTasks(taskIds);
Map<SingularityTaskId, List<SingularityTaskHistoryUpdate>> map = taskManager.getTaskHistoryUpdates(taskIds);
List<SingularityTaskIdHistory> histories = Lists.newArrayListWithCapacity(taskIds.size());
for (SingularityTaskId taskId : taskIds) {
List<SingularityTaskHistoryUpdate> historyUpdates = map.get(taskId);
SingularityTask task = tasks.get(taskId);
if (task != null) {
histories.add(SingularityTaskIdHistory.fromTaskIdAndTaskAndUpdates(taskId, task, historyUpdates));
}
}
Collections.sort(histories);
return histories;
}
use of com.hubspot.singularity.SingularityTaskIdHistory in project Singularity by HubSpot.
the class JDBIHistoryManager method saveTaskHistory.
@Override
public void saveTaskHistory(SingularityTaskHistory taskHistory) {
if (history.getTaskHistoryForTask(taskHistory.getTask().getTaskId().getId()) != null) {
return;
}
SingularityTaskIdHistory taskIdHistory = SingularityTaskIdHistory.fromTaskIdAndTaskAndUpdates(taskHistory.getTask().getTaskId(), taskHistory.getTask(), taskHistory.getTaskUpdates());
String lastTaskStatus = null;
if (taskIdHistory.getLastTaskState().isPresent()) {
lastTaskStatus = taskIdHistory.getLastTaskState().get().name();
}
history.insertTaskHistory(taskIdHistory.getTaskId().getRequestId(), taskIdHistory.getTaskId().getId(), taskHistoryTranscoder.toBytes(taskHistory), new Date(taskIdHistory.getUpdatedAt()), lastTaskStatus, taskHistory.getTask().getTaskRequest().getPendingTask().getRunId().orNull(), taskIdHistory.getTaskId().getDeployId(), taskIdHistory.getTaskId().getHost(), new Date(taskIdHistory.getTaskId().getStartedAt()));
}
use of com.hubspot.singularity.SingularityTaskIdHistory in project Singularity by HubSpot.
the class HistoryResource method getInactiveDeployTasksWithMetadata.
@GET
@Path("/request/{requestId}/deploy/{deployId}/tasks/inactive/withmetadata")
@ApiOperation("Retrieve the task history for a specific deploy.")
public SingularityPaginatedResponse<SingularityTaskIdHistory> getInactiveDeployTasksWithMetadata(@Auth SingularityUser user, @ApiParam("Request ID for deploy") @PathParam("requestId") String requestId, @ApiParam("Deploy ID") @PathParam("deployId") String deployId, @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);
SingularityDeployKey key = new SingularityDeployKey(requestId, deployId);
Optional<Integer> dataCount = deployTaskHistoryHelper.getBlendedHistoryCount(key);
final Integer limitCount = getLimitCount(count);
final Integer limitStart = getLimitStart(limitCount, page);
final List<SingularityTaskIdHistory> data = deployTaskHistoryHelper.getBlendedHistory(key, limitStart, limitCount);
Optional<Integer> pageCount = getPageCount(dataCount, limitCount);
return new SingularityPaginatedResponse<>(dataCount, pageCount, Optional.fromNullable(page), data);
}
use of com.hubspot.singularity.SingularityTaskIdHistory 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);
}
Aggregations