private Boolean updateRequestStatus (final Long requestId, Set<StageEntityPK> stagesWithChangedTaskStatus) {
    Boolean didStatusChanged = Boolean.FALSE;
    ActiveRequest request = activeRequestMap.get(requestId);
    HostRoleStatus requestCurrentStatus = request.getStatus();
    HostRoleStatus requestCurrentDisplayStatus = request.getDisplayStatus();

    if (!requestCurrentDisplayStatus.isCompletedState() || !requestCurrentStatus.isCompletedState()) {
      List <ActiveStage>  activeStagesWithChangesTaskStatus = new ArrayList<>();
      for (StageEntityPK stageEntityPK:stagesWithChangedTaskStatus) {
        if (requestId.equals(stageEntityPK.getRequestId())) {
          ActiveStage activeStage = activeStageMap.get(stageEntityPK);
          activeStagesWithChangesTaskStatus.add(activeStage);
        }
      }


      Map<CalculatedStatus.StatusType,Map<HostRoleStatus, Integer>> stageStatusCountFromPartialSet = CalculatedStatus.calculateStatusCountsForStage(activeStagesWithChangesTaskStatus);
      HostRoleStatus statusFromPartialSet = CalculatedStatus.calculateSummaryStatusFromPartialSet(stageStatusCountFromPartialSet.get(CalculatedStatus.StatusType.STATUS), Boolean.FALSE);
      HostRoleStatus displayStatusFromPartialSet = CalculatedStatus.calculateSummaryStatusFromPartialSet(stageStatusCountFromPartialSet.get(CalculatedStatus.StatusType.DISPLAY_STATUS), Boolean.FALSE);

      if (statusFromPartialSet == HostRoleStatus.PENDING || displayStatusFromPartialSet == HostRoleStatus.PENDING) {
        List <ActiveStage> allActiveStages = new ArrayList<>();
        for (StageEntityPK stageEntityPK:request.getStageEntityPks()) {
          ActiveStage activeStage = activeStageMap.get(stageEntityPK);
          allActiveStages.add(activeStage);
        }
        Map<CalculatedStatus.StatusType,Map<HostRoleStatus, Integer>> stageStatusCount = CalculatedStatus.calculateStatusCountsForStage(allActiveStages);

        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(stageStatusCount.get(CalculatedStatus.StatusType.DISPLAY_STATUS), allActiveStages.size(), false);
          if (display_status != requestCurrentDisplayStatus) {
            request.setDisplayStatus(display_status);
            didStatusChanged = Boolean.TRUE;
          }

        } else {
          request.setDisplayStatus(displayStatusFromPartialSet);
          didStatusChanged = Boolean.TRUE;
        }

        if (statusFromPartialSet == HostRoleStatus.PENDING) {
          // calculate status of the stage as per the new status of received host role commands
          HostRoleStatus status = CalculatedStatus.calculateSummaryStatus(stageStatusCount.get(CalculatedStatus.StatusType.STATUS), allActiveStages.size(), false);
          if (status != requestCurrentStatus) {
            request.setStatus(status);
            didStatusChanged = Boolean.TRUE;
          }
        } else {
          request.setDisplayStatus(displayStatusFromPartialSet);
          didStatusChanged = Boolean.TRUE;
        }
      } else {
        request.setStatus(statusFromPartialSet);
        request.setDisplayStatus(displayStatusFromPartialSet);
        didStatusChanged = Boolean.TRUE;
      }
    }

    return didStatusChanged;
  }
@param requestId {@link Request} whose status is to be updated
@param stagesWithChangedTaskStatus set of stages that have received tasks with changed status
@return {Boolean} <code>TRUE</code> if request status has changed from existing
ambari-server/src/main/java/org/apache/ambari/server/events/listeners/tasks/TaskStatusListener.java