From 0d000a2379d9e2833f1e7c26207fb36163fe2a2b Mon Sep 17 00:00:00 2001 From: Harald Musum Date: Sat, 26 Feb 2022 11:31:34 +0100 Subject: [PATCH 1/2] Add support for architecture in HostResources --- .../yahoo/vespa/flags/custom/HostResources.java | 15 ++++++++++++--- .../com/yahoo/vespa/flags/PermanentFlagsTest.java | 9 ++++----- .../yahoo/vespa/flags/custom/SharedHostTest.java | 8 ++++++-- 3 files changed, 22 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 31c3bdd84227..707125ff4ad4 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 @@ -21,6 +21,7 @@ public class HostResources { private static final Set validDiskSpeeds = Set.of("slow", "fast"); private static final Set validStorageTypes = Set.of("remote", "local"); private static final Set validClusterTypes = Set.of("container", "content", "combined", "admin"); + private static final Set validArchitectures = Set.of("arm64", "x86_64"); private final double vcpu; private final double memoryGb; @@ -33,6 +34,7 @@ public class HostResources { private final Optional clusterType; private final int containers; + private final String architecture; @JsonCreator public HostResources(@JsonProperty("vcpu") Double vcpu, @@ -42,7 +44,8 @@ public HostResources(@JsonProperty("vcpu") Double vcpu, @JsonProperty("diskSpeed") String diskSpeed, @JsonProperty("storageType") String storageType, @JsonProperty("clusterType") String clusterType, - @JsonProperty("containers") Integer containers) { + @JsonProperty("containers") Integer containers, + @JsonProperty("architecture") String architecture) { this.vcpu = requirePositive("vcpu", vcpu); this.memoryGb = requirePositive("memoryGb", memoryGb); this.diskGb = requirePositive("diskGb", diskGb); @@ -51,6 +54,7 @@ public HostResources(@JsonProperty("vcpu") Double vcpu, this.storageType = validateEnum("storageType", validStorageTypes, storageType); this.clusterType = Optional.ofNullable(clusterType).map(cType -> validateEnum("clusterType", validClusterTypes, cType)); this.containers = requirePositive("containers", containers); + this.architecture = validateEnum("architecture", validArchitectures, architecture); } @JsonProperty("vcpu") @@ -80,6 +84,9 @@ public HostResources(@JsonProperty("vcpu") Double vcpu, @JsonProperty("containers") public int containers() { return containers; } + @JsonProperty("architecture") + public String architecture() { return architecture == null ? "x86_64" : architecture; } + public boolean satisfiesClusterType(String clusterType) { return this.clusterType.map(clusterType::equalsIgnoreCase).orElse(true); } @@ -121,6 +128,7 @@ public String toString() { ", storageType='" + storageType + '\'' + ", clusterType='" + clusterType + '\'' + ", containers=" + containers + + ", architecture=" + architecture + '}'; } @@ -136,11 +144,12 @@ public boolean equals(Object o) { diskSpeed.equals(resources.diskSpeed) && storageType.equals(resources.storageType) && clusterType.equals(resources.clusterType) && - containers == resources.containers; + containers == resources.containers && + architecture.equals(resources.architecture); } @Override public int hashCode() { - return Objects.hash(vcpu, memoryGb, diskGb, bandwidthGbps, diskSpeed, storageType, clusterType, containers); + return Objects.hash(vcpu, memoryGb, diskGb, bandwidthGbps, diskSpeed, storageType, clusterType, containers, architecture); } } 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 a4d8ecd0f295..8cac286be5eb 100644 --- a/flags/src/test/java/com/yahoo/vespa/flags/PermanentFlagsTest.java +++ b/flags/src/test/java/com/yahoo/vespa/flags/PermanentFlagsTest.java @@ -15,11 +15,10 @@ class PermanentFlagsTest { @Test public void testSharedHostFlag() { - SharedHost sharedHost = new SharedHost(List.of(new HostResources( - 4.0, 16.0, 50.0, 0.3, - "fast", "local", "admin", - 10)), - null); + SharedHost sharedHost = new SharedHost(List.of(new HostResources(4.0, 16.0, 50.0, 0.3, + "fast", "local", "admin", + 10, "x86_64")), + 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 7bf39b884ef0..852e1f9b7b1f 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,12 @@ 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", "container", 5)), 6)); - verifySerialization(new SharedHost(List.of(new HostResources(1.0, 2.0, 3.0, 4.0, "fast", "remote", "admin", 5)), null)); + verifySerialization(new SharedHost(List.of( + new HostResources(1.0, 2.0, 3.0, 4.0, "fast", "remote", + "container", 5, "x86_64")), 6)); + verifySerialization(new SharedHost(List.of( + new HostResources(1.0, 2.0, 3.0, 4.0, "fast", "remote", + "admin", 5, "arm64")), null)); } private void verifySerialization(SharedHost sharedHost) throws IOException { From 3f960b1ceed51b06d2398e586de0f5986619e774 Mon Sep 17 00:00:00 2001 From: Harald Musum Date: Mon, 28 Feb 2022 10:51:25 +0100 Subject: [PATCH 2/2] Simplify, architecture will always be non-null (verified in constructor) --- .../main/java/com/yahoo/vespa/flags/custom/HostResources.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 707125ff4ad4..6b2cac390654 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 @@ -85,7 +85,7 @@ public HostResources(@JsonProperty("vcpu") Double vcpu, public int containers() { return containers; } @JsonProperty("architecture") - public String architecture() { return architecture == null ? "x86_64" : architecture; } + public String architecture() { return architecture; } public boolean satisfiesClusterType(String clusterType) { return this.clusterType.map(clusterType::equalsIgnoreCase).orElse(true);