summaryrefslogtreecommitdiffstats
path: root/flags
diff options
context:
space:
mode:
authorValerij Fredriksen <freva@users.noreply.github.com>2022-12-07 12:02:18 +0100
committerGitHub <noreply@github.com>2022-12-07 12:02:18 +0100
commit304816b9d4876fe33c66cdd8da4f084d32c8df67 (patch)
tree1206b455829e4ac25ce4e62b020ab045b4db649b /flags
parentc16592fe68c11b12e8c2f4da1fe8666115e65af1 (diff)
parent995fbd6391db6896905c26065a20edd4ab0feee8 (diff)
Merge pull request #25143 from vespa-engine/hmusum/support-empty-node-resources-for-node-capacity
Support not specifying vcpu, memoryGb and diskGb for ClusterCapacity
Diffstat (limited to 'flags')
-rw-r--r--flags/src/main/java/com/yahoo/vespa/flags/custom/ClusterCapacity.java43
-rw-r--r--flags/src/test/java/com/yahoo/vespa/flags/custom/ClusterCapacityTest.java17
2 files changed, 44 insertions, 16 deletions
diff --git a/flags/src/main/java/com/yahoo/vespa/flags/custom/ClusterCapacity.java b/flags/src/main/java/com/yahoo/vespa/flags/custom/ClusterCapacity.java
index 6d98c3a3283..b24d5f62174 100644
--- a/flags/src/main/java/com/yahoo/vespa/flags/custom/ClusterCapacity.java
+++ b/flags/src/main/java/com/yahoo/vespa/flags/custom/ClusterCapacity.java
@@ -19,37 +19,47 @@ import java.util.OptionalDouble;
@JsonInclude(value = JsonInclude.Include.NON_NULL)
public class ClusterCapacity {
private final int count;
- private final double vcpu;
- private final double memoryGb;
- private final double diskGb;
+ private final OptionalDouble vcpu;
+ private final OptionalDouble memoryGb;
+ private final OptionalDouble diskGb;
private final OptionalDouble bandwidthGbps;
@JsonCreator
public ClusterCapacity(@JsonProperty("count") int count,
- @JsonProperty("vcpu") double vcpu,
- @JsonProperty("memoryGb") double memoryGb,
- @JsonProperty("diskGb") double diskGb,
+ @JsonProperty("vcpu") Double vcpu,
+ @JsonProperty("memoryGb") Double memoryGb,
+ @JsonProperty("diskGb") Double diskGb,
@JsonProperty("bandwidthGbps") Double bandwidthGbps) {
this.count = (int) requireNonNegative("count", count);
- this.vcpu = requireNonNegative("vcpu", vcpu);
- this.memoryGb = requireNonNegative("memoryGb", memoryGb);
- this.diskGb = requireNonNegative("diskGb", diskGb);
+ this.vcpu = vcpu == null ? OptionalDouble.empty() : OptionalDouble.of(requireNonNegative("vcpu", vcpu));
+ this.memoryGb = memoryGb == null ? OptionalDouble.empty() : OptionalDouble.of(requireNonNegative("memoryGb", memoryGb));
+ this.diskGb = diskGb == null ? OptionalDouble.empty() : OptionalDouble.of(requireNonNegative("diskGb", diskGb));
this.bandwidthGbps = bandwidthGbps == null ? OptionalDouble.empty() : OptionalDouble.of(bandwidthGbps);
}
/** Returns a new ClusterCapacity equal to {@code this}, but with the given count. */
public ClusterCapacity withCount(int count) {
- return new ClusterCapacity(count, vcpu, memoryGb, diskGb, bandwidthGbpsOrNull());
+ return new ClusterCapacity(count, vcpuOrNull(), memoryGbOrNull(), diskGbOrNull(), bandwidthGbpsOrNull());
}
@JsonGetter("count") public int count() { return count; }
- @JsonGetter("vcpu") public double vcpu() { return vcpu; }
- @JsonGetter("memoryGb") public double memoryGb() { return memoryGb; }
- @JsonGetter("diskGb") public double diskGb() { return diskGb; }
+ @JsonGetter("vcpu") public Double vcpuOrNull() {
+ return vcpu.isPresent() ? vcpu.getAsDouble() : null;
+ }
+ @JsonGetter("memoryGb") public Double memoryGbOrNull() {
+ return memoryGb.isPresent() ? memoryGb.getAsDouble() : null;
+ }
+ @JsonGetter("diskGb") public Double diskGbOrNull() {
+ return diskGb.isPresent() ? diskGb.getAsDouble() : null;
+ }
@JsonGetter("bandwidthGbps") public Double bandwidthGbpsOrNull() {
return bandwidthGbps.isPresent() ? bandwidthGbps.getAsDouble() : null;
}
+ @JsonIgnore public Double vcpu() { return vcpu.orElse(0.0); }
+ @JsonIgnore public Double memoryGb() { return memoryGb.orElse(0.0); }
+ @JsonIgnore public Double diskGb() { return diskGb.orElse(0.0); }
+
@JsonIgnore
public double bandwidthGbps() { return bandwidthGbps.orElse(1.0); }
@@ -70,9 +80,9 @@ public class ClusterCapacity {
if (o == null || getClass() != o.getClass()) return false;
ClusterCapacity that = (ClusterCapacity) o;
return count == that.count &&
- Double.compare(that.vcpu, vcpu) == 0 &&
- Double.compare(that.memoryGb, memoryGb) == 0 &&
- Double.compare(that.diskGb, diskGb) == 0 &&
+ vcpu.equals(that.vcpu) &&
+ memoryGb.equals(that.memoryGb) &&
+ diskGb.equals(that.diskGb) &&
bandwidthGbps.equals(that.bandwidthGbps);
}
@@ -86,4 +96,5 @@ public class ClusterCapacity {
throw new IllegalArgumentException("'" + name + "' must be positive, was " + value);
return value;
}
+
}
diff --git a/flags/src/test/java/com/yahoo/vespa/flags/custom/ClusterCapacityTest.java b/flags/src/test/java/com/yahoo/vespa/flags/custom/ClusterCapacityTest.java
index 189e3fd79c9..796cdbf30d1 100644
--- a/flags/src/test/java/com/yahoo/vespa/flags/custom/ClusterCapacityTest.java
+++ b/flags/src/test/java/com/yahoo/vespa/flags/custom/ClusterCapacityTest.java
@@ -9,6 +9,7 @@ import java.io.IOException;
import static org.junit.jupiter.api.Assertions.assertEquals;
public class ClusterCapacityTest {
+
@Test
void serialization() throws IOException {
ClusterCapacity clusterCapacity = new ClusterCapacity(7, 1.2, 3.4, 5.6, null);
@@ -38,4 +39,20 @@ public class ClusterCapacityTest {
assertEquals(2.3, deserialized.bandwidthGbps(), 0.0001);
assertEquals(7, deserialized.count());
}
+
+ @Test
+ void serializationWithNoNodeResources() throws IOException {
+ ClusterCapacity clusterCapacity = new ClusterCapacity(7, null, null, null, null);
+ ObjectMapper mapper = new ObjectMapper();
+ String json = mapper.writeValueAsString(clusterCapacity);
+ assertEquals("{\"count\":7}", json);
+
+ ClusterCapacity deserialized = mapper.readValue(json, ClusterCapacity.class);
+ assertEquals(0.0, deserialized.vcpu(), 0.0001);
+ assertEquals(0.0, deserialized.memoryGb(), 0.0001);
+ assertEquals(0.0, deserialized.diskGb(), 0.0001);
+ assertEquals(1.0, deserialized.bandwidthGbps(), 0.0001); // 1.0 is used as fallback
+ assertEquals(7, deserialized.count());
+ }
+
} \ No newline at end of file