aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@gmail.com>2022-11-25 12:45:49 +0100
committerGitHub <noreply@github.com>2022-11-25 12:45:49 +0100
commitcc1a7c6d4e8d16ae578a882cf791c9da95d90949 (patch)
tree835bdb67f47c83ef25e0e5280a87431409c49682
parentad8906e7eca88ff9b8f7918e4913d2fd804d8a84 (diff)
parent5df29922963945c62fed8a19a5d231dbfb9c1cc7 (diff)
Merge pull request #24987 from vespa-engine/bratseth/explicit-zero
Bratseth/explicit zero
-rw-r--r--config-provisioning/src/main/java/com/yahoo/config/provision/Capacity.java2
-rw-r--r--config-provisioning/src/main/java/com/yahoo/config/provision/NodeResources.java15
-rw-r--r--node-repository/src/main/java/com/yahoo/vespa/hosted/provision/provisioning/NodeCandidate.java2
-rw-r--r--node-repository/src/main/java/com/yahoo/vespa/hosted/provision/provisioning/NodeRepositoryProvisioner.java2
4 files changed, 15 insertions, 6 deletions
diff --git a/config-provisioning/src/main/java/com/yahoo/config/provision/Capacity.java b/config-provisioning/src/main/java/com/yahoo/config/provision/Capacity.java
index dd8d181e1df..e63750e0e11 100644
--- a/config-provisioning/src/main/java/com/yahoo/config/provision/Capacity.java
+++ b/config-provisioning/src/main/java/com/yahoo/config/provision/Capacity.java
@@ -26,7 +26,7 @@ public final class Capacity {
if (max.smallerThan(min))
throw new IllegalArgumentException("The max capacity must be larger than the min capacity, but got min " +
min + " and max " + max);
- if (!min.equals(max) && Stream.of(min, max).anyMatch(cr -> !cr.nodeResources().gpuResources().isDefault()))
+ if (!min.equals(max) && Stream.of(min, max).anyMatch(cr -> !cr.nodeResources().gpuResources().isZero()))
throw new IllegalArgumentException("Capacity range does not allow GPU, got min " + min + " and max " + max);
this.min = min;
this.max = max;
diff --git a/config-provisioning/src/main/java/com/yahoo/config/provision/NodeResources.java b/config-provisioning/src/main/java/com/yahoo/config/provision/NodeResources.java
index 92513636eaf..2f2310c3703 100644
--- a/config-provisioning/src/main/java/com/yahoo/config/provision/NodeResources.java
+++ b/config-provisioning/src/main/java/com/yahoo/config/provision/NodeResources.java
@@ -123,7 +123,7 @@ public class NodeResources {
public record GpuResources(int count, double memoryGb) {
- private static final GpuResources none = new GpuResources(0, 0);
+ private static final GpuResources zero = new GpuResources(0, 0);
public GpuResources {
validate(memoryGb, "memory");
@@ -138,9 +138,14 @@ public class NodeResources {
this.memoryGb < other.memoryGb;
}
+ public boolean isZero() { return this.equals(zero); }
+
+ public static GpuResources zero() { return zero; }
+
public boolean isDefault() { return this.equals(getDefault()); }
- public static GpuResources getDefault() { return none; }
+ /** Returns zero gpu resources. */
+ public static GpuResources getDefault() { return zero; }
public GpuResources plus(GpuResources other) {
return new GpuResources(this.count + other.count, this.memoryGb + other.memoryGb);
@@ -274,7 +279,7 @@ public class NodeResources {
/** Returns this with all numbers set to 0 */
public NodeResources justNonNumbers() {
if (isUnspecified()) return unspecified();
- return withVcpu(0).withMemoryGb(0).withDiskGb(0).withBandwidthGbps(0).with(GpuResources.getDefault());
+ return withVcpu(0).withMemoryGb(0).withDiskGb(0).withBandwidthGbps(0).with(GpuResources.zero());
}
public NodeResources subtract(NodeResources other) {
@@ -499,6 +504,10 @@ public class NodeResources {
return value;
}
+ public boolean isZero() {
+ return this.equals(zero);
+ }
+
public static NodeResources zero() { return zero; }
}
diff --git a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/provisioning/NodeCandidate.java b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/provisioning/NodeCandidate.java
index 55b2bfc8329..4ad52a51df9 100644
--- a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/provisioning/NodeCandidate.java
+++ b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/provisioning/NodeCandidate.java
@@ -36,7 +36,7 @@ public abstract class NodeCandidate implements Nodelike, Comparable<NodeCandidat
private static final NodeResources zeroResources =
new NodeResources(0, 0, 0, 0, NodeResources.DiskSpeed.any, NodeResources.StorageType.any,
- NodeResources.Architecture.getDefault(), NodeResources.GpuResources.getDefault());
+ NodeResources.Architecture.getDefault(), NodeResources.GpuResources.zero());
/** The free capacity on the parent of this node, before adding this node to it */
protected final NodeResources freeParentCapacity;
diff --git a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/provisioning/NodeRepositoryProvisioner.java b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/provisioning/NodeRepositoryProvisioner.java
index 1022981f445..0ed4f4ee9b0 100644
--- a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/provisioning/NodeRepositoryProvisioner.java
+++ b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/provisioning/NodeRepositoryProvisioner.java
@@ -259,7 +259,7 @@ public class NodeRepositoryProvisioner implements Provisioner {
}
private static NodeResources requireCompatibleResources(NodeResources nodeResources, ClusterSpec cluster) {
- if (cluster.type() != ClusterSpec.Type.container && !nodeResources.gpuResources().isDefault()) {
+ if (cluster.type() != ClusterSpec.Type.container && !nodeResources.gpuResources().isZero()) {
throw new IllegalArgumentException(cluster.id() + " of type " + cluster.type() + " does not support GPU resources");
}
return nodeResources;