private Boolean updateStageStatus(final StageEntityPK stagePK, List<HostRoleCommand> hostRoleCommandListAll) {
    Boolean didAnyStatusChanged = Boolean.FALSE;
    ActiveStage reportedStage = activeStageMap.get(stagePK);
    HostRoleStatus stageCurrentStatus = reportedStage.getStatus();
    HostRoleStatus stageCurrentDisplayStatus = reportedStage.getDisplayStatus();


    // if stage is already marked to be completed then do not calculate reported status from host role commands
    // Presumption: There will be no status transition of the host role command from one completed state to another
    if (!stageCurrentDisplayStatus.isCompletedState() || !stageCurrentStatus.isCompletedState()) {
      Map<HostRoleStatus, Integer> receivedTaskStatusCount = CalculatedStatus.calculateStatusCountsForTasks(hostRoleCommandListAll, stagePK);
      HostRoleStatus statusFromPartialSet = CalculatedStatus.calculateSummaryStatusFromPartialSet(receivedTaskStatusCount, reportedStage.getSkippable());
      HostRoleStatus displayStatusFromPartialSet = CalculatedStatus.calculateSummaryStatusFromPartialSet(receivedTaskStatusCount, Boolean.FALSE);
      if (statusFromPartialSet == HostRoleStatus.PENDING || displayStatusFromPartialSet == HostRoleStatus.PENDING) {
        Function<Long,HostRoleCommand> transform = new Function<Long,HostRoleCommand>(){
          @Override
          public HostRoleCommand apply(Long taskId) {
            return activeTasksMap.get(taskId);
          }
        };

        List<HostRoleCommand> activeHostRoleCommandsOfStage = FluentIterable.from(reportedStage.getTaskIds())
            .transform(transform).toList();
        Map<HostRoleStatus, Integer> statusCount = CalculatedStatus.calculateStatusCountsForTasks(activeHostRoleCommandsOfStage);
        if (displayStatusFromPartialSet == HostRoleStatus.PENDING) {
          // calculate and get new display status of the stage as per the new status of received host role commands
          HostRoleStatus display_status = CalculatedStatus.calculateSummaryDisplayStatus(statusCount, activeHostRoleCommandsOfStage.size(), reportedStage.getSkippable());
          if (display_status != stageCurrentDisplayStatus) {
            reportedStage.setDisplayStatus(display_status);
            didAnyStatusChanged = Boolean.TRUE;
          }

        } else {
          reportedStage.setDisplayStatus(displayStatusFromPartialSet);
          didAnyStatusChanged = Boolean.TRUE;
        }

        if (statusFromPartialSet == HostRoleStatus.PENDING) {
          // calculate status of the stage as per the new status of received host role commands
          HostRoleStatus status = CalculatedStatus.calculateStageStatus(activeHostRoleCommandsOfStage, statusCount, reportedStage.getSuccessFactors(), reportedStage.getSkippable());
          if (status != stageCurrentStatus) {
            reportedStage.setStatus(status);
            didAnyStatusChanged = Boolean.TRUE;
          }
        } else {
          reportedStage.setDisplayStatus(displayStatusFromPartialSet);
          didAnyStatusChanged = Boolean.TRUE;
        }
      } else {
        reportedStage.setStatus(statusFromPartialSet);
        reportedStage.setDisplayStatus(displayStatusFromPartialSet);
        didAnyStatusChanged = Boolean.TRUE;
      }
    }

    return didAnyStatusChanged;
  }
Returns the computed status of the stage from the status of it's host role commands
@param stagePK {@link StageEntityPK} primary key for the stage entity
@param hostRoleCommandListAll list of all hrc received whose status has been received from agent
@return {@link Boolean} <code>TRUE</code> if status of the given stage changed.
ambari-server/src/main/java/org/apache/ambari/server/events/listeners/tasks/TaskStatusListener.java