@RequiresSession
  public Map<Long, HostRoleCommandStatusSummaryDTO> findAggregateCounts(Long requestId) {
    if (!hostRoleCommandStatusSummaryCacheEnabled) {
      return loadAggregateCounts(requestId);
    }

    Map<Long, HostRoleCommandStatusSummaryDTO> map = hrcStatusSummaryCache.getIfPresent(requestId);
    if (null != map) {
      return map;
    }

    // ensure that we wait for any running transactions working on this cache to
    // complete
    ReadWriteLock lock = transactionLocks.getLock(LockArea.HRC_STATUS_CACHE);
    lock.readLock().lock();

    try {
      map = loadAggregateCounts(requestId);
      hrcStatusSummaryCache.put(requestId, map);

      return map;
    } finally {
      lock.readLock().unlock();
    }
  }
Finds the counts of tasks for a request and groups them by stage id. If
caching is enabled, this will first consult the cache. Cache misses will
then defer to loading the data from the database and then caching the
result.

@param requestId
         the request id
@return the map of stage-to-summary objects
ambari-server/src/main/java/org/apache/ambari/server/orm/dao/HostRoleCommandDAO.java