Search in sources :

Example 1 with SingularityTaskIdHistory

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();
}
Also used : SingularityTaskHistoryUpdate(com.hubspot.singularity.SingularityTaskHistoryUpdate) SingularityTaskHistoryQuery(com.hubspot.singularity.SingularityTaskHistoryQuery) SingularityTaskId(com.hubspot.singularity.SingularityTaskId) SingularityTaskIdHistory(com.hubspot.singularity.SingularityTaskIdHistory)

Example 2 with SingularityTaskIdHistory

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;
}
Also used : SingularityTask(com.hubspot.singularity.SingularityTask) SingularityTaskHistoryUpdate(com.hubspot.singularity.SingularityTaskHistoryUpdate) ArrayList(java.util.ArrayList) List(java.util.List) SingularityTaskId(com.hubspot.singularity.SingularityTaskId) SingularityTaskIdHistory(com.hubspot.singularity.SingularityTaskIdHistory)

Example 3 with SingularityTaskIdHistory

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()));
}
Also used : SingularityTaskIdHistory(com.hubspot.singularity.SingularityTaskIdHistory) Date(java.util.Date)

Example 4 with SingularityTaskIdHistory

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);
}
Also used : SingularityDeployKey(com.hubspot.singularity.SingularityDeployKey) SingularityTaskIdHistory(com.hubspot.singularity.SingularityTaskIdHistory) SingularityPaginatedResponse(com.hubspot.singularity.SingularityPaginatedResponse) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET) ApiOperation(com.wordnik.swagger.annotations.ApiOperation)

Example 5 with SingularityTaskIdHistory

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);
}
Also used : SingularityTaskHistoryQuery(com.hubspot.singularity.SingularityTaskHistoryQuery) SingularityTaskIdHistory(com.hubspot.singularity.SingularityTaskIdHistory) SingularityPaginatedResponse(com.hubspot.singularity.SingularityPaginatedResponse) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET) ApiOperation(com.wordnik.swagger.annotations.ApiOperation)

Aggregations

SingularityTaskIdHistory (com.hubspot.singularity.SingularityTaskIdHistory)8 SingularityTaskHistoryQuery (com.hubspot.singularity.SingularityTaskHistoryQuery)5 ApiOperation (com.wordnik.swagger.annotations.ApiOperation)4 GET (javax.ws.rs.GET)4 Path (javax.ws.rs.Path)4 SingularityPaginatedResponse (com.hubspot.singularity.SingularityPaginatedResponse)3 SingularityTaskHistoryUpdate (com.hubspot.singularity.SingularityTaskHistoryUpdate)3 SingularityTaskId (com.hubspot.singularity.SingularityTaskId)3 List (java.util.List)3 SingularityTask (com.hubspot.singularity.SingularityTask)2 Optional (com.google.common.base.Optional)1 Inject (com.google.inject.Inject)1 Singleton (com.google.inject.Singleton)1 JavaUtils (com.hubspot.mesos.JavaUtils)1 ExtendedTaskState (com.hubspot.singularity.ExtendedTaskState)1 OrderDirection (com.hubspot.singularity.OrderDirection)1 RequestCleanupType (com.hubspot.singularity.RequestCleanupType)1 RequestState (com.hubspot.singularity.RequestState)1 RequestType (com.hubspot.singularity.RequestType)1 SingularityCreateResult (com.hubspot.singularity.SingularityCreateResult)1