summaryrefslogtreecommitdiffstats
path: root/filedistribution
diff options
context:
space:
mode:
authorHarald Musum <musum@yahooinc.com>2021-10-06 06:59:36 +0200
committerHarald Musum <musum@yahooinc.com>2021-10-06 06:59:36 +0200
commitcffdb889ab3e04ae9a38492664eff5f5cdca45d1 (patch)
tree78702ad5d35b77f03359bff979629f33c339157d /filedistribution
parentf29dd1fbbc6fba22c663431dbf963182ae0233f8 (diff)
Rewrite to use new apache http client
Diffstat (limited to 'filedistribution')
-rw-r--r--filedistribution/pom.xml5
-rw-r--r--filedistribution/src/main/java/com/yahoo/vespa/filedistribution/status/FileDistributionStatusClient.java45
2 files changed, 32 insertions, 18 deletions
diff --git a/filedistribution/pom.xml b/filedistribution/pom.xml
index b74bb8d2ee4..39bc725d518 100644
--- a/filedistribution/pom.xml
+++ b/filedistribution/pom.xml
@@ -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..42e27ee0438 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);
}
}
@@ -119,7 +128,7 @@ public class FileDistributionStatusClient {
tenantName, applicationName, environment, region, instanceName);
try {
return new URIBuilder()
- .setScheme("http")
+ .setScheme("https")
.setHost("localhost")
.setPort(19071)
.setPath(path)