aboutsummaryrefslogtreecommitdiffstats
path: root/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/noderepository/NodeResources.java
blob: a14bf599762a15dcd486ff92d63c5af93ca2c0af (plain) (blame)
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.hosted.controller.api.integration.noderepository;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;

/**
 * @author freva
 */
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(JsonInclude.Include.NON_NULL)
public class NodeResources {

    @JsonProperty
    private Double vcpu;
    @JsonProperty
    private Double memoryGb;
    @JsonProperty
    private Double diskGb;
    @JsonProperty
    private Double bandwidthGbps;
    @JsonProperty
    private String diskSpeed;
    @JsonProperty
    private String storageType;
    @JsonProperty
    private String architecture;
    @JsonProperty
    private Double gpuCount;
    @JsonProperty
    private Double gpuMemoryGb;


    public Double getVcpu() {
        return vcpu;
    }

    public void setVcpu(Double vcpu) {
        this.vcpu = vcpu;
    }

    public Double getMemoryGb() {
        return memoryGb;
    }

    public void setMemoryGb(Double memoryGb) {
        this.memoryGb = memoryGb;
    }

    public Double getDiskGb() {
        return diskGb;
    }

    public void setDiskGb(Double diskGb) {
        this.diskGb = diskGb;
    }

    public Double getBandwidthGbps() {
        return bandwidthGbps;
    }

    public void setBandwidthGbps(Double bandwidthGbps) {
        this.bandwidthGbps = bandwidthGbps;
    }

    public String getDiskSpeed() {
        return diskSpeed;
    }

    public void setDiskSpeed(String diskSpeed) {
        this.diskSpeed = diskSpeed;
    }

    public String getStorageType() {
        return storageType;
    }

    public void setStorageType(String storageType) {
        this.storageType = storageType;
    }

    public String getArchitecture() {
        return architecture;
    }

    public void setArchitecture(String architecture) {
        this.architecture = architecture;
    }

    public Double getGpuCount(){
        return gpuCount;
    }

    public void setGpuCount(Double gpuCount) {
        this.gpuCount = gpuCount;
    }

    public Double getGpuMemoryGb() {
        return gpuMemoryGb;
    }

    public void setGpuMemoryGb(Double gpuMemoryGb) {
        this.gpuMemoryGb = gpuMemoryGb;
    }

    public com.yahoo.config.provision.NodeResources toNodeResources() {
        return new com.yahoo.config.provision.NodeResources(vcpu, memoryGb, diskGb, bandwidthGbps,
                                                            toDiskSpeed(diskSpeed),
                                                            toStorageType(storageType),
                                                            toArchitecture(architecture),
                                                            toGpu(gpuCount, gpuMemoryGb));
    }

    private com.yahoo.config.provision.NodeResources.DiskSpeed toDiskSpeed(String diskSpeed) {
        switch (diskSpeed) {
            case "fast" : return com.yahoo.config.provision.NodeResources.DiskSpeed.fast;
            case "slow" : return com.yahoo.config.provision.NodeResources.DiskSpeed.slow;
            case "any" : return com.yahoo.config.provision.NodeResources.DiskSpeed.any;
            default : throw new IllegalArgumentException("Unknown disk speed '" + diskSpeed + "'");
        }
    }

    private com.yahoo.config.provision.NodeResources.StorageType toStorageType(String storageType) {
        switch (storageType) {
            case "remote" : return com.yahoo.config.provision.NodeResources.StorageType.remote;
            case "local" : return com.yahoo.config.provision.NodeResources.StorageType.local;
            case "any" : return com.yahoo.config.provision.NodeResources.StorageType.any;
            default : throw new IllegalArgumentException("Unknown storage type '" + storageType + "'");
        }
    }

    private com.yahoo.config.provision.NodeResources.Architecture toArchitecture(String architecture) {
        switch (architecture) {
            case "arm64" : return com.yahoo.config.provision.NodeResources.Architecture.arm64;
            case "x86_64" : return com.yahoo.config.provision.NodeResources.Architecture.x86_64;
            case "any" : return com.yahoo.config.provision.NodeResources.Architecture.any;
            default : throw new IllegalArgumentException("Unknown architecture '" + architecture + "'");
        }
    }

    private com.yahoo.config.provision.NodeResources.GpuResources toGpu(Double gpuCount, Double gpuMemoryGb) {
        // these are either both null or both have a value.  using OR to silence inspection.
        // we also cast the double to an integer.  assuming this must be OK as we are going
        // from NodeResources -> JSON -> NodeResources
        if (gpuCount == null || gpuMemoryGb == null) return com.yahoo.config.provision.NodeResources.GpuResources.getDefault();
        return new com.yahoo.config.provision.NodeResources.GpuResources(gpuCount.intValue(), gpuMemoryGb.intValue());
    }

    @Override
    public String toString() {
        return "NodeResources{" +
                "vcpu=" + vcpu +
                ", memoryGb=" + memoryGb +
                ", diskGb=" + diskGb +
                ", bandwidthGbps=" + bandwidthGbps +
                ", diskSpeed='" + diskSpeed + '\'' +
                ", storageType='" + storageType + '\'' +
                ", architecture='" + architecture + '\'' +
                ", gpuCount='" + gpuCount + '\'' +
                ", gpuMemoryGb='" + gpuMemoryGb + '\'' +
                '}';
    }
}