public static Optional checkProgress()

in maestro-engine/src/main/java/com/netflix/maestro/engine/utils/TaskHelper.java [233:300]


  public static Optional<Task.Status> checkProgress(
      Map<String, Task> realTaskMap,
      WorkflowSummary summary,
      WorkflowRuntimeOverview overview,
      boolean isFinal) {
    boolean allDone = true;
    boolean isFailed = false; // highest order
    boolean isTimeout = false;
    boolean isStopped = false; // lowest order
    boolean allTerminal =
        isFinal && realTaskMap.values().stream().allMatch(task -> task.getStatus().isTerminal());

    for (Map.Entry<StepInstance.Status, WorkflowStepStatusSummary> entry :
        overview.getStepOverview().entrySet()) {
      if (entry.getKey() != StepInstance.Status.NOT_CREATED && entry.getValue().getCnt() > 0) {
        if (!entry.getKey().isTerminal() || (!allTerminal && entry.getKey().isRetryable())) {
          allDone = false;
          break;
        } else if (entry.getKey() == StepInstance.Status.FATALLY_FAILED
            || entry.getKey() == StepInstance.Status.INTERNALLY_FAILED
            || entry.getKey() == StepInstance.Status.USER_FAILED
            || entry.getKey() == StepInstance.Status.PLATFORM_FAILED
            || entry.getKey() == StepInstance.Status.TIMEOUT_FAILED) {
          isFailed = true;
        } else if (entry.getKey() == StepInstance.Status.TIMED_OUT) {
          isTimeout = true;
        } else if (entry.getKey() == StepInstance.Status.STOPPED) {
          isStopped = true;
        }
      }
    }

    if (allDone && overview.existsNotCreatedStep()) {
      allDone = confirmDone(realTaskMap, summary);
    }

    // It's unexpected. Can happen if the flow fails the run before running maestro task logic
    if (allDone && !isFailed && !isTimeout && !isStopped && !overview.existsCreatedStep()) {
      LOG.error(
          "There are no created steps in the workflow [{}] and mark it as failed.",
          summary.getIdentity());
      isFailed = true;
    }

    LOG.trace(
        "Check task status: done [{}] and with flags: [isFailed: {}], [isTimeout: {}], [isStopped: {}] "
            + "with real task map: [{}] and workflow summary: [{}]",
        allDone,
        isFailed,
        isTimeout,
        isStopped,
        realTaskMap,
        summary);
    if (allDone) {
      if (isFailed) {
        return Optional.of(Task.Status.FAILED);
      } else if (isTimeout) {
        return Optional.of(Task.Status.TIMED_OUT);
      } else if (isStopped) {
        return Optional.of(Task.Status.CANCELED);
      } else {
        // Use this special status to indicate workflow succeeded.
        // So all dummy (NOT_CREATED) tasks will be cancelled.
        return Optional.of(Task.Status.FAILED_WITH_TERMINAL_ERROR);
      }
    }
    return Optional.empty();
  }