summaryrefslogtreecommitdiffstats
path: root/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/noderepository/NodeResources.java
blob: b46412376c74a9e452d5d9a413e532d383c27cd5 (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
// Copyright 2019 Oath Inc. 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;

    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 com.yahoo.config.provision.NodeResources toNodeResources() {
        return new com.yahoo.config.provision.NodeResources(vcpu, memoryGb, diskGb, bandwidthGbps,
                                                            toDiskSpeed(diskSpeed),
                                                            toStorageType(storageType));
    }

    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 + "'");
        }
    }

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