Search in sources :

Example 1 with ExtendedTaskState

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

the class SingularityHistoryPurger method purge.

private void purge(String requestId, long start, Optional<Integer> afterTasksPerRequest, Optional<Integer> afterDays, boolean deleteRow) {
    Optional<Date> purgeBefore = Optional.absent();
    Date checkBefore = new Date();
    if (afterDays.isPresent()) {
        purgeBefore = Optional.of(new Date(start - TimeUnit.DAYS.toMillis(afterDays.get().longValue())));
        if (!afterTasksPerRequest.isPresent()) {
            checkBefore = purgeBefore.get();
        }
    }
    LOG.info("Finding taskHistory counts before {} (purging tasks over limit of {} or created before {}) for request {}", checkBefore, afterTasksPerRequest, purgeBefore, requestId);
    int unpurgedCount;
    if (deleteRow) {
        unpurgedCount = historyManager.getTaskIdHistoryCount(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());
    } else {
        unpurgedCount = historyManager.getUnpurgedTaskHistoryCountByRequestBefore(requestId, checkBefore);
    }
    if (!afterDays.isPresent() && afterTasksPerRequest.isPresent() && unpurgedCount < afterTasksPerRequest.get()) {
        LOG.debug("Not purging old taskHistory for {} - {} count is less than {}", requestId, unpurgedCount, afterTasksPerRequest.get());
        return;
    }
    final long startRequestId = System.currentTimeMillis();
    historyManager.purgeTaskHistory(requestId, unpurgedCount, afterTasksPerRequest, purgeBefore, deleteRow, historyPurgingConfiguration.getPurgeLimitPerQuery());
    LOG.info("Purged old taskHistory for {} ({} count) in {} (deleteRows: {})", requestId, unpurgedCount, JavaUtils.duration(startRequestId), deleteRow);
}
Also used : ExtendedTaskState(com.hubspot.singularity.ExtendedTaskState) Date(java.util.Date)

Example 2 with ExtendedTaskState

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

the class SingularityMesosStatusUpdateHandler method unsafeProcessStatusUpdate.

private void unsafeProcessStatusUpdate(Protos.TaskStatus status, SingularityTaskId taskIdObj) {
    final String taskId = status.getTaskId().getValue();
    long timestamp = System.currentTimeMillis();
    if (status.hasTimestamp()) {
        timestamp = (long) (status.getTimestamp() * 1000);
    }
    long now = System.currentTimeMillis();
    long delta = now - timestamp;
    LOG.debug("Update: task {} is now {} ({}) at {} (delta: {})", taskId, status.getState(), status.getMessage(), timestamp, JavaUtils.durationFromMillis(delta));
    statusUpdateDeltas.put(now, delta);
    final SingularityTaskStatusHolder newTaskStatusHolder = new SingularityTaskStatusHolder(taskIdObj, Optional.of(mesosProtosUtils.taskStatusFromProtos(status)), System.currentTimeMillis(), serverId, Optional.<String>absent());
    final Optional<SingularityTaskStatusHolder> previousTaskStatusHolder = taskManager.getLastActiveTaskStatus(taskIdObj);
    final ExtendedTaskState taskState = MesosUtils.fromTaskState(status.getState());
    if (isDuplicateOrIgnorableStatusUpdate(previousTaskStatusHolder, newTaskStatusHolder)) {
        LOG.trace("Ignoring status update {} to {}", taskState, taskIdObj);
        saveNewTaskStatusHolder(taskIdObj, newTaskStatusHolder, taskState);
        return;
    }
    if (status.getState() == TaskState.TASK_LOST) {
        lostTasksMeter.mark();
        if (configuration.getDisasterDetection().isEnabled()) {
            taskLostReasons.add(status.getReason());
        }
    }
    final Optional<SingularityTask> task = taskManager.getTask(taskIdObj);
    final boolean isActiveTask = taskManager.isActiveTask(taskId);
    if (isActiveTask && !taskState.isDone()) {
        if (task.isPresent()) {
            final Optional<SingularityPendingDeploy> pendingDeploy = deployManager.getPendingDeploy(taskIdObj.getRequestId());
            Optional<SingularityRequestWithState> requestWithState = Optional.absent();
            if (taskState == ExtendedTaskState.TASK_RUNNING) {
                requestWithState = requestManager.getRequest(taskIdObj.getRequestId());
                healthchecker.enqueueHealthcheck(task.get(), pendingDeploy, requestWithState);
            }
            if (!pendingDeploy.isPresent() || !pendingDeploy.get().getDeployMarker().getDeployId().equals(taskIdObj.getDeployId())) {
                if (!requestWithState.isPresent()) {
                    requestWithState = requestManager.getRequest(taskIdObj.getRequestId());
                }
                newTaskChecker.enqueueNewTaskCheck(task.get(), requestWithState, healthchecker);
            }
        } else {
            final String message = String.format("Task %s is active but is missing task data", taskId);
            exceptionNotifier.notify(message);
            LOG.error(message);
        }
    }
    final Optional<String> statusMessage = getStatusMessage(status, task);
    final SingularityTaskHistoryUpdate taskUpdate = new SingularityTaskHistoryUpdate(taskIdObj, timestamp, taskState, statusMessage, status.hasReason() ? Optional.of(status.getReason().name()) : Optional.<String>absent());
    final SingularityCreateResult taskHistoryUpdateCreateResult = taskManager.saveTaskHistoryUpdate(taskUpdate);
    logSupport.checkDirectoryAndContainerId(taskIdObj);
    if (taskState.isDone()) {
        healthchecker.cancelHealthcheck(taskId);
        newTaskChecker.cancelNewTaskCheck(taskId);
        taskManager.deleteKilledRecord(taskIdObj);
        slaveAndRackManager.checkStateAfterFinishedTask(taskIdObj, status.getAgentId().getValue(), leaderCache);
        scheduler.handleCompletedTask(task, taskIdObj, isActiveTask, timestamp, taskState, taskHistoryUpdateCreateResult, status);
    }
    saveNewTaskStatusHolder(taskIdObj, newTaskStatusHolder, taskState);
}
Also used : SingularityCreateResult(com.hubspot.singularity.SingularityCreateResult) ExtendedTaskState(com.hubspot.singularity.ExtendedTaskState) SingularityTask(com.hubspot.singularity.SingularityTask) SingularityTaskHistoryUpdate(com.hubspot.singularity.SingularityTaskHistoryUpdate) SingularityPendingDeploy(com.hubspot.singularity.SingularityPendingDeploy) SingularityRequestWithState(com.hubspot.singularity.SingularityRequestWithState) SingularityTaskStatusHolder(com.hubspot.singularity.SingularityTaskStatusHolder)

Example 3 with ExtendedTaskState

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

the class MesosUtils method fromTaskState.

public static ExtendedTaskState fromTaskState(TaskState taskState) {
    ExtendedTaskState extendedTaskState = map.get(taskState);
    Preconditions.checkArgument(extendedTaskState != null, "No ExtendedTaskState for TaskState %s", taskState);
    return extendedTaskState;
}
Also used : ExtendedTaskState(com.hubspot.singularity.ExtendedTaskState)

Example 4 with ExtendedTaskState

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

the class SingularityExecutorTask method cleanup.

public void cleanup(TaskState state) {
    ExtendedTaskState extendedTaskState = MesosUtils.fromTaskState(org.apache.mesos.v1.Protos.TaskState.valueOf(state.toString()));
    boolean cleanupAppTaskDirectory = !extendedTaskState.isFailed() && !taskDefinition.getExecutorData().getPreserveTaskSandboxAfterFinish().or(Boolean.FALSE);
    boolean isDocker = (taskInfo.hasContainer() && taskInfo.getContainer().hasDocker());
    taskCleanup.cleanup(cleanupAppTaskDirectory, isDocker);
}
Also used : ExtendedTaskState(com.hubspot.singularity.ExtendedTaskState)

Example 5 with ExtendedTaskState

use of com.hubspot.singularity.ExtendedTaskState 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)6 SingularityTask (com.hubspot.singularity.SingularityTask)2 OrderDirection (com.hubspot.singularity.OrderDirection)1 SingularityCreateResult (com.hubspot.singularity.SingularityCreateResult)1 SingularityPendingDeploy (com.hubspot.singularity.SingularityPendingDeploy)1 SingularityRequestWithState (com.hubspot.singularity.SingularityRequestWithState)1 SingularityTaskHistoryQuery (com.hubspot.singularity.SingularityTaskHistoryQuery)1 SingularityTaskHistoryUpdate (com.hubspot.singularity.SingularityTaskHistoryUpdate)1 SingularityTaskIdHistory (com.hubspot.singularity.SingularityTaskIdHistory)1 SingularityTaskStatusHolder (com.hubspot.singularity.SingularityTaskStatusHolder)1 ApiOperation (com.wordnik.swagger.annotations.ApiOperation)1 Date (java.util.Date)1 HashSet (java.util.HashSet)1 List (java.util.List)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1