private static void configureConnParamsHA(JdbcConnectionParams connParams) throws ZooKeeperHiveClientException {
    try {
      Configuration registryConf = new Configuration();
      registryConf.set(HiveConf.ConfVars.HIVE_ZOOKEEPER_QUORUM.varname, connParams.getZooKeeperEnsemble());
      registryConf.set(HiveConf.ConfVars.HIVE_SERVER2_ACTIVE_PASSIVE_HA_REGISTRY_NAMESPACE.varname,
        getZooKeeperNamespace(connParams));
      HS2ActivePassiveHARegistry haRegistryClient = HS2ActivePassiveHARegistryClient.getClient(registryConf);
      boolean foundLeader = false;
      String maxRetriesConf = connParams.getSessionVars().get(JdbcConnectionParams.RETRIES);
      final int maxRetries = StringUtils.isEmpty(maxRetriesConf) ? 5 : Integer.parseInt(maxRetriesConf);
      int retries = 0;
      int sleepMs = 1000;
      while (!foundLeader && retries < maxRetries) {
        for (HiveServer2Instance hiveServer2Instance : haRegistryClient.getAll()) {
          if (hiveServer2Instance.isLeader()) {
            foundLeader = true;
            connParams.setHost(hiveServer2Instance.getHost());
            connParams.setPort(hiveServer2Instance.getRpcPort());
            final String mode = hiveServer2Instance.getTransportMode().equals("http") ? "http:/" + hiveServer2Instance
              .getHttpEndpoint() : hiveServer2Instance.getTransportMode();
            LOG.info("Found HS2 Active Host: {} Port: {} Identity: {} Mode: {}", hiveServer2Instance.getHost(),
              hiveServer2Instance.getRpcPort(), hiveServer2Instance.getWorkerIdentity(), mode);
            // configurations are always published to ServiceRecord. Read/apply configs to JDBC connection params
            String serverConfStr = Joiner.on(';').withKeyValueSeparator("=").join(hiveServer2Instance.getProperties());
            if (LOG.isDebugEnabled()) {
              LOG.debug("Configurations applied to JDBC connection params. {}", hiveServer2Instance.getProperties());
            }
            applyConfs(serverConfStr, connParams);
            break;
          }
        }
        if (!foundLeader) {
          LOG.warn("Unable to connect to HS2 Active Host (No Leader Found!). Retrying after {} ms. retries: {}",
            sleepMs, retries);
          Thread.sleep(sleepMs);
          retries++;
        }
      }
      if (!foundLeader) {
        throw new ZooKeeperHiveClientException("Unable to connect to HiveServer2 Active host (No leader found!) after" +
          " " + maxRetries + " retries.");
      }
    } catch (Exception e) {
      throw new ZooKeeperHiveClientException("Unable to read HiveServer2 configs from ZooKeeper", e);
    }
  }
Get a list of all HiveServer2 server hosts.

@param connParams The current JDBC connection parameters
@param zooKeeperClient The client to use to connect to ZooKeeper
@return A list of HiveServer2 hosts
@throws ZooKeeperHiveClientException Failed to communicate to ZooKeeper
jdbc/src/java/org/apache/hive/jdbc/ZooKeeperHiveClientHelper.java