summaryrefslogtreecommitdiffstats
path: root/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/configserver/Cluster.java
blob: ccfd32418103694ee6b56db151ddd4087fba9993 (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
// Copyright Verizon Media. 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.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;
    private final double maxQueryGrowthRate;
    private final double currentQueryFractionOfMax;

    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,
                   double maxQueryGrowthRate,
                   double currentQueryFractionOfMax) {
        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;
        this.maxQueryGrowthRate = maxQueryGrowthRate;
        this.currentQueryFractionOfMax = currentQueryFractionOfMax;
    }

    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; }
    public double maxQueryGrowthRate() { return maxQueryGrowthRate; }
    public double currentQueryFractionOfMax() { return currentQueryFractionOfMax; }

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

    public static class Utilization {

        private final double cpu, idealCpu, currentCpu, memory, idealMemory, currentMemory, disk, idealDisk, currentDisk;

        public Utilization(double cpu, double idealCpu, double currentCpu,
                           double memory, double idealMemory, double currentMemory,
                           double disk, double idealDisk, double currentDisk) {
            this.cpu = cpu;
            this.idealCpu = idealCpu;
            this.currentCpu = currentCpu;
            this.memory = memory;
            this.idealMemory = idealMemory;
            this.currentMemory = currentMemory;
            this.disk = disk;
            this.idealDisk = idealDisk;
            this.currentDisk = currentDisk;
        }

        public double cpu() { return cpu; }
        public double idealCpu() { return idealCpu; }
        public double currentCpu() { return currentCpu; }

        public double memory() { return memory; }
        public double idealMemory() { return idealMemory; }
        public double currentMemory() { return currentMemory; }

        public double disk() { return disk; }
        public double idealDisk() { return idealDisk; }
        public double currentDisk() { return currentDisk; }

        public static Utilization empty() { return new Utilization(0, 0, 0, 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; }

    }

}