Search in sources :

Example 1 with GoalState

use of com.mesosphere.sdk.specification.GoalState in project dcos-commons by mesosphere.

the class DefaultStepFactory method getStatus.

private Status getStatus(PodInstance podInstance, Protos.TaskInfo taskInfo, UUID targetConfigId) throws TaskException {
    boolean isOnTarget = isOnTarget(taskInfo, targetConfigId);
    boolean hasReachedGoal = hasReachedGoalState(podInstance, taskInfo);
    if (hasReachedGoal) {
        GoalState goalState = TaskUtils.getGoalState(podInstance, taskInfo.getName());
        if (goalState.equals(GoalState.FINISHED) || goalState.equals(GoalState.ONCE)) {
            LOGGER.info("Automatically on target configuration due to having reached {} goal.", goalState);
            isOnTarget = true;
        }
    }
    boolean hasPermanentlyFailed = FailureUtils.isPermanentlyFailed(taskInfo);
    String bitsLog = String.format("onTarget=%s reachedGoal=%s permanentlyFailed=%s", isOnTarget, hasReachedGoal, hasPermanentlyFailed);
    if ((isOnTarget && hasReachedGoal) || hasPermanentlyFailed) {
        LOGGER.info("Deployment of task '{}' is COMPLETE: {}", taskInfo.getName(), bitsLog);
        return Status.COMPLETE;
    } else {
        LOGGER.info("Deployment of task '{}' is PENDING: {}", taskInfo.getName(), bitsLog);
        return Status.PENDING;
    }
}
Also used : GoalState(com.mesosphere.sdk.specification.GoalState)

Example 2 with GoalState

use of com.mesosphere.sdk.specification.GoalState in project dcos-commons by mesosphere.

the class DefaultStepFactory method hasReachedGoalState.

@VisibleForTesting
protected boolean hasReachedGoalState(PodInstance podInstance, Protos.TaskInfo taskInfo) throws TaskException {
    GoalState goalState = TaskUtils.getGoalState(podInstance, taskInfo.getName());
    Optional<Protos.TaskStatus> status = stateStore.fetchStatus(taskInfo.getName());
    if (!status.isPresent()) {
        return false;
    }
    if (goalState.equals(GoalState.RUNNING)) {
        switch(status.get().getState()) {
            case TASK_RUNNING:
                if (Capabilities.getInstance().supportsDefaultExecutor()) {
                    return new TaskLabelReader(taskInfo).isReadinessCheckSucceeded(status.get());
                }
                // readiness checks on restart.
                return true;
            default:
                return false;
        }
    } else if (goalState.equals(GoalState.ONCE) || goalState.equals(GoalState.FINISH) || goalState.equals(GoalState.FINISHED)) {
        switch(status.get().getState()) {
            case TASK_FINISHED:
                return true;
            default:
                return false;
        }
    } else {
        throw new TaskException("Unexpected goal state encountered: " + goalState);
    }
}
Also used : GoalState(com.mesosphere.sdk.specification.GoalState) TaskLabelReader(com.mesosphere.sdk.offer.taskdata.TaskLabelReader) TaskException(com.mesosphere.sdk.offer.TaskException) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 3 with GoalState

use of com.mesosphere.sdk.specification.GoalState in project dcos-commons by mesosphere.

the class DeploymentStep method update.

/**
 * Synchronized to ensure consistency between this and {@link #updateOfferStatus(Collection)}.
 */
@Override
public synchronized void update(Protos.TaskStatus status) {
    logger.debug("Step {} received status: {}", getName(), TextFormat.shortDebugString(status));
    if (!tasks.containsKey(status.getTaskId())) {
        logger.debug("Step {} ignoring irrelevant TaskStatus: {}", getName(), TextFormat.shortDebugString(status));
        return;
    }
    if (isComplete()) {
        logger.debug("Step {} ignoring TaskStatus due to being Complete: {}", getName(), TextFormat.shortDebugString(status));
        return;
    }
    GoalState goalState = null;
    try {
        goalState = TaskUtils.getGoalState(podInstanceRequirement.getPodInstance(), CommonIdUtils.toTaskName(status.getTaskId()));
    } catch (TaskException e) {
        logger.error(String.format("Failed to get goal state for step %s with status %s", getName(), getStatus()), e);
        return;
    }
    logger.info("Goal state for: {} is: {}", status.getTaskId().getValue(), goalState.name());
    switch(status.getState()) {
        case TASK_ERROR:
        case TASK_FAILED:
        case TASK_KILLED:
        case TASK_KILLING:
        case TASK_LOST:
            setTaskStatus(status.getTaskId(), Status.PENDING);
            break;
        case TASK_STAGING:
        case TASK_STARTING:
            setTaskStatus(status.getTaskId(), Status.STARTING);
            break;
        case TASK_RUNNING:
            Protos.TaskInfo taskInfo = tasks.get(status.getTaskId()).getTaskInfo();
            if (goalState.equals(GoalState.RUNNING) && new TaskLabelReader(taskInfo).isReadinessCheckSucceeded(status)) {
                setTaskStatus(status.getTaskId(), Status.COMPLETE);
            } else {
                setTaskStatus(status.getTaskId(), Status.STARTED);
            }
            break;
        case TASK_FINISHED:
            if (goalState.equals(GoalState.ONCE) || goalState.equals(GoalState.FINISH) || goalState.equals(GoalState.FINISHED)) {
                setTaskStatus(status.getTaskId(), Status.COMPLETE);
            } else {
                setTaskStatus(status.getTaskId(), Status.PENDING);
            }
            break;
        default:
            logger.error("Failed to process unexpected state: " + status.getState());
    }
    updateStatus();
}
Also used : GoalState(com.mesosphere.sdk.specification.GoalState) TaskLabelReader(com.mesosphere.sdk.offer.taskdata.TaskLabelReader) Protos(org.apache.mesos.Protos) GoalStateOverride(com.mesosphere.sdk.state.GoalStateOverride)

Aggregations

GoalState (com.mesosphere.sdk.specification.GoalState)3 TaskLabelReader (com.mesosphere.sdk.offer.taskdata.TaskLabelReader)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 TaskException (com.mesosphere.sdk.offer.TaskException)1 GoalStateOverride (com.mesosphere.sdk.state.GoalStateOverride)1 Protos (org.apache.mesos.Protos)1