blob: e70a05dcb7c598fa24ca3a145e8a9d4026ad1951 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.orchestrator.controller;
import ai.vespa.hosted.client.AbstractHttpClient;
import ai.vespa.hosted.client.HttpClient;
import ai.vespa.util.http.hc5.VespaHttpClientBuilder;
import com.yahoo.component.annotation.Inject;
import com.yahoo.component.AbstractComponent;
import com.yahoo.vespa.applicationmodel.HostName;
import org.apache.hc.core5.http.message.BasicHeader;
import org.apache.hc.core5.util.Timeout;
import java.io.IOException;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
* @author jonmv
*/
public class RetryingClusterControllerClientFactory extends AbstractComponent implements ClusterControllerClientFactory {
private static final Logger log = Logger.getLogger(RetryingClusterControllerClientFactory.class.getName());
private final HttpClient client;
@Inject
public RetryingClusterControllerClientFactory() {
this(AbstractHttpClient.wrapping(VespaHttpClientBuilder
.custom()
.connectTimeout(Timeout.ofSeconds(5))
.apacheBuilder()
.setUserAgent("orchestrator-cluster-controller-client")
.setDefaultHeaders(List.of(new BasicHeader("Accept", "application/json")))
.build()));
}
RetryingClusterControllerClientFactory(HttpClient client) {
this.client = client;
}
@Override
public ClusterControllerClient createClient(List<HostName> clusterControllers, String clusterName) {
return new ClusterControllerClientImpl(client, clusterControllers, clusterName);
}
@Override
public void deconstruct() {
try {
client.close();
}
catch (IOException e) {
log.log(Level.WARNING, "failed shutting down", e);
}
}
}
|