Skip to content

Commit

Permalink
Merge pull request #21411 from vespa-engine/hmusum/support-architecto…
Browse files Browse the repository at this point in the history
…re-in-HostResources

Add support for architecture in HostResources
  • Loading branch information
Harald Musum authored Mar 1, 2022
2 parents 891b71d + 3f960b1 commit 4b75187
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ 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 static final Set<String> validArchitectures = Set.of("arm64", "x86_64");

private final double vcpu;
private final double memoryGb;
Expand All @@ -33,6 +34,7 @@ public class HostResources {
private final Optional<String> clusterType;

private final int containers;
private final String architecture;

@JsonCreator
public HostResources(@JsonProperty("vcpu") Double vcpu,
Expand All @@ -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);
Expand All @@ -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")
Expand Down Expand Up @@ -80,6 +84,9 @@ public HostResources(@JsonProperty("vcpu") Double vcpu,
@JsonProperty("containers")
public int containers() { return containers; }

@JsonProperty("architecture")
public String architecture() { return architecture; }

public boolean satisfiesClusterType(String clusterType) {
return this.clusterType.map(clusterType::equalsIgnoreCase).orElse(true);
}
Expand Down Expand Up @@ -121,6 +128,7 @@ public String toString() {
", storageType='" + storageType + '\'' +
", clusterType='" + clusterType + '\'' +
", containers=" + containers +
", architecture=" + architecture +
'}';
}

Expand All @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 4b75187

Please sign in to comment.