diff options
author | Håkon Hallingstad <hakon@verizonmedia.com> | 2020-11-30 20:20:22 +0100 |
---|---|---|
committer | Håkon Hallingstad <hakon@verizonmedia.com> | 2020-11-30 20:20:22 +0100 |
commit | e43bf39e6ec973297649f7e462b37e5aec8f155f (patch) | |
tree | ab81b1a3aafc564d382dc51a6a809a2ccf43ee71 /flags | |
parent | fa4302626526d3dcba9aa93825392ee24e2bf7e4 (diff) |
Support lower bound on number of shared hosts
Adds a 'minCount' field to the shared host jackson flag, denoting the minimum
number of "shared hosts" that must exist, otherwise the deficit will be
provisioned by DynamicProvisioningMaintainer.
A "shared host" is one that is considered for allocation if current tenant node
allocations were removed: It must be a tenant host, cannot be an exclusiveTo
host, etc.
minCount requires the setting of (at least one) shared host.
Diffstat (limited to 'flags')
3 files changed, 67 insertions, 7 deletions
diff --git a/flags/src/main/java/com/yahoo/vespa/flags/custom/SharedHost.java b/flags/src/main/java/com/yahoo/vespa/flags/custom/SharedHost.java index e463159eb8f..ab9127ebfe4 100644 --- a/flags/src/main/java/com/yahoo/vespa/flags/custom/SharedHost.java +++ b/flags/src/main/java/com/yahoo/vespa/flags/custom/SharedHost.java @@ -2,6 +2,7 @@ package com.yahoo.vespa.flags.custom; import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonGetter; import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonInclude; @@ -19,29 +20,50 @@ import java.util.Objects; @JsonIgnoreProperties(ignoreUnknown = true) @JsonInclude(value = JsonInclude.Include.NON_NULL) public class SharedHost { + private final int DEFAULT_MIN_COUNT = 0; + private final List<HostResources> resources; + private final int minCount; public static SharedHost createDisabled() { - return new SharedHost(null); + return new SharedHost(null, null); } + /** + * @param resourcesOrNull the resources of the shared host (or several to support e.g. tiers or + * fast/slow disks separately) + * @param minCountOrNull the minimum number of shared hosts + */ @JsonCreator - public SharedHost(@JsonProperty("resources") List<HostResources> resources) { - this.resources = resources == null ? List.of() : List.copyOf(resources); + public SharedHost(@JsonProperty("resources") List<HostResources> resourcesOrNull, + @JsonProperty("min-count") Integer minCountOrNull) { + this.resources = resourcesOrNull == null ? List.of() : List.copyOf(resourcesOrNull); + this.minCount = requireNonNegative(minCountOrNull, DEFAULT_MIN_COUNT, "min-count"); } - @JsonProperty("resources") + @JsonGetter("resources") public List<HostResources> getResourcesOrNull() { return resources.isEmpty() ? null : resources; } + @JsonGetter("min-count") + public Integer getMinCountOrNull() { + return minCount == DEFAULT_MIN_COUNT ? null : minCount; + } + + @JsonIgnore + public boolean isEnabled() { + return resources.size() > 0; + } + @JsonIgnore public List<HostResources> getHostResources() { return resources; } - public boolean isEnabled() { - return resources.size() > 0; + @JsonIgnore + public int getMinCount() { + return minCount; } @Override @@ -61,4 +83,16 @@ public class SharedHost { public int hashCode() { return Objects.hash(resources); } + + private int requireNonNegative(Integer integerOrNull, int defaultValue, String fieldName) { + if (integerOrNull == null) { + return defaultValue; + } + + if (integerOrNull < 0) { + throw new IllegalArgumentException(fieldName + " cannot be negative"); + } + + return integerOrNull; + } } diff --git a/flags/src/test/java/com/yahoo/vespa/flags/FlagsTest.java b/flags/src/test/java/com/yahoo/vespa/flags/FlagsTest.java index 636eea2c33c..6b043ea5a89 100644 --- a/flags/src/test/java/com/yahoo/vespa/flags/FlagsTest.java +++ b/flags/src/test/java/com/yahoo/vespa/flags/FlagsTest.java @@ -114,7 +114,8 @@ public class FlagsTest { SharedHost sharedHost = new SharedHost(List.of(new HostResources( 4.0, 16.0, 50.0, 0.3, "fast", "local", - 10))); + 10)), + null); testGeneric(Flags.SHARED_HOST, sharedHost); } diff --git a/flags/src/test/java/com/yahoo/vespa/flags/custom/SharedHostTest.java b/flags/src/test/java/com/yahoo/vespa/flags/custom/SharedHostTest.java new file mode 100644 index 00000000000..f0a11f244a4 --- /dev/null +++ b/flags/src/test/java/com/yahoo/vespa/flags/custom/SharedHostTest.java @@ -0,0 +1,25 @@ +// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.vespa.flags.custom; + +import com.fasterxml.jackson.databind.ObjectMapper; +import org.junit.Test; + +import java.io.IOException; +import java.util.List; + +import static org.junit.Assert.assertEquals; + +public class SharedHostTest { + @Test + public void serialization() throws IOException { + verifySerialization(new SharedHost(List.of(new HostResources(1.0, 2.0, 3.0, 4.0, "fast", "remote", 5)), 6)); + verifySerialization(new SharedHost(List.of(new HostResources(1.0, 2.0, 3.0, 4.0, "fast", "remote", 5)), null)); + } + + private void verifySerialization(SharedHost sharedHost) throws IOException { + ObjectMapper mapper = new ObjectMapper(); + String json = mapper.writeValueAsString(sharedHost); + SharedHost deserialized = mapper.readValue(json, SharedHost.class); + assertEquals(sharedHost, deserialized); + } +}
\ No newline at end of file |