blob: 7459f0a6b119a08a5ce2b48dd293446e80445249 (
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
|
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.orchestrator.controller;
import com.yahoo.log.LogLevel;
import com.yahoo.vespa.applicationmodel.HostName;
import com.yahoo.vespa.jaxrs.client.JaxRsClientFactory;
import com.yahoo.vespa.jaxrs.client.JaxRsStrategy;
import com.yahoo.vespa.jaxrs.client.NoRetryJaxRsStrategy;
import java.util.List;
import java.util.logging.Logger;
/**
* @author bakksjo
*/
public class SingleInstanceClusterControllerClientFactory implements ClusterControllerClientFactory {
public static final int CLUSTERCONTROLLER_HARDCODED_PORT = 19050;
public static final String CLUSTERCONTROLLER_HARDCODED_SCHEME = "http";
public static final String CLUSTERCONTROLLER_API_PATH = "/";
private static final Logger log = Logger.getLogger(SingleInstanceClusterControllerClientFactory.class.getName());
private JaxRsClientFactory jaxRsClientFactory;
public SingleInstanceClusterControllerClientFactory(JaxRsClientFactory jaxRsClientFactory) {
this.jaxRsClientFactory = jaxRsClientFactory;
}
@Override
public ClusterControllerClient createClient(List<HostName> clusterControllers,
String clusterName) {
if (clusterControllers.isEmpty()) {
throw new IllegalArgumentException("No cluster controller instances found");
}
HostName controllerHostName = clusterControllers.iterator().next();
int port = CLUSTERCONTROLLER_HARDCODED_PORT; // TODO: Get this from service monitor.
log.log(LogLevel.DEBUG, () ->
"For cluster '" + clusterName + "' with controllers " + clusterControllers
+ ", creating api client for " + controllerHostName.s() + ":" + port);
JaxRsStrategy<ClusterControllerJaxRsApi> strategy = new NoRetryJaxRsStrategy<>(
controllerHostName,
port,
jaxRsClientFactory,
ClusterControllerJaxRsApi.class,
CLUSTERCONTROLLER_API_PATH,
CLUSTERCONTROLLER_HARDCODED_SCHEME);
return new ClusterControllerClientImpl(strategy, clusterName);
}
}
|