dengzhhu653 commented on code in PR #6589:
URL: https://github.com/apache/hive/pull/6589#discussion_r3601909390
##########
pom.xml:
##########
@@ -448,6 +448,11 @@
<artifactId>jjwt-jackson</artifactId>
<version>${jjwt.version}</version>
</dependency>
+ <dependency>
+ <groupId>org.asynchttpclient</groupId>
Review Comment:
any reason why a new dependency is needed?
##########
druid-handler/src/java/org/apache/hadoop/hive/druid/http/HiveDruidHttpClient.java:
##########
@@ -0,0 +1,286 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.hive.druid.http;
+
+import org.apache.hadoop.hive.druid.security.DruidKerberosUtil;
+import org.apache.hadoop.security.UserGroupInformation;
+import org.apache.http.client.config.RequestConfig;
+import org.apache.http.client.methods.CloseableHttpResponse;
+import org.apache.http.client.methods.HttpEntityEnclosingRequestBase;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.client.methods.HttpRequestBase;
+import org.apache.http.client.methods.HttpUriRequest;
+import org.apache.http.entity.ByteArrayEntity;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.HttpClients;
+import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
+import org.apache.http.util.EntityUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.Closeable;
+import java.io.FilterInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.CookieManager;
+import java.net.URI;
+import java.security.PrivilegedExceptionAction;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+
+/**
+ * Apache HttpClient based HTTP client for Druid REST calls.
+ * Replaces Druid's Netty 3 HttpClientInit/KerberosHttpClient stack
(HIVE-25013).
+ */
+public class HiveDruidHttpClient implements Closeable {
+ private static final Logger LOG =
LoggerFactory.getLogger(HiveDruidHttpClient.class);
+
+ private final CloseableHttpClient httpClient;
+ private final PoolingHttpClientConnectionManager connectionManager;
+ private final CookieManager cookieManager;
+ private final boolean kerberosEnabled;
+ private final ExecutorService executor;
+
+ public HiveDruidHttpClient(int readTimeoutMs, int maxConnections, boolean
kerberosEnabled) {
+ this.kerberosEnabled = kerberosEnabled &&
UserGroupInformation.isSecurityEnabled();
+ this.cookieManager = new CookieManager();
+ int connections = maxConnections > 0 ? maxConnections : 20;
+ this.connectionManager = new PoolingHttpClientConnectionManager();
+ this.connectionManager.setMaxTotal(connections);
+ this.connectionManager.setDefaultMaxPerRoute(connections);
+ this.httpClient = HttpClients.custom()
+ .setConnectionManager(connectionManager)
+ .setDefaultRequestConfig(RequestConfig.custom()
+ .setConnectTimeout(readTimeoutMs)
+ .setSocketTimeout(readTimeoutMs)
+ .setConnectionRequestTimeout(readTimeoutMs)
+ .build())
+ .disableCookieManagement()
+ .build();
+ this.executor = Executors.newFixedThreadPool(connections, r -> {
+ Thread t = new Thread(r, "HiveDruidHttpClient");
+ t.setDaemon(true);
+ return t;
+ });
+ if (this.kerberosEnabled) {
+ LOG.info("HiveDruidHttpClient Kerberos authentication enabled");
+ }
+ }
+
+ public HiveDruidHttpResponse execute(HiveDruidHttpRequest request) throws
IOException {
+ return innerExecute(request);
+ }
+
+ public InputStream executeStream(HiveDruidHttpRequest request) throws
IOException {
+ return innerExecuteStream(request);
+ }
+
+ public Future<InputStream> executeStreamAsync(HiveDruidHttpRequest request) {
+ return executor.submit(() -> executeStream(request));
+ }
+
+ private HiveDruidHttpResponse innerExecute(HiveDruidHttpRequest request)
throws IOException {
+ HiveDruidHttpRequest current = request.copy();
+ boolean shouldRetryOnUnauthorized = prepareKerberosAuth(current);
+
+ while (true) {
Review Comment:
Can we have any test covering Kerberos auth and retry on failure?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]