summaryrefslogtreecommitdiffstats
path: root/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/configserver/ApplicationReindexing.java
blob: 868d251d7ee2524cb77efceafa342f0a026448bd (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
177
178
179
180
181
182
183
184
// 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 java.time.Instant;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;

import static java.util.Objects.requireNonNull;

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

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

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

    public boolean enabled() {
        return enabled;
    }

    public Status common() {
        return common;
    }

    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 &&
               common.equals(that.common) &&
               clusters.equals(that.clusters);
    }

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

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


    public static class Cluster {

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

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

        public Optional<Status> common() {
            return common;
        }

        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 common.equals(cluster.common) &&
                   pending.equals(cluster.pending) &&
                   ready.equals(cluster.ready);
        }

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

        @Override
        public String toString() {
            return "Cluster{" +
                   "common=" + common +
                   ", 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 String progress;

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

        public Status(Instant readyAt) {
            this(readyAt, null, null, null, null, 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<String> progress() { return Optional.ofNullable(progress); }

        @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);
        }

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

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

    }


    public enum State {

        PENDING, RUNNING, FAILED, SUCCESSFUL;

    }

}