This is an automated email from the ASF dual-hosted git repository.

kharekartik pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/pinot.git


The following commit(s) were added to refs/heads/master by this push:
     new 55db06fab1 Add TLS1.3, Remove TLS1.0, Add User Agent Header, Add 
Timeouts for Pi… (#9008)
55db06fab1 is described below

commit 55db06fab16682fcac40d12cbdb7fc1df3ca6a91
Author: rino-kadijk <106676047+rino-kad...@users.noreply.github.com>
AuthorDate: Tue Aug 2 13:27:33 2022 +0200

    Add TLS1.3, Remove TLS1.0, Add User Agent Header, Add Timeouts for Pi… 
(#9008)
---
 pinot-clients/pinot-java-client/pom.xml            |  6 +++
 .../org/apache/pinot/client/ConnectionFactory.java | 12 +++--
 .../apache/pinot/client/ConnectionTimeouts.java    | 53 ++++++++++++++++++++++
 .../client/JsonAsyncHttpPinotClientTransport.java  | 49 +++++++++++++++-----
 .../JsonAsyncHttpPinotClientTransportFactory.java  | 31 ++++++++++++-
 .../java/org/apache/pinot/client/TlsProtocols.java | 52 +++++++++++++++++++++
 .../src/main/resources/version.properties          | 20 ++++++++
 pinot-clients/pinot-jdbc-client/pom.xml            |  4 ++
 .../org/apache/pinot/client/PinotConnection.java   |  3 +-
 .../java/org/apache/pinot/client/PinotDriver.java  |  6 ++-
 .../controller/PinotControllerTransport.java       | 32 ++++++++-----
 .../PinotControllerTransportFactory.java           | 32 ++++++++++++-
 .../src/main/resources/version.properties          | 20 ++++++++
 .../client/DummyPinotControllerTransport.java      | 13 ++++++
 .../apache/pinot/client/PinotConnectionTest.java   |  2 +-
 .../pinot/client/PinotPreparedStatementTest.java   |  2 +-
 .../apache/pinot/client/PinotStatementTest.java    |  2 +-
 17 files changed, 304 insertions(+), 35 deletions(-)

diff --git a/pinot-clients/pinot-java-client/pom.xml 
b/pinot-clients/pinot-java-client/pom.xml
index 0a4b1eca51..d25c369ac7 100644
--- a/pinot-clients/pinot-java-client/pom.xml
+++ b/pinot-clients/pinot-java-client/pom.xml
@@ -49,6 +49,12 @@
         <artifactId>maven-enforcer-plugin</artifactId>
       </plugin>
     </plugins>
+    <resources>
+      <resource>
+        <directory>src/main/resources</directory>
+        <filtering>true</filtering>
+      </resource>
+    </resources>
   </build>
   <dependencies>
     <dependency>
diff --git 
a/pinot-clients/pinot-java-client/src/main/java/org/apache/pinot/client/ConnectionFactory.java
 
b/pinot-clients/pinot-java-client/src/main/java/org/apache/pinot/client/ConnectionFactory.java
index f228c9e28b..0469c12b14 100644
--- 
a/pinot-clients/pinot-java-client/src/main/java/org/apache/pinot/client/ConnectionFactory.java
+++ 
b/pinot-clients/pinot-java-client/src/main/java/org/apache/pinot/client/ConnectionFactory.java
@@ -123,7 +123,7 @@ public class ConnectionFactory {
    * @return A connection that connects to the brokers specified in the 
properties
    */
   public static Connection fromProperties(Properties properties) {
-    return fromProperties(properties, getDefault());
+    return fromProperties(properties, getDefault(properties));
   }
 
   /**
@@ -171,14 +171,20 @@ public class ConnectionFactory {
     return new Connection(properties, brokers, transport);
   }
 
-  private static PinotClientTransport getDefault() {
+  private static PinotClientTransport getDefault(Properties 
connectionProperties) {
     if (_defaultTransport == null) {
       synchronized (ConnectionFactory.class) {
         if (_defaultTransport == null) {
-          _defaultTransport = new 
JsonAsyncHttpPinotClientTransportFactory().buildTransport();
+          _defaultTransport = new JsonAsyncHttpPinotClientTransportFactory()
+              .withConnectionProperties(connectionProperties)
+              .buildTransport();
         }
       }
     }
     return _defaultTransport;
   }
+
+  private static PinotClientTransport getDefault() {
+    return getDefault(new Properties());
+  }
 }
diff --git 
a/pinot-clients/pinot-java-client/src/main/java/org/apache/pinot/client/ConnectionTimeouts.java
 
b/pinot-clients/pinot-java-client/src/main/java/org/apache/pinot/client/ConnectionTimeouts.java
new file mode 100644
index 0000000000..90502467fc
--- /dev/null
+++ 
b/pinot-clients/pinot-java-client/src/main/java/org/apache/pinot/client/ConnectionTimeouts.java
@@ -0,0 +1,53 @@
+/**
+ * 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.pinot.client;
+
+/**
+ * Connections time out for AsyncHttpClient
+ */
+public class ConnectionTimeouts {
+    private final int _readTimeoutMs;
+    private final int _connectTimeoutMs;
+    private final int _handshakeTimeoutMs;
+
+    private ConnectionTimeouts(int readTimeoutMs, int connectTimeoutMs, int 
handshakeTimeoutMs) {
+        _readTimeoutMs = readTimeoutMs;
+        _connectTimeoutMs = connectTimeoutMs;
+        _handshakeTimeoutMs = handshakeTimeoutMs;
+    }
+
+    public static ConnectionTimeouts create(int readTimeoutMs, int 
connectTimeoutMs, int handshakeTimeoutMs) {
+        if (readTimeoutMs < 1 || connectTimeoutMs < 1 || handshakeTimeoutMs < 
1) {
+            throw new IllegalArgumentException("Timeouts must be > 0");
+        }
+        return new ConnectionTimeouts(readTimeoutMs, connectTimeoutMs, 
handshakeTimeoutMs);
+    }
+
+    public int getReadTimeoutMs() {
+        return _readTimeoutMs;
+    }
+
+    public int getConnectTimeoutMs() {
+        return _connectTimeoutMs;
+    }
+
+    public int getHandshakeTimeoutMs() {
+        return _handshakeTimeoutMs;
+    }
+}
diff --git 
a/pinot-clients/pinot-java-client/src/main/java/org/apache/pinot/client/JsonAsyncHttpPinotClientTransport.java
 
b/pinot-clients/pinot-java-client/src/main/java/org/apache/pinot/client/JsonAsyncHttpPinotClientTransport.java
index 71ea4b4262..073f1b8a09 100644
--- 
a/pinot-clients/pinot-java-client/src/main/java/org/apache/pinot/client/JsonAsyncHttpPinotClientTransport.java
+++ 
b/pinot-clients/pinot-java-client/src/main/java/org/apache/pinot/client/JsonAsyncHttpPinotClientTransport.java
@@ -28,6 +28,7 @@ import java.io.IOException;
 import java.nio.charset.StandardCharsets;
 import java.util.HashMap;
 import java.util.Map;
+import java.util.Properties;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.Future;
 import java.util.concurrent.TimeUnit;
@@ -54,19 +55,19 @@ public class JsonAsyncHttpPinotClientTransport implements 
PinotClientTransport {
   private final Map<String, String> _headers;
   private final String _scheme;
 
-  private static final long BROKER_READ_TIMEOUT_MS = 60000L;
-  private static final int BROKER_CONNECT_TIMEOUT_MS = 2000;
-
+  private final int _brokerReadTimeout;
   private final AsyncHttpClient _httpClient;
 
   public JsonAsyncHttpPinotClientTransport() {
+    _brokerReadTimeout = 60000;
     _headers = new HashMap<>();
     _scheme = CommonConstants.HTTP_PROTOCOL;
     _httpClient = Dsl.asyncHttpClient();
   }
 
   public JsonAsyncHttpPinotClientTransport(Map<String, String> headers, String 
scheme,
-    @Nullable SSLContext sslContext) {
+    @Nullable SSLContext sslContext, ConnectionTimeouts connectionTimeouts, 
TlsProtocols tlsProtocols) {
+    _brokerReadTimeout = connectionTimeouts.getReadTimeoutMs();
     _headers = headers;
     _scheme = scheme;
 
@@ -75,13 +76,17 @@ public class JsonAsyncHttpPinotClientTransport implements 
PinotClientTransport {
       builder.setSslContext(new JdkSslContext(sslContext, true, 
ClientAuth.OPTIONAL));
     }
 
-    builder.setReadTimeout((int) BROKER_READ_TIMEOUT_MS)
-        .setConnectTimeout(BROKER_CONNECT_TIMEOUT_MS);
+    builder.setReadTimeout(connectionTimeouts.getReadTimeoutMs())
+            .setConnectTimeout(connectionTimeouts.getConnectTimeoutMs())
+            .setHandshakeTimeout(connectionTimeouts.getHandshakeTimeoutMs())
+            .setUserAgent(getUserAgentVersionFromClassPath())
+            
.setEnabledProtocols(tlsProtocols.getEnabledProtocols().toArray(new String[0]));
     _httpClient = Dsl.asyncHttpClient(builder.build());
   }
 
   public JsonAsyncHttpPinotClientTransport(Map<String, String> headers, String 
scheme,
-    @Nullable SslContext sslContext) {
+    @Nullable SslContext sslContext, ConnectionTimeouts connectionTimeouts, 
TlsProtocols tlsProtocols) {
+    _brokerReadTimeout = connectionTimeouts.getReadTimeoutMs();
     _headers = headers;
     _scheme = scheme;
 
@@ -90,14 +95,32 @@ public class JsonAsyncHttpPinotClientTransport implements 
PinotClientTransport {
       builder.setSslContext(sslContext);
     }
 
+    builder.setReadTimeout(connectionTimeouts.getReadTimeoutMs())
+            .setConnectTimeout(connectionTimeouts.getConnectTimeoutMs())
+            .setHandshakeTimeout(connectionTimeouts.getHandshakeTimeoutMs())
+            .setUserAgent(getUserAgentVersionFromClassPath())
+            
.setEnabledProtocols(tlsProtocols.getEnabledProtocols().toArray(new String[0]));
     _httpClient = Dsl.asyncHttpClient(builder.build());
   }
 
+  private String getUserAgentVersionFromClassPath() {
+    Properties userAgentProperties = new Properties();
+    try {
+      
userAgentProperties.load(JsonAsyncHttpPinotClientTransport.class.getClassLoader()
+              .getResourceAsStream("version.properties"));
+    } catch (IOException e) {
+      LOGGER.warn("Unable to set user agent version");
+    }
+    return userAgentProperties.getProperty("ua", "pinot-java");
+  }
+
+
+
   @Override
   public BrokerResponse executeQuery(String brokerAddress, String query)
     throws PinotClientException {
     try {
-      return executeQueryAsync(brokerAddress, 
query).get(BROKER_READ_TIMEOUT_MS, TimeUnit.MILLISECONDS);
+      return executeQueryAsync(brokerAddress, query).get(_brokerReadTimeout, 
TimeUnit.MILLISECONDS);
     } catch (Exception e) {
       throw new PinotClientException(e);
     }
@@ -120,7 +143,7 @@ public class JsonAsyncHttpPinotClientTransport implements 
PinotClientTransport {
       Future<Response> response =
           requestBuilder.addHeader("Content-Type", "application/json; 
charset=utf-8").setBody(json.toString())
               .execute();
-      return new BrokerResponseFuture(response, query, url);
+      return new BrokerResponseFuture(response, query, url, 
_brokerReadTimeout);
     } catch (Exception e) {
       throw new PinotClientException(e);
     }
@@ -130,7 +153,7 @@ public class JsonAsyncHttpPinotClientTransport implements 
PinotClientTransport {
   public BrokerResponse executeQuery(String brokerAddress, Request request)
       throws PinotClientException {
     try {
-      return executeQueryAsync(brokerAddress, 
request).get(BROKER_READ_TIMEOUT_MS, TimeUnit.MILLISECONDS);
+      return executeQueryAsync(brokerAddress, request).get(_brokerReadTimeout, 
TimeUnit.MILLISECONDS);
     } catch (Exception e) {
       throw new PinotClientException(e);
     }
@@ -159,11 +182,13 @@ public class JsonAsyncHttpPinotClientTransport implements 
PinotClientTransport {
     private final Future<Response> _response;
     private final String _query;
     private final String _url;
+    private final long _brokerReadTimeout;
 
-    public BrokerResponseFuture(Future<Response> response, String query, 
String url) {
+    public BrokerResponseFuture(Future<Response> response, String query, 
String url, long brokerReadTimeout) {
       _response = response;
       _query = query;
       _url = url;
+      _brokerReadTimeout = brokerReadTimeout;
     }
 
     @Override
@@ -184,7 +209,7 @@ public class JsonAsyncHttpPinotClientTransport implements 
PinotClientTransport {
     @Override
     public BrokerResponse get()
         throws ExecutionException {
-      return get(BROKER_READ_TIMEOUT_MS, TimeUnit.MILLISECONDS);
+      return get(_brokerReadTimeout, TimeUnit.MILLISECONDS);
     }
 
     @Override
diff --git 
a/pinot-clients/pinot-java-client/src/main/java/org/apache/pinot/client/JsonAsyncHttpPinotClientTransportFactory.java
 
b/pinot-clients/pinot-java-client/src/main/java/org/apache/pinot/client/JsonAsyncHttpPinotClientTransportFactory.java
index bcf4408010..a8c568380c 100644
--- 
a/pinot-clients/pinot-java-client/src/main/java/org/apache/pinot/client/JsonAsyncHttpPinotClientTransportFactory.java
+++ 
b/pinot-clients/pinot-java-client/src/main/java/org/apache/pinot/client/JsonAsyncHttpPinotClientTransportFactory.java
@@ -20,6 +20,7 @@ package org.apache.pinot.client;
 
 import java.util.HashMap;
 import java.util.Map;
+import java.util.Properties;
 import javax.net.ssl.SSLContext;
 import org.apache.pinot.spi.utils.CommonConstants;
 
@@ -28,15 +29,27 @@ import org.apache.pinot.spi.utils.CommonConstants;
  * Pinot client transport factory for JSON encoded BrokerResults through HTTP.
  */
 public class JsonAsyncHttpPinotClientTransportFactory implements 
PinotClientTransportFactory {
+
+  private static final String DEFAULT_BROKER_READ_TIMEOUT_MS = "60000";
+  private static final String DEFAULT_BROKER_CONNECT_TIMEOUT_MS = "2000";
+  private static final String DEFAULT_BROKER_HANDSHAKE_TIMEOUT_MS = "2000";
+  private static final String DEFAULT_BROKER_TLS_V10_ENABLED = "false";
+
   private Map<String, String> _headers = new HashMap<>();
   private String _scheme = CommonConstants.HTTP_PROTOCOL;
   private SSLContext _sslContext = null;
+  private boolean _tlsV10Enabled = false;
+  private int _readTimeoutMs = 
Integer.parseInt(DEFAULT_BROKER_READ_TIMEOUT_MS);
+  private int _connectTimeoutMs = 
Integer.parseInt(DEFAULT_BROKER_READ_TIMEOUT_MS);
+  private int _handshakeTimeoutMs = 
Integer.parseInt(DEFAULT_BROKER_HANDSHAKE_TIMEOUT_MS);
 
   @Override
   public PinotClientTransport buildTransport() {
-    return new JsonAsyncHttpPinotClientTransport(_headers, _scheme, 
_sslContext);
+    ConnectionTimeouts connectionTimeouts = 
ConnectionTimeouts.create(_readTimeoutMs, _connectTimeoutMs,
+            _handshakeTimeoutMs);
+    TlsProtocols tlsProtocols = TlsProtocols.defaultProtocols(_tlsV10Enabled);
+    return new JsonAsyncHttpPinotClientTransport(_headers, _scheme, 
_sslContext, connectionTimeouts, tlsProtocols);
   }
-
   public Map<String, String> getHeaders() {
     return _headers;
   }
@@ -60,4 +73,18 @@ public class JsonAsyncHttpPinotClientTransportFactory 
implements PinotClientTran
   public void setSslContext(SSLContext sslContext) {
     _sslContext = sslContext;
   }
+
+  public JsonAsyncHttpPinotClientTransportFactory 
withConnectionProperties(Properties properties) {
+    _readTimeoutMs = 
Integer.parseInt(properties.getProperty("brokerReadTimeoutMs",
+            DEFAULT_BROKER_READ_TIMEOUT_MS));
+    _connectTimeoutMs = 
Integer.parseInt(properties.getProperty("brokerConnectTimeoutMs",
+            DEFAULT_BROKER_CONNECT_TIMEOUT_MS));
+    _handshakeTimeoutMs = 
Integer.parseInt(properties.getProperty("brokerHandshakeTimeoutMs",
+            DEFAULT_BROKER_HANDSHAKE_TIMEOUT_MS));
+    _tlsV10Enabled = 
Boolean.parseBoolean(properties.getProperty("brokerTlsV10Enabled",
+            DEFAULT_BROKER_TLS_V10_ENABLED))
+            || 
Boolean.parseBoolean(System.getProperties().getProperty("broker.tlsV10Enabled",
+            DEFAULT_BROKER_TLS_V10_ENABLED));
+    return this;
+  }
 }
diff --git 
a/pinot-clients/pinot-java-client/src/main/java/org/apache/pinot/client/TlsProtocols.java
 
b/pinot-clients/pinot-java-client/src/main/java/org/apache/pinot/client/TlsProtocols.java
new file mode 100644
index 0000000000..9cc78a224f
--- /dev/null
+++ 
b/pinot-clients/pinot-java-client/src/main/java/org/apache/pinot/client/TlsProtocols.java
@@ -0,0 +1,52 @@
+/**
+ * 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.pinot.client;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+/**
+ * TLS Protocols enabled for AsyncHttpClient
+ */
+public class TlsProtocols {
+    private final List<String> _enabledProtocols;
+
+    private TlsProtocols(List<String> enabledProtocols) {
+        _enabledProtocols = enabledProtocols;
+    }
+
+    public List<String> getEnabledProtocols() {
+        if (_enabledProtocols != null) {
+            return _enabledProtocols;
+        }
+        return Collections.emptyList();
+    }
+
+    public static TlsProtocols defaultProtocols(boolean tlsV10Enabled) {
+        List<String> enabledProtocols = new ArrayList<>();
+        enabledProtocols.add("TLSv1.3");
+        enabledProtocols.add("TLSv1.2");
+        enabledProtocols.add("TLSv1.1");
+        if (tlsV10Enabled) {
+            enabledProtocols.add("TLSv1.0");
+        }
+        return new TlsProtocols(enabledProtocols);
+    }
+}
diff --git 
a/pinot-clients/pinot-java-client/src/main/resources/version.properties 
b/pinot-clients/pinot-java-client/src/main/resources/version.properties
new file mode 100644
index 0000000000..cf91e7b89a
--- /dev/null
+++ b/pinot-clients/pinot-java-client/src/main/resources/version.properties
@@ -0,0 +1,20 @@
+#
+# 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.
+#
+
+ua=pinot-java/${project.version}
diff --git a/pinot-clients/pinot-jdbc-client/pom.xml 
b/pinot-clients/pinot-jdbc-client/pom.xml
index 80b67521b4..7a7b92a68b 100644
--- a/pinot-clients/pinot-jdbc-client/pom.xml
+++ b/pinot-clients/pinot-jdbc-client/pom.xml
@@ -57,6 +57,10 @@
           <include>java.sql.Driver</include>
         </includes>
       </resource>
+      <resource>
+        <directory>src/main/resources</directory>
+        <filtering>true</filtering>
+      </resource>
     </resources>
   </build>
   <dependencies>
diff --git 
a/pinot-clients/pinot-jdbc-client/src/main/java/org/apache/pinot/client/PinotConnection.java
 
b/pinot-clients/pinot-jdbc-client/src/main/java/org/apache/pinot/client/PinotConnection.java
index c71019bac5..6847122605 100644
--- 
a/pinot-clients/pinot-jdbc-client/src/main/java/org/apache/pinot/client/PinotConnection.java
+++ 
b/pinot-clients/pinot-jdbc-client/src/main/java/org/apache/pinot/client/PinotConnection.java
@@ -28,6 +28,7 @@ import java.util.List;
 import java.util.Properties;
 import org.apache.pinot.client.base.AbstractBaseConnection;
 import org.apache.pinot.client.controller.PinotControllerTransport;
+import org.apache.pinot.client.controller.PinotControllerTransportFactory;
 import 
org.apache.pinot.client.controller.response.ControllerTenantBrokerResponse;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -52,7 +53,7 @@ public class PinotConnection extends AbstractBaseConnection {
     _closed = false;
     _controllerURL = controllerURL;
     if (controllerTransport == null) {
-      _controllerTransport = new PinotControllerTransport();
+      _controllerTransport = new 
PinotControllerTransportFactory().buildTransport();
     } else {
       _controllerTransport = controllerTransport;
     }
diff --git 
a/pinot-clients/pinot-jdbc-client/src/main/java/org/apache/pinot/client/PinotDriver.java
 
b/pinot-clients/pinot-jdbc-client/src/main/java/org/apache/pinot/client/PinotDriver.java
index af08dd7ed5..2e44fadeb5 100644
--- 
a/pinot-clients/pinot-jdbc-client/src/main/java/org/apache/pinot/client/PinotDriver.java
+++ 
b/pinot-clients/pinot-jdbc-client/src/main/java/org/apache/pinot/client/PinotDriver.java
@@ -112,8 +112,10 @@ public class PinotDriver implements Driver {
         pinotControllerTransportFactory.setHeaders(headers);
       }
 
-      PinotClientTransport pinotClientTransport = factory.buildTransport();
-      PinotControllerTransport pinotControllerTransport = 
pinotControllerTransportFactory.buildTransport();
+      PinotClientTransport pinotClientTransport = 
factory.withConnectionProperties(info).buildTransport();
+      PinotControllerTransport pinotControllerTransport = 
pinotControllerTransportFactory
+              .withConnectionProperties(info)
+              .buildTransport();
       String controllerUrl = DriverUtils.getControllerFromURL(url);
       String tenant = info.getProperty(INFO_TENANT, DEFAULT_TENANT);
       return new PinotConnection(info, controllerUrl, pinotClientTransport, 
tenant, pinotControllerTransport);
diff --git 
a/pinot-clients/pinot-jdbc-client/src/main/java/org/apache/pinot/client/controller/PinotControllerTransport.java
 
b/pinot-clients/pinot-jdbc-client/src/main/java/org/apache/pinot/client/controller/PinotControllerTransport.java
index d0df4e2116..46c15d4ad3 100644
--- 
a/pinot-clients/pinot-jdbc-client/src/main/java/org/apache/pinot/client/controller/PinotControllerTransport.java
+++ 
b/pinot-clients/pinot-jdbc-client/src/main/java/org/apache/pinot/client/controller/PinotControllerTransport.java
@@ -21,17 +21,18 @@ package org.apache.pinot.client.controller;
 import io.netty.handler.ssl.ClientAuth;
 import io.netty.handler.ssl.JdkSslContext;
 import java.io.IOException;
-import java.util.Collections;
 import java.util.Map;
+import java.util.Properties;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.Future;
 import javax.annotation.Nullable;
 import javax.net.ssl.SSLContext;
+import org.apache.pinot.client.ConnectionTimeouts;
 import org.apache.pinot.client.PinotClientException;
+import org.apache.pinot.client.TlsProtocols;
 import 
org.apache.pinot.client.controller.response.ControllerTenantBrokerResponse;
 import org.apache.pinot.client.controller.response.SchemaResponse;
 import org.apache.pinot.client.controller.response.TableResponse;
-import org.apache.pinot.spi.utils.CommonConstants;
 import org.asynchttpclient.AsyncHttpClient;
 import org.asynchttpclient.BoundRequestBuilder;
 import org.asynchttpclient.DefaultAsyncHttpClientConfig;
@@ -50,16 +51,8 @@ public class PinotControllerTransport {
   private final AsyncHttpClient _httpClient;
 
 
-  public PinotControllerTransport() {
-    this(Collections.emptyMap(), CommonConstants.HTTP_PROTOCOL, null);
-  }
-
-  public PinotControllerTransport(Map<String, String> headers) {
-    this(headers, CommonConstants.HTTP_PROTOCOL, null);
-  }
-
   public PinotControllerTransport(Map<String, String> headers, String scheme,
-      @Nullable SSLContext sslContext) {
+    @Nullable SSLContext sslContext, ConnectionTimeouts connectionTimeouts, 
TlsProtocols tlsProtocols) {
     _headers = headers;
     _scheme = scheme;
 
@@ -68,9 +61,26 @@ public class PinotControllerTransport {
       builder.setSslContext(new JdkSslContext(sslContext, true, 
ClientAuth.OPTIONAL));
     }
 
+    builder.setReadTimeout(connectionTimeouts.getReadTimeoutMs())
+            .setConnectTimeout(connectionTimeouts.getConnectTimeoutMs())
+            .setHandshakeTimeout(connectionTimeouts.getHandshakeTimeoutMs())
+            .setUserAgent(getUserAgentVersionFromClassPath())
+            
.setEnabledProtocols(tlsProtocols.getEnabledProtocols().toArray(new String[0]));
+
     _httpClient = Dsl.asyncHttpClient(builder.build());
   }
 
+  private String getUserAgentVersionFromClassPath() {
+    Properties userAgentProperties = new Properties();
+    try {
+      userAgentProperties.load(PinotControllerTransport.class.getClassLoader()
+              .getResourceAsStream("version.properties"));
+    } catch (IOException e) {
+      LOGGER.warn("Unable to set user agent version");
+    }
+    return userAgentProperties.getProperty("ua", "unknown");
+  }
+
   public TableResponse getAllTables(String controllerAddress) {
     try {
       String url = _scheme + "://" + controllerAddress + "/tables";
diff --git 
a/pinot-clients/pinot-jdbc-client/src/main/java/org/apache/pinot/client/controller/PinotControllerTransportFactory.java
 
b/pinot-clients/pinot-jdbc-client/src/main/java/org/apache/pinot/client/controller/PinotControllerTransportFactory.java
index ead3ee637f..3dbe899e75 100644
--- 
a/pinot-clients/pinot-jdbc-client/src/main/java/org/apache/pinot/client/controller/PinotControllerTransportFactory.java
+++ 
b/pinot-clients/pinot-jdbc-client/src/main/java/org/apache/pinot/client/controller/PinotControllerTransportFactory.java
@@ -20,17 +20,33 @@ package org.apache.pinot.client.controller;
 
 import java.util.HashMap;
 import java.util.Map;
+import java.util.Properties;
 import javax.net.ssl.SSLContext;
+import org.apache.pinot.client.ConnectionTimeouts;
+import org.apache.pinot.client.TlsProtocols;
 import org.apache.pinot.spi.utils.CommonConstants;
 
 
 public class PinotControllerTransportFactory {
+  private static final String DEFAULT_CONTROLLER_READ_TIMEOUT_MS = "60000";
+  private static final String DEFAULT_CONTROLLER_CONNECT_TIMEOUT_MS = "2000";
+  private static final String DEFAULT_CONTROLLER_HANDSHAKE_TIMEOUT_MS = "2000";
+  private static final String DEFAULT_CONTROLLER_TLS_V10_ENABLED = "false";
+
   private Map<String, String> _headers = new HashMap<>();
   private String _scheme = CommonConstants.HTTP_PROTOCOL;
   private SSLContext _sslContext = null;
 
+  private boolean _tlsV10Enabled = false;
+  private int _readTimeoutMs = 
Integer.parseInt(DEFAULT_CONTROLLER_READ_TIMEOUT_MS);
+  private int _connectTimeoutMs = 
Integer.parseInt(DEFAULT_CONTROLLER_CONNECT_TIMEOUT_MS);
+  private int _handshakeTimeoutMs = 
Integer.parseInt(DEFAULT_CONTROLLER_HANDSHAKE_TIMEOUT_MS);
+
   public PinotControllerTransport buildTransport() {
-    return new PinotControllerTransport(_headers, _scheme, _sslContext);
+    ConnectionTimeouts connectionTimeouts = 
ConnectionTimeouts.create(_readTimeoutMs, _connectTimeoutMs,
+            _handshakeTimeoutMs);
+    TlsProtocols tlsProtocols = TlsProtocols.defaultProtocols(_tlsV10Enabled);
+    return new PinotControllerTransport(_headers, _scheme, _sslContext, 
connectionTimeouts, tlsProtocols);
   }
 
   public Map<String, String> getHeaders() {
@@ -56,4 +72,18 @@ public class PinotControllerTransportFactory {
   public void setSslContext(SSLContext sslContext) {
     _sslContext = sslContext;
   }
+
+  public PinotControllerTransportFactory withConnectionProperties(Properties 
properties) {
+    _readTimeoutMs = 
Integer.parseInt(properties.getProperty("controllerReadTimeoutMs",
+            DEFAULT_CONTROLLER_READ_TIMEOUT_MS));
+    _connectTimeoutMs = 
Integer.parseInt(properties.getProperty("controllerConnectTimeoutMs",
+            DEFAULT_CONTROLLER_CONNECT_TIMEOUT_MS));
+    _handshakeTimeoutMs = 
Integer.parseInt(properties.getProperty("controllerHandshakeTimeoutMs",
+            DEFAULT_CONTROLLER_HANDSHAKE_TIMEOUT_MS));
+    _tlsV10Enabled = 
Boolean.parseBoolean(properties.getProperty("controllerTlsV10Enabled",
+            DEFAULT_CONTROLLER_TLS_V10_ENABLED))
+            || 
Boolean.parseBoolean(System.getProperties().getProperty("controller.tlsV10Enabled",
+            DEFAULT_CONTROLLER_TLS_V10_ENABLED));
+    return this;
+  }
 }
diff --git 
a/pinot-clients/pinot-jdbc-client/src/main/resources/version.properties 
b/pinot-clients/pinot-jdbc-client/src/main/resources/version.properties
new file mode 100644
index 0000000000..db66ca9319
--- /dev/null
+++ b/pinot-clients/pinot-jdbc-client/src/main/resources/version.properties
@@ -0,0 +1,20 @@
+#
+# 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.
+#
+
+ua=pinot-jdbc/${project.version}
diff --git 
a/pinot-clients/pinot-jdbc-client/src/test/java/org/apache/pinot/client/DummyPinotControllerTransport.java
 
b/pinot-clients/pinot-jdbc-client/src/test/java/org/apache/pinot/client/DummyPinotControllerTransport.java
index 0a11da3fc6..03e5ad5e76 100644
--- 
a/pinot-clients/pinot-jdbc-client/src/test/java/org/apache/pinot/client/DummyPinotControllerTransport.java
+++ 
b/pinot-clients/pinot-jdbc-client/src/test/java/org/apache/pinot/client/DummyPinotControllerTransport.java
@@ -19,6 +19,9 @@
 package org.apache.pinot.client;
 
 import com.fasterxml.jackson.databind.JsonNode;
+import java.util.Map;
+import javax.annotation.Nullable;
+import javax.net.ssl.SSLContext;
 import org.apache.pinot.client.controller.PinotControllerTransport;
 import 
org.apache.pinot.client.controller.response.ControllerTenantBrokerResponse;
 import org.apache.pinot.spi.utils.JsonUtils;
@@ -26,6 +29,12 @@ import org.apache.pinot.spi.utils.JsonUtils;
 
 public class DummyPinotControllerTransport extends PinotControllerTransport {
 
+  public DummyPinotControllerTransport(Map<String, String> headers, String 
scheme, @Nullable SSLContext sslContext) {
+    super(headers, scheme, sslContext,
+            ConnectionTimeouts.create(1000, 1000, 1000),
+            TlsProtocols.defaultProtocols(true));
+  }
+
   @Override
   public ControllerTenantBrokerResponse getBrokersFromController(String 
controllerAddress, String tenant) {
     try {
@@ -36,4 +45,8 @@ public class DummyPinotControllerTransport extends 
PinotControllerTransport {
     }
     return ControllerTenantBrokerResponse.empty();
   }
+
+  public static DummyPinotControllerTransport create() {
+    return new DummyPinotControllerTransport(null, null, null);
+  }
 }
diff --git 
a/pinot-clients/pinot-jdbc-client/src/test/java/org/apache/pinot/client/PinotConnectionTest.java
 
b/pinot-clients/pinot-jdbc-client/src/test/java/org/apache/pinot/client/PinotConnectionTest.java
index e2136ae6e1..1d783f82f2 100644
--- 
a/pinot-clients/pinot-jdbc-client/src/test/java/org/apache/pinot/client/PinotConnectionTest.java
+++ 
b/pinot-clients/pinot-jdbc-client/src/test/java/org/apache/pinot/client/PinotConnectionTest.java
@@ -25,7 +25,7 @@ import org.testng.annotations.Test;
 
 public class PinotConnectionTest {
   private DummyPinotClientTransport _dummyPinotClientTransport = new 
DummyPinotClientTransport();
-  private DummyPinotControllerTransport _dummyPinotControllerTransport = new 
DummyPinotControllerTransport();
+  private DummyPinotControllerTransport _dummyPinotControllerTransport = 
DummyPinotControllerTransport.create();
 
   @Test
   public void createStatementTest()
diff --git 
a/pinot-clients/pinot-jdbc-client/src/test/java/org/apache/pinot/client/PinotPreparedStatementTest.java
 
b/pinot-clients/pinot-jdbc-client/src/test/java/org/apache/pinot/client/PinotPreparedStatementTest.java
index 54b886b18b..0cc203a994 100644
--- 
a/pinot-clients/pinot-jdbc-client/src/test/java/org/apache/pinot/client/PinotPreparedStatementTest.java
+++ 
b/pinot-clients/pinot-jdbc-client/src/test/java/org/apache/pinot/client/PinotPreparedStatementTest.java
@@ -36,7 +36,7 @@ public class PinotPreparedStatementTest {
   public static final String DATE_QUERY = "SELECT * FROM dummy WHERE date = ? 
and updated_at = ? and created_at = ?";
   public static final String SINGLE_STRING_QUERY = "SELECT * FROM dummy WHERE 
value = ?";
   private DummyPinotClientTransport _dummyPinotClientTransport = new 
DummyPinotClientTransport();
-  private DummyPinotControllerTransport _dummyPinotControllerTransport = new 
DummyPinotControllerTransport();
+  private DummyPinotControllerTransport _dummyPinotControllerTransport = 
DummyPinotControllerTransport.create();
 
   @Test
   public void testSetAndClearValues()
diff --git 
a/pinot-clients/pinot-jdbc-client/src/test/java/org/apache/pinot/client/PinotStatementTest.java
 
b/pinot-clients/pinot-jdbc-client/src/test/java/org/apache/pinot/client/PinotStatementTest.java
index a29a49d6ba..db4e1dfbb0 100644
--- 
a/pinot-clients/pinot-jdbc-client/src/test/java/org/apache/pinot/client/PinotStatementTest.java
+++ 
b/pinot-clients/pinot-jdbc-client/src/test/java/org/apache/pinot/client/PinotStatementTest.java
@@ -26,7 +26,7 @@ import org.testng.annotations.Test;
 
 public class PinotStatementTest {
   private DummyPinotClientTransport _dummyPinotClientTransport = new 
DummyPinotClientTransport();
-  private DummyPinotControllerTransport _dummyPinotControllerTransport = new 
DummyPinotControllerTransport();
+  private DummyPinotControllerTransport _dummyPinotControllerTransport = 
DummyPinotControllerTransport.create();
 
   @Test
   public void testExecuteQuery()


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org
For additional commands, e-mail: commits-h...@pinot.apache.org

Reply via email to