summaryrefslogtreecommitdiffstats
path: root/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/configserver/Node.java
blob: 04f1448bec1ba5b9b7a4499f2591dc8f407fe233 (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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
// Copyright 2018 Yahoo Holdings. 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.fasterxml.jackson.databind.JsonNode;
import com.yahoo.component.Version;
import com.yahoo.config.provision.ApplicationId;
import com.yahoo.config.provision.DockerImage;
import com.yahoo.config.provision.HostName;
import com.yahoo.config.provision.NodeResources;
import com.yahoo.config.provision.NodeType;
import com.yahoo.config.provision.TenantName;
import com.yahoo.vespa.hosted.controller.api.integration.noderepository.NodeHistory;

import java.time.Instant;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;

/**
 * A node in hosted Vespa.
 *
 * @author mpolden
 * @author jonmv
 */
public class Node {

    private final HostName hostname;
    private final Optional<HostName> parentHostname;
    private final State state;
    private final NodeType type;
    private final NodeResources resources;
    private final Optional<ApplicationId> owner;
    private final Version currentVersion;
    private final Version wantedVersion;
    private final Version currentOsVersion;
    private final Version wantedOsVersion;
    private final DockerImage currentDockerImage;
    private final DockerImage wantedDockerImage;
    private final ServiceState serviceState;
    private final Optional<Instant> suspendedSince;
    private final Optional<Instant> currentFirmwareCheck;
    private final Optional<Instant> wantedFirmwareCheck;
    private final long restartGeneration;
    private final long wantedRestartGeneration;
    private final long rebootGeneration;
    private final long wantedRebootGeneration;
    private final int cost;
    private final String flavor;
    private final String clusterId;
    private final ClusterType clusterType;
    private final boolean wantToRetire;
    private final boolean wantToDeprovision;
    private final Optional<TenantName> reservedTo;
    private final Optional<ApplicationId> exclusiveTo;
    private final Map<String, JsonNode> reports;
    private final List<NodeHistory> history;
    private final Set<String> additionalIpAddresses;
    private final String openStackId;
    private final Optional<String> switchHostname;

    public Node(HostName hostname, Optional<HostName> parentHostname, State state, NodeType type, NodeResources resources, Optional<ApplicationId> owner,
                Version currentVersion, Version wantedVersion, Version currentOsVersion, Version wantedOsVersion,
                Optional<Instant> currentFirmwareCheck, Optional<Instant> wantedFirmwareCheck, ServiceState serviceState,
                Optional<Instant> suspendedSince, long restartGeneration, long wantedRestartGeneration, long rebootGeneration, long wantedRebootGeneration,
                int cost, String flavor, String clusterId, ClusterType clusterType, boolean wantToRetire, boolean wantToDeprovision,
                Optional<TenantName> reservedTo, Optional<ApplicationId> exclusiveTo,
                DockerImage wantedDockerImage, DockerImage currentDockerImage, Map<String, JsonNode> reports, List<NodeHistory> history,
                Set<String> additionalIpAddresses, String openStackId, Optional<String> switchHostname) {
        this.hostname = hostname;
        this.parentHostname = parentHostname;
        this.state = state;
        this.type = type;
        this.resources = resources;
        this.owner = owner;
        this.currentVersion = currentVersion;
        this.wantedVersion = wantedVersion;
        this.currentOsVersion = currentOsVersion;
        this.wantedOsVersion = wantedOsVersion;
        this.currentFirmwareCheck = currentFirmwareCheck;
        this.wantedFirmwareCheck = wantedFirmwareCheck;
        this.serviceState = serviceState;
        this.suspendedSince = suspendedSince;
        this.restartGeneration = restartGeneration;
        this.wantedRestartGeneration = wantedRestartGeneration;
        this.rebootGeneration = rebootGeneration;
        this.wantedRebootGeneration = wantedRebootGeneration;
        this.cost = cost;
        this.flavor = flavor;
        this.clusterId = clusterId;
        this.clusterType = clusterType;
        this.wantToRetire = wantToRetire;
        this.wantToDeprovision = wantToDeprovision;
        this.reservedTo = reservedTo;
        this.exclusiveTo = exclusiveTo;
        this.wantedDockerImage = wantedDockerImage;
        this.currentDockerImage = currentDockerImage;
        this.reports = reports;
        this.history = history;
        this.openStackId = openStackId;
        this.additionalIpAddresses = additionalIpAddresses;
        this.switchHostname = switchHostname;
    }

    public HostName hostname() {
        return hostname;
    }

    public Optional<HostName> parentHostname() {
        return parentHostname;
    }

    public State state() { return state; }

    public NodeType type() {
        return type;
    }

    public NodeResources resources() {
        return resources;
    }

    public Optional<ApplicationId> owner() {
        return owner;
    }

    public Version currentVersion() {
        return currentVersion;
    }

    public Version wantedVersion() {
        return wantedVersion;
    }

    public Version currentOsVersion() {
        return currentOsVersion;
    }

    public Version wantedOsVersion() {
        return wantedOsVersion;
    }

    public DockerImage currentDockerImage() {
        return currentDockerImage;
    }

    public DockerImage wantedDockerImage() {
        return wantedDockerImage;
    }

    public Optional<Instant> currentFirmwareCheck() {
        return currentFirmwareCheck;
    }

    public Optional<Instant> wantedFirmwareCheck() {
        return wantedFirmwareCheck;
    }

    public ServiceState serviceState() {
        return serviceState;
    }

    public Optional<Instant> suspendedSince() {
        return suspendedSince;
    }

    public long restartGeneration() {
        return restartGeneration;
    }

    public long wantedRestartGeneration() {
        return wantedRestartGeneration;
    }

    public long rebootGeneration() {
        return rebootGeneration;
    }

    public long wantedRebootGeneration() {
        return wantedRebootGeneration;
    }

    public int cost() {
        return cost;
    }

    public String flavor() {
        return flavor;
    }

    public String clusterId() {
        return clusterId;
    }

    public ClusterType clusterType() {
        return clusterType;
    }

    public boolean wantToRetire() {
        return wantToRetire;
    }

    public boolean wantToDeprovision() {
        return wantToDeprovision;
    }

    public Optional<TenantName> reservedTo() { return reservedTo; }

    public Optional<ApplicationId> exclusiveTo() { return exclusiveTo; }

    public Map<String, JsonNode> reports() {
        return reports;
    }

    public List<NodeHistory> history() {
        return history;
    }

    public Set<String> additionalIpAddresses() {
        return additionalIpAddresses;
    }

    public String openStackId() {
        return openStackId;
    }

    public Optional<String> switchHostname() {
        return switchHostname;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Node node = (Node) o;
        return Objects.equals(hostname, node.hostname);
    }

    @Override
    public int hashCode() {
        return Objects.hash(hostname);
    }

    /** Known node states */
    public enum State {
        provisioned,
        ready,
        reserved,
        active,
        inactive,
        dirty,
        failed,
        parked,
        breakfixed,
        unknown
    }

    /** Known node states with regards to service orchestration */
    public enum ServiceState {
        expectedUp,
        allowedDown,
        unorchestrated
    }

    /** Known cluster types. */
    public enum ClusterType {
        admin,
        container,
        content,
        combined,
        unknown
    }

    public static class Builder {
        private HostName hostname;
        private Optional<HostName> parentHostname = Optional.empty();
        private State state;
        private NodeType type;
        private NodeResources resources;
        private Optional<ApplicationId> owner = Optional.empty();
        private Version currentVersion;
        private Version wantedVersion;
        private Version currentOsVersion;
        private Version wantedOsVersion;
        private DockerImage currentDockerImage;
        private DockerImage wantedDockerImage;
        private Optional<Instant> currentFirmwareCheck = Optional.empty();
        private Optional<Instant> wantedFirmwareCheck = Optional.empty();
        private ServiceState serviceState;
        private Optional<Instant> suspendedSince = Optional.empty();
        private long restartGeneration;
        private long wantedRestartGeneration;
        private long rebootGeneration;
        private long wantedRebootGeneration;
        private int cost;
        private String flavor;
        private String clusterId;
        private ClusterType clusterType;
        private boolean wantToRetire;
        private boolean wantToDeprovision;
        private Optional<TenantName> reservedTo = Optional.empty();
        private Optional<ApplicationId> exclusiveTo = Optional.empty();
        private Map<String, JsonNode> reports = new HashMap<>();
        private List<NodeHistory> history = new ArrayList<>();
        private Set<String> additionalIpAddresses = new HashSet<>();
        private String openStackId;
        private Optional<String> switchHostname = Optional.empty();

        public Builder() { }

        public Builder(Node node) {
            this.hostname = node.hostname;
            this.parentHostname = node.parentHostname;
            this.state = node.state;
            this.type = node.type;
            this.resources = node.resources;
            this.owner = node.owner;
            this.currentVersion = node.currentVersion;
            this.wantedVersion = node.wantedVersion;
            this.currentOsVersion = node.currentOsVersion;
            this.wantedOsVersion = node.wantedOsVersion;
            this.currentDockerImage = node.currentDockerImage;
            this.wantedDockerImage = node.wantedDockerImage;
            this.currentFirmwareCheck = node.currentFirmwareCheck;
            this.wantedFirmwareCheck = node.wantedFirmwareCheck;
            this.serviceState = node.serviceState;
            this.suspendedSince = node.suspendedSince;
            this.restartGeneration = node.restartGeneration;
            this.wantedRestartGeneration = node.wantedRestartGeneration;
            this.rebootGeneration = node.rebootGeneration;
            this.wantedRebootGeneration = node.wantedRebootGeneration;
            this.cost = node.cost;
            this.flavor = node.flavor;
            this.clusterId = node.clusterId;
            this.clusterType = node.clusterType;
            this.wantToRetire = node.wantToRetire;
            this.wantToDeprovision = node.wantToDeprovision;
            this.reservedTo = node.reservedTo;
            this.exclusiveTo = node.exclusiveTo;
            this.reports = node.reports;
            this.history = node.history;
            this.additionalIpAddresses = node.additionalIpAddresses;
            this.openStackId = node.openStackId;
            this.switchHostname = node.switchHostname;
        }

        public Builder hostname(HostName hostname) {
            this.hostname = hostname;
            return this;
        }

        public Builder parentHostname(HostName parentHostname) {
            this.parentHostname = Optional.ofNullable(parentHostname);
            return this;
        }

        public Builder state(State state) {
            this.state = state;
            return this;
        }

        public Builder type(NodeType type) {
            this.type = type;
            return this;
        }

        public Builder resources(NodeResources resources) {
            this.resources = resources;
            return this;
        }

        public Builder owner(ApplicationId owner) {
            this.owner = Optional.ofNullable(owner);
            return this;
        }

        public Builder currentVersion(Version currentVersion) {
            this.currentVersion = currentVersion;
            return this;
        }

        public Builder wantedVersion(Version wantedVersion) {
            this.wantedVersion = wantedVersion;
            return this;
        }

        public Builder currentOsVersion(Version currentOsVersion) {
            this.currentOsVersion = currentOsVersion;
            return this;
        }

        public Builder wantedOsVersion(Version wantedOsVersion) {
            this.wantedOsVersion = wantedOsVersion;
            return this;
        }

        public Builder currentDockerImage(DockerImage currentDockerImage) {
            this.currentDockerImage = currentDockerImage;
            return this;
        }

        public Builder wantedDockerImage(DockerImage wantedDockerImage) {
            this.wantedDockerImage = wantedDockerImage;
            return this;
        }

        public Builder currentFirmwareCheck(Instant currentFirmwareCheck) {
            this.currentFirmwareCheck = Optional.ofNullable(currentFirmwareCheck);
            return this;
        }

        public Builder wantedFirmwareCheck(Instant wantedFirmwareCheck) {
            this.wantedFirmwareCheck = Optional.ofNullable(wantedFirmwareCheck);
            return this;
        }

        public Builder serviceState(ServiceState serviceState) {
            this.serviceState = serviceState;
            return this;
        }

        public Builder suspendedSince(Instant suspendedSince) {
            this.suspendedSince = Optional.ofNullable(suspendedSince);
            return this;
        }

        public Builder restartGeneration(long restartGeneration) {
            this.restartGeneration = restartGeneration;
            return this;
        }

        public Builder wantedRestartGeneration(long wantedRestartGeneration) {
            this.wantedRestartGeneration = wantedRestartGeneration;
            return this;
        }

        public Builder rebootGeneration(long rebootGeneration) {
            this.rebootGeneration = rebootGeneration;
            return this;
        }

        public Builder wantedRebootGeneration(long wantedRebootGeneration) {
            this.wantedRebootGeneration = wantedRebootGeneration;
            return this;
        }

        public Builder cost(int cost) {
            this.cost = cost;
            return this;
        }

        public Builder flavor(String flavor) {
            this.flavor = flavor;
            return this;
        }

        public Builder clusterId(String clusterId) {
            this.clusterId = clusterId;
            return this;
        }

        public Builder clusterType(ClusterType clusterType) {
            this.clusterType = clusterType;
            return this;
        }

        public Builder wantToRetire(boolean wantToRetire) {
            this.wantToRetire = wantToRetire;
            return this;
        }

        public Builder wantToDeprovision(boolean wantToDeprovision) {
            this.wantToDeprovision = wantToDeprovision;
            return this;
        }

        public Builder reservedTo(TenantName tenant) {
            this.reservedTo = Optional.of(tenant);
            return this;
        }

        public Builder exclusiveTo(ApplicationId exclusiveTo) {
            this.exclusiveTo = Optional.of(exclusiveTo);
            return this;
        }

        public Builder history(List<NodeHistory> history) {
            this.history = history;
            return this;
        }

        public Builder additionalIpAddresses(Set<String> additionalIpAddresses) {
            this.additionalIpAddresses = additionalIpAddresses;
            return this;
        }

        public Builder openStackId(String openStackId) {
            this.openStackId = openStackId;
            return this;
        }

        public Builder switchHostname(String switchHostname) {
            this.switchHostname = Optional.ofNullable(switchHostname);
            return this;
        }

        public Node build() {
            return new Node(hostname, parentHostname, state, type, resources, owner, currentVersion, wantedVersion,
                            currentOsVersion, wantedOsVersion, currentFirmwareCheck, wantedFirmwareCheck, serviceState,
                            suspendedSince, restartGeneration, wantedRestartGeneration, rebootGeneration, wantedRebootGeneration,
                            cost, flavor, clusterId, clusterType, wantToRetire, wantToDeprovision, reservedTo, exclusiveTo,
                            wantedDockerImage, currentDockerImage, reports, history, additionalIpAddresses, openStackId, switchHostname);
        }

    }
}