blob: 9e94f6ed7e4a60863fb79dfb3500bd6b28533f79 (
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
// Copyright 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.hosted.node.admin.component;
import com.yahoo.vespa.athenz.api.AthenzService;
import com.yahoo.vespa.athenz.utils.AthenzIdentities;
import com.yahoo.vespa.hosted.node.admin.config.ConfigServerConfig;
import java.net.URI;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import static java.util.stream.Collectors.toMap;
/**
* Information necessary to e.g. establish communication with the config servers
*
* @author hakon
*/
public class ConfigServerInfo {
private final List<String> configServerHostNames;
private final URI loadBalancerEndpoint;
private final Map<String, URI> configServerURIs;
private final AthenzService configServerIdentity;
public ConfigServerInfo(ConfigServerConfig config) {
this.configServerHostNames = config.hosts();
this.configServerURIs = createConfigServerUris(
config.scheme(),
config.hosts(),
config.port());
this.loadBalancerEndpoint = createLoadBalancerEndpoint(config.loadBalancerHost(), config.scheme(), config.port());
this.configServerIdentity = (AthenzService) AthenzIdentities.from(config.configserverAthenzIdentity());
}
private static URI createLoadBalancerEndpoint(String loadBalancerHost, String scheme, int port) {
return URI.create(scheme + "://" + loadBalancerHost + ":" + port);
}
public List<String> getConfigServerHostNames() {
return configServerHostNames;
}
public List<URI> getConfigServerUris() {
return new ArrayList<>(configServerURIs.values());
}
public URI getConfigServerUri(String hostname) {
URI uri = configServerURIs.get(hostname);
if (uri == null) {
throw new IllegalArgumentException("There is no config server '" + hostname + "'");
}
return uri;
}
public URI getLoadBalancerEndpoint() {
return loadBalancerEndpoint;
}
public AthenzService getConfigServerIdentity() {
return configServerIdentity;
}
private static Map<String, URI> createConfigServerUris(
String scheme,
List<String> configServerHosts,
int port) {
return configServerHosts.stream().collect(toMap(
Function.identity(),
hostname -> URI.create(scheme + "://" + hostname + ":" + port)));
}
}
|