blob: 39addbd3b6330da1fdc44e6db348cd7aa59d9d8a (
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
|
// 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.deployment;
import com.yahoo.component.Version;
import com.yahoo.vespa.hosted.controller.api.integration.configserver.Node;
import com.yahoo.vespa.hosted.controller.api.integration.configserver.ServiceConvergence;
import java.time.Instant;
import java.util.List;
import java.util.Objects;
import static java.util.Objects.requireNonNull;
/**
* Aggregate of a node and its services, fetched from different sources.
*
* @author jonmv
*/
public class NodeWithServices {
private final Node node;
private final Node parent;
private final long wantedConfigGeneration;
private final List<ServiceConvergence.Status> services;
public NodeWithServices(Node node, Node parent, long wantedConfigGeneration, List<ServiceConvergence.Status> services) {
this.node = requireNonNull(node);
this.parent = requireNonNull(parent);
if (wantedConfigGeneration <= 0)
throw new IllegalArgumentException("Wanted config generation must be positive");
this.wantedConfigGeneration = wantedConfigGeneration;
this.services = List.copyOf(services);
}
public Node node() { return node; }
public Node parent() { return parent; }
public long wantedConfigGeneration() { return wantedConfigGeneration; }
public List<ServiceConvergence.Status> services() { return services; }
public boolean needsOsUpgrade() {
return parent.wantedOsVersion().isAfter(parent.currentOsVersion());
}
public boolean needsFirmwareUpgrade(){
return parent.wantedFirmwareCheck()
.map(wanted -> parent.currentFirmwareCheck()
.map(wanted::isAfter)
.orElse(true))
.orElse(false);
}
public boolean hasParentDown() {
return parent.serviceState() == Node.ServiceState.allowedDown;
}
public boolean needsPlatformUpgrade() {
return node.wantedVersion().isAfter(node.currentVersion())
|| ! node.wantedDockerImage().equals(node.currentDockerImage());
}
public boolean needsReboot() {
return node.wantedRebootGeneration() > node.rebootGeneration();
}
public boolean needsRestart() {
return node.wantedRestartGeneration() > node.restartGeneration();
}
public boolean isAllowedDown() {
return node.serviceState() == Node.ServiceState.allowedDown;
}
public boolean isNewlyProvisioned() {
return node.currentVersion().equals(Version.emptyVersion);
}
public boolean isSuspendedSince(Instant instant) {
return node.suspendedSince().map(instant::isAfter).orElse(false);
}
public boolean needsNewConfig() {
return services.stream().anyMatch(service -> wantedConfigGeneration > service.currentGeneration());
}
public boolean isStateful() {
return node.clusterType() == Node.ClusterType.content || node.clusterType() == Node.ClusterType.combined;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
NodeWithServices that = (NodeWithServices) o;
return node.equals(that.node);
}
@Override
public int hashCode() {
return Objects.hash(node);
}
}
|