private void checkQueueAccessInternal(
      String queueName, String userName) throws IOException, HiveException {
    String urlSuffix = String.format(PERMISSION_PATH, queueName, userName);
    // TODO: if we ever use this endpoint for anything else, refactor cycling into a separate class.
    int urlIx = lastKnownGoodUrl, lastUrlIx = ((urlIx == 0) ? rmNodes.length : urlIx) - 1;
    Exception firstError = null;
    while (true) {
      String node = rmNodes[urlIx];
      String error = null;
      boolean isCallOk = false;
      String urlToCheck;
      if (sslForYarn){
        urlToCheck = "https://" + node + urlSuffix;
      }else{
        urlToCheck = "http://" + node + urlSuffix;
      }
      try {
        error = checkQueueAccessFromSingleRm(urlToCheck);
        isCallOk = true;
      } catch (Exception ex) {
        LOG.warn("Cannot check queue access against RM " + node, ex);
        if (firstError == null) {
          firstError = ex;
        }
      }
      if (isCallOk) {
        lastKnownGoodUrl = urlIx;
        if (error == null) return; // null error message here means the user has access.
        throw new HiveException(error.isEmpty()
            ? (userName + " has no access to " + queueName) : error);
      }
      if (urlIx == lastUrlIx) {
        throw new IOException("Cannot access any RM service; first error", firstError);
      }
      urlIx = (urlIx + 1) % rmNodes.length;
    }
  }
Checks yarn queue access of a given user for a given queue, and throws
HiveException in case the user doesn't have access to the queue.
@param  queueName the yarn queue name
@param  userName the username
@throws IOException when doAs throws an exception, we simply throw it
InterruptedException when doAs throws an exception, we simply throw it
ql/src/java/org/apache/hadoop/hive/ql/exec/tez/YarnQueueHelper.java