aboutsummaryrefslogtreecommitdiffstats
path: root/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/configserver/Cluster.java
blob: d2b1f6a08035b8daf88a873935a3158f3c2a566d (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
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.hosted.controller.api.integration.configserver;

import com.yahoo.config.provision.ClusterResources;
import com.yahoo.config.provision.ClusterSpec;

import java.time.Duration;
import java.time.Instant;
import java.util.List;
import java.util.Objects;
import java.util.Optional;

/**
 * @author bratseth
 */
public class Cluster {

    private final ClusterSpec.Id id;
    private final ClusterSpec.Type type;
    private final ClusterResources min;
    private final ClusterResources max;
    private final ClusterResources current;
    private final Optional<ClusterResources> target;
    private final Optional<ClusterResources> suggested;
    private final Utilization utilization;
    private final List<ScalingEvent> scalingEvents;
    private final String autoscalingStatusCode;
    private final String autoscalingStatus;
    private final Duration scalingDuration;

    public Cluster(ClusterSpec.Id id,
                   ClusterSpec.Type type,
                   ClusterResources min,
                   ClusterResources max,
                   ClusterResources current,
                   Optional<ClusterResources> target,
                   Optional<ClusterResources> suggested,
                   Utilization utilization,
                   List<ScalingEvent> scalingEvents,
                   String autoscalingStatusCode,
                   String autoscalingStatus,
                   Duration scalingDuration) {
        this.id = id;
        this.type = type;
        this.min = min;
        this.max = max;
        this.current = current;
        this.target = target;
        this.suggested = suggested;
        this.utilization = utilization;
        this.scalingEvents = scalingEvents;
        this.autoscalingStatusCode = autoscalingStatusCode;
        this.autoscalingStatus = autoscalingStatus;
        this.scalingDuration = scalingDuration;
    }

    public ClusterSpec.Id id() { return id; }
    public ClusterSpec.Type type() { return type; }
    public ClusterResources min() { return min; }
    public ClusterResources max() { return max; }
    public ClusterResources current() { return current; }
    public Optional<ClusterResources> target() { return target; }
    public Optional<ClusterResources> suggested() { return suggested; }
    public Utilization utilization() { return utilization; }
    public List<ScalingEvent> scalingEvents() { return scalingEvents; }
    public String autoscalingStatusCode() { return autoscalingStatusCode; }
    public String autoscalingStatus() { return autoscalingStatus; }
    public Duration scalingDuration() { return scalingDuration; }

    @Override
    public String toString() {
        return "cluster '" + id + "'";
    }

    public static class Utilization {

        private final double idealCpu, peakCpu;
        private final double idealMemory, peakMemory;
        private final double idealDisk, peakDisk;

        public Utilization(double idealCpu, double peakCpu,
                           double idealMemory, double peakMemory,
                           double idealDisk, double peakDisk) {
            this.idealCpu = idealCpu;
            this.peakCpu = peakCpu;

            this.idealMemory = idealMemory;
            this.peakMemory = peakMemory;

            this.idealDisk = idealDisk;
            this.peakDisk = peakDisk;
        }

        public double idealCpu() { return idealCpu; }
        public double peakCpu() { return peakCpu; }

        public double idealMemory() { return idealMemory; }
        public double peakMemory() { return peakMemory; }

        public double idealDisk() { return idealDisk; }
        public double peakDisk() { return peakDisk; }

        public static Utilization empty() { return new Utilization(0, 0,
                                                                   0, 0,
                                                                   0, 0); }

    }

    public static class ScalingEvent {

        private final ClusterResources from, to;
        private final Instant at;
        private final Optional<Instant> completion;

        public ScalingEvent(ClusterResources from, ClusterResources to, Instant at, Optional<Instant> completion) {
            this.from = from;
            this.to = to;
            this.at = at;
            this.completion = completion;
        }

        public ClusterResources from() { return from; }
        public ClusterResources to() { return to; }
        public Instant at() { return at; }
        public Optional<Instant> completion() { return completion; }

        @Override
        public boolean equals(Object o) {
            if (this == o) return true;
            if (o == null || getClass() != o.getClass()) return false;
            ScalingEvent that = (ScalingEvent) o;
            return Objects.equals(from, that.from) && Objects.equals(to, that.to) && Objects.equals(at, that.at) && Objects.equals(completion, that.completion);
        }

        @Override
        public int hashCode() {
            return Objects.hash(from, to, at, completion);
        }

        @Override
        public String toString() {
            return "ScalingEvent{" +
                    "from=" + from +
                    ", to=" + to +
                    ", at=" + at +
                    ", completion=" + completion +
                    '}';
        }
    }

}