aboutsummaryrefslogtreecommitdiffstats
path: root/config-provisioning
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@gmail.com>2021-12-08 15:04:08 +0100
committerJon Bratseth <bratseth@gmail.com>2021-12-08 15:04:08 +0100
commit4c85018009650ea810ed1617f3852fd48b99d2a5 (patch)
tree5428085ef7c8e3c89c2b00548ae636efebfc44df /config-provisioning
parent7f44adea8f300668be27eda4a08d33165aec6ed7 (diff)
Don't propagate unspecified resources
Diffstat (limited to 'config-provisioning')
-rw-r--r--config-provisioning/src/main/java/com/yahoo/config/provision/ClusterResources.java7
-rw-r--r--config-provisioning/src/main/java/com/yahoo/config/provision/NodeResources.java25
2 files changed, 28 insertions, 4 deletions
diff --git a/config-provisioning/src/main/java/com/yahoo/config/provision/ClusterResources.java b/config-provisioning/src/main/java/com/yahoo/config/provision/ClusterResources.java
index 9938823768b..66e03a9f5fa 100644
--- a/config-provisioning/src/main/java/com/yahoo/config/provision/ClusterResources.java
+++ b/config-provisioning/src/main/java/com/yahoo/config/provision/ClusterResources.java
@@ -48,8 +48,11 @@ public class ClusterResources {
public boolean isWithin(ClusterResources min, ClusterResources max) {
if (this.smallerThan(min)) return false;
if (max.smallerThan(this)) return false;
- if ( ! this.nodeResources.justNonNumbers().compatibleWith(min.nodeResources.justNonNumbers())) return false;
- if ( ! this.nodeResources.justNonNumbers().compatibleWith(max.nodeResources.justNonNumbers())) return false;
+ if (min.nodeResources().isUnspecified())
+ if ( ! min.nodeResources().isUnspecified()
+ && ! this.nodeResources.justNonNumbers().compatibleWith(min.nodeResources.justNonNumbers())) return false;
+ if ( ! max.nodeResources().isUnspecified()
+ && ! this.nodeResources.justNonNumbers().compatibleWith(max.nodeResources.justNonNumbers())) return false;
return true;
}
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 b887a2a93e6..aa30c1373cb 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
@@ -17,6 +17,7 @@ public class NodeResources {
private static final double diskUnitCost = 0.0003;
private static final NodeResources zero = new NodeResources(0, 0, 0, 0);
+ private static final NodeResources unspecified = new NodeResources(0, 0, 0, 0);
public enum DiskSpeed {
@@ -125,31 +126,37 @@ public class NodeResources {
}
public NodeResources withVcpu(double vcpu) {
+ ensureSpecified();
if (vcpu == this.vcpu) return this;
return new NodeResources(vcpu, memoryGb, diskGb, bandwidthGbps, diskSpeed, storageType);
}
public NodeResources withMemoryGb(double memoryGb) {
+ ensureSpecified();
if (memoryGb == this.memoryGb) return this;
return new NodeResources(vcpu, memoryGb, diskGb, bandwidthGbps, diskSpeed, storageType);
}
public NodeResources withDiskGb(double diskGb) {
+ ensureSpecified();
if (diskGb == this.diskGb) return this;
return new NodeResources(vcpu, memoryGb, diskGb, bandwidthGbps, diskSpeed, storageType);
}
public NodeResources withBandwidthGbps(double bandwidthGbps) {
+ ensureSpecified();
if (bandwidthGbps == this.bandwidthGbps) return this;
return new NodeResources(vcpu, memoryGb, diskGb, bandwidthGbps, diskSpeed, storageType);
}
public NodeResources with(DiskSpeed diskSpeed) {
+ ensureSpecified();
if (diskSpeed == this.diskSpeed) return this;
return new NodeResources(vcpu, memoryGb, diskGb, bandwidthGbps, diskSpeed, storageType);
}
public NodeResources with(StorageType storageType) {
+ ensureSpecified();
if (storageType == this.storageType) return this;
return new NodeResources(vcpu, memoryGb, diskGb, bandwidthGbps, diskSpeed, storageType);
}
@@ -165,6 +172,8 @@ public class NodeResources {
}
public NodeResources subtract(NodeResources other) {
+ ensureSpecified();
+ other.ensureSpecified();
if ( ! this.isInterchangeableWith(other))
throw new IllegalArgumentException(this + " and " + other + " are not interchangeable");
return new NodeResources(vcpu - other.vcpu,
@@ -176,6 +185,7 @@ public class NodeResources {
}
public NodeResources add(NodeResources other) {
+ ensureSpecified();
if ( ! this.isInterchangeableWith(other))
throw new IllegalArgumentException(this + " and " + other + " are not interchangeable");
return new NodeResources(vcpu + other.vcpu,
@@ -187,6 +197,8 @@ public class NodeResources {
}
private boolean isInterchangeableWith(NodeResources other) {
+ ensureSpecified();
+ other.ensureSpecified();
if (this.diskSpeed != DiskSpeed.any && other.diskSpeed != DiskSpeed.any && this.diskSpeed != other.diskSpeed)
return false;
if (this.storageType != StorageType.any && other.storageType != StorageType.any && this.storageType != other.storageType)
@@ -248,6 +260,8 @@ public class NodeResources {
/** Returns true if all the resources of this are the same or larger than the given resources */
public boolean satisfies(NodeResources other) {
+ ensureSpecified();
+ other.ensureSpecified();
if (this.vcpu < other.vcpu) return false;
if (this.memoryGb < other.memoryGb) return false;
if (this.diskGb < other.diskGb) return false;
@@ -266,6 +280,8 @@ public class NodeResources {
/** Returns true if all the resources of this are the same as or compatible with the given resources */
public boolean compatibleWith(NodeResources other) {
+ ensureSpecified();
+ other.ensureSpecified();
if ( ! equal(this.vcpu, other.vcpu)) return false;
if ( ! equal(this.memoryGb, other.memoryGb)) return false;
if ( ! equal(this.diskGb, other.diskGb)) return false;
@@ -276,9 +292,14 @@ public class NodeResources {
return true;
}
- public static NodeResources unspecified() { return zero; }
+ public static NodeResources unspecified() { return unspecified; }
- public boolean isUnspecified() { return this.equals(zero); }
+ public boolean isUnspecified() { return this == unspecified; }
+
+ private void ensureSpecified() {
+ if (isUnspecified())
+ throw new IllegalStateException("Cannot perform this on unspecified resources");
+ }
// Returns squared euclidean distance of the relevant numerical values of two node resources
public double distanceTo(NodeResources other) {