private BatchRequest calculateActiveBatch(RequestExecution requestExecution) {
    BatchRequest result = null;
    Batch batch = requestExecution.getBatch();
    if (batch != null) {
      List<BatchRequest> batchRequests = batch.getBatchRequests();
      if (batchRequests != null) {
        Collections.sort(batchRequests);
        ListIterator<BatchRequest> iterator = batchRequests.listIterator();
        do {
          result = iterator.next();
        } while (iterator.hasNext() && result.getStatus() != null &&
                 HostRoleStatus.getCompletedStates().contains(HostRoleStatus.valueOf(result.getStatus())) &&
                 !HostRoleStatus.ABORTED.name().equals(result.getStatus()));
      }
    }

    if (result != null && result.getStatus() != null &&
      HostRoleStatus.getCompletedStates().contains(HostRoleStatus.valueOf(result.getStatus())) &&
      !HostRoleStatus.ABORTED.name().equals(result.getStatus())) {
      return null;
    }

    return result;
  }
Iterate through the batches and find the first one with not completed status, if all were completed return null
@param requestExecution
@return
ambari-server/src/main/java/org/apache/ambari/server/scheduler/ExecutionScheduleManager.java