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
76
77
78
79
80
81
|
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.hosted.provision.lb;
import ai.vespa.http.DomainName;
import com.yahoo.config.provision.ClusterSpec;
import com.yahoo.config.provision.EndpointsChecker.Availability;
import com.yahoo.config.provision.EndpointsChecker.Endpoint;
import com.yahoo.config.provision.NodeType;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
/**
* This implementation of {@link LoadBalancerService} returns the load balancer(s) that exist by default in the shared
* routing layer.
* <p>
* Since such load balancers always exist, we can return the hostname of the routing layer VIP directly. Nothing has to
* be provisioned.
*
* @author ogronnesby
*/
public class SharedLoadBalancerService implements LoadBalancerService {
private final String vipHostname;
public SharedLoadBalancerService(String vipHostname) {
this.vipHostname = Objects.requireNonNull(vipHostname);
}
@Override
public LoadBalancerInstance provision(LoadBalancerSpec spec) {
if ( ! spec.settings().isPublicEndpoint())
throw new IllegalArgumentException("non-public endpoints is not supported with " + getClass());
return new LoadBalancerInstance(Optional.of(DomainName.of(vipHostname)),
Optional.empty(),
Optional.empty(),
Optional.empty(),
Set.of(4443),
Set.of(),
spec.reals(),
spec.settings(),
List.of(),
spec.cloudAccount());
}
@Override
public LoadBalancerInstance configure(LoadBalancerInstance instance, LoadBalancerSpec spec, boolean force) {
return instance.with(spec.reals(), spec.settings(), Optional.empty());
}
@Override
public void reallocate(LoadBalancerSpec spec) {
throw new UnsupportedOperationException("reallocate is not supported with " + getClass());
}
@Override
public void remove(LoadBalancer loadBalancer) {
// Do nothing, we have no external state to modify
}
@Override
public Protocol protocol(boolean enclave) {
if (enclave) throw new IllegalArgumentException("enclave is not supported with " + getClass());
return Protocol.dualstack;
}
@Override
public boolean supports(NodeType nodeType, ClusterSpec.Type clusterType) {
// Shared routing layer only supports routing to tenant nodes
return nodeType == NodeType.tenant && clusterType.isContainer();
}
@Override
public Availability healthy(Endpoint endpoint, String idSeed) {
return Availability.ready;
}
}
|