summaryrefslogtreecommitdiffstats
path: root/configserver-client/src/main/java/ai/vespa/hosted/client/HttpConfigServerClient.java
diff options
context:
space:
mode:
Diffstat (limited to 'configserver-client/src/main/java/ai/vespa/hosted/client/HttpConfigServerClient.java')
-rw-r--r--configserver-client/src/main/java/ai/vespa/hosted/client/HttpConfigServerClient.java61
1 files changed, 61 insertions, 0 deletions
diff --git a/configserver-client/src/main/java/ai/vespa/hosted/client/HttpConfigServerClient.java b/configserver-client/src/main/java/ai/vespa/hosted/client/HttpConfigServerClient.java
new file mode 100644
index 00000000000..c5b07eceaf5
--- /dev/null
+++ b/configserver-client/src/main/java/ai/vespa/hosted/client/HttpConfigServerClient.java
@@ -0,0 +1,61 @@
+// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package ai.vespa.hosted.client;
+
+import ai.vespa.util.http.hc5.VespaHttpClientBuilder;
+import com.yahoo.vespa.athenz.api.AthenzIdentity;
+import com.yahoo.vespa.athenz.tls.AthenzIdentityVerifier;
+import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
+import org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManager;
+import org.apache.hc.client5.http.protocol.HttpClientContext;
+import org.apache.hc.core5.http.ClassicHttpRequest;
+import org.apache.hc.core5.http.ClassicHttpResponse;
+import org.apache.hc.core5.http.io.SocketConfig;
+import org.apache.hc.core5.util.TimeValue;
+import org.apache.hc.core5.util.Timeout;
+
+import java.io.IOException;
+import java.util.Collection;
+import java.util.Set;
+
+/**
+ * @author jonmv
+ */
+public class HttpConfigServerClient extends AbstractConfigServerClient {
+
+ private final CloseableHttpClient client;
+
+ public HttpConfigServerClient(Collection<AthenzIdentity> serverIdentities, String userAgent) {
+ if (serverIdentities.isEmpty())
+ throw new IllegalArgumentException("At least one trusted server identity must be provided");
+
+ this.client = createClient(serverIdentities, userAgent);
+ }
+
+ @Override
+ public void close() throws IOException {
+ client.close();
+ }
+
+ @Override
+ protected ClassicHttpResponse execute(ClassicHttpRequest request, HttpClientContext context) throws IOException {
+ return client.execute(request, context);
+ }
+
+ private static CloseableHttpClient createClient(Collection<AthenzIdentity> serverIdentities, String userAgent) {
+ return VespaHttpClientBuilder.create(socketFactories -> {
+ var manager = new PoolingHttpClientConnectionManager(socketFactories);
+ manager.setMaxTotal(256);
+ manager.setDefaultMaxPerRoute(8);
+ manager.setDefaultSocketConfig(SocketConfig.custom().setSoTimeout(Timeout.ofSeconds(5)).build());
+ manager.setValidateAfterInactivity(TimeValue.ofSeconds(10));
+ return manager;
+ },
+ new AthenzIdentityVerifier(Set.copyOf(serverIdentities)),
+ false)
+ .disableAutomaticRetries()
+ .setUserAgent(userAgent)
+ .setDefaultRequestConfig(defaultRequestConfig)
+ .build();
+ }
+
+}