summaryrefslogtreecommitdiffstats
path: root/config-model/src/main/java/com/yahoo/config/model/provision/Host.java
blob: ea7a0bc0504bb5db96655136746b57f4d7304b0c (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
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.config.model.provision;

import com.google.common.collect.ImmutableList;
import com.yahoo.component.Version;
import com.yahoo.config.provision.Flavor;

import java.util.List;
import java.util.Optional;

/**
 * A hostname with zero or more aliases. This is immutable.
 *
 * @author hmusum
 */
public class Host {

    private final String hostname;
    private final ImmutableList<String> aliases;
    private final Optional<Flavor> flavor;
    private final Optional<Version> version;

    public Host(String hostname) {
        this(hostname, ImmutableList.of(), Optional.empty());
    }

    public Host(String hostname, List<String> hostAliases) {
        this(hostname, hostAliases, Optional.empty());
    }

    public Host(String hostname, List<String> hostAliases, Optional<Flavor> flavor) {
        this(hostname, hostAliases, flavor, Optional.empty());
    }

    public Host(String hostname, List<String> hostAliases, Optional<Flavor> flavor, Optional<Version> version) {
        this.hostname = hostname;
        this.aliases = ImmutableList.copyOf(hostAliases);
        this.flavor = flavor;
        this.version = version;
    }

    public String hostname() { return hostname; }

    /** Returns an immutable list of the aliases of this node, which may be empty but never null */
    public List<String> aliases() { return aliases; }

    public Optional<Flavor> flavor() { return flavor; }

    /** The current Vespa version running on this host, or empty if not known */
    public Optional<Version> version() { return version; }

    @Override
    public String toString() {
        return hostname + (aliases.size() > 0 ? " (aliases: " + aliases + ")" : "" ) +
                (flavor.isPresent() ? " (flavor: " + flavor.get() + ")" : "");
    }

}