public static CalculatedStatus statusFromStageEntities(Collection<StageEntity> stages) {
    Collection<HostRoleStatus> stageStatuses = new HashSet<>();
    Collection<HostRoleCommandEntity> tasks = new HashSet<>();

    for (StageEntity stage : stages) {
      // get all the tasks for the stage
      Collection<HostRoleCommandEntity> stageTasks = stage.getHostRoleCommands();

      // calculate the stage status from the task status counts
      HostRoleStatus stageStatus =
          calculateSummaryStatus(calculateTaskEntityStatusCounts(stageTasks), stageTasks.size(), stage.isSkippable());

      stageStatuses.add(stageStatus);

      // keep track of all of the tasks for all stages
      tasks.addAll(stageTasks);
    }

    // calculate the overall status from the stage statuses
    HostRoleStatus status = calculateSummaryStatusOfUpgrade(calculateStatusCounts(stageStatuses), stageStatuses.size());

    // calculate the progress from the task status counts
    double progressPercent = calculateProgressPercent(calculateTaskEntityStatusCounts(tasks), tasks.size());

    return new CalculatedStatus(status, progressPercent);
  }
Factory method to create a calculated status.  Calculate request status from the given
collection of stage entities.

@param stages  the collection of stage entities

@return a calculated status
ambari-server/src/main/java/org/apache/ambari/server/controller/internal/CalculatedStatus.java