summaryrefslogtreecommitdiffstats
path: root/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/provisioning/HostIpConfig.java
blob: 891251fc892793bcf94d3be335014c77160002dd (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
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.hosted.provision.provisioning;

import com.yahoo.vespa.hosted.provision.node.IP;

import java.util.Map;
import java.util.Objects;

/**
 * IP config of a host and its children.
 *
 * @author mpolden
 */
public record HostIpConfig(Map<String, IP.Config> ipConfigByHostname) {

    public static final HostIpConfig EMPTY = new HostIpConfig(Map.of());

    public HostIpConfig(Map<String, IP.Config> ipConfigByHostname) {
        this.ipConfigByHostname = Map.copyOf(Objects.requireNonNull(ipConfigByHostname));
    }

    public Map<String, IP.Config> asMap() {
        return ipConfigByHostname;
    }

    public boolean contains(String hostname) {
        return ipConfigByHostname.containsKey(hostname);
    }

    public IP.Config require(String hostname) {
        IP.Config ipConfig = this.ipConfigByHostname.get(hostname);
        if (ipConfig == null) throw new IllegalArgumentException("No IP config exists for node '" + hostname + "'");
        return ipConfig;
    }

    public boolean isEmpty() {
        return this.equals(EMPTY);
    }

}