diff options
author | Harald Musum <musum@verizonmedia.com> | 2021-10-06 08:40:55 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-10-06 08:40:55 +0200 |
commit | 4de0026c1065403d028d7157abb571830603e6c9 (patch) | |
tree | 374154c13738e18df29eecf04bbed2c058a5bc7a | |
parent | 86e782da93c62933f9ab1e592f7ed6459f083963 (diff) | |
parent | 3ab33bba7ad8c79f64a33fdf40d1f35ccc689037 (diff) |
Merge pull request #19427 from vespa-engine/hmusum/depend-on-http-client-with-compile-scope
Update http client used in vespa-status-filedistribution [run-systemtest]
-rw-r--r-- | filedistribution/pom.xml | 7 | ||||
-rw-r--r-- | filedistribution/src/main/java/com/yahoo/vespa/filedistribution/status/FileDistributionStatusClient.java | 43 |
2 files changed, 32 insertions, 18 deletions
diff --git a/filedistribution/pom.xml b/filedistribution/pom.xml index e922d878dd7..39bc725d518 100644 --- a/filedistribution/pom.xml +++ b/filedistribution/pom.xml @@ -22,7 +22,7 @@ <groupId>com.yahoo.vespa</groupId> <artifactId>container-apache-http-client-bundle</artifactId> <version>${project.version}</version> - <scope>provided</scope> + <scope>compile</scope> </dependency> <dependency> <groupId>com.yahoo.vespa</groupId> @@ -67,6 +67,11 @@ <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-databind</artifactId> </dependency> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-api</artifactId> + <scope>compile</scope> + </dependency> </dependencies> <build> diff --git a/filedistribution/src/main/java/com/yahoo/vespa/filedistribution/status/FileDistributionStatusClient.java b/filedistribution/src/main/java/com/yahoo/vespa/filedistribution/status/FileDistributionStatusClient.java index 1675366fc5e..a9bbfafeaf0 100644 --- a/filedistribution/src/main/java/com/yahoo/vespa/filedistribution/status/FileDistributionStatusClient.java +++ b/filedistribution/src/main/java/com/yahoo/vespa/filedistribution/status/FileDistributionStatusClient.java @@ -1,19 +1,22 @@ -// Copyright 2018 Yahoo Holdings. 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.filedistribution.status; +import ai.vespa.util.http.hc5.VespaHttpClientBuilder; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import io.airlift.airline.Command; import io.airlift.airline.HelpOption; import io.airlift.airline.Option; import io.airlift.airline.SingleCommand; -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.client.utils.URIBuilder; -import org.apache.http.impl.client.CloseableHttpClient; -import org.apache.http.impl.client.HttpClientBuilder; -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.core5.http.HttpEntity; +import org.apache.hc.core5.http.ParseException; +import org.apache.hc.core5.http.io.entity.EntityUtils; +import org.apache.hc.core5.net.URIBuilder; +import org.apache.hc.core5.util.Timeout; import javax.inject.Inject; import java.io.IOException; @@ -23,6 +26,8 @@ import java.util.ArrayList; import java.util.Iterator; import java.util.Map; +import static org.apache.hc.client5.http.config.RequestConfig.custom; + /** * Tool for getting file distribution status * @@ -67,28 +72,32 @@ public class FileDistributionStatusClient { } private String doHttpRequest() { - int timeoutInMillis = (int) (timeout * 1000); - RequestConfig config = RequestConfig.custom() + Timeout timeoutInMillis = Timeout.ofMilliseconds((long) (timeout * 1000)); + RequestConfig config = custom() .setConnectTimeout(timeoutInMillis) .setConnectionRequestTimeout(timeoutInMillis) - .setSocketTimeout(timeoutInMillis) + .setResponseTimeout(timeoutInMillis) .build(); - CloseableHttpClient httpClient = HttpClientBuilder.create().setDefaultRequestConfig(config).build(); + CloseableHttpClient httpClient = VespaHttpClientBuilder.create().build(); URI statusUri = createStatusApiUri(); if (debug) System.out.println("URI:" + statusUri); try { - CloseableHttpResponse response = httpClient.execute(new HttpGet(statusUri)); - String content = EntityUtils.toString(response.getEntity()); + HttpGet request = new HttpGet(statusUri); + request.addHeader("Connection", "Close"); + request.setConfig(config); + CloseableHttpResponse response = httpClient.execute(request); + HttpEntity entity = response.getEntity(); + String content = EntityUtils.toString(entity); if (debug) System.out.println("response:" + content); - if (response.getStatusLine().getStatusCode() == 200) { + if (response.getCode() == 200) { return content; } else { throw new RuntimeException("Failed to get status for request " + statusUri + ": " + - response.getStatusLine() + ": " + content); + response.getCode() + ": " + content); } - } catch (IOException e) { + } catch (IOException | ParseException e) { throw new RuntimeException(e); } } |