diff options
author | Valerij Fredriksen <valerij92@gmail.com> | 2021-07-27 09:48:31 +0200 |
---|---|---|
committer | Valerij Fredriksen <valerijf@verizonmedia.com> | 2021-07-27 13:58:51 +0200 |
commit | 44b6365684c2d7d931d5d9f0c300a750648d875d (patch) | |
tree | 058120742257ad80e56fba9bf6b59afa8c3e4513 /flags/src | |
parent | d8acae4eeb9d66457e596fb06b0009d95b973f13 (diff) |
Add clusterType to SharedHost/HostResources
Diffstat (limited to 'flags/src')
4 files changed, 25 insertions, 10 deletions
diff --git a/flags/src/main/java/com/yahoo/vespa/flags/custom/HostResources.java b/flags/src/main/java/com/yahoo/vespa/flags/custom/HostResources.java index 129e1020b04..a4e25288d1d 100644 --- a/flags/src/main/java/com/yahoo/vespa/flags/custom/HostResources.java +++ b/flags/src/main/java/com/yahoo/vespa/flags/custom/HostResources.java @@ -2,10 +2,12 @@ package com.yahoo.vespa.flags.custom; import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import java.util.Objects; +import java.util.Optional; import java.util.Set; /** @@ -18,19 +20,18 @@ import java.util.Set; public class HostResources { private static final Set<String> validDiskSpeeds = Set.of("slow", "fast"); private static final Set<String> validStorageTypes = Set.of("remote", "local"); + private static final Set<String> validClusterTypes = Set.of("container", "content", "combined", "admin"); private final double vcpu; - private final double memoryGb; - private final double diskGb; - private final double bandwidthGbps; private final String diskSpeed; - private final String storageType; + private final Optional<String> clusterType; + private final int containers; @JsonCreator @@ -40,6 +41,7 @@ public class HostResources { @JsonProperty("bandwidthGbps") Double bandwidthGbps, @JsonProperty("diskSpeed") String diskSpeed, @JsonProperty("storageType") String storageType, + @JsonProperty("clusterType") String clusterType, @JsonProperty("containers") Integer containers) { this.vcpu = requirePositive("vcpu", vcpu); this.memoryGb = requirePositive("memoryGb", memoryGb); @@ -47,6 +49,7 @@ public class HostResources { this.bandwidthGbps = requirePositive("bandwidthGbps", bandwidthGbps); this.diskSpeed = validateEnum("diskSpeed", validDiskSpeeds, diskSpeed); this.storageType = validateEnum("storageType", validStorageTypes, storageType); + this.clusterType = Optional.ofNullable(clusterType).map(cType -> validateEnum("clusterType", validClusterTypes, cType)); this.containers = requirePositive("containers", containers); } @@ -68,9 +71,19 @@ public class HostResources { @JsonProperty("storageType") public String storageType() { return storageType; } + @JsonProperty("clusterType") + public String clusterTypeOrNull() { return clusterType.orElse(null); } + + @JsonIgnore + public Optional<String> clusterType() { return clusterType; } + @JsonProperty("containers") public int containers() { return containers; } + public boolean satisfiesClusterType(String clusterType) { + return this.clusterType.map(clusterType::equalsIgnoreCase).orElse(true); + } + private static double requirePositive(String name, Double value) { requireNonNull(name, value); if (value <= 0) @@ -106,6 +119,7 @@ public class HostResources { ", bandwidthGbps=" + bandwidthGbps + ", diskSpeed='" + diskSpeed + '\'' + ", storageType='" + storageType + '\'' + + ", clusterType='" + clusterType + '\'' + ", containers=" + containers + '}'; } @@ -121,11 +135,12 @@ public class HostResources { Double.compare(resources.bandwidthGbps, bandwidthGbps) == 0 && diskSpeed.equals(resources.diskSpeed) && storageType.equals(resources.storageType) && + clusterType.equals(resources.clusterType) && containers == resources.containers; } @Override public int hashCode() { - return Objects.hash(vcpu, memoryGb, diskGb, bandwidthGbps, diskSpeed, storageType, containers); + return Objects.hash(vcpu, memoryGb, diskGb, bandwidthGbps, diskSpeed, storageType, clusterType, containers); } } 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 c952161cf72..afbb2ce00b3 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 @@ -52,8 +52,8 @@ public class SharedHost { } @JsonIgnore - public boolean isEnabled() { - return resources.size() > 0; + public boolean isEnabled(String clusterType) { + return resources.stream().anyMatch(hr -> hr.satisfiesClusterType(clusterType)); } @JsonIgnore diff --git a/flags/src/test/java/com/yahoo/vespa/flags/PermanentFlagsTest.java b/flags/src/test/java/com/yahoo/vespa/flags/PermanentFlagsTest.java index 956048f6e24..32098ca4cce 100644 --- a/flags/src/test/java/com/yahoo/vespa/flags/PermanentFlagsTest.java +++ b/flags/src/test/java/com/yahoo/vespa/flags/PermanentFlagsTest.java @@ -17,7 +17,7 @@ class PermanentFlagsTest { public void testSharedHostFlag() { SharedHost sharedHost = new SharedHost(List.of(new HostResources( 4.0, 16.0, 50.0, 0.3, - "fast", "local", + "fast", "local", "admin", 10)), null); testGeneric(PermanentFlags.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 index f0a11f244a4..2c78dda48e5 100644 --- a/flags/src/test/java/com/yahoo/vespa/flags/custom/SharedHostTest.java +++ b/flags/src/test/java/com/yahoo/vespa/flags/custom/SharedHostTest.java @@ -12,8 +12,8 @@ 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)); + verifySerialization(new SharedHost(List.of(new HostResources(1.0, 2.0, 3.0, 4.0, "fast", "remote", "container", 5)), 6)); + verifySerialization(new SharedHost(List.of(new HostResources(1.0, 2.0, 3.0, 4.0, "fast", "remote", "admin", 5)), null)); } private void verifySerialization(SharedHost sharedHost) throws IOException { |