diff options
author | Harald Musum <musum@verizonmedia.com> | 2021-10-27 21:58:43 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-10-27 21:58:43 +0200 |
commit | ece3f07b8c9428a6ed0d8dda674dbb4c08903e52 (patch) | |
tree | 66d87cbd518d722318808c7603cb11ef82abb21e /configserver | |
parent | 84385999eb3ad3a6a04882e336a876e5c0c5b7d2 (diff) | |
parent | 469e5d8b9c2bcf257c3dac38670c18bd19991694 (diff) |
Merge pull request #19750 from vespa-engine/hmusum/move-to-apache-http-client-version-5
Move to apache http client version 5 [run-systemtest]
Diffstat (limited to 'configserver')
6 files changed, 58 insertions, 53 deletions
diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/http/LogRetriever.java b/configserver/src/main/java/com/yahoo/vespa/config/server/http/LogRetriever.java index 98d88932848..5fa8edb7803 100644 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/http/LogRetriever.java +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/http/LogRetriever.java @@ -1,12 +1,11 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.vespa.config.server.http; -import ai.vespa.util.http.hc4.VespaHttpClientBuilder; +import ai.vespa.util.http.hc5.VespaHttpClientBuilder; import com.yahoo.container.jdisc.HttpResponse; import com.yahoo.yolean.Exceptions; -import org.apache.http.client.methods.CloseableHttpResponse; -import org.apache.http.client.methods.HttpGet; -import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.hc.client5.http.classic.methods.HttpGet; +import org.apache.hc.client5.http.impl.classic.CloseableHttpClient; import java.io.IOException; diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/http/ProxyResponse.java b/configserver/src/main/java/com/yahoo/vespa/config/server/http/ProxyResponse.java index 120790da3af..f7042b49c3f 100644 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/http/ProxyResponse.java +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/http/ProxyResponse.java @@ -1,9 +1,9 @@ -// Copyright 2019 Oath Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.vespa.config.server.http; import com.yahoo.container.jdisc.HttpResponse; -import org.apache.http.Header; -import org.apache.http.client.methods.CloseableHttpResponse; +import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse; +import org.apache.hc.core5.http.NameValuePair; import java.io.IOException; import java.io.OutputStream; @@ -20,14 +20,14 @@ class ProxyResponse extends HttpResponse { private final CloseableHttpResponse clientResponse; ProxyResponse(CloseableHttpResponse clientResponse) { - super(clientResponse.getStatusLine().getStatusCode()); + super(clientResponse.getCode()); this.clientResponse = clientResponse; } @Override public String getContentType() { return Optional.ofNullable(clientResponse.getFirstHeader("Content-Type")) - .map(Header::getValue) + .map(NameValuePair::getValue) .orElseGet(super::getContentType); } diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/http/SecretStoreValidator.java b/configserver/src/main/java/com/yahoo/vespa/config/server/http/SecretStoreValidator.java index dc3f32472a2..17f33e477ec 100644 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/http/SecretStoreValidator.java +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/http/SecretStoreValidator.java @@ -1,7 +1,7 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.vespa.config.server.http; -import ai.vespa.util.http.hc4.VespaHttpClientBuilder; +import ai.vespa.util.http.hc5.VespaHttpClientBuilder; import com.yahoo.config.model.api.HostInfo; import com.yahoo.config.provision.SystemName; import com.yahoo.config.provision.TenantName; @@ -12,10 +12,10 @@ import com.yahoo.slime.SlimeUtils; import com.yahoo.vespa.config.server.application.Application; import com.yahoo.vespa.config.server.tenant.SecretStoreExternalIdRetriever; import com.yahoo.yolean.Exceptions; -import org.apache.http.client.methods.CloseableHttpResponse; -import org.apache.http.client.methods.HttpPost; -import org.apache.http.entity.ByteArrayEntity; -import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.hc.client5.http.classic.methods.HttpPost; +import org.apache.hc.client5.http.impl.classic.CloseableHttpClient; +import org.apache.hc.core5.http.ContentType; +import org.apache.hc.core5.http.io.entity.ByteArrayEntity; import java.io.IOException; import java.net.URI; @@ -61,7 +61,7 @@ public class SecretStoreValidator { private HttpResponse postRequest(URI uri, Slime slime) { var postRequest = new HttpPost(uri); var data = uncheck(() -> SlimeUtils.toJsonBytes(slime)); - var entity = new ByteArrayEntity(data); + var entity = new ByteArrayEntity(data, ContentType.DEFAULT_BINARY); postRequest.setEntity(entity); try { return new ProxyResponse(httpClient.execute(postRequest)); diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/http/TesterClient.java b/configserver/src/main/java/com/yahoo/vespa/config/server/http/TesterClient.java index 815e2cbb8e2..69bccfe788d 100644 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/http/TesterClient.java +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/http/TesterClient.java @@ -1,16 +1,16 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.vespa.config.server.http; -import ai.vespa.util.http.hc4.VespaHttpClientBuilder; +import ai.vespa.util.http.hc5.VespaHttpClientBuilder; import com.yahoo.container.jdisc.HttpResponse; import com.yahoo.yolean.Exceptions; -import org.apache.http.client.methods.CloseableHttpResponse; -import org.apache.http.client.methods.HttpGet; -import org.apache.http.client.methods.HttpPost; -import org.apache.http.client.methods.HttpUriRequest; +import org.apache.hc.client5.http.classic.methods.HttpGet; +import org.apache.hc.client5.http.classic.methods.HttpPost; +import org.apache.hc.client5.http.classic.methods.HttpUriRequest; +import org.apache.hc.client5.http.impl.classic.CloseableHttpClient; +import org.apache.hc.core5.http.ContentType; +import org.apache.hc.core5.http.io.entity.ByteArrayEntity; import org.apache.http.client.utils.URIBuilder; -import org.apache.http.entity.ByteArrayEntity; -import org.apache.http.impl.client.CloseableHttpClient; import java.io.IOException; import java.net.URI; @@ -48,7 +48,7 @@ public class TesterClient { public HttpResponse startTests(String testerHostname, int port, String suite, byte[] config) { URI testerUri = createURI(testerHostname, port, "/tester/v1/run/" + suite); HttpPost request = new HttpPost(testerUri); - request.setEntity(new ByteArrayEntity(config)); + request.setEntity(new ByteArrayEntity(config, ContentType.DEFAULT_BINARY)); return execute(request, "Failed to start tests"); } @@ -65,7 +65,7 @@ public class TesterClient { } private HttpResponse execute(HttpUriRequest request, String messageIfRequestFails) { - logger.log(Level.FINE, () -> "Sending request to tester container " + request.getURI().toString()); + logger.log(Level.FINE, () -> "Sending request to tester container " + request.getRequestUri()); try { return new ProxyResponse(httpClient.execute(request)); } catch (IOException e) { diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/metrics/ClusterDeploymentMetricsRetriever.java b/configserver/src/main/java/com/yahoo/vespa/config/server/metrics/ClusterDeploymentMetricsRetriever.java index 5659360d56b..a95b9c4cfc2 100644 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/metrics/ClusterDeploymentMetricsRetriever.java +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/metrics/ClusterDeploymentMetricsRetriever.java @@ -1,7 +1,7 @@ -// Copyright 2019 Oath Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.vespa.config.server.metrics; -import ai.vespa.util.http.hc4.VespaHttpClientBuilder; +import ai.vespa.util.http.hc5.VespaHttpClientBuilder; import com.yahoo.concurrent.DaemonThreadFactory; import com.yahoo.slime.ArrayTraverser; import com.yahoo.slime.Cursor; @@ -9,16 +9,17 @@ import com.yahoo.slime.Inspector; import com.yahoo.slime.Slime; import com.yahoo.slime.SlimeUtils; import com.yahoo.yolean.Exceptions; -import org.apache.http.client.config.RequestConfig; -import org.apache.http.client.methods.CloseableHttpResponse; -import org.apache.http.client.methods.HttpGet; -import org.apache.http.impl.client.CloseableHttpClient; -import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; -import org.apache.http.util.EntityUtils; +import org.apache.hc.client5.http.classic.methods.HttpGet; +import org.apache.hc.client5.http.config.RequestConfig; +import org.apache.hc.client5.http.impl.classic.CloseableHttpClient; +import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse; +import org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManager; +import org.apache.hc.core5.http.io.entity.EntityUtils; +import org.apache.hc.core5.util.TimeValue; +import org.apache.hc.core5.util.Timeout; import java.io.IOException; import java.net.URI; -import java.time.Duration; import java.util.Collection; import java.util.List; import java.util.Map; @@ -54,16 +55,19 @@ public class ClusterDeploymentMetricsRetriever { private static final ExecutorService executor = Executors.newFixedThreadPool(10, new DaemonThreadFactory("cluster-deployment-metrics-retriever-")); - private static final CloseableHttpClient httpClient = VespaHttpClientBuilder - .create(registry -> - new PoolingHttpClientConnectionManager(registry, null, null, null, 1, TimeUnit.MINUTES)) - .setDefaultRequestConfig( - RequestConfig.custom() - .setConnectionRequestTimeout((int)Duration.ofSeconds(60).toMillis()) - .setConnectTimeout((int)Duration.ofSeconds(10).toMillis()) - .setSocketTimeout((int)Duration.ofSeconds(10).toMillis()) - .build()) - .build(); + private static final CloseableHttpClient httpClient = + VespaHttpClientBuilder + .create(registry -> new PoolingHttpClientConnectionManager(registry, + null, + null, + TimeValue.ofMinutes(1))) + .setDefaultRequestConfig( + RequestConfig.custom() + .setConnectionRequestTimeout(Timeout.ofSeconds(60)) + .setConnectTimeout(Timeout.ofSeconds(10)) + .setResponseTimeout(Timeout.ofSeconds(10)) + .build()) + .build(); /** * Call the metrics API on each host and aggregate the metrics diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/metrics/ClusterProtonMetricsRetriever.java b/configserver/src/main/java/com/yahoo/vespa/config/server/metrics/ClusterProtonMetricsRetriever.java index bce6b877f80..d6fde04cd71 100644 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/metrics/ClusterProtonMetricsRetriever.java +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/metrics/ClusterProtonMetricsRetriever.java @@ -1,25 +1,27 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.vespa.config.server.metrics; -import ai.vespa.util.http.hc4.VespaHttpClientBuilder; +import ai.vespa.util.http.hc5.VespaHttpClientBuilder; import com.yahoo.slime.ArrayTraverser; import com.yahoo.slime.Cursor; import com.yahoo.slime.Inspector; import com.yahoo.slime.Slime; import com.yahoo.slime.SlimeUtils; import com.yahoo.yolean.Exceptions; +import org.apache.hc.client5.http.classic.methods.HttpGet; +import org.apache.hc.client5.http.config.RequestConfig; +import org.apache.hc.client5.http.impl.classic.CloseableHttpClient; +import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse; +import org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManager; +import org.apache.hc.core5.http.io.entity.EntityUtils; +import org.apache.hc.core5.util.Timeout; + import java.io.IOException; import java.net.URI; import java.util.Collection; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import java.util.logging.Logger; -import org.apache.http.client.config.RequestConfig; -import org.apache.http.client.methods.CloseableHttpResponse; -import org.apache.http.client.methods.HttpGet; -import org.apache.http.impl.client.CloseableHttpClient; -import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; -import org.apache.http.util.EntityUtils; public class ClusterProtonMetricsRetriever { @@ -29,9 +31,9 @@ public class ClusterProtonMetricsRetriever { .create(PoolingHttpClientConnectionManager::new) .setDefaultRequestConfig( RequestConfig.custom() - .setConnectTimeout(10 * 1000) - .setSocketTimeout(10 * 1000) - .build()) + .setConnectTimeout(Timeout.ofSeconds(10)) + .setResponseTimeout(Timeout.ofSeconds(10)) + .build()) .build(); |