From 3645decae2cd476feed925dcde3feceab3f773b5 Mon Sep 17 00:00:00 2001 From: Christopher Harris Date: Sat, 20 Jan 2024 08:55:03 -0600 Subject: [PATCH 1/3] Upgrade async http client Current usages of async http client when making SSL connections is having issues. Upgrading the client, similar to pinot in this PR https://github.com/apache/pinot/pull/7968/ --- subprojects/parseq-http-client/build.gradle | 2 +- .../parseq/httpclient/HttpClient.java | 30 ++++++----- .../httpclient/WrappedRequestBuilder.java | 53 ++++++++----------- 3 files changed, 40 insertions(+), 45 deletions(-) diff --git a/subprojects/parseq-http-client/build.gradle b/subprojects/parseq-http-client/build.gradle index 8a8108d0..8e82b853 100644 --- a/subprojects/parseq-http-client/build.gradle +++ b/subprojects/parseq-http-client/build.gradle @@ -3,5 +3,5 @@ ext { } dependencies { - compile group: 'com.ning', name: 'async-http-client', version:'1.9.21' + implementation group: 'org.asynchttpclient', name: 'async-http-client', version:'2.12.3' } diff --git a/subprojects/parseq-http-client/src/main/java/com/linkedin/parseq/httpclient/HttpClient.java b/subprojects/parseq-http-client/src/main/java/com/linkedin/parseq/httpclient/HttpClient.java index 7a23ee44..d7893fd3 100644 --- a/subprojects/parseq-http-client/src/main/java/com/linkedin/parseq/httpclient/HttpClient.java +++ b/subprojects/parseq-http-client/src/main/java/com/linkedin/parseq/httpclient/HttpClient.java @@ -1,9 +1,13 @@ package com.linkedin.parseq.httpclient; +import java.io.IOException; import java.util.concurrent.atomic.AtomicReference; -import com.ning.http.client.AsyncHttpClient; -import com.ning.http.client.AsyncHttpClientConfig; +import org.asynchttpclient.AsyncHttpClient; +import org.asynchttpclient.AsyncHttpClientConfig; +import org.asynchttpclient.DefaultAsyncHttpClientConfig.Builder; +import org.asynchttpclient.Dsl; + public class HttpClient { @@ -15,9 +19,9 @@ public class HttpClient { * then new client is created with default configuration. * @return raw http client */ - public static synchronized AsyncHttpClient getNingClient() { + public static synchronized AsyncHttpClient getAsyncHttpClient() { if (_client.get() == null) { - initialize(new AsyncHttpClientConfig.Builder().build()); + initialize(new Builder().build()); } return _client.get(); } @@ -29,43 +33,43 @@ public static synchronized AsyncHttpClient getNingClient() { */ @SuppressWarnings("resource") public static synchronized void initialize(AsyncHttpClientConfig cfg) { - if (!_client.compareAndSet(null, new AsyncHttpClient(cfg))) { + if (!_client.compareAndSet(null, Dsl.asyncHttpClient(cfg))) { throw new RuntimeException("async http client concurrently initialized"); } } - public static void close() { + public static void close() throws IOException { if (_client.get() != null) { _client.get().close(); } } public static WrappedRequestBuilder get(String url) { - return new WrappedRequestBuilder(getNingClient().prepareGet(url), "GET " + url); + return new WrappedRequestBuilder(getAsyncHttpClient().prepareGet(url), "GET " + url); } public static WrappedRequestBuilder connect(String url) { - return new WrappedRequestBuilder(getNingClient().prepareConnect(url), "CONNECT " + url); + return new WrappedRequestBuilder(getAsyncHttpClient().prepareConnect(url), "CONNECT " + url); } public static WrappedRequestBuilder options(String url) { - return new WrappedRequestBuilder(getNingClient().prepareOptions(url), "OPTIONS " + url); + return new WrappedRequestBuilder(getAsyncHttpClient().prepareOptions(url), "OPTIONS " + url); } public static WrappedRequestBuilder head(String url) { - return new WrappedRequestBuilder(getNingClient().prepareHead(url), "HEAD " + url); + return new WrappedRequestBuilder(getAsyncHttpClient().prepareHead(url), "HEAD " + url); } public static WrappedRequestBuilder post(String url) { - return new WrappedRequestBuilder(getNingClient().preparePost(url), "POST " + url); + return new WrappedRequestBuilder(getAsyncHttpClient().preparePost(url), "POST " + url); } public static WrappedRequestBuilder put(String url) { - return new WrappedRequestBuilder(getNingClient().preparePut(url), "PUT " + url); + return new WrappedRequestBuilder(getAsyncHttpClient().preparePut(url), "PUT " + url); } public static WrappedRequestBuilder delete(String url) { - return new WrappedRequestBuilder(getNingClient().prepareDelete(url), "DELETE " + url); + return new WrappedRequestBuilder(getAsyncHttpClient().prepareDelete(url), "DELETE " + url); } } diff --git a/subprojects/parseq-http-client/src/main/java/com/linkedin/parseq/httpclient/WrappedRequestBuilder.java b/subprojects/parseq-http-client/src/main/java/com/linkedin/parseq/httpclient/WrappedRequestBuilder.java index 0a96314e..8bdf5035 100644 --- a/subprojects/parseq-http-client/src/main/java/com/linkedin/parseq/httpclient/WrappedRequestBuilder.java +++ b/subprojects/parseq-http-client/src/main/java/com/linkedin/parseq/httpclient/WrappedRequestBuilder.java @@ -10,20 +10,21 @@ import com.linkedin.parseq.Task; import com.linkedin.parseq.promise.Promises; import com.linkedin.parseq.promise.SettablePromise; -import com.ning.http.client.AsyncHttpClient.BoundRequestBuilder; -import com.ning.http.client.AsyncCompletionHandler; -import com.ning.http.client.BodyGenerator; -import com.ning.http.client.ConnectionPoolPartitioning; -import com.ning.http.client.FluentCaseInsensitiveStringsMap; -import com.ning.http.client.Param; -import com.ning.http.client.ProxyServer; -import com.ning.http.client.Realm; -import com.ning.http.client.Request; -import com.ning.http.client.Response; -import com.ning.http.client.SignatureCalculator; -import com.ning.http.client.cookie.Cookie; -import com.ning.http.client.multipart.Part; -import com.ning.http.client.uri.Uri; +import org.asynchttpclient.BoundRequestBuilder; + +import org.asynchttpclient.AsyncCompletionHandler; +import org.asynchttpclient.request.body.generator.BodyGenerator; +import org.asynchttpclient.channel.ChannelPoolPartitioning; +import io.netty.handler.codec.http.HttpHeaders; +import org.asynchttpclient.Param; +import org.asynchttpclient.proxy.ProxyServer; +import org.asynchttpclient.Realm; +import org.asynchttpclient.Request; +import org.asynchttpclient.Response; +import org.asynchttpclient.SignatureCalculator; +import io.netty.handler.codec.http.cookie.Cookie; +import org.asynchttpclient.request.body.multipart.Part; +import org.asynchttpclient.uri.Uri; public class WrappedRequestBuilder { @@ -58,12 +59,12 @@ public WrappedRequestBuilder addBodyPart(Part part) { } public WrappedRequestBuilder setInetAddress(InetAddress address) { - _delegate.setInetAddress(address); + _delegate.setAddress(address); return this; } public WrappedRequestBuilder setLocalInetAddress(InetAddress address) { - _delegate.setLocalInetAddress(address); + _delegate.setLocalAddress(address); return this; } @@ -101,11 +102,6 @@ public WrappedRequestBuilder setBody(InputStream stream) { return this; } - public WrappedRequestBuilder setContentLength(int length) { - _delegate.setContentLength(length); - return this; - } - public WrappedRequestBuilder setBody(String data) { _delegate.setBody(data); return this; @@ -121,7 +117,7 @@ public WrappedRequestBuilder setCookies(Collection cookies) { return this; } - public WrappedRequestBuilder setHeaders(FluentCaseInsensitiveStringsMap headers) { + public WrappedRequestBuilder setHeaders(HttpHeaders headers) { _delegate.setHeaders(headers); return this; } @@ -222,7 +218,7 @@ public WrappedRequestBuilder setRealm(Realm realm) { } public WrappedRequestBuilder setFollowRedirects(boolean followRedirects) { - _delegate.setFollowRedirects(followRedirects); + _delegate.setFollowRedirect(followRedirects); return this; } @@ -241,13 +237,8 @@ public WrappedRequestBuilder setMethod(String method) { return this; } - public WrappedRequestBuilder setBodyEncoding(String charset) { - _delegate.setBodyEncoding(charset); - return this; - } - - public WrappedRequestBuilder setConnectionPoolKeyStrategy(ConnectionPoolPartitioning connectionPoolKeyStrategy) { - _delegate.setConnectionPoolKeyStrategy(connectionPoolKeyStrategy); + public WrappedRequestBuilder setConnectionPoolKeyStrategy(ChannelPoolPartitioning connectionPoolKeyStrategy) { + _delegate.setChannelPoolPartitioning(connectionPoolKeyStrategy); return this; } @@ -257,7 +248,7 @@ public Task task(final String desc) { _delegate.execute(new AsyncCompletionHandler() { @Override - public Response onCompleted(final Response response) throws Exception { + public Response onCompleted(final Response response) { result.done(response); return response; } From 95b9d34e7f1e253abbaeb7438a91f197f2485057 Mon Sep 17 00:00:00 2001 From: Christopher Harris Date: Mon, 22 Jan 2024 09:25:40 -0600 Subject: [PATCH 2/3] Bumping the version, updating other sub projects --- CHANGELOG.md | 4 ++++ gradle.properties | 2 +- .../parseq/example/introduction/IntroductoryExample.java | 2 +- .../com/linkedin/parseq/example/javadoc/JavadocExamples.java | 1 - subprojects/parseq-http-client/build.gradle | 2 +- 5 files changed, 7 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d99ffcee..58a61668 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +v5.2.0 +------ +* Upgrade AsyncHttpClient - Backwards incompatible due to namespace of AsyncHttpClient changing along with class names and private vs public access. + v5.1.17 ------ * Use dedicated executor service for lambda analysis diff --git a/gradle.properties b/gradle.properties index fe103ea0..9ed908d9 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,3 +1,3 @@ -version=5.1.17 +version=5.2.0 group=com.linkedin.parseq org.gradle.parallel=true diff --git a/subprojects/parseq-examples/src/main/java/com/linkedin/parseq/example/introduction/IntroductoryExample.java b/subprojects/parseq-examples/src/main/java/com/linkedin/parseq/example/introduction/IntroductoryExample.java index 165e963e..fd7ebb2e 100644 --- a/subprojects/parseq-examples/src/main/java/com/linkedin/parseq/example/introduction/IntroductoryExample.java +++ b/subprojects/parseq-examples/src/main/java/com/linkedin/parseq/example/introduction/IntroductoryExample.java @@ -5,7 +5,7 @@ import com.linkedin.parseq.example.common.AbstractExample; import com.linkedin.parseq.example.common.ExampleUtil; import com.linkedin.parseq.httpclient.HttpClient; -import com.ning.http.client.Response; +import org.asynchttpclient.Response; /** diff --git a/subprojects/parseq-examples/src/main/java/com/linkedin/parseq/example/javadoc/JavadocExamples.java b/subprojects/parseq-examples/src/main/java/com/linkedin/parseq/example/javadoc/JavadocExamples.java index 8c867b04..aca18f84 100644 --- a/subprojects/parseq-examples/src/main/java/com/linkedin/parseq/example/javadoc/JavadocExamples.java +++ b/subprojects/parseq-examples/src/main/java/com/linkedin/parseq/example/javadoc/JavadocExamples.java @@ -12,7 +12,6 @@ import com.linkedin.parseq.function.Success; import com.linkedin.parseq.function.Try; import com.linkedin.parseq.httpclient.HttpClient; -import com.ning.http.client.Response; /** diff --git a/subprojects/parseq-http-client/build.gradle b/subprojects/parseq-http-client/build.gradle index 8e82b853..fb2f22b9 100644 --- a/subprojects/parseq-http-client/build.gradle +++ b/subprojects/parseq-http-client/build.gradle @@ -3,5 +3,5 @@ ext { } dependencies { - implementation group: 'org.asynchttpclient', name: 'async-http-client', version:'2.12.3' + api group: 'org.asynchttpclient', name: 'async-http-client', version:'2.12.3' } From 9da3e0e081d1d2133d81d1de713e4520c7f7b9a1 Mon Sep 17 00:00:00 2001 From: Christopher Harris Date: Tue, 23 Jan 2024 08:34:18 -0600 Subject: [PATCH 3/3] Missed a lingering import of the old package --- .../src/main/java/com/linkedin/parseq/JhatHandler.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/subprojects/parseq-tracevis-server/src/main/java/com/linkedin/parseq/JhatHandler.java b/subprojects/parseq-tracevis-server/src/main/java/com/linkedin/parseq/JhatHandler.java index 33ba7557..441b8035 100644 --- a/subprojects/parseq-tracevis-server/src/main/java/com/linkedin/parseq/JhatHandler.java +++ b/subprojects/parseq-tracevis-server/src/main/java/com/linkedin/parseq/JhatHandler.java @@ -18,6 +18,7 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import org.asynchttpclient.Response; import org.codehaus.jackson.JsonNode; import org.codehaus.jackson.map.ObjectMapper; import org.eclipse.jetty.server.Request; @@ -29,7 +30,7 @@ import com.linkedin.parseq.trace.TraceBuilder; import com.linkedin.parseq.trace.TraceRelationship; import com.linkedin.parseq.trace.codec.json.JsonTraceCodec; -import com.ning.http.client.Response; + final class JhatHandler extends AbstractHandler {