1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
|
// Copyright Vespa.ai. 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.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;
import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.Objects;
import java.util.Optional;
import java.util.OptionalDouble;
import static com.yahoo.vespa.flags.custom.Validation.requireNonNegative;
import static com.yahoo.vespa.flags.custom.Validation.validArchitectures;
import static com.yahoo.vespa.flags.custom.Validation.validClusterTypes;
import static com.yahoo.vespa.flags.custom.Validation.validDiskSpeeds;
import static com.yahoo.vespa.flags.custom.Validation.validStorageTypes;
import static com.yahoo.vespa.flags.custom.Validation.validateEnum;
/**
* @author freva
*/
// @Immutable
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(value = JsonInclude.Include.NON_NULL)
public class ClusterCapacity {
private final int count;
private final OptionalDouble vcpu;
private final OptionalDouble memoryGb;
private final OptionalDouble diskGb;
private final OptionalDouble bandwidthGbps;
private final String diskSpeed;
private final String storageType;
private final String architecture;
private final Optional<String> clusterType;
private final Optional<String> clusterId;
@JsonCreator
public ClusterCapacity(@JsonProperty("count") Integer count,
@JsonProperty("vcpu") Double vcpu,
@JsonProperty("memoryGb") Double memoryGb,
@JsonProperty("diskGb") Double diskGb,
@JsonProperty("bandwidthGbps") Double bandwidthGbps,
@JsonProperty("diskSpeed") String diskSpeed,
@JsonProperty("storageType") String storageType,
@JsonProperty("architecture") String architecture,
@JsonProperty("clusterType") String clusterType,
@JsonProperty("clusterId") String clusterId) {
this.count = count == null ? 1 : (int) requireNonNegative("count", count);
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);
this.diskSpeed = validateEnum("diskSpeed", validDiskSpeeds, diskSpeed == null ? "fast" : diskSpeed);
this.storageType = validateEnum("storageType", validStorageTypes, storageType == null ? "any" : storageType);
this.architecture = validateEnum("architecture", validArchitectures, architecture == null ? "x86_64" : architecture);
this.clusterType = clusterType == null ? Optional.empty() : Optional.of(validateEnum("clusterType", validClusterTypes, clusterType));
this.clusterId = clusterId == null ? Optional.empty() : Optional.of(clusterId);
}
@JsonGetter("count") public int count() { return count; }
@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; }
@JsonGetter("diskSpeed") public String diskSpeed() { return diskSpeed; }
@JsonGetter("storageType") public String storageType() { return storageType; }
@JsonGetter("architecture") public String architecture() { return architecture; }
@JsonGetter("clusterType") public String clusterTypeOrNull() { return clusterType.orElse(null); }
@JsonGetter("clusterId") public String clusterIdOrNull() { return clusterId.orElse(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); }
@JsonIgnore public Optional<String> clusterType() { return clusterType; }
@JsonIgnore public Optional<String> clusterId() { return clusterId; }
@Override
public String toString() {
return "ClusterCapacity{" +
"count=" + count +
", vcpu=" + vcpu +
", memoryGb=" + memoryGb +
", diskGb=" + diskGb +
", bandwidthGbps=" + bandwidthGbps +
", diskSpeed=" + diskSpeed +
", storageType=" + storageType +
", architecture=" + architecture +
", clusterType=" + clusterType +
", clusterId=" + clusterId +
'}';
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
ClusterCapacity that = (ClusterCapacity) o;
return count == that.count &&
vcpu.equals(that.vcpu) &&
memoryGb.equals(that.memoryGb) &&
diskGb.equals(that.diskGb) &&
bandwidthGbps.equals(that.bandwidthGbps) &&
diskSpeed.equals(that.diskSpeed) &&
storageType.equals(that.storageType) &&
architecture.equals(that.architecture) &&
clusterType.equals(that.clusterType) &&
clusterId.equals(that.clusterId);
}
@Override
public int hashCode() {
return Objects.hash(count, vcpu, memoryGb, diskGb, bandwidthGbps, diskSpeed, storageType, architecture, clusterType, clusterId);
}
}
|