Search in sources :

Example 1 with SimplifiedTaskState

use of com.hubspot.singularity.SingularityTaskHistoryUpdate.SimplifiedTaskState in project Singularity by HubSpot.

the class SingularitySchedulerTestBase method runLaunchedTasks.

protected void runLaunchedTasks() {
    for (SingularityTaskId taskId : taskManager.getActiveTaskIds()) {
        Collection<SingularityTaskHistoryUpdate> updates = taskManager.getTaskHistoryUpdates(taskId);
        SimplifiedTaskState currentState = SingularityTaskHistoryUpdate.getCurrentState(updates);
        switch(currentState) {
            case UNKNOWN:
            case WAITING:
                statusUpdate(taskManager.getTask(taskId).get(), TaskState.TASK_RUNNING);
                break;
            case DONE:
            case RUNNING:
                break;
        }
    }
}
Also used : SingularityTaskHistoryUpdate(com.hubspot.singularity.SingularityTaskHistoryUpdate) SimplifiedTaskState(com.hubspot.singularity.SingularityTaskHistoryUpdate.SimplifiedTaskState) SingularityTaskId(com.hubspot.singularity.SingularityTaskId)

Example 2 with SimplifiedTaskState

use of com.hubspot.singularity.SingularityTaskHistoryUpdate.SimplifiedTaskState in project Singularity by HubSpot.

the class SingularityDeployHealthHelper method getNoHealthcheckDeployHealth.

private DeployHealth getNoHealthcheckDeployHealth(final Optional<SingularityDeploy> deploy, final Collection<SingularityTaskId> matchingActiveTasks) {
    final Map<SingularityTaskId, List<SingularityTaskHistoryUpdate>> taskUpdates = taskManager.getTaskHistoryUpdates(matchingActiveTasks);
    for (SingularityTaskId taskId : matchingActiveTasks) {
        Collection<SingularityTaskHistoryUpdate> updates = taskUpdates.get(taskId);
        SimplifiedTaskState currentState = SingularityTaskHistoryUpdate.getCurrentState(updates);
        switch(currentState) {
            case UNKNOWN:
            case WAITING:
                return DeployHealth.WAITING;
            case DONE:
                LOG.warn("Unexpectedly found an active task ({}) in done state: {}}", taskId, updates);
                return DeployHealth.UNHEALTHY;
            case RUNNING:
                if (!isRunningTaskHealthy(deploy, updates, taskId)) {
                    return DeployHealth.WAITING;
                }
        }
    }
    return DeployHealth.HEALTHY;
}
Also used : SingularityTaskHistoryUpdate(com.hubspot.singularity.SingularityTaskHistoryUpdate) ArrayList(java.util.ArrayList) List(java.util.List) SimplifiedTaskState(com.hubspot.singularity.SingularityTaskHistoryUpdate.SimplifiedTaskState) SingularityTaskId(com.hubspot.singularity.SingularityTaskId)

Example 3 with SimplifiedTaskState

use of com.hubspot.singularity.SingularityTaskHistoryUpdate.SimplifiedTaskState in project Singularity by HubSpot.

the class S3LogResource method getS3PrefixesForTask.

// Generation of prefixes
private Collection<String> getS3PrefixesForTask(S3Configuration s3Configuration, SingularityTaskId taskId, Optional<Long> startArg, Optional<Long> endArg, String group, SingularityUser user) {
    Optional<SingularityTaskHistory> history = getTaskHistory(taskId, user);
    long start = taskId.getStartedAt();
    if (startArg.isPresent()) {
        start = Math.max(startArg.get(), start);
    }
    long end = start + s3Configuration.getMissingTaskDefaultS3SearchPeriodMillis();
    if (history.isPresent()) {
        SimplifiedTaskState taskState = SingularityTaskHistoryUpdate.getCurrentState(history.get().getTaskUpdates());
        if (taskState == SimplifiedTaskState.DONE) {
            end = Iterables.getLast(history.get().getTaskUpdates()).getTimestamp();
        } else {
            end = System.currentTimeMillis();
        }
    }
    if (endArg.isPresent()) {
        end = Math.min(endArg.get(), end);
    }
    Optional<String> tag = Optional.absent();
    if (history.isPresent() && history.get().getTask().getTaskRequest().getDeploy().getExecutorData().isPresent()) {
        tag = history.get().getTask().getTaskRequest().getDeploy().getExecutorData().get().getLoggingTag();
    }
    Collection<String> prefixes = SingularityS3FormatHelper.getS3KeyPrefixes(s3Configuration.getS3KeyFormat(), taskId, tag, start, end, group);
    for (SingularityS3UploaderFile additionalFile : s3Configuration.getS3UploaderAdditionalFiles()) {
        if (additionalFile.getS3UploaderKeyPattern().isPresent() && !additionalFile.getS3UploaderKeyPattern().get().equals(s3Configuration.getS3KeyFormat())) {
            prefixes.addAll(SingularityS3FormatHelper.getS3KeyPrefixes(additionalFile.getS3UploaderKeyPattern().get(), taskId, tag, start, end, group));
        }
    }
    LOG.trace("Task {} got S3 prefixes {} for start {}, end {}, tag {}", taskId, prefixes, start, end, tag);
    return prefixes;
}
Also used : SingularityTaskHistory(com.hubspot.singularity.SingularityTaskHistory) SimplifiedTaskState(com.hubspot.singularity.SingularityTaskHistoryUpdate.SimplifiedTaskState) SingularityS3UploaderFile(com.hubspot.singularity.SingularityS3UploaderFile)

Example 4 with SimplifiedTaskState

use of com.hubspot.singularity.SingularityTaskHistoryUpdate.SimplifiedTaskState in project Singularity by HubSpot.

the class SingularityNewTaskChecker method getTaskState.

@VisibleForTesting
CheckTaskState getTaskState(SingularityTask task, Optional<SingularityRequestWithState> requestWithState, SingularityHealthchecker healthchecker) {
    if (!taskManager.isActiveTask(task.getTaskId().getId())) {
        return CheckTaskState.OBSOLETE;
    }
    SimplifiedTaskState taskState = SingularityTaskHistoryUpdate.getCurrentState(taskManager.getTaskHistoryUpdates(task.getTaskId()));
    switch(taskState) {
        case DONE:
            return CheckTaskState.OBSOLETE;
        case WAITING:
        case UNKNOWN:
            return CheckTaskState.CHECK_IF_TASK_OVERDUE;
        case RUNNING:
            break;
    }
    if (hasHealthcheck(task, requestWithState)) {
        Optional<SingularityTaskHealthcheckResult> maybeHealthCheck = taskManager.getLastHealthcheck(task.getTaskId());
        DeployHealth health = deployHealthHelper.getTaskHealth(task.getTaskRequest().getDeploy(), false, maybeHealthCheck, task.getTaskId());
        switch(health) {
            case WAITING:
                healthchecker.checkHealthcheck(task);
                return CheckTaskState.CHECK_IF_HEALTHCHECK_OVERDUE;
            case UNHEALTHY:
                taskManager.clearStartupHealthchecks(task.getTaskId());
                return CheckTaskState.UNHEALTHY_KILL_TASK;
            case HEALTHY:
                taskManager.clearStartupHealthchecks(task.getTaskId());
                break;
        }
    }
    // task is running + has succeeded healthcheck if available.
    if (!task.getTaskRequest().getRequest().isLoadBalanced()) {
        return CheckTaskState.HEALTHY;
    }
    Optional<SingularityLoadBalancerUpdate> lbUpdate = taskManager.getLoadBalancerState(task.getTaskId(), LoadBalancerRequestType.ADD);
    SingularityLoadBalancerUpdate newLbUpdate;
    final LoadBalancerRequestId loadBalancerRequestId = new LoadBalancerRequestId(task.getTaskId().getId(), LoadBalancerRequestType.ADD, Optional.absent());
    boolean taskCleaning = taskManager.getCleanupTaskIds().contains(task.getTaskId());
    if ((!lbUpdate.isPresent() || unknownNotRemoving(lbUpdate.get())) && !taskCleaning) {
        taskManager.saveLoadBalancerState(task.getTaskId(), LoadBalancerRequestType.ADD, new SingularityLoadBalancerUpdate(BaragonRequestState.UNKNOWN, loadBalancerRequestId, Optional.absent(), System.currentTimeMillis(), LoadBalancerMethod.PRE_ENQUEUE, Optional.absent()));
        newLbUpdate = lbClient.enqueue(loadBalancerRequestId, task.getTaskRequest().getRequest(), task.getTaskRequest().getDeploy(), Collections.singletonList(task), Collections.emptyList());
    } else {
        Optional<CheckTaskState> maybeCheckTaskState = checkLbState(lbUpdate.get().getLoadBalancerState());
        if (maybeCheckTaskState.isPresent()) {
            return maybeCheckTaskState.get();
        }
        newLbUpdate = lbClient.getState(loadBalancerRequestId);
    }
    taskManager.saveLoadBalancerState(task.getTaskId(), LoadBalancerRequestType.ADD, newLbUpdate);
    Optional<CheckTaskState> maybeCheckTaskState = checkLbState(newLbUpdate.getLoadBalancerState());
    if (maybeCheckTaskState.isPresent()) {
        return maybeCheckTaskState.get();
    }
    return CheckTaskState.LB_IN_PROGRESS_CHECK_AGAIN;
}
Also used : SingularityLoadBalancerUpdate(com.hubspot.singularity.SingularityLoadBalancerUpdate) SingularityTaskHealthcheckResult(com.hubspot.singularity.SingularityTaskHealthcheckResult) LoadBalancerRequestId(com.hubspot.singularity.LoadBalancerRequestType.LoadBalancerRequestId) SimplifiedTaskState(com.hubspot.singularity.SingularityTaskHistoryUpdate.SimplifiedTaskState) DeployHealth(com.hubspot.singularity.scheduler.SingularityDeployHealthHelper.DeployHealth) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 5 with SimplifiedTaskState

use of com.hubspot.singularity.SingularityTaskHistoryUpdate.SimplifiedTaskState in project Singularity by HubSpot.

the class SingularityDeployHealthHelper method getNoHealthcheckHealthyTasks.

private List<SingularityTaskId> getNoHealthcheckHealthyTasks(final Optional<SingularityDeploy> deploy, final Collection<SingularityTaskId> matchingActiveTasks) {
    final Map<SingularityTaskId, List<SingularityTaskHistoryUpdate>> taskUpdates = taskManager.getTaskHistoryUpdates(matchingActiveTasks);
    final List<SingularityTaskId> healthyTaskIds = Lists.newArrayListWithCapacity(matchingActiveTasks.size());
    for (SingularityTaskId taskId : matchingActiveTasks) {
        Collection<SingularityTaskHistoryUpdate> updates = taskUpdates.get(taskId);
        SimplifiedTaskState currentState = SingularityTaskHistoryUpdate.getCurrentState(updates);
        if (currentState == SimplifiedTaskState.RUNNING && isRunningTaskHealthy(deploy, updates, taskId)) {
            healthyTaskIds.add(taskId);
        }
    }
    return healthyTaskIds;
}
Also used : SingularityTaskHistoryUpdate(com.hubspot.singularity.SingularityTaskHistoryUpdate) ArrayList(java.util.ArrayList) List(java.util.List) SimplifiedTaskState(com.hubspot.singularity.SingularityTaskHistoryUpdate.SimplifiedTaskState) SingularityTaskId(com.hubspot.singularity.SingularityTaskId)

Aggregations

SimplifiedTaskState (com.hubspot.singularity.SingularityTaskHistoryUpdate.SimplifiedTaskState)6 SingularityTaskId (com.hubspot.singularity.SingularityTaskId)4 SingularityTaskHistoryUpdate (com.hubspot.singularity.SingularityTaskHistoryUpdate)3 List (java.util.List)3 ArrayList (java.util.ArrayList)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 LoadBalancerRequestId (com.hubspot.singularity.LoadBalancerRequestType.LoadBalancerRequestId)1 SingularityDeployKey (com.hubspot.singularity.SingularityDeployKey)1 SingularityLoadBalancerUpdate (com.hubspot.singularity.SingularityLoadBalancerUpdate)1 SingularityPendingDeploy (com.hubspot.singularity.SingularityPendingDeploy)1 SingularityRequestWithState (com.hubspot.singularity.SingularityRequestWithState)1 SingularityS3UploaderFile (com.hubspot.singularity.SingularityS3UploaderFile)1 SingularityTask (com.hubspot.singularity.SingularityTask)1 SingularityTaskHealthcheckResult (com.hubspot.singularity.SingularityTaskHealthcheckResult)1 SingularityTaskHistory (com.hubspot.singularity.SingularityTaskHistory)1 DeployHealth (com.hubspot.singularity.scheduler.SingularityDeployHealthHelper.DeployHealth)1 Map (java.util.Map)1