public KyuubiConnection()

in kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/KyuubiConnection.java [128:238]


  public KyuubiConnection(String uri, Properties info) throws SQLException {
    isBeeLineMode = Boolean.parseBoolean(info.getProperty(BEELINE_MODE_PROPERTY));
    try {
      connParams = Utils.parseURL(uri, info);
    } catch (ZooKeeperHiveClientException e) {
      throw new KyuubiSQLException(e);
    }
    jdbcUriString = connParams.getJdbcUriString();
    sessConfMap = connParams.getSessionVars();

    if (!sessConfMap.containsKey(AUTH_PRINCIPAL)
        && sessConfMap.containsKey(AUTH_KYUUBI_SERVER_PRINCIPAL)) {
      sessConfMap.put(AUTH_PRINCIPAL, sessConfMap.get(AUTH_KYUUBI_SERVER_PRINCIPAL));
    }

    // JDBC URL: jdbc:hive2://<host>:<port>/dbName;sess_var_list?hive_conf_list#hive_var_list
    // each list: <key1>=<val1>;<key2>=<val2> and so on
    // sess_var_list -> sessConfMap
    // hive_conf_list -> hiveConfMap
    // hive_var_list -> hiveVarMap
    if (isKerberosAuthMode()) {
      if (isEnableCanonicalHostnameCheck()) {
        host = Utils.getCanonicalHostName(connParams.getHost());
      } else {
        host = connParams.getHost();
      }
    } else {
      host = connParams.getHost();
    }
    port = connParams.getPort();

    setupTimeout();

    if (sessConfMap.containsKey(FETCH_SIZE)) {
      fetchSize = Integer.parseInt(sessConfMap.get(FETCH_SIZE));
    }
    if (sessConfMap.containsKey(INIT_FILE)) {
      initFile = sessConfMap.get(INIT_FILE);
    }
    wmPool = sessConfMap.get(WM_POOL);
    for (String application : APPLICATION) {
      wmApp = sessConfMap.get(application);
      if (wmApp != null) break;
    }

    // add supported protocols
    Collections.addAll(supportedProtocols, TProtocolVersion.values());

    int maxRetries = 1;
    try {
      String strRetries = sessConfMap.get(RETRIES);
      if (StringUtils.isNotBlank(strRetries)) {
        maxRetries = Integer.parseInt(strRetries);
      }
    } catch (NumberFormatException e) { // Ignore the exception
    }

    for (int numRetries = 0; ; ) {
      try {
        // open the client transport
        openTransport();
        // set up the client
        TCLIService.Iface _client = new TCLIService.Client(new TBinaryProtocol(transport));
        // Wrap the client with a thread-safe proxy to serialize the RPC calls
        client = newSynchronizedClient(_client);
        // open client session
        openSession();
        if (!isBeeLineMode) {
          showLaunchEngineLog();
          waitLaunchEngineToComplete();
          executeInitSql();
        }
        break;
      } catch (Exception e) {
        LOG.warn("Failed to connect to " + connParams.getHost() + ":" + connParams.getPort());
        String errMsg = null;
        String warnMsg = "Could not open client transport with JDBC Uri: " + jdbcUriString + ": ";
        try {
          close();
        } catch (Exception ex) {
          // Swallow the exception
          LOG.debug("Error while closing the connection", ex);
        }
        if (ZooKeeperHiveClientHelper.isZkDynamicDiscoveryMode(sessConfMap)) {
          errMsg = "Could not open client transport for any of the Server URI's in ZooKeeper: ";
          // Try next available server in zookeeper, or retry all the servers again if retry is
          // enabled
          while (!Utils.updateConnParamsFromZooKeeper(connParams) && ++numRetries < maxRetries) {
            connParams.getRejectedHostZnodePaths().clear();
          }
          // Update with new values
          jdbcUriString = connParams.getJdbcUriString();
          if (isKerberosAuthMode() && isEnableCanonicalHostnameCheck()) {
            host = Utils.getCanonicalHostName(connParams.getHost());
          } else {
            host = connParams.getHost();
          }
          port = connParams.getPort();
        } else {
          errMsg = warnMsg;
          ++numRetries;
        }

        if (numRetries >= maxRetries) {
          throw new KyuubiSQLException(errMsg + e.getMessage(), "08S01", e);
        } else {
          LOG.warn(warnMsg + e.getMessage() + " Retrying " + numRetries + " of " + maxRetries);
        }
      }
    }
  }