aboutsummaryrefslogtreecommitdiffstats
path: root/tenant-cd-commons/src/main/java/ai/vespa/hosted/cd/commons/HttpDeployment.java
blob: 6a42d8746866db68484c5c73ce48c2147201b672 (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
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package ai.vespa.hosted.cd.commons;

import ai.vespa.hosted.cd.Deployment;
import ai.vespa.hosted.cd.Endpoint;
import ai.vespa.hosted.cd.EndpointAuthenticator;

import java.net.URI;
import java.time.Instant;
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 Deployment {

    private final Map<String, Endpoint> endpoints;
    private final String platform;
    private final long revision;
    private final Instant deployedAt;

    /** Creates a representation of the given deployment endpoints, using the authenticator for data plane access. */
    public HttpDeployment(String platform, long revision, Instant deployedAt,
                          Map<String, URI> endpoints, EndpointAuthenticator authenticator) {
        this.platform = platform;
        this.revision = revision;
        this.deployedAt = deployedAt;
        this.endpoints = endpoints.entrySet().stream()
                .collect(Collectors.toUnmodifiableMap(entry -> entry.getKey(),
                                                      entry -> new HttpEndpoint(entry.getValue(), authenticator)));
    }

    @Override
    public Endpoint endpoint(String id) {
        if ( ! endpoints.containsKey(id))
            throw new NoSuchElementException("No cluster with id '" + id + "'");

        return endpoints.get(id);
    }

    @Override
    public String platform() {
        return platform;
    }

    @Override
    public long revision() {
        return revision;
    }

    @Override
    public Instant deployedAt() {
        return deployedAt;
    }

}