com.yahoo.vespa.hosted.provision.provisioning.HostIpConfig Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of node-repository Show documentation
Show all versions of node-repository Show documentation
Keeps track of node assignment in a multi-application setup.
The newest version!
// 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.provisioning;
import com.yahoo.vespa.hosted.provision.node.IP;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
/**
* IP config of a host and its children, and an optional extra host ID.
*
* @author mpolden
*/
public record HostIpConfig(Map ipConfigByHostname, Optional hostId) {
public static final HostIpConfig EMPTY = new HostIpConfig(Map.of(), Optional.empty());
public HostIpConfig(Map ipConfigByHostname, Optional hostId) {
this.ipConfigByHostname = Map.copyOf(Objects.requireNonNull(ipConfigByHostname));
this.hostId = Objects.requireNonNull(hostId);
}
public Map 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);
}
@Override
public String toString() {
return ipConfigByHostname.toString();
}
}