blob: 04cebcf50b234bb08ad6265025b364190c53fbdf (
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
|
package ai.vespa.hosted.cd.http;
import ai.vespa.hosted.api.Authenticator;
import ai.vespa.hosted.cd.TestDeployment;
import ai.vespa.hosted.cd.TestEndpoint;
import com.yahoo.config.provision.Environment;
import com.yahoo.config.provision.zone.ZoneId;
import java.net.URI;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.stream.Collectors;
/**
* A remote deployment of a Vespa application, reachable over HTTP. Contains {@link HttpEndpoint}s.
*
* @author jonmv
*/
public class HttpDeployment implements TestDeployment {
private final ZoneId zone;
private final Map<String, HttpEndpoint> endpoints;
/** Creates a representation of the given deployment endpoints, using the authenticator for data plane access. */
public HttpDeployment(Map<String, URI> endpoints, ZoneId zone, Authenticator authenticator) {
this.zone = zone;
this.endpoints = endpoints.entrySet().stream()
.collect(Collectors.toUnmodifiableMap(entry -> entry.getKey(),
entry -> new HttpEndpoint(entry.getValue(), authenticator)));
}
@Override
public TestEndpoint endpoint() {
return endpoint("default");
}
@Override
public TestEndpoint endpoint(String id) {
if ( ! endpoints.containsKey(id))
throw new NoSuchElementException("No cluster with id '" + id + "'");
return endpoints.get(id);
}
@Override
public TestDeployment asTestDeployment() {
if (zone.environment() == Environment.prod)
throw new IllegalArgumentException("Won't return a mutable view of a production deployment");
return this;
}
}
|