public static HostRoleStatus calculateSummaryStatus(Map<HostRoleStatus, Integer> counters,
      int total, boolean skippable) {

    // when there are 0 tasks, return COMPLETED
    if (total == 0) {
      return HostRoleStatus.COMPLETED;
    }

    if (counters.get(HostRoleStatus.PENDING) == total) {
      return HostRoleStatus.PENDING;
    }

    // By definition, any tasks in a future stage must be held in a PENDING status.
    if (counters.get(HostRoleStatus.HOLDING) > 0 || counters.get(HostRoleStatus.HOLDING_FAILED) > 0 || counters.get(HostRoleStatus.HOLDING_TIMEDOUT) > 0) {
      return counters.get(HostRoleStatus.HOLDING) > 0 ? HostRoleStatus.HOLDING :
      counters.get(HostRoleStatus.HOLDING_FAILED) > 0 ? HostRoleStatus.HOLDING_FAILED :
      HostRoleStatus.HOLDING_TIMEDOUT;
    }

    // Because tasks are not skippable, guaranteed to be FAILED
    if (counters.get(HostRoleStatus.FAILED) > 0 && !skippable) {
      return HostRoleStatus.FAILED;
    }

    // Because tasks are not skippable, guaranteed to be TIMEDOUT
    if (counters.get(HostRoleStatus.TIMEDOUT) > 0  && !skippable) {
      return HostRoleStatus.TIMEDOUT;
    }

    int numActiveTasks = counters.get(HostRoleStatus.PENDING) + counters.get(HostRoleStatus.QUEUED) + counters.get(HostRoleStatus.IN_PROGRESS);
    // ABORTED only if there are no other active tasks
    if (counters.get(HostRoleStatus.ABORTED) > 0 && numActiveTasks == 0) {
      return HostRoleStatus.ABORTED;
    }

    if (counters.get(HostRoleStatus.COMPLETED) == total) {
      return HostRoleStatus.COMPLETED;
    }

    return HostRoleStatus.IN_PROGRESS;
  }
Calculate overall status of a stage or upgrade based on the given status counts.

@param counters   counts of resources that are in various states
@param total      total number of resources in request. NOTE, completed tasks may be counted twice.
@param skippable  true if a single failed status should NOT result in an overall failed status return

@return summary request status based on statuses of tasks in different states.
ambari-server/src/main/java/org/apache/ambari/server/controller/internal/CalculatedStatus.java