@RequiresSession
  public Map<Long, String> findRequestContext(List<Long> requestIds) {
    Map<Long, String> resultMap = new HashMap<>();
    if (CollectionUtils.isNotEmpty(requestIds)) {
      TypedQuery<StageEntity> query = entityManagerProvider.get()
        .createQuery("SELECT stage FROM StageEntity stage WHERE " +
          "stage.requestId IN (SELECT DISTINCT s.requestId FROM StageEntity s " +
          "WHERE s.requestId IN ?1)", StageEntity.class);

      List<StageEntity> result = new ArrayList<>();
      SQLOperations.batch(requestIds, SQLConstants.IN_ARGUMENT_MAX_SIZE, (chunk, currentBatch, totalBatches, totalSize) -> {
        result.addAll(daoUtils.selectList(query, chunk));
        return 0;
      });

      for (StageEntity entity : result) {
        resultMap.put(entity.getRequestId(), entity.getRequestContext());
      }
    }
    return resultMap;
  }
Finds the first stage matching any of the specified statuses for every
request. For example, to find the first {@link HostRoleStatus#IN_PROGRESS}
stage for every request, pass in
{@link HostRoleStatus#IN_PROGRESS_STATUSES}.

@param statuses
         {@link HostRoleStatus}
@return the list of the first matching stage for the given statuses for
        every request.
ambari-server/src/main/java/org/apache/ambari/server/orm/dao/StageDAO.java