aboutsummaryrefslogtreecommitdiffstats
path: root/node-repository/src
diff options
context:
space:
mode:
authorMartin Polden <mpolden@mpolden.no>2023-02-15 15:58:39 +0100
committerMartin Polden <mpolden@mpolden.no>2023-03-13 09:37:26 +0100
commitf3f818f76dfa230ea31ec0e0b0fe72e1c29123d3 (patch)
treee3c2143447152d254e2a7f9cab77de243475b23e /node-repository/src
parent16b55f4d4311e7142037476f12568d6118f00ade (diff)
Remove redundant Address class
Diffstat (limited to 'node-repository/src')
-rw-r--r--node-repository/src/main/java/com/yahoo/vespa/hosted/provision/NodeList.java4
-rw-r--r--node-repository/src/main/java/com/yahoo/vespa/hosted/provision/node/Address.java17
-rw-r--r--node-repository/src/main/java/com/yahoo/vespa/hosted/provision/node/IP.java70
-rw-r--r--node-repository/src/main/java/com/yahoo/vespa/hosted/provision/persistence/NodeSerializer.java20
-rw-r--r--node-repository/src/main/java/com/yahoo/vespa/hosted/provision/provisioning/HostProvisioner.java1
-rw-r--r--node-repository/src/main/java/com/yahoo/vespa/hosted/provision/provisioning/ProvisionedHost.java30
-rw-r--r--node-repository/src/main/java/com/yahoo/vespa/hosted/provision/restapi/NodePatcher.java22
-rw-r--r--node-repository/src/main/java/com/yahoo/vespa/hosted/provision/restapi/NodesResponse.java15
-rw-r--r--node-repository/src/main/java/com/yahoo/vespa/hosted/provision/restapi/NodesV2ApiHandler.java8
-rw-r--r--node-repository/src/main/java/com/yahoo/vespa/hosted/provision/testutils/MockHostProvisioner.java8
-rw-r--r--node-repository/src/test/java/com/yahoo/vespa/hosted/provision/maintenance/HostCapacityMaintainerTest.java5
-rw-r--r--node-repository/src/test/java/com/yahoo/vespa/hosted/provision/node/IPTest.java4
-rw-r--r--node-repository/src/test/java/com/yahoo/vespa/hosted/provision/persistence/NodeSerializerTest.java8
-rw-r--r--node-repository/src/test/java/com/yahoo/vespa/hosted/provision/provisioning/HostCapacityTest.java7
14 files changed, 100 insertions, 119 deletions
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 800cf2150e9..62b60858b3f 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
@@ -337,8 +337,8 @@ public class NodeList extends AbstractFilteringList<Node, NodeList> {
// otherwise fall back to the address/hostname pool.
if (host.ipConfig().pool().ipSet().isEmpty()) {
Set<String> allHostnames = cache().keySet();
- return (int) host.ipConfig().pool().getAddressList().stream()
- .filter(address -> !allHostnames.contains(address.hostname()))
+ return (int) host.ipConfig().pool().hostnames().stream()
+ .filter(hostname -> !allHostnames.contains(hostname.value()))
.count();
}
Set<String> allIps = ipCache.updateAndGet(old ->
diff --git a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/node/Address.java b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/node/Address.java
deleted file mode 100644
index d7ef2228960..00000000000
--- a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/node/Address.java
+++ /dev/null
@@ -1,17 +0,0 @@
-// 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 java.util.Objects;
-
-/**
- * Address info about a container that might run on a host.
- *
- * @author hakon
- */
-public record Address(String hostname) {
- public Address {
- Objects.requireNonNull(hostname, "hostname cannot be null");
- if (hostname.isEmpty())
- throw new IllegalArgumentException("hostname cannot be empty");
- }
-}
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 bee14321435..8e045255b21 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
@@ -4,6 +4,7 @@ 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;
import com.yahoo.vespa.hosted.provision.LockedNodeList;
import com.yahoo.vespa.hosted.provision.Node;
import com.yahoo.vespa.hosted.provision.NodeList;
@@ -70,8 +71,8 @@ public class IP {
return new Config(primary, Set.of(), List.of());
}
- public static Config of(Set<String> primary, Set<String> ipPool, List<Address> addressPool) {
- return new Config(primary, ipPool, addressPool);
+ public static Config of(Set<String> primary, Set<String> ipPool, List<HostName> hostnames) {
+ return new Config(primary, ipPool, hostnames);
}
/** LEGACY TEST CONSTRUCTOR - use of() variants and/or the with- methods. */
@@ -80,10 +81,10 @@ public class IP {
}
/** DO NOT USE: Public for NodeSerializer. */
- public Config(Set<String> primary, Set<String> pool, List<Address> addresses) {
+ 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(addresses, "addresses must be non-null"));
+ Objects.requireNonNull(hostnames, "addresses must be non-null"));
}
/** The primary addresses of this. These addresses are used when communicating with the node itself */
@@ -98,12 +99,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.getAddressList());
+ return new Config(primary, pool.ipSet(), pool.hostnames());
}
/** Returns a copy of this with pool set to given value */
public Config withPrimary(Set<String> primary) {
- return new Config(primary, pool.ipSet(), pool.getAddressList());
+ return new Config(primary, pool.ipSet(), pool.hostnames());
}
@Override
@@ -249,7 +250,7 @@ public class IP {
public static class Pool {
private final IpAddresses ipAddresses;
- private final List<Address> addresses;
+ private final List<HostName> hostnames;
/** Creates an empty pool. */
public static Pool of() {
@@ -257,14 +258,14 @@ public class IP {
}
/** Create a new pool containing given ipAddresses */
- public static Pool of(Set<String> ipAddresses, List<Address> addresses) {
+ public static Pool of(Set<String> ipAddresses, List<HostName> hostnames) {
IpAddresses ips = IpAddresses.of(ipAddresses);
- return new Pool(ips, addresses);
+ return new Pool(ips, hostnames);
}
- private Pool(IpAddresses ipAddresses, List<Address> addresses) {
+ private Pool(IpAddresses ipAddresses, List<HostName> hostnames) {
this.ipAddresses = Objects.requireNonNull(ipAddresses, "ipAddresses must be non-null");
- this.addresses = Objects.requireNonNull(addresses, "addresses must be non-null");
+ this.hostnames = Objects.requireNonNull(hostnames, "hostnames must be non-null");
}
/**
@@ -276,14 +277,13 @@ public class IP {
public Optional<Allocation> findAllocation(LockedNodeList nodes, NameResolver resolver, boolean hasPtr) {
if (ipAddresses.asSet().isEmpty()) {
// IP addresses have not yet been resolved and should be done later.
- return findUnusedAddressStream(nodes)
- .map(Allocation::ofAddress)
- .findFirst();
+ return findUnusedHostnames(nodes).map(Allocation::ofHostname)
+ .findFirst();
}
if (!hasPtr) {
// Without PTR records (reverse IP mapping): Ensure only forward resolving from hostnames.
- return findUnusedAddressStream(nodes).findFirst().map(address -> Allocation.fromAddress(address, resolver, ipAddresses.protocol));
+ return findUnusedHostnames(nodes).findFirst().map(address -> Allocation.fromHostname(address, resolver, ipAddresses.protocol));
}
if (ipAddresses.protocol == IpAddresses.Protocol.ipv4) {
@@ -319,9 +319,9 @@ public class IP {
return Collections.unmodifiableSet(unusedAddresses);
}
- private Stream<Address> findUnusedAddressStream(NodeList nodes) {
- Set<String> hostnames = nodes.stream().map(Node::hostname).collect(Collectors.toSet());
- return addresses.stream().filter(address -> !hostnames.contains(address.hostname()));
+ private Stream<HostName> findUnusedHostnames(NodeList nodes) {
+ Set<String> usedHostnames = nodes.stream().map(Node::hostname).collect(Collectors.toSet());
+ return hostnames.stream().filter(hostname -> !usedHostnames.contains(hostname.value()));
}
public IpAddresses.Protocol getProtocol() {
@@ -333,16 +333,16 @@ public class IP {
return ipAddresses.asSet();
}
- public List<Address> getAddressList() {
- return addresses;
+ public List<HostName> hostnames() {
+ return hostnames;
}
public Pool withIpAddresses(Set<String> ipAddresses) {
- return Pool.of(ipAddresses, addresses);
+ return Pool.of(ipAddresses, hostnames);
}
- public Pool withAddresses(List<Address> addresses) {
- return Pool.of(ipAddresses.ipAddresses, addresses);
+ public Pool withHostnames(List<HostName> hostnames) {
+ return Pool.of(ipAddresses.asSet(), hostnames);
}
@Override
@@ -350,12 +350,12 @@ public class IP {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Pool pool = (Pool) o;
- return ipAddresses.equals(pool.ipAddresses) && addresses.equals(pool.addresses);
+ return ipAddresses.equals(pool.ipAddresses) && hostnames.equals(pool.hostnames);
}
@Override
public int hashCode() {
- return Objects.hash(ipAddresses, addresses);
+ return Objects.hash(ipAddresses, hostnames);
}
}
@@ -427,22 +427,22 @@ public class IP {
return new Allocation(hostname4, Optional.of(addresses.get(0)), Optional.empty());
}
- private static Allocation fromAddress(Address address, NameResolver resolver, IpAddresses.Protocol protocol) {
+ private static Allocation fromHostname(HostName hostname, NameResolver resolver, IpAddresses.Protocol protocol) {
// Resolve both A and AAAA to verify they match the protocol and to avoid surprises later on.
- Optional<String> ipv4Address = resolveOptional(address.hostname(), resolver, RecordType.A);
+ Optional<String> ipv4Address = resolveOptional(hostname.value(), resolver, RecordType.A);
if (protocol != IpAddresses.Protocol.ipv6 && ipv4Address.isEmpty())
- throw new IllegalArgumentException(protocol.description + " hostname " + address.hostname() + " did not resolve to an IPv4 address");
+ throw new IllegalArgumentException(protocol.description + " hostname " + hostname.value() + " did not resolve to an IPv4 address");
if (protocol == IpAddresses.Protocol.ipv6 && ipv4Address.isPresent())
- throw new IllegalArgumentException(protocol.description + " hostname " + address.hostname() + " has an IPv4 address: " + ipv4Address.get());
+ throw new IllegalArgumentException(protocol.description + " hostname " + hostname.value() + " has an IPv4 address: " + ipv4Address.get());
- Optional<String> ipv6Address = resolveOptional(address.hostname(), resolver, RecordType.AAAA);
+ Optional<String> ipv6Address = resolveOptional(hostname.value(), resolver, RecordType.AAAA);
if (protocol != IpAddresses.Protocol.ipv4 && ipv6Address.isEmpty())
- throw new IllegalArgumentException(protocol.description + " hostname " + address.hostname() + " did not resolve to an IPv6 address");
+ throw new IllegalArgumentException(protocol.description + " hostname " + hostname.value() + " did not resolve to an IPv6 address");
if (protocol == IpAddresses.Protocol.ipv4 && ipv6Address.isPresent())
- throw new IllegalArgumentException(protocol.description + " hostname " + address.hostname() + " has an IPv6 address: " + ipv6Address.get());
+ throw new IllegalArgumentException(protocol.description + " hostname " + hostname.value() + " has an IPv6 address: " + ipv6Address.get());
- return new Allocation(address.hostname(), ipv4Address, ipv6Address);
+ return new Allocation(hostname.value(), ipv4Address, ipv6Address);
}
private static Optional<String> resolveOptional(String hostname, NameResolver resolver, RecordType recordType) {
@@ -454,8 +454,8 @@ public class IP {
};
}
- private static Allocation ofAddress(Address address) {
- return new Allocation(address.hostname(), Optional.empty(), Optional.empty());
+ private static Allocation ofHostname(HostName hostName) {
+ return new Allocation(hostName.value(), Optional.empty(), Optional.empty());
}
/** Hostname pointing to the IP addresses in this */
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 39cccafb8ef..d55bf36e839 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
@@ -14,6 +14,7 @@ import com.yahoo.config.provision.ClusterMembership;
import com.yahoo.config.provision.ClusterSpec;
import com.yahoo.config.provision.DockerImage;
import com.yahoo.config.provision.Flavor;
+import com.yahoo.config.provision.HostName;
import com.yahoo.config.provision.InstanceName;
import com.yahoo.config.provision.NodeFlavors;
import com.yahoo.config.provision.NodeResources;
@@ -28,7 +29,6 @@ import com.yahoo.slime.Inspector;
import com.yahoo.slime.Slime;
import com.yahoo.slime.SlimeUtils;
import com.yahoo.vespa.hosted.provision.Node;
-import com.yahoo.vespa.hosted.provision.node.Address;
import com.yahoo.vespa.hosted.provision.node.Agent;
import com.yahoo.vespa.hosted.provision.node.Allocation;
import com.yahoo.vespa.hosted.provision.node.Generation;
@@ -168,7 +168,7 @@ public class NodeSerializer {
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().getAddressList(), object);
+ toSlime(node.ipConfig().pool().hostnames(), object);
object.setString(idKey, node.id());
node.parentHostname().ifPresent(hostname -> object.setString(parentHostnameKey, hostname));
toSlime(node.flavor(), object);
@@ -247,11 +247,11 @@ public class NodeSerializer {
ipAddresses.stream().map(IP::parse).sorted(IP.NATURAL_ORDER).map(IP::asString).forEach(array::addString);
}
- private void toSlime(List<Address> addresses, Cursor object) {
- if (addresses.isEmpty()) return;
- Cursor addressCursor = object.setArray(containersKey);
- addresses.forEach(address -> {
- addressCursor.addObject().setString(containerHostnameKey, address.hostname());
+ private void toSlime(List<HostName> hostnames, Cursor object) {
+ if (hostnames.isEmpty()) return;
+ Cursor containersArray = object.setArray(containersKey);
+ hostnames.forEach(hostname -> {
+ containersArray.addObject().setString(containerHostnameKey, hostname.value());
});
}
@@ -279,7 +279,7 @@ public class NodeSerializer {
return new Node(object.field(idKey).asString(),
new IP.Config(ipAddressesFromSlime(object, ipAddressesKey),
ipAddressesFromSlime(object, ipAddressPoolKey),
- addressesFromSlime(object)),
+ hostnamesFromSlime(object)),
object.field(hostnameKey).asString(),
SlimeUtils.optionalString(object.field(parentHostnameKey)),
flavor,
@@ -394,9 +394,9 @@ public class NodeSerializer {
return ipAddresses.build();
}
- private List<Address> addressesFromSlime(Inspector object) {
+ private List<HostName> hostnamesFromSlime(Inspector object) {
return SlimeUtils.entriesStream(object.field(containersKey))
- .map(elem -> new Address(elem.field(containerHostnameKey).asString()))
+ .map(elem -> HostName.of(elem.field(containerHostnameKey).asString()))
.toList();
}
diff --git a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/provisioning/HostProvisioner.java b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/provisioning/HostProvisioner.java
index f07185cbe60..3d2f5b6737a 100644
--- a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/provisioning/HostProvisioner.java
+++ b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/provisioning/HostProvisioner.java
@@ -10,7 +10,6 @@ import com.yahoo.config.provision.NodeAllocationException;
import com.yahoo.config.provision.NodeResources;
import com.yahoo.config.provision.NodeType;
import com.yahoo.vespa.hosted.provision.Node;
-import com.yahoo.vespa.hosted.provision.NodeRepository;
import java.util.List;
import java.util.Optional;
diff --git a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/provisioning/ProvisionedHost.java b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/provisioning/ProvisionedHost.java
index 15a6b6ba523..d083d81c196 100644
--- a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/provisioning/ProvisionedHost.java
+++ b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/provisioning/ProvisionedHost.java
@@ -6,10 +6,10 @@ import com.yahoo.config.provision.ApplicationId;
import com.yahoo.config.provision.CloudAccount;
import com.yahoo.config.provision.ClusterSpec;
import com.yahoo.config.provision.Flavor;
+import com.yahoo.config.provision.HostName;
import com.yahoo.config.provision.NodeResources;
import com.yahoo.config.provision.NodeType;
import com.yahoo.vespa.hosted.provision.Node;
-import com.yahoo.vespa.hosted.provision.node.Address;
import com.yahoo.vespa.hosted.provision.node.IP;
import com.yahoo.vespa.hosted.provision.node.OsVersion;
import com.yahoo.vespa.hosted.provision.node.Status;
@@ -32,38 +32,38 @@ public class ProvisionedHost {
private final NodeType hostType;
private final Optional<ApplicationId> exclusiveToApplicationId;
private final Optional<ClusterSpec.Type> exclusiveToClusterType;
- private final List<Address> nodeAddresses;
+ private final List<HostName> nodeHostnames;
private final NodeResources nodeResources;
private final Version osVersion;
private final CloudAccount cloudAccount;
public ProvisionedHost(String id, String hostHostname, Flavor hostFlavor, NodeType hostType,
Optional<ApplicationId> exclusiveToApplicationId, Optional<ClusterSpec.Type> exclusiveToClusterType,
- List<Address> nodeAddresses, NodeResources nodeResources, Version osVersion, CloudAccount cloudAccount) {
+ List<HostName> nodeHostnames, NodeResources nodeResources, Version osVersion, CloudAccount cloudAccount) {
this.id = Objects.requireNonNull(id, "Host id must be set");
this.hostHostname = Objects.requireNonNull(hostHostname, "Host hostname must be set");
this.hostFlavor = Objects.requireNonNull(hostFlavor, "Host flavor must be set");
this.hostType = Objects.requireNonNull(hostType, "Host type must be set");
this.exclusiveToApplicationId = Objects.requireNonNull(exclusiveToApplicationId, "exclusiveToApplicationId must be set");
this.exclusiveToClusterType = Objects.requireNonNull(exclusiveToClusterType, "exclusiveToClusterType must be set");
- this.nodeAddresses = validateNodeAddresses(nodeAddresses);
+ this.nodeHostnames = validateNodeAddresses(nodeHostnames);
this.nodeResources = Objects.requireNonNull(nodeResources, "Node resources must be set");
this.osVersion = Objects.requireNonNull(osVersion, "OS version must be set");
this.cloudAccount = Objects.requireNonNull(cloudAccount, "Cloud account must be set");
if (!hostType.isHost()) throw new IllegalArgumentException(hostType + " is not a host");
}
- private static List<Address> validateNodeAddresses(List<Address> nodeAddresses) {
- Objects.requireNonNull(nodeAddresses, "Node addresses must be set");
- if (nodeAddresses.isEmpty()) {
- throw new IllegalArgumentException("There must be at least one node address");
+ private static List<HostName> validateNodeAddresses(List<HostName> nodeHostnames) {
+ Objects.requireNonNull(nodeHostnames, "Node hostnames must be set");
+ if (nodeHostnames.isEmpty()) {
+ throw new IllegalArgumentException("There must be at least one node hostname");
}
- return nodeAddresses;
+ return nodeHostnames;
}
/** Generate {@link Node} instance representing the provisioned physical host */
public Node generateHost() {
- Node.Builder builder = Node.create(id, IP.Config.of(Set.of(), Set.of(), nodeAddresses), hostHostname, hostFlavor,
+ Node.Builder builder = Node.create(id, IP.Config.of(Set.of(), Set.of(), nodeHostnames), hostHostname, hostFlavor,
hostType)
.status(Status.initial().withOsVersion(OsVersion.EMPTY.withCurrent(Optional.of(osVersion))))
.cloudAccount(cloudAccount);
@@ -85,12 +85,12 @@ public class ProvisionedHost {
public NodeType hostType() { return hostType; }
public Optional<ApplicationId> exclusiveToApplicationId() { return exclusiveToApplicationId; }
public Optional<ClusterSpec.Type> exclusiveToClusterType() { return exclusiveToClusterType; }
- public List<Address> nodeAddresses() { return nodeAddresses; }
+ public List<HostName> nodeHostnames() { return nodeHostnames; }
public NodeResources nodeResources() { return nodeResources; }
public Version osVersion() { return osVersion; }
public CloudAccount cloudAccount() { return cloudAccount; }
- public String nodeHostname() { return nodeAddresses.get(0).hostname(); }
+ public String nodeHostname() { return nodeHostnames.get(0).value(); }
@Override
public boolean equals(Object o) {
@@ -103,7 +103,7 @@ public class ProvisionedHost {
hostType == that.hostType &&
exclusiveToApplicationId.equals(that.exclusiveToApplicationId) &&
exclusiveToClusterType.equals(that.exclusiveToClusterType) &&
- nodeAddresses.equals(that.nodeAddresses) &&
+ nodeHostnames.equals(that.nodeHostnames) &&
nodeResources.equals(that.nodeResources) &&
osVersion.equals(that.osVersion) &&
cloudAccount.equals(that.cloudAccount);
@@ -111,7 +111,7 @@ public class ProvisionedHost {
@Override
public int hashCode() {
- return Objects.hash(id, hostHostname, hostFlavor, hostType, exclusiveToApplicationId, exclusiveToClusterType, nodeAddresses, nodeResources, osVersion, cloudAccount);
+ return Objects.hash(id, hostHostname, hostFlavor, hostType, exclusiveToApplicationId, exclusiveToClusterType, nodeHostnames, nodeResources, osVersion, cloudAccount);
}
@Override
@@ -123,7 +123,7 @@ public class ProvisionedHost {
", hostType=" + hostType +
", exclusiveToApplicationId=" + exclusiveToApplicationId +
", exclusiveToClusterType=" + exclusiveToClusterType +
- ", nodeAddresses=" + nodeAddresses +
+ ", nodeAddresses=" + nodeHostnames +
", nodeResources=" + nodeResources +
", osVersion=" + osVersion +
", cloudAccount=" + cloudAccount +
diff --git a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/restapi/NodePatcher.java b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/restapi/NodePatcher.java
index 582d5963cfd..dfe01f5f1c3 100644
--- a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/restapi/NodePatcher.java
+++ b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/restapi/NodePatcher.java
@@ -6,6 +6,7 @@ import com.yahoo.component.Version;
import com.yahoo.config.provision.ApplicationId;
import com.yahoo.config.provision.ClusterSpec;
import com.yahoo.config.provision.DockerImage;
+import com.yahoo.config.provision.HostName;
import com.yahoo.config.provision.NodeFlavors;
import com.yahoo.config.provision.NodeResources;
import com.yahoo.config.provision.TenantName;
@@ -19,7 +20,6 @@ import com.yahoo.vespa.hosted.provision.Node;
import com.yahoo.vespa.hosted.provision.NodeList;
import com.yahoo.vespa.hosted.provision.NodeMutex;
import com.yahoo.vespa.hosted.provision.NodeRepository;
-import com.yahoo.vespa.hosted.provision.node.Address;
import com.yahoo.vespa.hosted.provision.node.Agent;
import com.yahoo.vespa.hosted.provision.node.Allocation;
import com.yahoo.vespa.hosted.provision.node.IP;
@@ -245,12 +245,15 @@ public class NodePatcher {
private Node applyIpconfigField(Node node, String name, Inspector value, LockedNodeList nodes) {
switch (name) {
- case "ipAddresses":
+ case "ipAddresses" -> {
return IP.Config.verify(node.with(node.ipConfig().withPrimary(asStringSet(value))), nodes);
- case "additionalIpAddresses":
+ }
+ case "additionalIpAddresses" -> {
return IP.Config.verify(node.with(node.ipConfig().withPool(node.ipConfig().pool().withIpAddresses(asStringSet(value)))), nodes);
- case "additionalHostnames":
- return IP.Config.verify(node.with(node.ipConfig().withPool(node.ipConfig().pool().withAddresses(asAddressList(value)))), nodes);
+ }
+ case "additionalHostnames" -> {
+ return IP.Config.verify(node.with(node.ipConfig().withPool(node.ipConfig().pool().withHostnames(asHostnames(value)))), nodes);
+ }
}
throw new IllegalArgumentException("Could not apply field '" + name + "' on a node: No such modifiable field");
}
@@ -317,20 +320,19 @@ public class NodePatcher {
return strings;
}
- private List<Address> asAddressList(Inspector field) {
+ private List<HostName> asHostnames(Inspector field) {
if ( ! field.type().equals(Type.ARRAY))
throw new IllegalArgumentException("Expected an ARRAY value, got a " + field.type());
- List<Address> addresses = new ArrayList<>(field.entries());
+ List<HostName> hostnames = new ArrayList<>(field.entries());
for (int i = 0; i < field.entries(); i++) {
Inspector entry = field.entry(i);
if ( ! entry.type().equals(Type.STRING))
throw new IllegalArgumentException("Expected a STRING value, got a " + entry.type());
- Address address = new Address(entry.asString());
- addresses.add(address);
+ hostnames.add(HostName.of(entry.asString()));
}
- return addresses;
+ return hostnames;
}
private Node patchRequiredDiskSpeed(Node node, String value) {
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 6bf07077c81..6b44038730d 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
@@ -6,18 +6,17 @@ import com.yahoo.config.provision.ApplicationId;
import com.yahoo.config.provision.CloudAccount;
import com.yahoo.config.provision.ClusterMembership;
import com.yahoo.config.provision.DockerImage;
+import com.yahoo.config.provision.HostName;
import com.yahoo.config.provision.NodeResources;
import com.yahoo.config.provision.serialization.NetworkPortsSerializer;
import com.yahoo.container.jdisc.HttpRequest;
import com.yahoo.restapi.SlimeJsonResponse;
import com.yahoo.slime.Cursor;
-import com.yahoo.vespa.applicationmodel.HostName;
import com.yahoo.vespa.flags.FetchVector;
import com.yahoo.vespa.flags.PermanentFlags;
import com.yahoo.vespa.flags.StringFlag;
import com.yahoo.vespa.hosted.provision.Node;
import com.yahoo.vespa.hosted.provision.NodeRepository;
-import com.yahoo.vespa.hosted.provision.node.Address;
import com.yahoo.vespa.hosted.provision.node.Allocation;
import com.yahoo.vespa.hosted.provision.node.History;
import com.yahoo.vespa.hosted.provision.node.TrustStoreItem;
@@ -52,7 +51,7 @@ class NodesResponse extends SlimeJsonResponse {
private final NodeFilter filter;
private final boolean recursive;
- private final Function<HostName, Optional<HostInfo>> orchestrator;
+ private final Function<com.yahoo.vespa.applicationmodel.HostName, Optional<HostInfo>> orchestrator;
private final NodeRepository nodeRepository;
private final StringFlag wantedDockerTagFlag;
@@ -151,7 +150,7 @@ class NodesResponse extends SlimeJsonResponse {
object.setString("wantedVespaVersion", allocation.membership().cluster().vespaVersion().toFullString());
NodeResourcesSerializer.toSlime(allocation.requestedResources(), object.setObject("requestedResources"));
allocation.networkPorts().ifPresent(ports -> NetworkPortsSerializer.toSlime(ports, object.setArray("networkPorts")));
- orchestrator.apply(new HostName(node.hostname()))
+ orchestrator.apply(new com.yahoo.vespa.applicationmodel.HostName(node.hostname()))
.ifPresent(info -> {
if (info.status() != HostStatus.NO_REMARKS) {
object.setString("orchestratorStatus", info.status().asString());
@@ -181,7 +180,7 @@ class NodesResponse extends SlimeJsonResponse {
toSlime(node.history().log(), object.setArray("log"));
ipAddressesToSlime(node.ipConfig().primary(), object.setArray("ipAddresses"));
ipAddressesToSlime(node.ipConfig().pool().ipSet(), object.setArray("additionalIpAddresses"));
- addressesToSlime(node.ipConfig().pool().getAddressList(), object);
+ hostnamesToSlime(node.ipConfig().pool().hostnames(), object);
node.reports().toSlime(object, "reports");
node.modelName().ifPresent(modelName -> object.setString("modelName", modelName));
node.switchHostname().ifPresent(switchHostname -> object.setString("switchHostname", switchHostname));
@@ -249,11 +248,11 @@ class NodesResponse extends SlimeJsonResponse {
ipAddresses.forEach(array::addString);
}
- private void addressesToSlime(List<Address> addresses, Cursor object) {
- if (addresses.isEmpty()) return;
+ private void hostnamesToSlime(List<HostName> hostnames, Cursor object) {
+ if (hostnames.isEmpty()) return;
// When/if Address becomes richer: add another field (e.g. "addresses") and expand to array of objects
Cursor addressesArray = object.setArray("additionalHostnames");
- addresses.forEach(address -> addressesArray.addString(address.hostname()));
+ hostnames.forEach(hostname -> addressesArray.addString(hostname.value()));
}
private void trustedCertsToSlime(List<TrustStoreItem> trustStoreItems, Cursor object) {
diff --git a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/restapi/NodesV2ApiHandler.java b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/restapi/NodesV2ApiHandler.java
index d0eb95e2d72..eb935ba6a5c 100644
--- a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/restapi/NodesV2ApiHandler.java
+++ b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/restapi/NodesV2ApiHandler.java
@@ -7,6 +7,7 @@ import com.yahoo.config.provision.ApplicationLockException;
import com.yahoo.config.provision.CloudAccount;
import com.yahoo.config.provision.Flavor;
import com.yahoo.config.provision.HostFilter;
+import com.yahoo.config.provision.HostName;
import com.yahoo.config.provision.NodeFlavors;
import com.yahoo.config.provision.NodeResources;
import com.yahoo.config.provision.NodeType;
@@ -33,7 +34,6 @@ import com.yahoo.vespa.hosted.provision.NodeMutex;
import com.yahoo.vespa.hosted.provision.NodeRepository;
import com.yahoo.vespa.hosted.provision.applications.Application;
import com.yahoo.vespa.hosted.provision.autoscale.Load;
-import com.yahoo.vespa.hosted.provision.node.Address;
import com.yahoo.vespa.hosted.provision.node.Agent;
import com.yahoo.vespa.hosted.provision.node.IP;
import com.yahoo.vespa.hosted.provision.node.filter.ApplicationFilter;
@@ -281,12 +281,12 @@ public class NodesV2ApiHandler extends ThreadedHttpRequestHandler {
Set<String> ipAddressPool = new HashSet<>();
inspector.field("additionalIpAddresses").traverse((ArrayTraverser) (i, item) -> ipAddressPool.add(item.asString()));
- List<Address> addressPool = new ArrayList<>();
+ List<HostName> hostnames = new ArrayList<>();
inspector.field("additionalHostnames").traverse((ArrayTraverser) (i, item) ->
- addressPool.add(new Address(item.asString())));
+ hostnames.add(HostName.of(item.asString())));
Node.Builder builder = Node.create(inspector.field("id").asString(),
- IP.Config.of(ipAddresses, ipAddressPool, addressPool),
+ IP.Config.of(ipAddresses, ipAddressPool, hostnames),
inspector.field("hostname").asString(),
flavorFromSlime(inspector),
nodeTypeFromSlime(inspector.field("type")))
diff --git a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/testutils/MockHostProvisioner.java b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/testutils/MockHostProvisioner.java
index 7e83e265496..1a180d593a4 100644
--- a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/testutils/MockHostProvisioner.java
+++ b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/testutils/MockHostProvisioner.java
@@ -7,11 +7,11 @@ import com.yahoo.config.provision.CloudAccount;
import com.yahoo.config.provision.ClusterSpec;
import com.yahoo.config.provision.Flavor;
import com.yahoo.config.provision.HostEvent;
+import com.yahoo.config.provision.HostName;
import com.yahoo.config.provision.NodeAllocationException;
import com.yahoo.config.provision.NodeResources;
import com.yahoo.config.provision.NodeType;
import com.yahoo.vespa.hosted.provision.Node;
-import com.yahoo.vespa.hosted.provision.node.Address;
import com.yahoo.vespa.hosted.provision.node.Agent;
import com.yahoo.vespa.hosted.provision.node.IP;
import com.yahoo.vespa.hosted.provision.provisioning.FatalProvisioningException;
@@ -84,7 +84,7 @@ public class MockHostProvisioner implements HostProvisioner {
hostType,
sharing == HostSharing.exclusive ? Optional.of(applicationId) : Optional.empty(),
Optional.empty(),
- createAddressesForHost(hostType, hostFlavor, index),
+ createHostnames(hostType, hostFlavor, index),
resources,
osVersion,
cloudAccount));
@@ -195,14 +195,14 @@ public class MockHostProvisioner implements HostProvisioner {
return flavor.resources().compatibleWith(resourcesToVerify);
}
- private List<Address> createAddressesForHost(NodeType hostType, Flavor flavor, int hostIndex) {
+ private List<HostName> createHostnames(NodeType hostType, Flavor flavor, int hostIndex) {
long numAddresses = Math.max(2, Math.round(flavor.resources().bandwidthGbps()));
return IntStream.range(1, (int) numAddresses)
.mapToObj(i -> {
String hostname = hostType == NodeType.host
? "host" + hostIndex + "-" + i
: hostType.childNodeType().name() + i;
- return new Address(hostname);
+ return HostName.of(hostname);
})
.toList();
}
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 e075995c89e..c0ec65dd6d7 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
@@ -27,7 +27,6 @@ import com.yahoo.vespa.flags.custom.ClusterCapacity;
import com.yahoo.vespa.hosted.provision.Node;
import com.yahoo.vespa.hosted.provision.NodeList;
import com.yahoo.vespa.hosted.provision.NodeRepository;
-import com.yahoo.vespa.hosted.provision.node.Address;
import com.yahoo.vespa.hosted.provision.node.Agent;
import com.yahoo.vespa.hosted.provision.node.Allocation;
import com.yahoo.vespa.hosted.provision.node.Generation;
@@ -651,9 +650,9 @@ public class HostCapacityMaintainerTest {
flavor.resources(),
Generation.initial(),
false));
- List<Address> addresses = Stream.of(additionalHostnames).map(Address::new).toList();
+ 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(), addresses));
+ .ipConfig(new IP.Config(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/node/IPTest.java b/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/node/IPTest.java
index c26ffdaa023..59c02871844 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
@@ -2,6 +2,7 @@
package com.yahoo.vespa.hosted.provision.node;
import com.google.common.collect.ImmutableSet;
+import com.yahoo.config.provision.HostName;
import com.yahoo.config.provision.NodeFlavors;
import com.yahoo.config.provision.NodeType;
import com.yahoo.vespa.hosted.provision.LockedNodeList;
@@ -14,7 +15,6 @@ import java.util.LinkedHashSet;
import java.util.List;
import java.util.Optional;
import java.util.Set;
-import java.util.stream.Collectors;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
@@ -156,7 +156,7 @@ public class IPTest {
IP.Config config = IP.Config.of(Set.of("2600:1f10:::1"),
Set.of("2600:1f10:::2", "2600:1f10:::3"),
- List.of(new Address("node1"), new Address("node2")));
+ List.of(HostName.of("node1"), HostName.of("node2")));
IP.Pool pool = config.pool();
Optional<IP.Allocation> allocation = pool.findAllocation(emptyList, resolver, false);
}
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 d61a3d95a65..fc7b0ddce21 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
@@ -9,6 +9,7 @@ import com.yahoo.config.provision.ApplicationName;
import com.yahoo.config.provision.CloudAccount;
import com.yahoo.config.provision.ClusterMembership;
import com.yahoo.config.provision.ClusterSpec;
+import com.yahoo.config.provision.HostName;
import com.yahoo.config.provision.InstanceName;
import com.yahoo.config.provision.NetworkPorts;
import com.yahoo.config.provision.NodeFlavors;
@@ -23,7 +24,6 @@ import com.yahoo.test.ManualClock;
import com.yahoo.text.Utf8;
import com.yahoo.vespa.hosted.provision.Node;
import com.yahoo.vespa.hosted.provision.Node.State;
-import com.yahoo.vespa.hosted.provision.node.Address;
import com.yahoo.vespa.hosted.provision.node.Agent;
import com.yahoo.vespa.hosted.provision.node.Generation;
import com.yahoo.vespa.hosted.provision.node.History;
@@ -272,16 +272,16 @@ public class NodeSerializerTest {
// Test round-trip with address pool
node = node.with(node.ipConfig().withPool(IP.Pool.of(
Set.of("::1", "::2", "::3"),
- List.of(new Address("a"), new Address("b"), new Address("c")))));
+ 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().getAddressList()), Set.copyOf(copy.ipConfig().pool().getAddressList()));
+ assertEquals(Set.copyOf(node.ipConfig().pool().hostnames()), Set.copyOf(copy.ipConfig().pool().hostnames()));
// 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().getAddressList()), Set.copyOf(copy.ipConfig().pool().getAddressList()));
+ assertEquals(Set.copyOf(node.ipConfig().pool().hostnames()), Set.copyOf(copy.ipConfig().pool().hostnames()));
}
@Test
diff --git a/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/provisioning/HostCapacityTest.java b/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/provisioning/HostCapacityTest.java
index ea2af5f3fca..12a8e4d9386 100644
--- a/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/provisioning/HostCapacityTest.java
+++ b/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/provisioning/HostCapacityTest.java
@@ -2,12 +2,12 @@
package com.yahoo.vespa.hosted.provision.provisioning;
import com.yahoo.config.provision.Flavor;
+import com.yahoo.config.provision.HostName;
import com.yahoo.config.provision.NodeFlavors;
import com.yahoo.config.provision.NodeResources;
import com.yahoo.config.provision.NodeType;
import com.yahoo.vespa.hosted.provision.LockedNodeList;
import com.yahoo.vespa.hosted.provision.Node;
-import com.yahoo.vespa.hosted.provision.node.Address;
import com.yahoo.vespa.hosted.provision.node.IP;
import org.junit.Before;
import org.junit.Test;
@@ -16,7 +16,6 @@ import java.util.ArrayList;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
-import java.util.stream.Collectors;
import java.util.stream.Stream;
import static org.junit.Assert.assertEquals;
@@ -167,7 +166,7 @@ public class HostCapacityTest {
}
private Node setupHostWithAdditionalHostnames(String hostHostname, String... additionalHostnames) {
- List<Address> addresses = Stream.of(additionalHostnames).map(Address::new).toList();
+ List<HostName> hostnames = Stream.of(additionalHostnames).map(HostName::of).toList();
doAnswer(invocation -> ((Flavor)invocation.getArguments()[0]).resources())
.when(hostResourcesCalculator).advertisedResourcesOf(any());
@@ -176,7 +175,7 @@ public class HostCapacityTest {
"host", // 7-100-120-5
"docker"); // 2- 40- 40-0.5 = resources1
- return Node.create(hostHostname, IP.Config.of(Set.of("::1"), Set.of(), addresses), hostHostname,
+ return Node.create(hostHostname, IP.Config.of(Set.of("::1"), Set.of(), hostnames), hostHostname,
nodeFlavors.getFlavorOrThrow("host"), NodeType.host).build();
}