diff options
author | Martin Polden <mpolden@mpolden.no> | 2023-02-16 11:13:06 +0100 |
---|---|---|
committer | Martin Polden <mpolden@mpolden.no> | 2023-02-16 13:30:50 +0100 |
commit | 4b627f0a674e2207fa2a710b5bc2326fc9b98145 (patch) | |
tree | a33d202107cfeb0a8d75b34ce2cb7a5f5abf3912 /node-repository/src | |
parent | 386f9d13db8fdc239dc060c0373e6a586952ad66 (diff) |
Convert IP classes to records
Diffstat (limited to 'node-repository/src')
21 files changed, 84 insertions, 191 deletions
diff --git a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/Node.java b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/Node.java index 79382a8bf5b..31283998702 100644 --- a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/Node.java +++ b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/Node.java @@ -116,11 +116,11 @@ public final class Node implements Nodelike { if (state == State.ready && type.isHost()) { requireNonEmpty(ipConfig.primary(), "A " + type + " must have at least one primary IP address in state " + state); - requireNonEmpty(ipConfig.pool().ipSet(), "A " + type + " must have a non-empty IP address pool in state " + state); + requireNonEmpty(ipConfig.pool().asSet(), "A " + type + " must have a non-empty IP address pool in state " + state); } if (parentHostname.isPresent()) { - if (!ipConfig.pool().ipSet().isEmpty()) throw new IllegalArgumentException("A child node cannot have an IP address pool"); + if (!ipConfig.pool().asSet().isEmpty()) throw new IllegalArgumentException("A child node cannot have an IP address pool"); if (modelName.isPresent()) throw new IllegalArgumentException("A child node cannot have model name set"); if (switchHostname.isPresent()) throw new IllegalArgumentException("A child node cannot have switch hostname set"); if (status.wantToRebuild()) throw new IllegalArgumentException("A child node cannot be rebuilt"); diff --git a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/NodeList.java b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/NodeList.java index 62b60858b3f..1cf7bcfa4f2 100644 --- a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/NodeList.java +++ b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/NodeList.java @@ -9,7 +9,6 @@ import com.yahoo.config.provision.ClusterSpec; import com.yahoo.config.provision.NodeResources; import com.yahoo.config.provision.NodeType; import com.yahoo.vespa.hosted.provision.node.ClusterId; -import com.yahoo.vespa.hosted.provision.node.IP; import java.util.ArrayList; import java.util.Comparator; @@ -330,12 +329,12 @@ public class NodeList extends AbstractFilteringList<Node, NodeList> { /** * Returns the number of unused IP addresses in the pool, assuming any and all unaccounted for hostnames - * in the pool are resolved to exactly 1 IP address (or 2 with {@link IP.IpAddresses.Protocol#dualStack}). + * in the pool are resolved to exactly 1 IP address (or 2 if dual-stack). */ public int eventuallyUnusedIpAddressCount(Node host) { // The count in this method relies on the size of the IP address pool if that's non-empty, // otherwise fall back to the address/hostname pool. - if (host.ipConfig().pool().ipSet().isEmpty()) { + if (host.ipConfig().pool().asSet().isEmpty()) { Set<String> allHostnames = cache().keySet(); return (int) host.ipConfig().pool().hostnames().stream() .filter(hostname -> !allHostnames.contains(hostname.value())) @@ -345,7 +344,7 @@ public class NodeList extends AbstractFilteringList<Node, NodeList> { old != null ? old : stream().flatMap(node -> node.ipConfig().primary().stream()) .collect(Collectors.toUnmodifiableSet()) ); - return (int) host.ipConfig().pool().ipSet().stream() + return (int) host.ipConfig().pool().asSet().stream() .filter(address -> !allIps.contains(address)) .count(); } diff --git a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/maintenance/CapacityChecker.java b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/maintenance/CapacityChecker.java index 603056856e2..c8b736cb25b 100644 --- a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/maintenance/CapacityChecker.java +++ b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/maintenance/CapacityChecker.java @@ -127,12 +127,12 @@ public class CapacityChecker { for (var host : hosts) { NodeResources hostResources = host.flavor().resources(); int occupiedIps = 0; - Set<String> ipPool = host.ipConfig().pool().ipSet(); + Set<String> ipPool = host.ipConfig().pool().asSet(); for (var child : nodeChildren.get(host)) { hostResources = hostResources.subtract(child.resources().justNumbers()); occupiedIps += child.ipConfig().primary().stream().filter(ipPool::contains).count(); } - availableResources.put(host, new AllocationResources(hostResources, host.ipConfig().pool().ipSet().size() - occupiedIps)); + availableResources.put(host, new AllocationResources(hostResources, host.ipConfig().pool().asSet().size() - occupiedIps)); } return availableResources; diff --git a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/node/IP.java b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/node/IP.java index 8e045255b21..708d84ba655 100644 --- a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/node/IP.java +++ b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/node/IP.java @@ -1,7 +1,6 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.vespa.hosted.provision.node; -import com.google.common.collect.ImmutableSet; import com.google.common.net.InetAddresses; import com.google.common.primitives.UnsignedBytes; import com.yahoo.config.provision.HostName; @@ -32,7 +31,7 @@ import static com.yahoo.config.provision.NodeType.proxyhost; * * @author mpolden */ -public class IP { +public record IP() { /** Comparator for sorting IP addresses by their natural order */ public static final Comparator<InetAddress> NATURAL_ORDER = (ip1, ip2) -> { @@ -60,31 +59,26 @@ public class IP { }; /** IP configuration of a node */ - public static class Config { + public record Config(Set<String> primary, Pool pool) { public static final Config EMPTY = Config.ofEmptyPool(Set.of()); - private final Set<String> primary; - private final Pool pool; - public static Config ofEmptyPool(Set<String> primary) { - return new Config(primary, Set.of(), List.of()); + return new Config(primary, Pool.EMPTY); } public static Config of(Set<String> primary, Set<String> ipPool, List<HostName> hostnames) { - return new Config(primary, ipPool, hostnames); + return new Config(primary, new Pool(IpAddresses.of(ipPool), hostnames)); } - /** LEGACY TEST CONSTRUCTOR - use of() variants and/or the with- methods. */ - public Config(Set<String> primary, Set<String> pool) { - this(primary, pool, List.of()); + public static Config of(Set<String> primary, Set<String> pool) { + return of(primary, pool, List.of()); } /** DO NOT USE: Public for NodeSerializer. */ - public Config(Set<String> primary, Set<String> pool, List<HostName> hostnames) { - this.primary = ImmutableSet.copyOf(Objects.requireNonNull(primary, "primary must be non-null")); - this.pool = Pool.of(Objects.requireNonNull(pool, "pool must be non-null"), - Objects.requireNonNull(hostnames, "addresses must be non-null")); + public Config(Set<String> primary, Pool pool) { + this.primary = Collections.unmodifiableSet(new LinkedHashSet<>(Objects.requireNonNull(primary, "primary must be non-null"))); + this.pool = Objects.requireNonNull(pool, "pool must be non-null"); } /** The primary addresses of this. These addresses are used when communicating with the node itself */ @@ -99,31 +93,12 @@ public class IP { /** Returns a copy of this with pool set to given value */ public Config withPool(Pool pool) { - return new Config(primary, pool.ipSet(), pool.hostnames()); + return new Config(primary, pool); } /** Returns a copy of this with pool set to given value */ public Config withPrimary(Set<String> primary) { - return new Config(primary, pool.ipSet(), pool.hostnames()); - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - Config config = (Config) o; - return primary.equals(config.primary) && - pool.equals(config.pool); - } - - @Override - public int hashCode() { - return Objects.hash(primary, pool); - } - - @Override - public String toString() { - return String.format("ip config primary=%s pool=%s", primary, pool.ipSet()); + return new Config(primary, pool); } /** @@ -141,8 +116,8 @@ public class IP { var addresses = new HashSet<>(node.ipConfig().primary()); var otherAddresses = new HashSet<>(other.ipConfig().primary()); if (node.type().isHost()) { // Addresses of a host can never overlap with any other nodes - addresses.addAll(node.ipConfig().pool().ipSet()); - otherAddresses.addAll(other.ipConfig().pool().ipSet()); + addresses.addAll(node.ipConfig().pool().asSet()); + otherAddresses.addAll(other.ipConfig().pool().asSet()); } otherAddresses.retainAll(addresses); if (!otherAddresses.isEmpty()) @@ -174,25 +149,13 @@ public class IP { } /** A list of IP addresses and their protocol */ - public static class IpAddresses { - - private final Set<String> ipAddresses; - private final Protocol protocol; + record IpAddresses(Set<String> addresses, Protocol protocol) { - private IpAddresses(Set<String> ipAddresses, Protocol protocol) { - this.ipAddresses = ImmutableSet.copyOf(Objects.requireNonNull(ipAddresses, "addresses must be non-null")); + public IpAddresses(Set<String> addresses, Protocol protocol) { + this.addresses = Collections.unmodifiableSet(new LinkedHashSet<>(Objects.requireNonNull(addresses, "addresses must be non-null"))); this.protocol = Objects.requireNonNull(protocol, "type must be non-null"); } - public Set<String> asSet() { - return ipAddresses; - } - - /** The protocol of addresses in this */ - public Protocol protocol() { - return protocol; - } - /** Create addresses of the given set */ private static IpAddresses of(Set<String> addresses) { long ipv6AddrCount = addresses.stream().filter(IP::isV6).count(); @@ -217,6 +180,7 @@ public class IP { } public enum Protocol { + dualStack("dual-stack"), ipv4("IPv4-only"), ipv6("IPv6-only"); @@ -225,21 +189,8 @@ public class IP { Protocol(String description) { this.description = description; } - public String getDescription() { return description; } - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - IpAddresses that = (IpAddresses) o; - return ipAddresses.equals(that.ipAddresses) && protocol == that.protocol; } - @Override - public int hashCode() { - return Objects.hash(ipAddresses, protocol); - } } /** @@ -247,15 +198,9 @@ public class IP { * * Addresses in this are available for use by Linux containers. */ - public static class Pool { - - private final IpAddresses ipAddresses; - private final List<HostName> hostnames; + public record Pool(IpAddresses ipAddresses, List<HostName> hostnames) { - /** Creates an empty pool. */ - public static Pool of() { - return of(Set.of(), List.of()); - } + public static final Pool EMPTY = new Pool(IpAddresses.of(Set.of()), List.of()); /** Create a new pool containing given ipAddresses */ public static Pool of(Set<String> ipAddresses, List<HostName> hostnames) { @@ -263,9 +208,13 @@ public class IP { return new Pool(ips, hostnames); } - private Pool(IpAddresses ipAddresses, List<HostName> hostnames) { + public Pool(IpAddresses ipAddresses, List<HostName> hostnames) { this.ipAddresses = Objects.requireNonNull(ipAddresses, "ipAddresses must be non-null"); - this.hostnames = Objects.requireNonNull(hostnames, "hostnames must be non-null"); + this.hostnames = List.copyOf(Objects.requireNonNull(hostnames, "hostnames must be non-null")); + } + + public Set<String> asSet() { + return ipAddresses.addresses; } /** @@ -275,7 +224,7 @@ public class IP { * @return an allocation from the pool, if any can be made */ public Optional<Allocation> findAllocation(LockedNodeList nodes, NameResolver resolver, boolean hasPtr) { - if (ipAddresses.asSet().isEmpty()) { + if (ipAddresses.addresses.isEmpty()) { // IP addresses have not yet been resolved and should be done later. return findUnusedHostnames(nodes).map(Allocation::ofHostname) .findFirst(); @@ -313,8 +262,8 @@ public class IP { * @param nodes a list of all nodes in the repository */ public Set<String> findUnusedIpAddresses(NodeList nodes) { - var unusedAddresses = new LinkedHashSet<>(ipSet()); - nodes.matching(node -> node.ipConfig().primary().stream().anyMatch(ip -> ipSet().contains(ip))) + Set<String> unusedAddresses = new LinkedHashSet<>(asSet()); + nodes.matching(node -> node.ipConfig().primary().stream().anyMatch(ip -> asSet().contains(ip))) .forEach(node -> unusedAddresses.removeAll(node.ipConfig().primary())); return Collections.unmodifiableSet(unusedAddresses); } @@ -324,53 +273,23 @@ public class IP { return hostnames.stream().filter(hostname -> !usedHostnames.contains(hostname.value())); } - public IpAddresses.Protocol getProtocol() { - return ipAddresses.protocol; - } - - /** Returns the IP addresses in this pool as a set */ - public Set<String> ipSet() { - return ipAddresses.asSet(); - } - - public List<HostName> hostnames() { - return hostnames; - } - public Pool withIpAddresses(Set<String> ipAddresses) { return Pool.of(ipAddresses, hostnames); } public Pool withHostnames(List<HostName> hostnames) { - return Pool.of(ipAddresses.asSet(), hostnames); - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - Pool pool = (Pool) o; - return ipAddresses.equals(pool.ipAddresses) && hostnames.equals(pool.hostnames); - } - - @Override - public int hashCode() { - return Objects.hash(ipAddresses, hostnames); + return Pool.of(ipAddresses.addresses, hostnames); } } /** An address allocation from a pool */ - public static class Allocation { - - private final String hostname; - private final Optional<String> ipv4Address; - private final Optional<String> ipv6Address; + public record Allocation(String hostname, Optional<String> ipv4Address, Optional<String> ipv6Address) { - private Allocation(String hostname, Optional<String> ipv4Address, Optional<String> ipv6Address) { - this.hostname = Objects.requireNonNull(hostname, "hostname must be non-null"); - this.ipv4Address = Objects.requireNonNull(ipv4Address, "ipv4Address must be non-null"); - this.ipv6Address = Objects.requireNonNull(ipv6Address, "ipv6Address must be non-null"); + public Allocation { + Objects.requireNonNull(hostname, "hostname must be non-null"); + Objects.requireNonNull(ipv4Address, "ipv4Address must be non-null"); + Objects.requireNonNull(ipv6Address, "ipv6Address must be non-null"); } /** @@ -458,33 +377,10 @@ public class IP { return new Allocation(hostName.value(), Optional.empty(), Optional.empty()); } - /** Hostname pointing to the IP addresses in this */ - public String hostname() { - return hostname; - } - - /** IPv4 address of this allocation */ - public Optional<String> ipv4Address() { - return ipv4Address; - } - - /** IPv6 address of this allocation */ - public Optional<String> ipv6Address() { - return ipv6Address; - } - /** All IP addresses in this */ public Set<String> addresses() { - ImmutableSet.Builder<String> builder = ImmutableSet.builder(); - ipv4Address.ifPresent(builder::add); - ipv6Address.ifPresent(builder::add); - return builder.build(); - } - - @Override - public String toString() { - return String.format("Address allocation [hostname=%s, IPv4=%s, IPv6=%s]", - hostname, ipv4Address.orElse("<none>"), ipv6Address.orElse("<none>")); + return Stream.concat(ipv4Address.stream(), ipv6Address.stream()) + .collect(Collectors.toUnmodifiableSet()); } } diff --git a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/persistence/NodeSerializer.java b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/persistence/NodeSerializer.java index d55bf36e839..23ea14da4cc 100644 --- a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/persistence/NodeSerializer.java +++ b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/persistence/NodeSerializer.java @@ -167,7 +167,7 @@ public class NodeSerializer { object.setString(hostnameKey, node.hostname()); object.setString(stateKey, toString(node.state())); toSlime(node.ipConfig().primary(), object.setArray(ipAddressesKey)); - toSlime(node.ipConfig().pool().ipSet(), object.setArray(ipAddressPoolKey)); + toSlime(node.ipConfig().pool().asSet(), object.setArray(ipAddressPoolKey)); toSlime(node.ipConfig().pool().hostnames(), object); object.setString(idKey, node.id()); node.parentHostname().ifPresent(hostname -> object.setString(parentHostnameKey, hostname)); @@ -277,9 +277,9 @@ public class NodeSerializer { private Node nodeFromSlime(Inspector object) { Flavor flavor = flavorFromSlime(object); return new Node(object.field(idKey).asString(), - new IP.Config(ipAddressesFromSlime(object, ipAddressesKey), - ipAddressesFromSlime(object, ipAddressPoolKey), - hostnamesFromSlime(object)), + IP.Config.of(ipAddressesFromSlime(object, ipAddressesKey), + ipAddressesFromSlime(object, ipAddressPoolKey), + hostnamesFromSlime(object)), object.field(hostnameKey).asString(), SlimeUtils.optionalString(object.field(parentHostnameKey)), flavor, diff --git a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/restapi/NodesResponse.java b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/restapi/NodesResponse.java index ac23af43b4a..f98c4ba1199 100644 --- a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/restapi/NodesResponse.java +++ b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/restapi/NodesResponse.java @@ -179,7 +179,7 @@ class NodesResponse extends SlimeJsonResponse { toSlime(node.history().events(), object.setArray("history")); toSlime(node.history().log(), object.setArray("log")); ipAddressesToSlime(node.ipConfig().primary(), object.setArray("ipAddresses")); - ipAddressesToSlime(node.ipConfig().pool().ipSet(), object.setArray("additionalIpAddresses")); + ipAddressesToSlime(node.ipConfig().pool().asSet(), object.setArray("additionalIpAddresses")); hostnamesToSlime(node.ipConfig().pool().hostnames(), object); node.reports().toSlime(object, "reports"); node.modelName().ifPresent(modelName -> object.setString("modelName", modelName)); diff --git a/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/NodeRepositoryTester.java b/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/NodeRepositoryTester.java index b964bf871c1..4d0b3e75740 100644 --- a/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/NodeRepositoryTester.java +++ b/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/NodeRepositoryTester.java @@ -74,7 +74,7 @@ public class NodeRepositoryTester { private Node addNode(String id, String hostname, String parentHostname, Flavor flavor, NodeType type) { Set<String> ips = nodeRepository.nameResolver().resolveAll(hostname); - IP.Config ipConfig = new IP.Config(ips, type.isHost() ? ips : Set.of()); + IP.Config ipConfig = IP.Config.of(ips, type.isHost() ? ips : Set.of()); Node node = Node.create(id, ipConfig, hostname, flavor, type).parentHostname(parentHostname).build(); return nodeRepository.nodes().addNodes(List.of(node), Agent.system).get(0); } diff --git a/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/autoscale/AutoscalingTester.java b/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/autoscale/AutoscalingTester.java index 19c6ce16674..7c75b07eb47 100644 --- a/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/autoscale/AutoscalingTester.java +++ b/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/autoscale/AutoscalingTester.java @@ -105,9 +105,9 @@ class AutoscalingTester { public void makeReady(String hostname) { Node node = nodeRepository().nodes().node(hostname).get(); - provisioningTester.patchNode(node, (n) -> n.with(new IP.Config(Set.of("::" + 0 + ":0"), Set.of()))); + provisioningTester.patchNode(node, (n) -> n.with(IP.Config.of(Set.of("::" + 0 + ":0"), Set.of()))); Node host = nodeRepository().nodes().node(node.parentHostname().get()).get(); - host = host.with(new IP.Config(Set.of("::" + 0 + ":0"), Set.of("::" + 0 + ":2"))); + host = host.with(IP.Config.of(Set.of("::" + 0 + ":0"), Set.of("::" + 0 + ":2"))); if (host.state() == Node.State.provisioned) provisioningTester.move(Node.State.ready, host); } diff --git a/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/maintenance/CapacityCheckerTester.java b/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/maintenance/CapacityCheckerTester.java index 606bc55fdd2..f8ec271ce5f 100644 --- a/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/maintenance/CapacityCheckerTester.java +++ b/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/maintenance/CapacityCheckerTester.java @@ -156,8 +156,8 @@ public class CapacityCheckerTester { .collect(Collectors.toSet()); NodeResources nr = containingNodeResources(childResources, excessCapacity); - Node node = Node.create(hostname, new IP.Config(Set.of("::"), availableIps), hostname, - new Flavor(nr), NodeType.host).build(); + Node node = Node.create(hostname, IP.Config.of(Set.of("::"), availableIps), hostname, + new Flavor(nr), NodeType.host).build(); hosts.computeIfAbsent(tenantHostApp, (ignored) -> new ArrayList<>()) .add(node); } @@ -175,8 +175,8 @@ public class CapacityCheckerTester { Set<String> availableIps = IntStream.range(2000, 2000 + ips) .mapToObj(n -> String.format("%04X::%04X", hostId, n)) .collect(Collectors.toSet()); - Node node = Node.create(hostname, new IP.Config(Set.of("::" + (1000 + hostId)), availableIps), hostname, - new Flavor(capacity), NodeType.host).build(); + Node node = Node.create(hostname, IP.Config.of(Set.of("::" + (1000 + hostId)), availableIps), hostname, + new Flavor(capacity), NodeType.host).build(); hosts.add(node); } return hosts; @@ -290,7 +290,7 @@ public class CapacityCheckerTester { Flavor f = new Flavor(nr); Node.Builder builder = Node.create(nodeModel.id, nodeModel.hostname, f, nodeModel.state, nodeModel.type) - .ipConfig(new IP.Config(nodeModel.ipAddresses, nodeModel.additionalIpAddresses)); + .ipConfig(IP.Config.of(nodeModel.ipAddresses, nodeModel.additionalIpAddresses)); nodeModel.parentHostname.ifPresent(builder::parentHostname); Node node = builder.build(); diff --git a/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/maintenance/HostCapacityMaintainerTest.java b/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/maintenance/HostCapacityMaintainerTest.java index bf5df53450b..e6d056d126d 100644 --- a/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/maintenance/HostCapacityMaintainerTest.java +++ b/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/maintenance/HostCapacityMaintainerTest.java @@ -651,7 +651,7 @@ public class HostCapacityMaintainerTest { false)); List<com.yahoo.config.provision.HostName> hostnames = Stream.of(additionalHostnames).map(com.yahoo.config.provision.HostName::of).toList(); Node.Builder builder = Node.create("fake-id-" + hostname, hostname, flavor, state, nodeType) - .ipConfig(new IP.Config(state == Node.State.active ? Set.of("::1") : Set.of(), Set.of(), hostnames)); + .ipConfig(IP.Config.of(state == Node.State.active ? Set.of("::1") : Set.of(), Set.of(), hostnames)); parentHostname.ifPresent(builder::parentHostname); allocation.ifPresent(builder::allocation); if (hostname.equals("host2-1")) diff --git a/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/maintenance/HostResumeProvisionerTest.java b/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/maintenance/HostResumeProvisionerTest.java index 5e507d447ab..8280c0e33fc 100644 --- a/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/maintenance/HostResumeProvisionerTest.java +++ b/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/maintenance/HostResumeProvisionerTest.java @@ -78,12 +78,12 @@ public class HostResumeProvisionerTest { hostResumeProvisioner.maintain(); assertTrue("No IP addresses written as DNS updates are failing", - provisioning.get().stream().allMatch(host -> host.ipConfig().pool().ipSet().isEmpty())); + provisioning.get().stream().allMatch(host -> host.ipConfig().pool().asSet().isEmpty())); hostProvisioner.without(MockHostProvisioner.Behaviour.failDnsUpdate); hostResumeProvisioner.maintain(); assertTrue("IP addresses written as DNS updates are succeeding", - provisioning.get().stream().noneMatch(host -> host.ipConfig().pool().ipSet().isEmpty())); + provisioning.get().stream().noneMatch(host -> host.ipConfig().pool().asSet().isEmpty())); } @Test diff --git a/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/maintenance/MetricsReporterTest.java b/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/maintenance/MetricsReporterTest.java index 44050fa747c..2187611b702 100644 --- a/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/maintenance/MetricsReporterTest.java +++ b/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/maintenance/MetricsReporterTest.java @@ -176,7 +176,7 @@ public class MetricsReporterTest { // Allow 4 containers Set<String> ipAddressPool = Set.of("::2", "::3", "::4", "::5"); - Node dockerHost = Node.create("node-id-1", new IP.Config(Set.of("::1"), ipAddressPool), "dockerHost", + Node dockerHost = Node.create("node-id-1", IP.Config.of(Set.of("::1"), ipAddressPool), "dockerHost", nodeFlavors.getFlavorOrThrow("host"), NodeType.host).build(); nodeRepository.nodes().addNodes(List.of(dockerHost), Agent.system); nodeRepository.nodes().deallocateRecursively("dockerHost", Agent.system, getClass().getSimpleName()); diff --git a/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/maintenance/NodeFailTester.java b/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/maintenance/NodeFailTester.java index 1b0826a8323..a07a4f2c72a 100644 --- a/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/maintenance/NodeFailTester.java +++ b/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/maintenance/NodeFailTester.java @@ -244,8 +244,8 @@ public class NodeFailTester { for (int i = startIndex; i < startIndex + count; i++) { String hostname = "host" + i; Set<String> ipPool = nodeType.isHost() ? Set.of("127.0." + i + "." + (++lastOctetOfPoolAddress)) : Set.of(); - IP.Config ipConfig = new IP.Config(nodeRepository.nameResolver().resolveAll(hostname), - ipPool); + IP.Config ipConfig = IP.Config.of(nodeRepository.nameResolver().resolveAll(hostname), + ipPool); Node.Builder builder = Node.create("node" + i, ipConfig, hostname, flavor, nodeType); parentHostname.ifPresent(builder::parentHostname); nodes.add(builder.build()); diff --git a/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/maintenance/RetiredExpirerTest.java b/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/maintenance/RetiredExpirerTest.java index f5e524a90cc..58f4be18992 100644 --- a/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/maintenance/RetiredExpirerTest.java +++ b/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/maintenance/RetiredExpirerTest.java @@ -239,8 +239,8 @@ public class RetiredExpirerTest { MockNameResolver nameResolver = (MockNameResolver) tester.nodeRepository().nameResolver(); String ipv4 = "127.0.1.4"; nameResolver.addRecord(retiredNode.hostname(), ipv4); - Node node = Node.create(retiredNode.hostname(), new IP.Config(Set.of(ipv4), Set.of()), retiredNode.hostname(), - tester.asFlavor("default", NodeType.config), NodeType.config).build(); + Node node = Node.create(retiredNode.hostname(), IP.Config.of(Set.of(ipv4), Set.of()), retiredNode.hostname(), + tester.asFlavor("default", NodeType.config), NodeType.config).build(); var nodes = List.of(node); nodes = nodeRepository.nodes().addNodes(nodes, Agent.system); nodes = nodeRepository.nodes().deallocate(nodes, Agent.system, getClass().getSimpleName()); diff --git a/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/maintenance/SpareCapacityMaintainerTest.java b/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/maintenance/SpareCapacityMaintainerTest.java index c9421f098e7..b54975cbf41 100644 --- a/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/maintenance/SpareCapacityMaintainerTest.java +++ b/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/maintenance/SpareCapacityMaintainerTest.java @@ -327,8 +327,8 @@ public class SpareCapacityMaintainerTest { } private IP.Config ipConfig(int id, boolean host) { - return new IP.Config(Set.of(String.format("%04X::%04X", id, 0)), - host ? IntStream.range(0, 10) + return IP.Config.of(Set.of(String.format("%04X::%04X", id, 0)), + host ? IntStream.range(0, 10) .mapToObj(n -> String.format("%04X::%04X", id, n)) .collect(Collectors.toSet()) : Set.of()); diff --git a/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/node/IPTest.java b/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/node/IPTest.java index 59c02871844..88fe88dbaad 100644 --- a/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/node/IPTest.java +++ b/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/node/IPTest.java @@ -193,12 +193,12 @@ public class IPTest { } IP.Pool pool = node.ipConfig().pool(); - assertNotEquals(dualStack, pool.getProtocol() == IP.IpAddresses.Protocol.ipv4); + assertNotEquals(dualStack, pool.ipAddresses().protocol() == IP.IpAddresses.Protocol.ipv4); return pool; } private static Node createNode(Set<String> ipAddresses) { - return Node.create("id1", new IP.Config(Set.of("127.0.0.1"), ipAddresses), + return Node.create("id1", IP.Config.of(Set.of("127.0.0.1"), ipAddresses), "host1", nodeFlavors.getFlavorOrThrow("default"), NodeType.host).build(); } diff --git a/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/persistence/NodeSerializerTest.java b/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/persistence/NodeSerializerTest.java index fc7b0ddce21..1086f2026a8 100644 --- a/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/persistence/NodeSerializerTest.java +++ b/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/persistence/NodeSerializerTest.java @@ -249,7 +249,7 @@ public class NodeSerializerTest { @Test public void serialize_parent_hostname() { final String parentHostname = "parent.yahoo.com"; - Node node = Node.create("myId", new IP.Config(Set.of("127.0.0.1"), Set.of()), "myHostname", nodeFlavors.getFlavorOrThrow("default"), NodeType.tenant) + Node node = Node.create("myId", IP.Config.of(Set.of("127.0.0.1"), Set.of()), "myHostname", nodeFlavors.getFlavorOrThrow("default"), NodeType.tenant) .parentHostname(parentHostname) .build(); @@ -274,14 +274,12 @@ public class NodeSerializerTest { Set.of("::1", "::2", "::3"), List.of(HostName.of("a"), HostName.of("b"), HostName.of("c"))))); Node copy = nodeSerializer.fromJson(nodeSerializer.toJson(node)); - assertEquals(node.ipConfig().pool().ipSet(), copy.ipConfig().pool().ipSet()); - assertEquals(Set.copyOf(node.ipConfig().pool().hostnames()), Set.copyOf(copy.ipConfig().pool().hostnames())); + assertEquals(node.ipConfig(), copy.ipConfig()); // Test round-trip without address pool (handle empty pool) node = createNode(); copy = nodeSerializer.fromJson(nodeSerializer.toJson(node)); - assertEquals(node.ipConfig().pool().ipSet(), copy.ipConfig().pool().ipSet()); - assertEquals(Set.copyOf(node.ipConfig().pool().hostnames()), Set.copyOf(copy.ipConfig().pool().hostnames())); + assertEquals(node.ipConfig(), copy.ipConfig()); } @Test @@ -529,7 +527,7 @@ public class NodeSerializerTest { private Node createNode() { return Node.create("myId", - new IP.Config(Set.of("127.0.0.1"), Set.of()), + IP.Config.of(Set.of("127.0.0.1"), Set.of()), "myHostname", nodeFlavors.getFlavorOrThrow("default"), NodeType.tenant).build(); diff --git a/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/provisioning/DynamicAllocationTest.java b/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/provisioning/DynamicAllocationTest.java index 23c2d0fc47a..47d34a76dd6 100644 --- a/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/provisioning/DynamicAllocationTest.java +++ b/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/provisioning/DynamicAllocationTest.java @@ -534,7 +534,7 @@ public class DynamicAllocationTest { } private void addAndAssignNode(ApplicationId id, String hostname, String parentHostname, ClusterSpec clusterSpec, NodeResources flavor, int index, ProvisioningTester tester) { - Node node1a = Node.create("open1", new IP.Config(Set.of("127.0.233." + index), Set.of()), hostname, + Node node1a = Node.create("open1", IP.Config.of(Set.of("127.0.233." + index), Set.of()), hostname, new Flavor(flavor), NodeType.tenant).parentHostname(parentHostname).build(); ClusterMembership clusterMembership1 = ClusterMembership.from( clusterSpec.with(Optional.of(ClusterSpec.Group.from(0))), index); // Need to add group here so that group is serialized in node allocation diff --git a/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/provisioning/NodeCandidateTest.java b/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/provisioning/NodeCandidateTest.java index 20819daf356..32db213c445 100644 --- a/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/provisioning/NodeCandidateTest.java +++ b/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/provisioning/NodeCandidateTest.java @@ -146,7 +146,7 @@ public class NodeCandidateTest { .parentHostname(hostname + "parent") .ipConfigWithEmptyPool(Set.of("::1")).build(); Node parent = Node.create(hostname + "parent", hostname, new Flavor(totalHostResources), Node.State.ready, NodeType.host) - .ipConfig(new IP.Config(Set.of("::1"), Set.of("::2"))) + .ipConfig(IP.Config.of(Set.of("::1"), Set.of("::2"))) .build(); return new NodeCandidate.ConcreteNodeCandidate(node, totalHostResources.subtract(allocatedHostResources), Optional.of(parent), false, exclusiveSwitch, false, true, false); diff --git a/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/provisioning/ProvisioningTest.java b/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/provisioning/ProvisioningTest.java index 471fabb1206..68857719bf0 100644 --- a/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/provisioning/ProvisioningTest.java +++ b/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/provisioning/ProvisioningTest.java @@ -919,10 +919,10 @@ public class ProvisioningTest { // Add 2 config server hosts and 2 config servers Flavor flavor = tester.nodeRepository().flavors().getFlavorOrThrow("default"); List<Node> nodes = List.of( - Node.create("cfghost1", new IP.Config(Set.of("::1:0"), Set.of("::1:1")), "cfghost1", flavor, NodeType.confighost).build(), - Node.create("cfghost2", new IP.Config(Set.of("::2:0"), Set.of("::2:1")), "cfghost2", flavor, NodeType.confighost).ipConfig(IP.Config.of(Set.of("::2:0"), Set.of("::2:1"), List.of())).build(), - Node.create("cfg1", new IP.Config(Set.of("::1:1"), Set.of()), "cfg1", flavor, NodeType.config).parentHostname("cfghost1").build(), - Node.create("cfg2", new IP.Config(Set.of("::2:1"), Set.of()), "cfg2", flavor, NodeType.config).parentHostname("cfghost2").build()); + Node.create("cfghost1", IP.Config.of(Set.of("::1:0"), Set.of("::1:1")), "cfghost1", flavor, NodeType.confighost).build(), + Node.create("cfghost2", IP.Config.of(Set.of("::2:0"), Set.of("::2:1")), "cfghost2", flavor, NodeType.confighost).ipConfig(IP.Config.of(Set.of("::2:0"), Set.of("::2:1"), List.of())).build(), + Node.create("cfg1", IP.Config.of(Set.of("::1:1"), Set.of()), "cfg1", flavor, NodeType.config).parentHostname("cfghost1").build(), + Node.create("cfg2", IP.Config.of(Set.of("::2:1"), Set.of()), "cfg2", flavor, NodeType.config).parentHostname("cfghost2").build()); tester.move(Node.State.ready, tester.nodeRepository().nodes().addNodes(nodes, Agent.system)); InfraApplication cfgHostApp = new ConfigServerHostApplication(); diff --git a/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/provisioning/ProvisioningTester.java b/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/provisioning/ProvisioningTester.java index 0ab6e31b20f..e1747a910c9 100644 --- a/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/provisioning/ProvisioningTester.java +++ b/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/provisioning/ProvisioningTester.java @@ -201,7 +201,7 @@ public class ProvisioningTester { try (var lock = nodeRepository.nodes().lockAndGetRequired(prepared.hostname())) { Node node = lock.node(); if (node.ipConfig().primary().isEmpty()) { - node = node.with(new IP.Config(Set.of("::" + 0 + ":0"), Set.of())); + node = node.with(IP.Config.of(Set.of("::" + 0 + ":0"), Set.of())); nodeRepository.nodes().write(node, lock); } if (node.parentHostname().isEmpty()) continue; @@ -209,7 +209,7 @@ public class ProvisioningTester { if (parent.state() == Node.State.active) continue; NestedTransaction t = new NestedTransaction(); if (parent.ipConfig().primary().isEmpty()) - parent = parent.with(new IP.Config(Set.of("::" + 0 + ":0"), Set.of("::" + 0 + ":2"))); + parent = parent.with(IP.Config.of(Set.of("::" + 0 + ":0"), Set.of("::" + 0 + ":2"))); nodeRepository.nodes().activate(List.of(parent), t); t.commit(); } @@ -447,7 +447,7 @@ public class ProvisioningTester { nameResolver.addRecord(nodeHostname, ipv4Addr); } } - Node.Builder builder = Node.create(hostname, new IP.Config(hostIps, ipAddressPool), hostname, flavor, type); + Node.Builder builder = Node.create(hostname, IP.Config.of(hostIps, ipAddressPool), hostname, flavor, type); reservedTo.ifPresent(builder::reservedTo); nodes.add(builder.build()); } @@ -464,8 +464,8 @@ public class ProvisioningTester { String ipv4 = "127.0.1." + i; nameResolver.addRecord(hostname, ipv4); - Node node = Node.create(hostname, new IP.Config(Set.of(ipv4), Set.of()), hostname, - nodeFlavors.getFlavorOrThrow(flavor), NodeType.config).build(); + Node node = Node.create(hostname, IP.Config.of(Set.of(ipv4), Set.of()), hostname, + nodeFlavors.getFlavorOrThrow(flavor), NodeType.config).build(); nodes.add(node); } @@ -532,7 +532,7 @@ public class ProvisioningTester { List<Node> nodes = new ArrayList<>(count); for (int i = startIndex; i < count + startIndex; i++) { String hostname = nodeNamer.apply(i); - IP.Config ipConfig = new IP.Config(nodeRepository.nameResolver().resolveAll(hostname), Set.of()); + IP.Config ipConfig = IP.Config.of(nodeRepository.nameResolver().resolveAll(hostname), Set.of()); Node node = Node.create("node-id", ipConfig, hostname, new Flavor(resources), nodeType) .parentHostname(parentHostname) .build(); |