aboutsummaryrefslogtreecommitdiffstats
path: root/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/configserver/ApplicationReindexing.java
blob: 3f341a8db9b70e8d5fae49d4be779b87fd37b92d (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
165
166
167
168
169
170
171
172
173
174
175
176
// 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.configserver;

import java.time.Instant;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;

/**
 * Reindexing status for a single Vespa application.
 *
 * @author jonmv
 */
public class ApplicationReindexing {

    private final boolean enabled;
    private final Map<String, Cluster> clusters;

    public ApplicationReindexing(boolean enabled, Map<String, Cluster> clusters) {
        this.enabled = enabled;
        this.clusters = Map.copyOf(clusters);
    }

    public boolean enabled() {
        return enabled;
    }

    public Map<String, Cluster> clusters() {
        return clusters;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        ApplicationReindexing that = (ApplicationReindexing) o;
        return enabled == that.enabled &&
               clusters.equals(that.clusters);
    }

    @Override
    public int hashCode() {
        return Objects.hash(enabled, clusters);
    }

    @Override
    public String toString() {
        return "ApplicationReindexing{" +
               "enabled=" + enabled +
               ", clusters=" + clusters +
               '}';
    }


    public static class Cluster {

        private final Map<String, Long> pending;
        private final Map<String, Status> ready;

        public Cluster(Map<String, Long> pending, Map<String, Status> ready) {
            this.pending = Map.copyOf(pending);
            this.ready = Map.copyOf(ready);
        }

        public Map<String, Long> pending() {
            return pending;
        }

        public Map<String, Status> ready() {
            return ready;
        }

        @Override
        public boolean equals(Object o) {
            if (this == o) return true;
            if (o == null || getClass() != o.getClass()) return false;
            Cluster cluster = (Cluster) o;
            return pending.equals(cluster.pending) &&
                   ready.equals(cluster.ready);
        }

        @Override
        public int hashCode() {
            return Objects.hash(pending, ready);
        }

        @Override
        public String toString() {
            return "Cluster{" +
                   "pending=" + pending +
                   ", ready=" + ready +
                   '}';
        }

    }


    public static class Status {

        private final Instant readyAt;
        private final Instant startedAt;
        private final Instant endedAt;
        private final State state;
        private final String message;
        private final Double progress;
        private final Double speed;
        private final String cause;

        public Status(Instant readyAt, Instant startedAt, Instant endedAt, State state, String message, Double progress, Double speed, String cause) {
            this.readyAt = readyAt;
            this.startedAt = startedAt;
            this.endedAt = endedAt;
            this.state = state;
            this.message = message;
            this.progress = progress;
            this.speed = speed;
            this.cause = cause;
        }

        public Status(Instant readyAt) {
            this(readyAt, null, null, null, null, null, 1.0, null);
        }

        public Optional<Instant> readyAt() { return Optional.ofNullable(readyAt); }
        public Optional<Instant> startedAt() { return Optional.ofNullable(startedAt); }
        public Optional<Instant> endedAt() { return Optional.ofNullable(endedAt); }
        public Optional<State> state() { return Optional.ofNullable(state); }
        public Optional<String> message() { return Optional.ofNullable(message); }
        public Optional<Double> progress() { return Optional.ofNullable(progress); }
        public Optional<Double> speed() { return Optional.ofNullable(speed); }
        public Optional<String> cause() { return Optional.ofNullable(cause); }

        @Override
        public boolean equals(Object o) {
            if (this == o) return true;
            if (o == null || getClass() != o.getClass()) return false;
            Status status = (Status) o;
            return Objects.equals(readyAt, status.readyAt) &&
                   Objects.equals(startedAt, status.startedAt) &&
                   Objects.equals(endedAt, status.endedAt) &&
                   state == status.state &&
                   Objects.equals(message, status.message) &&
                   Objects.equals(progress, status.progress) &&
                   Objects.equals(speed, status.speed) &&
                   Objects.equals(cause, status.cause);
        }

        @Override
        public int hashCode() {
            return Objects.hash(readyAt, startedAt, endedAt, state, message, progress, speed, cause);
        }

        @Override
        public String toString() {
            return "Status{" +
                   "readyAt=" + readyAt +
                   ", startedAt=" + startedAt +
                   ", endedAt=" + endedAt +
                   ", state=" + state +
                   ", message='" + message + '\'' +
                   ", progress=" + progress +
                   ", speed=" + speed +
                   ", cause='" + cause + '\'' +
                   '}';
        }

    }


    public enum State {

        PENDING, RUNNING, FAILED, SUCCESSFUL;

    }

}