Search in sources :

Example 6 with SingularityTaskIdHistory

use of com.hubspot.singularity.SingularityTaskIdHistory 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)

Example 7 with SingularityTaskIdHistory

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

the class HistoryResource method getTaskHistoryWithMetadata.

@GET
@Path("/tasks/withmetadata")
@ApiOperation("Retrieve the history sorted by startedAt for all inactive tasks.")
public SingularityPaginatedResponse<SingularityTaskIdHistory> getTaskHistoryWithMetadata(@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 Optional<Integer> dataCount = taskHistoryHelper.getBlendedHistoryCount(new SingularityTaskHistoryQuery(requestId, deployId, runId, host, lastTaskStatus, startedBefore, startedAfter, updatedBefore, updatedAfter, orderDirection));
    final int limitCount = getLimitCount(count);
    final List<SingularityTaskIdHistory> data = this.getTaskHistory(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)

Example 8 with SingularityTaskIdHistory

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

the class RequestHelper method fillDataForRequestsAndFilter.

public List<SingularityRequestParent> fillDataForRequestsAndFilter(List<SingularityRequestWithState> requests, SingularityUser user, boolean filterRelevantForUser, boolean includeFullRequestData, Optional<Integer> limit, List<RequestType> requestTypeFilters) {
    final Map<String, Optional<SingularityTaskIdHistory>> mostRecentTasks = new ConcurrentHashMap<>();
    final Map<String, SingularityRequestDeployState> deployStates = deployManager.getRequestDeployStatesByRequestIds(requests.stream().map((r) -> r.getRequest().getId()).collect(Collectors.toList()));
    final Map<String, Optional<SingularityRequestHistory>> requestIdToLastHistory;
    if (includeFullRequestData) {
        requestIdToLastHistory = requests.parallelStream().collect(Collectors.toMap((r) -> r.getRequest().getId(), (r) -> getMostRecentHistoryFromZk(r.getRequest().getId())));
    } else {
        requestIdToLastHistory = Collections.emptyMap();
    }
    Optional<SingularityUserSettings> maybeUserSettings = userManager.getUserSettings(user.getId());
    return requests.parallelStream().filter((request) -> {
        if (!requestTypeFilters.isEmpty() && !requestTypeFilters.contains(request.getRequest().getRequestType())) {
            return false;
        }
        if (!filterRelevantForUser || user.equals(SingularityUser.DEFAULT_USER)) {
            return true;
        }
        String requestId = request.getRequest().getId();
        if (maybeUserSettings.isPresent() && maybeUserSettings.get().getStarredRequestIds().contains(requestId)) {
            // This is a starred request for the user
            return true;
        }
        if (request.getRequest().getGroup().isPresent() && user.getGroups().contains(request.getRequest().getGroup().get())) {
            // The user is in the group for this request
            return true;
        }
        if (includeFullRequestData) {
            if (userModifiedRequestLast(requestIdToLastHistory.getOrDefault(requestId, Optional.absent()), user)) {
                return true;
            }
        }
        return userAssociatedWithDeploy(Optional.fromNullable(deployStates.get(requestId)), user);
    }).map((request) -> {
        Long lastActionTime = null;
        if (includeFullRequestData) {
            lastActionTime = getLastActionTimeForRequest(request.getRequest(), requestIdToLastHistory.getOrDefault(request.getRequest().getId(), Optional.absent()), Optional.fromNullable(deployStates.get(request.getRequest().getId())), mostRecentTasks.computeIfAbsent(request.getRequest().getId(), (id) -> getMostRecentTask(request.getRequest())));
        } else {
            // To save on zk calls, if not returning all data, use the most recent deploy timestamps
            Optional<SingularityRequestDeployState> deployState = Optional.fromNullable(deployStates.get(request.getRequest().getId()));
            if (deployState.isPresent()) {
                if (deployState.get().getPendingDeploy().isPresent()) {
                    lastActionTime = deployState.get().getPendingDeploy().get().getTimestamp();
                }
                if (deployState.get().getActiveDeploy().isPresent()) {
                    lastActionTime = deployState.get().getActiveDeploy().get().getTimestamp();
                }
            }
            if (lastActionTime == null) {
                lastActionTime = 0L;
            }
        }
        return new RequestParentWithLastActionTime(request, lastActionTime, maybeUserSettings.isPresent() && maybeUserSettings.get().getStarredRequestIds().contains(request.getRequest().getId()));
    }).sorted().limit(limit.or(requests.size())).map((parentWithActionTime) -> {
        SingularityRequestWithState requestWithState = parentWithActionTime.getRequestWithState();
        if (includeFullRequestData) {
            CompletableFuture<Optional<SingularityTaskIdsByStatus>> maybeTaskIdsByStatus = CompletableFuture.supplyAsync(() -> getTaskIdsByStatusForRequest(requestWithState)).exceptionally((throwable) -> Optional.absent());
            CompletableFuture<Optional<SingularityExpiringBounce>> maybeExpiringBounce = CompletableFuture.supplyAsync(() -> requestManager.getExpiringBounce(requestWithState.getRequest().getId())).exceptionally((throwable) -> Optional.absent());
            CompletableFuture<Optional<SingularityExpiringPause>> maybeExpiringPause = CompletableFuture.supplyAsync(() -> requestManager.getExpiringPause(requestWithState.getRequest().getId())).exceptionally((throwable) -> Optional.absent());
            CompletableFuture<Optional<SingularityExpiringScale>> maybeExpiringScale = CompletableFuture.supplyAsync(() -> requestManager.getExpiringScale(requestWithState.getRequest().getId())).exceptionally((throwable) -> Optional.absent());
            CompletableFuture<Optional<SingularityExpiringSkipHealthchecks>> maybeExpiringSkipHealthchecks = CompletableFuture.supplyAsync(() -> requestManager.getExpiringSkipHealthchecks(requestWithState.getRequest().getId())).exceptionally((throwable) -> Optional.absent());
            return new SingularityRequestParent(requestWithState.getRequest(), requestWithState.getState(), Optional.fromNullable(deployStates.get(requestWithState.getRequest().getId())), // full deploy data not provided
            Optional.absent(), // full deploy data not provided
            Optional.absent(), // full deploy data not provided
            Optional.absent(), maybeExpiringBounce.join(), maybeExpiringPause.join(), maybeExpiringScale.join(), maybeExpiringSkipHealthchecks.join(), maybeTaskIdsByStatus.join(), requestIdToLastHistory.getOrDefault(requestWithState.getRequest().getId(), Optional.absent()), mostRecentTasks.computeIfAbsent(requestWithState.getRequest().getId(), (id) -> getMostRecentTask(requestWithState.getRequest())));
        } else {
            return new SingularityRequestParent(requestWithState.getRequest(), requestWithState.getState(), Optional.fromNullable(deployStates.get(requestWithState.getRequest().getId())), Optional.absent(), Optional.absent(), Optional.absent(), Optional.absent(), Optional.absent(), Optional.absent(), Optional.absent(), Optional.absent(), Optional.absent(), Optional.absent());
        }
    }).collect(Collectors.toList());
}
Also used : DeployManager(com.hubspot.singularity.data.DeployManager) Inject(com.google.inject.Inject) SingularityRequestCleanup(com.hubspot.singularity.SingularityRequestCleanup) RequestManager(com.hubspot.singularity.data.RequestManager) LoggerFactory(org.slf4j.LoggerFactory) SingularityUserSettings(com.hubspot.singularity.SingularityUserSettings) SingularityExpiringScale(com.hubspot.singularity.expiring.SingularityExpiringScale) SingularityBounceRequest(com.hubspot.singularity.api.SingularityBounceRequest) RequestHistoryType(com.hubspot.singularity.SingularityRequestHistory.RequestHistoryType) SingularityExpiringBounce(com.hubspot.singularity.expiring.SingularityExpiringBounce) Optional(com.google.common.base.Optional) Map(java.util.Map) SingularityValidator(com.hubspot.singularity.data.SingularityValidator) TaskManager(com.hubspot.singularity.data.TaskManager) SingularityPendingTaskId(com.hubspot.singularity.SingularityPendingTaskId) SingularityTaskId(com.hubspot.singularity.SingularityTaskId) UserManager(com.hubspot.singularity.data.UserManager) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) SingularityExpiringSkipHealthchecks(com.hubspot.singularity.expiring.SingularityExpiringSkipHealthchecks) UUID(java.util.UUID) SingularityExpiringPause(com.hubspot.singularity.expiring.SingularityExpiringPause) Collectors(java.util.stream.Collectors) RequestState(com.hubspot.singularity.RequestState) PendingType(com.hubspot.singularity.SingularityPendingRequest.PendingType) List(java.util.List) JavaUtils(com.hubspot.mesos.JavaUtils) TaskHistoryHelper(com.hubspot.singularity.data.history.TaskHistoryHelper) RequestCleanupType(com.hubspot.singularity.RequestCleanupType) Singleton(com.google.inject.Singleton) SingularityCreateResult(com.hubspot.singularity.SingularityCreateResult) SingularityRequestWithState(com.hubspot.singularity.SingularityRequestWithState) SingularityTaskHistoryQuery(com.hubspot.singularity.SingularityTaskHistoryQuery) SingularityRequest(com.hubspot.singularity.SingularityRequest) SingularityTaskHistoryUpdate(com.hubspot.singularity.SingularityTaskHistoryUpdate) SingularityRequestHistory(com.hubspot.singularity.SingularityRequestHistory) SingularityTaskIdHistory(com.hubspot.singularity.SingularityTaskIdHistory) SingularityUser(com.hubspot.singularity.SingularityUser) SingularityPendingRequest(com.hubspot.singularity.SingularityPendingRequest) CompletableFuture(java.util.concurrent.CompletableFuture) SingularityTaskIdsByStatus(com.hubspot.singularity.SingularityTaskIdsByStatus) ArrayList(java.util.ArrayList) RequestType(com.hubspot.singularity.RequestType) SingularityDeployHealthHelper(com.hubspot.singularity.scheduler.SingularityDeployHealthHelper) Logger(org.slf4j.Logger) SingularityDeploy(com.hubspot.singularity.SingularityDeploy) SingularityPendingDeploy(com.hubspot.singularity.SingularityPendingDeploy) SingularityMailer(com.hubspot.singularity.smtp.SingularityMailer) SingularityRequestDeployState(com.hubspot.singularity.SingularityRequestDeployState) SingularityRequestParent(com.hubspot.singularity.SingularityRequestParent) Collections(java.util.Collections) Optional(com.google.common.base.Optional) SingularityRequestDeployState(com.hubspot.singularity.SingularityRequestDeployState) SingularityExpiringScale(com.hubspot.singularity.expiring.SingularityExpiringScale) SingularityRequestParent(com.hubspot.singularity.SingularityRequestParent) SingularityUserSettings(com.hubspot.singularity.SingularityUserSettings) CompletableFuture(java.util.concurrent.CompletableFuture) SingularityExpiringSkipHealthchecks(com.hubspot.singularity.expiring.SingularityExpiringSkipHealthchecks) SingularityExpiringPause(com.hubspot.singularity.expiring.SingularityExpiringPause) SingularityExpiringBounce(com.hubspot.singularity.expiring.SingularityExpiringBounce) SingularityRequestWithState(com.hubspot.singularity.SingularityRequestWithState) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) SingularityTaskIdsByStatus(com.hubspot.singularity.SingularityTaskIdsByStatus)

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