blob: f93ee4b191f7f654c2f2a87a0ad9d0a5863f54a0 (
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
|
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.orchestrator.model;
import com.yahoo.vespa.applicationmodel.ApplicationInstance;
import com.yahoo.vespa.applicationmodel.ApplicationInstanceReference;
import com.yahoo.vespa.applicationmodel.HostName;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;
/**
* A group of nodes belonging to the same application instance.
*/
public class NodeGroup {
private final ApplicationInstance application;
private final Set<HostName> hostNames = new HashSet<>();
public NodeGroup(ApplicationInstance application, HostName... hostNames) {
this.application = application;
this.hostNames.addAll(Arrays.asList(hostNames));
}
public void addNode(HostName hostName) {
if (!this.hostNames.add(hostName)) {
throw new IllegalArgumentException("Node " + hostName + " is already in the group");
}
}
public ApplicationInstanceReference getApplicationReference() {
return application.reference();
}
ApplicationInstance getApplication() {
return application;
}
public boolean contains(HostName hostName) {
return hostNames.contains(hostName);
}
public List<HostName> getHostNames() {
return hostNames.stream().sorted().toList();
}
public String toCommaSeparatedString() {
return getHostNames().stream().map(HostName::toString).collect(Collectors.joining(","));
}
@Override
public String toString() {
return "NodeGroup{" +
"application=" + application.reference() +
", hostNames=" + hostNames +
'}';
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof NodeGroup nodeGroup)) return false;
return Objects.equals(application, nodeGroup.application) &&
Objects.equals(hostNames, nodeGroup.hostNames);
}
@Override
public int hashCode() {
return Objects.hash(application, hostNames);
}
}
|