[ https://issues.apache.org/jira/browse/HIVE-27129?focusedWorklogId=850207&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-850207 ]
ASF GitHub Bot logged work on HIVE-27129: ----------------------------------------- Author: ASF GitHub Bot Created on: 10/Mar/23 01:17 Start Date: 10/Mar/23 01:17 Worklog Time Spent: 10m Work Description: junlinzeng-db commented on code in PR #4104: URL: https://github.com/apache/hive/pull/4104#discussion_r1131834462 ########## standalone-metastore/metastore-common/src/main/java/org/apache/hadoop/hive/metastore/HiveMetaStoreClient.java: ########## @@ -621,31 +611,84 @@ private <T extends TTransport> T configureThriftMaxMessageSize(T transport) { return transport; } + private Map<String, String> getAdditionalHeaders() { + Map<String, String> headers = new HashMap<>(); + String keyValuePairs = MetastoreConf.getVar(conf, ConfVars.METASTORE_CLIENT_ADDITIONAL_HEADERS); + try { + List<String> headerKeyValues = Splitter.on(',').trimResults().splitToList(keyValuePairs); + for (String header : headerKeyValues) { + String[] parts = header.split("="); + headers.put(parts[0].trim(), parts[1].trim()); + LOG.warn(parts[0].trim() + "=" + parts[1].trim()); + } + } catch (Exception ex) { + LOG.warn("Could not parse the headers provided in " + ConfVars.METASTORE_CLIENT_ADDITIONAL_HEADERS, ex); + } + return headers; + } + /* Creates a THttpClient if HTTP mode is enabled. If Client auth mode is set to JWT, then the method fetches JWT from environment variable: HMS_JWT and sets in auth header in http request */ - private THttpClient createHttpClient(URI store, boolean useSSL) throws MetaException, - TTransportException { + private THttpClient createHttpClient(URI store, boolean useSSL) throws MetaException, TTransportException { String path = MetaStoreUtils.getHttpPath(MetastoreConf.getVar(conf, ConfVars.THRIFT_HTTP_PATH)); - String httpUrl = (useSSL ? "https://" : "http://") + store.getHost() + ":" + store.getPort() + path; + String urlScheme; + if (useSSL || Objects.equals(store.getScheme(), "https")) { + urlScheme = "https://"; + } else { + urlScheme = "http://"; + } + String httpUrl = urlScheme + store.getHost() + ":" + store.getPort() + path; + + HttpClientBuilder httpClientBuilder = createHttpClientBuilder(); + THttpClient tHttpClient; + try { + if (useSSL) { + String trustStorePath = MetastoreConf.getVar(conf, ConfVars.SSL_TRUSTSTORE_PATH).trim(); + if (trustStorePath.isEmpty()) { + throw new IllegalArgumentException(ConfVars.SSL_TRUSTSTORE_PATH + " Not configured for SSL connection"); + } + String trustStorePassword = MetastoreConf.getPassword(conf, MetastoreConf.ConfVars.SSL_TRUSTSTORE_PASSWORD); + String trustStoreType = MetastoreConf.getVar(conf, ConfVars.SSL_TRUSTSTORE_TYPE).trim(); + String trustStoreAlgorithm = MetastoreConf.getVar(conf, ConfVars.SSL_TRUSTMANAGERFACTORY_ALGORITHM).trim(); + tHttpClient = + SecurityUtils.getThriftHttpsClient(httpUrl, trustStorePath, trustStorePassword, trustStoreAlgorithm, + trustStoreType, httpClientBuilder); + } else { + tHttpClient = new THttpClient(httpUrl, httpClientBuilder.build()); + } + } catch (Exception e) { + if (e instanceof TTransportException) { + throw (TTransportException) e; + } else { + throw new MetaException("Failed to create http transport client to url: " + httpUrl + ". Error:" + e); + } + } + LOG.debug("Created thrift http client for URL: " + httpUrl); + return configureThriftMaxMessageSize(tHttpClient); + } + protected HttpClientBuilder createHttpClientBuilder() throws MetaException { Review Comment: do I still need this to be protocted? Issue Time Tracking ------------------- Worklog Id: (was: 850207) Time Spent: 50m (was: 40m) > Enhanced support to Hive Client http support > -------------------------------------------- > > Key: HIVE-27129 > URL: https://issues.apache.org/jira/browse/HIVE-27129 > Project: Hive > Issue Type: Improvement > Reporter: Junlin Zeng > Assignee: Junlin Zeng > Priority: Major > Labels: pull-request-available > Time Spent: 50m > Remaining Estimate: 0h > > Currently we support using http in the hive metastore connection. However, we > do not support custom headers and also default trust store. This ticket > tracks the work to improve the http journey. -- This message was sent by Atlassian Jira (v8.20.10#820010)