Skip to content

Commit

Permalink
Use OkHttp for CLI and JDBC driver
Browse files Browse the repository at this point in the history
  • Loading branch information
electrum committed Jun 23, 2017
1 parent 3ca2819 commit 62a8af4
Show file tree
Hide file tree
Showing 27 changed files with 1,048 additions and 531 deletions.
13 changes: 13 additions & 0 deletions pom.xml
Expand Up @@ -51,6 +51,7 @@
<dep.packaging.version>${dep.airlift.version}</dep.packaging.version> <dep.packaging.version>${dep.airlift.version}</dep.packaging.version>
<dep.slice.version>0.29</dep.slice.version> <dep.slice.version>0.29</dep.slice.version>
<dep.aws-sdk.version>1.11.30</dep.aws-sdk.version> <dep.aws-sdk.version>1.11.30</dep.aws-sdk.version>
<dep.okhttp.version>3.8.1</dep.okhttp.version>
<dep.tempto.version>1.31</dep.tempto.version> <dep.tempto.version>1.31</dep.tempto.version>
<dep.testng.version>6.10</dep.testng.version> <dep.testng.version>6.10</dep.testng.version>
<dep.nifty.version>0.15.1</dep.nifty.version> <dep.nifty.version>0.15.1</dep.nifty.version>
Expand Down Expand Up @@ -631,6 +632,18 @@
<version>2.78</version> <version>2.78</version>
</dependency> </dependency>


<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>${dep.okhttp.version}</version>
</dependency>

<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>mockwebserver</artifactId>
<version>${dep.okhttp.version}</version>
</dependency>

<dependency> <dependency>
<groupId>com.facebook.swift</groupId> <groupId>com.facebook.swift</groupId>
<artifactId>swift-annotations</artifactId> <artifactId>swift-annotations</artifactId>
Expand Down
5 changes: 5 additions & 0 deletions presto-benchmark-driver/pom.xml
Expand Up @@ -72,6 +72,11 @@
<artifactId>commons-math3</artifactId> <artifactId>commons-math3</artifactId>
</dependency> </dependency>


<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
</dependency>

<!-- for testing --> <!-- for testing -->
<dependency> <dependency>
<groupId>org.testng</groupId> <groupId>org.testng</groupId>
Expand Down
Expand Up @@ -15,7 +15,6 @@


import com.facebook.presto.client.ClientSession; import com.facebook.presto.client.ClientSession;
import com.facebook.presto.client.QueryError; import com.facebook.presto.client.QueryError;
import com.facebook.presto.client.QueryResults;
import com.facebook.presto.client.StatementClient; import com.facebook.presto.client.StatementClient;
import com.facebook.presto.client.StatementStats; import com.facebook.presto.client.StatementStats;
import com.google.common.base.Throwables; import com.google.common.base.Throwables;
Expand All @@ -28,8 +27,8 @@
import io.airlift.http.client.JsonResponseHandler; import io.airlift.http.client.JsonResponseHandler;
import io.airlift.http.client.Request; import io.airlift.http.client.Request;
import io.airlift.http.client.jetty.JettyHttpClient; import io.airlift.http.client.jetty.JettyHttpClient;
import io.airlift.json.JsonCodec;
import io.airlift.units.Duration; import io.airlift.units.Duration;
import okhttp3.OkHttpClient;


import java.io.Closeable; import java.io.Closeable;
import java.net.URI; import java.net.URI;
Expand All @@ -39,6 +38,7 @@


import static com.facebook.presto.benchmark.driver.BenchmarkQueryResult.failResult; import static com.facebook.presto.benchmark.driver.BenchmarkQueryResult.failResult;
import static com.facebook.presto.benchmark.driver.BenchmarkQueryResult.passResult; import static com.facebook.presto.benchmark.driver.BenchmarkQueryResult.passResult;
import static com.facebook.presto.client.OkHttpUtil.setupSocksProxy;
import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkArgument;
import static io.airlift.http.client.HttpUriBuilder.uriBuilderFrom; import static io.airlift.http.client.HttpUriBuilder.uriBuilderFrom;
import static io.airlift.http.client.JsonResponseHandler.createJsonResponseHandler; import static io.airlift.http.client.JsonResponseHandler.createJsonResponseHandler;
Expand All @@ -59,8 +59,8 @@ public class BenchmarkQueryRunner
private final int maxFailures; private final int maxFailures;


private final HttpClient httpClient; private final HttpClient httpClient;
private final OkHttpClient okHttpClient;
private final List<URI> nodes; private final List<URI> nodes;
private final JsonCodec<QueryResults> queryResultsCodec;


private int failures; private int failures;


Expand All @@ -77,8 +77,6 @@ public BenchmarkQueryRunner(int warm, int runs, boolean debug, int maxFailures,


this.debug = debug; this.debug = debug;


this.queryResultsCodec = jsonCodec(QueryResults.class);

requireNonNull(socksProxy, "socksProxy is null"); requireNonNull(socksProxy, "socksProxy is null");
HttpClientConfig httpClientConfig = new HttpClientConfig(); HttpClientConfig httpClientConfig = new HttpClientConfig();
if (socksProxy.isPresent()) { if (socksProxy.isPresent()) {
Expand All @@ -87,6 +85,10 @@ public BenchmarkQueryRunner(int warm, int runs, boolean debug, int maxFailures,


this.httpClient = new JettyHttpClient(httpClientConfig.setConnectTimeout(new Duration(10, TimeUnit.SECONDS))); this.httpClient = new JettyHttpClient(httpClientConfig.setConnectTimeout(new Duration(10, TimeUnit.SECONDS)));


OkHttpClient.Builder builder = new OkHttpClient.Builder();
setupSocksProxy(builder, socksProxy);
this.okHttpClient = builder.build();

nodes = getAllNodes(requireNonNull(serverUri, "serverUri is null")); nodes = getAllNodes(requireNonNull(serverUri, "serverUri is null"));
} }


Expand Down Expand Up @@ -149,7 +151,7 @@ public List<String> getSchemas(ClientSession session)
failures = 0; failures = 0;
while (true) { while (true) {
// start query // start query
StatementClient client = new StatementClient(httpClient, queryResultsCodec, session, "show schemas"); StatementClient client = new StatementClient(okHttpClient, session, "show schemas");


// read query output // read query output
ImmutableList.Builder<String> schemas = ImmutableList.builder(); ImmutableList.Builder<String> schemas = ImmutableList.builder();
Expand Down Expand Up @@ -190,7 +192,7 @@ public List<String> getSchemas(ClientSession session)
private StatementStats execute(ClientSession session, String name, String query) private StatementStats execute(ClientSession session, String name, String query)
{ {
// start query // start query
StatementClient client = new StatementClient(httpClient, queryResultsCodec, session, query); StatementClient client = new StatementClient(okHttpClient, session, query);


// read query output // read query output
while (client.isValid() && client.advance()) { while (client.isValid() && client.advance()) {
Expand Down
15 changes: 5 additions & 10 deletions presto-cli/pom.xml
Expand Up @@ -37,16 +37,6 @@
<artifactId>concurrent</artifactId> <artifactId>concurrent</artifactId>
</dependency> </dependency>


<dependency>
<groupId>io.airlift</groupId>
<artifactId>http-client</artifactId>
</dependency>

<dependency>
<groupId>io.airlift</groupId>
<artifactId>json</artifactId>
</dependency>

<dependency> <dependency>
<groupId>io.airlift</groupId> <groupId>io.airlift</groupId>
<artifactId>log</artifactId> <artifactId>log</artifactId>
Expand Down Expand Up @@ -87,6 +77,11 @@
<artifactId>opencsv</artifactId> <artifactId>opencsv</artifactId>
</dependency> </dependency>


<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
</dependency>

<!-- for testing --> <!-- for testing -->
<dependency> <dependency>
<groupId>org.testng</groupId> <groupId>org.testng</groupId>
Expand Down
Expand Up @@ -18,10 +18,8 @@
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.common.net.HostAndPort; import com.google.common.net.HostAndPort;
import io.airlift.airline.Option; import io.airlift.airline.Option;
import io.airlift.http.client.spnego.KerberosConfig;
import io.airlift.units.Duration; import io.airlift.units.Duration;


import java.io.File;
import java.net.URI; import java.net.URI;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import java.nio.charset.CharsetEncoder; import java.nio.charset.CharsetEncoder;
Expand Down Expand Up @@ -146,22 +144,6 @@ public ClientSession toClientSession()
clientRequestTimeout); clientRequestTimeout);
} }


public KerberosConfig toKerberosConfig()
{
KerberosConfig config = new KerberosConfig();
if (krb5ConfigPath != null) {
config.setConfig(new File(krb5ConfigPath));
}
if (krb5KeytabPath != null) {
config.setKeytab(new File(krb5KeytabPath));
}
if (krb5CredentialCachePath != null) {
config.setCredentialCache(new File(krb5CredentialCachePath));
}
config.setUseCanonicalHostname(!krb5DisableRemoteServiceHostnameCanonicalization);
return config;
}

public static URI parseServer(String server) public static URI parseServer(String server)
{ {
server = server.toLowerCase(ENGLISH); server = server.toLowerCase(ENGLISH);
Expand Down
11 changes: 6 additions & 5 deletions presto-cli/src/main/java/com/facebook/presto/cli/Console.java
Expand Up @@ -27,7 +27,6 @@
import com.google.common.io.Files; import com.google.common.io.Files;
import io.airlift.airline.Command; import io.airlift.airline.Command;
import io.airlift.airline.HelpOption; import io.airlift.airline.HelpOption;
import io.airlift.http.client.spnego.KerberosConfig;
import io.airlift.log.Logging; import io.airlift.log.Logging;
import io.airlift.log.LoggingConfiguration; import io.airlift.log.LoggingConfiguration;
import io.airlift.units.Duration; import io.airlift.units.Duration;
Expand Down Expand Up @@ -94,7 +93,6 @@ public class Console
public void run() public void run()
{ {
ClientSession session = clientOptions.toClientSession(); ClientSession session = clientOptions.toClientSession();
KerberosConfig kerberosConfig = clientOptions.toKerberosConfig();
boolean hasQuery = !Strings.isNullOrEmpty(clientOptions.execute); boolean hasQuery = !Strings.isNullOrEmpty(clientOptions.execute);
boolean isFromFile = !Strings.isNullOrEmpty(clientOptions.file); boolean isFromFile = !Strings.isNullOrEmpty(clientOptions.file);


Expand Down Expand Up @@ -125,7 +123,7 @@ public void run()
AtomicBoolean exiting = new AtomicBoolean(); AtomicBoolean exiting = new AtomicBoolean();
interruptThreadOnExit(Thread.currentThread(), exiting); interruptThreadOnExit(Thread.currentThread(), exiting);


try (QueryRunner queryRunner = QueryRunner.create( try (QueryRunner queryRunner = new QueryRunner(
session, session,
Optional.ofNullable(clientOptions.socksProxy), Optional.ofNullable(clientOptions.socksProxy),
Optional.ofNullable(clientOptions.keystorePath), Optional.ofNullable(clientOptions.keystorePath),
Expand All @@ -136,8 +134,11 @@ public void run()
clientOptions.password ? Optional.of(getPassword()) : Optional.empty(), clientOptions.password ? Optional.of(getPassword()) : Optional.empty(),
Optional.ofNullable(clientOptions.krb5Principal), Optional.ofNullable(clientOptions.krb5Principal),
Optional.ofNullable(clientOptions.krb5RemoteServiceName), Optional.ofNullable(clientOptions.krb5RemoteServiceName),
clientOptions.authenticationEnabled, Optional.ofNullable(clientOptions.krb5ConfigPath),
kerberosConfig)) { Optional.ofNullable(clientOptions.krb5KeytabPath),
Optional.ofNullable(clientOptions.krb5CredentialCachePath),
!clientOptions.krb5DisableRemoteServiceHostnameCanonicalization,
clientOptions.authenticationEnabled)) {
if (hasQuery) { if (hasQuery) {
executeCommand(queryRunner, query, clientOptions.outputFormat); executeCommand(queryRunner, query, clientOptions.outputFormat);
} }
Expand Down

This file was deleted.

0 comments on commit 62a8af4

Please sign in to comment.