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
|
// Copyright 2019 Oath Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.hosted.controller.versions;
import com.yahoo.component.Version;
import com.yahoo.config.provision.HostName;
import java.time.Instant;
import java.util.Objects;
/**
* Version information for a node allocated to a {@link com.yahoo.vespa.hosted.controller.application.SystemApplication}.
*
* This is immutable.
*
* @author mpolden
*/
public class NodeVersion {
private final HostName hostname;
private final Version currentVersion;
private final Version wantedVersion;
private final Instant changedAt;
public NodeVersion(HostName hostname, Version currentVersion, Version wantedVersion, Instant changedAt) {
this.hostname = Objects.requireNonNull(hostname, "hostname must be non-null");
this.currentVersion = Objects.requireNonNull(currentVersion, "version must be non-null");
this.wantedVersion = Objects.requireNonNull(wantedVersion, "wantedVersion must be non-null");
this.changedAt = Objects.requireNonNull(changedAt, "changedAt must be non-null");
}
/** Hostname of this */
public HostName hostname() {
return hostname;
}
/** Current version of this */
public Version currentVersion() {
return currentVersion;
}
/** Wanted version of this */
public Version wantedVersion() {
return wantedVersion;
}
/** Returns whether this is changing (upgrading or downgrading) */
public boolean changing() {
return !currentVersion.equals(wantedVersion);
}
/** The most recent time the version of this changed */
public Instant changedAt() {
return changedAt;
}
/** Returns a copy of this with current version set to given version */
public NodeVersion withCurrentVersion(Version version, Instant changedAt) {
if (currentVersion.equals(version)) return this;
return new NodeVersion(hostname, version, wantedVersion, changedAt);
}
/** Returns a copy of this with wanted version set to given version */
public NodeVersion withWantedVersion(Version version) {
if (wantedVersion.equals(version)) return this;
return new NodeVersion(hostname, currentVersion, version, changedAt);
}
@Override
public String toString() {
return hostname + ": " + currentVersion + " -> " + wantedVersion + " [changedAt=" + changedAt + "]";
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
NodeVersion that = (NodeVersion) o;
return hostname.equals(that.hostname) &&
currentVersion.equals(that.currentVersion) &&
wantedVersion.equals(that.wantedVersion) &&
changedAt.equals(that.changedAt);
}
@Override
public int hashCode() {
return Objects.hash(hostname, currentVersion, wantedVersion, changedAt);
}
public static NodeVersion empty(HostName hostname) {
return new NodeVersion(hostname, Version.emptyVersion, Version.emptyVersion, Instant.EPOCH);
}
}
|