public Map<Long, HostRoleCommandStatusSummaryDTO> getStageSummaries() {
    Map<Long, HostRoleCommandStatusSummaryDTO> summaryMap = new HashMap<>();

    Map<Long, Collection<HostRoleCommand>> stageTasksMap = new HashMap<>();

    Map<Long, Long> taskToStageMap = new HashMap<>();


    for (HostRequest hostRequest : getHostRequests()) {
      Map<Long, Long> physicalTaskMapping = hostRequest.getPhysicalTaskMapping();
      Collection<Long> stageTasks = physicalTaskMapping.values();
      for (Long stageTask : stageTasks) {
        taskToStageMap.put(stageTask, hostRequest.getStageId());
      }
    }

    Collection<HostRoleCommand> physicalTasks = topology.getAmbariContext().getPhysicalTasks(taskToStageMap.keySet());

    for (HostRoleCommand physicalTask : physicalTasks) {
      Long stageId = taskToStageMap.get(physicalTask.getTaskId());
      Collection<HostRoleCommand> stageTasks = stageTasksMap.get(stageId);
      if (stageTasks == null) {
        stageTasks = new ArrayList<>();
        stageTasksMap.put(stageId, stageTasks);
      }
      stageTasks.add(physicalTask);
    }

    for (Long stageId : stageTasksMap.keySet()) {
      //Number minStartTime = 0;
      //Number maxEndTime = 0;
      int aborted = 0;
      int completed = 0;
      int failed = 0;
      int holding = 0;
      int holdingFailed = 0;
      int holdingTimedout = 0;
      int inProgress = 0;
      int pending = 0;
      int queued = 0;
      int timedout = 0;
      int skippedFailed = 0;

      //todo: where does this logic belong?
      for (HostRoleCommand task : stageTasksMap.get(stageId)) {
        HostRoleStatus taskStatus = task.getStatus();

        switch (taskStatus) {
          case ABORTED:
            aborted += 1;
            break;
          case COMPLETED:
            completed += 1;
            break;
          case FAILED:
            failed += 1;
            break;
          case HOLDING:
            holding += 1;
            break;
          case HOLDING_FAILED:
            holdingFailed += 1;
            break;
          case HOLDING_TIMEDOUT:
            holdingTimedout += 1;
            break;
          case IN_PROGRESS:
            inProgress += 1;
            break;
          case PENDING:
            pending += 1;
            break;
          case QUEUED:
            queued += 1;
            break;
          case TIMEDOUT:
            timedout += 1;
            break;
          case SKIPPED_FAILED:
            skippedFailed += 1;
            break;
          default:
            System.out.println("Unexpected status when creating stage summaries: " + taskStatus);
        }
      }

      HostRoleCommandStatusSummaryDTO stageSummary = new HostRoleCommandStatusSummaryDTO(
          0, 0, 0, stageId, aborted, completed, failed,
          holding, holdingFailed, holdingTimedout, inProgress, pending, queued, timedout,
          skippedFailed);

      summaryMap.put(stageId, stageSummary);
    }

    return summaryMap;
  }
Removes pending host requests (outstanding requests not picked up by any host, where hostName is null) for a host group.
@param hostGroupName
@return
ambari-server/src/main/java/org/apache/ambari/server/topology/LogicalRequest.java