public static CalculatedStatus statusFromRequest(HostRoleCommandDAO s_hostRoleCommandDAO,
                                                   TopologyManager topologyManager, Long requestId) {
    Map<Long, HostRoleCommandStatusSummaryDTO> summary = s_hostRoleCommandDAO.findAggregateCounts(requestId);

    // get summaries from TopologyManager for logical requests
    summary.putAll(topologyManager.getStageSummaries(requestId));

    // summary might be empty due to delete host have cleared all
    // HostRoleCommands or due to hosts haven't registered yet with the cluster
    // when the cluster is provisioned with a Blueprint
    final CalculatedStatus status;
    LogicalRequest logicalRequest = topologyManager.getRequest(requestId);
    if (summary.isEmpty() && null != logicalRequest) {
      // In this case, it appears that there are no tasks but this is a logical
      // topology request, so it's a matter of hosts simply not registering yet
      // for tasks to be created ==> status = PENDING.
      // For a new LogicalRequest there should be at least one HostRequest,
      // while if they were removed already ==> status = COMPLETED.
      if (logicalRequest.getHostRequests().isEmpty()) {
        status = CalculatedStatus.COMPLETED;
      } else {
        status = CalculatedStatus.PENDING;
      }
    } else {
      // there are either tasks or this is not a logical request, so do normal
      // status calculations
      status = CalculatedStatus.statusFromStageSummary(summary, summary.keySet());
    }
    return status;
  }
Calculates the status for specified request by id.
@param s_hostRoleCommandDAO is used to retrieve the map of stage-to-summary value objects
@param topologyManager topology manager
@param requestId the request id
@return the calculated status
ambari-server/src/main/java/org/apache/ambari/server/controller/internal/CalculatedStatus.java