private void printProgressesInPlace()

in odps-console-basic/src/main/java/com/aliyun/openservices/odps/console/output/state/InstanceProgressReporter.java [204:287]


  private void printProgressesInPlace(List<Instance.StageProgress> stageprogresses,
                                      boolean forceComplete) {
    StringBuilder reportBuffer = new StringBuilder();
    int sumComplete = 0;
    int sumTotal = 0;
    int idx = 0;
    int maxProgress = stageprogresses.size();
    int lines = context.getRepositionLines();

    if (lines > 0) {
      InPlaceUpdates.rePositionCursor(out, lines);
      InPlaceUpdates.resetForward(out);
      lines = 0;
    }

    // print header
    // -------------------------------------------------------------------------------
    //          STAGES      STATUS  TOTAL  COMPLETED  RUNNING  PENDING  BACKUP
    // -------------------------------------------------------------------------------
    InPlaceUpdates.reprintLine(out, SEPARATOR);
    lines++;
    InPlaceUpdates.reprintLineWithColorAsBold(out, HEADER, Ansi.Color.CYAN);
    lines++;
    for (Instance.StageProgress progress : stageprogresses) {
      idx++;
      final String name = progress.getName();
      // NOTE: getTotalWorkers() 不包含 backupWorkers,用户不需要感知 backupWorkers 这件事情
      // 大部分情况下 getBackupWorkers() 返回 0qu
      final int backup = progress.getBackupWorkers();
      final int total = progress.getTotalWorkers();
      final int all = backup + total;
      final int running = forceComplete ? 0 : progress.getRunningWorkers();
      final int completed = forceComplete ? all : progress.getTerminatedWorkers();
      final int pending = all - completed - running;

      final Instance.StageProgress.Status
          status =
          forceComplete ? Instance.StageProgress.Status.TERMINATED : getStatus(progress);
      String statusString = status != null ? status.toString() : "NULL";

      String nameWithProgress = getNameWithProgress(name, completed, total);
      // Stage 1 .......... mode  RUNNING      7          7        0        0       0       0     0
      String vertexStr = String.format(STAGE_FORMAT,
                                       nameWithProgress,
                                       statusString,
                                       total,
                                       completed,
                                       running,
                                       pending,
                                       backup);

      sumComplete += completed;
      sumTotal += total;

      // Mark the stage as Completed
      if (status == Instance.StageProgress.Status.TERMINATED && !completedStageNames
          .contains(name)) {
        completedStageNames.add(name);
      }

      reportBuffer.append(vertexStr);
      if (idx != maxProgress) {
        reportBuffer.append("\n");
      }
    }
    lines += InPlaceUpdates.reprintMultiLine(out, reportBuffer.toString());

    // -------------------------------------------------------------------------------
    // STAGES: 03/04            [=================>>-----] 86%  ELAPSED TIME: 1.71 s
    // -------------------------------------------------------------------------------
    InPlaceUpdates.reprintLine(out, SEPARATOR);
    lines++;
    final float progress = (sumTotal == 0) ? 0.0f : (float) sumComplete / (float) sumTotal;
    String
        footer =
        getFooter(stageprogresses.size(), completedStageNames.size(), progress,
                  context.getInstanceStartTime());
    InPlaceUpdates.reprintLineWithColorAsBold(out, footer, Ansi.Color.RED);
    lines++;
    InPlaceUpdates.reprintLine(out, SEPARATOR);
    lines++;

    context.setRepositionLines(lines);
  }