public static CalculatedStatus statusFromStageSummary(Map<Long, HostRoleCommandStatusSummaryDTO> stageDto,
      Set<Long> stageIds) {

    // if either are empty, then we have no tasks and therefore no status - we
    // should return COMPLETED. This can happen if someone removes all tasks but
    // leaves the stages and request
    if (stageDto.isEmpty() || stageIds.isEmpty()) {
      return COMPLETED;
    }

    Collection<HostRoleStatus> stageStatuses = new HashSet<>();
    Collection<HostRoleStatus> stageDisplayStatuses = new HashSet<>();
    Collection<HostRoleStatus> taskStatuses = new ArrayList<>();

    for (Long stageId : stageIds) {
      if (!stageDto.containsKey(stageId)) {
        continue;
      }

      HostRoleCommandStatusSummaryDTO summary = stageDto.get(stageId);

      int total = summary.getTaskTotal();
      boolean skip = summary.isStageSkippable();
      Map<HostRoleStatus, Integer> counts = calculateStatusCounts(summary.getTaskStatuses());
      HostRoleStatus stageStatus = calculateSummaryStatus(counts, total, skip);
      HostRoleStatus stageDisplayStatus = calculateSummaryDisplayStatus(counts, total, skip);

      stageStatuses.add(stageStatus);
      stageDisplayStatuses.add(stageDisplayStatus);
      taskStatuses.addAll(summary.getTaskStatuses());
    }

    // calculate the overall status from the stage statuses
    Map<HostRoleStatus, Integer> counts = calculateStatusCounts(stageStatuses);
    Map<HostRoleStatus, Integer> displayCounts = calculateStatusCounts(stageDisplayStatuses);

    HostRoleStatus status = calculateSummaryStatusOfUpgrade(counts, stageStatuses.size());
    HostRoleStatus displayStatus = calculateSummaryDisplayStatus(displayCounts, stageDisplayStatuses.size(), false);

    double progressPercent = calculateProgressPercent(calculateStatusCounts(taskStatuses), taskStatuses.size());

    return new CalculatedStatus(status, displayStatus, progressPercent);
  }
Calculates the overall status of an upgrade. If there are no tasks, then a
status of {@link HostRoleStatus#COMPLETED} is returned.

@param stageDto
         the map of stage-to-summary value objects
@param stageIds
         the stage ids to consider from the value objects
@return the calculated status
ambari-server/src/main/java/org/apache/ambari/server/controller/internal/CalculatedStatus.java