summaryrefslogtreecommitdiffstats
path: root/node-repository
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@gmail.com>2020-12-10 15:12:31 +0100
committerJon Bratseth <bratseth@gmail.com>2020-12-10 15:12:31 +0100
commitfdf963af01ce963de8f02938252fa45b30f16c37 (patch)
tree870127c42ee3a4ba750d9640f28c274c589eb027 /node-repository
parentf35b94bd4c3f7d02d0e47ec7073ebed3086e739b (diff)
Do more checks
Diffstat (limited to 'node-repository')
-rw-r--r--node-repository/src/main/java/com/yahoo/vespa/hosted/provision/NodeList.java35
1 files changed, 25 insertions, 10 deletions
diff --git a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/NodeList.java b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/NodeList.java
index 35217cb4d05..5c635551692 100644
--- a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/NodeList.java
+++ b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/NodeList.java
@@ -186,22 +186,25 @@ public class NodeList extends AbstractFilteringList<Node, NodeList> {
/**
* Returns the cluster spec of the nodes in this, without any group designation
*
- * @throws IllegalStateException if there are no nodes in thus list or they do niot all belong
+ * @throws IllegalStateException if there are no nodes in thus list or they do not all belong
* to the same cluster
*/
public ClusterSpec clusterSpec() {
- if (first().isEmpty()) throw new IllegalStateException("No nodes");
- if (stream().anyMatch(node -> node.allocation().isEmpty()))
- throw new IllegalStateException("Some nodes are not allocated to a cluster");
-
- ClusterSpec firstNodeSpec = first().get().allocation().get().membership().cluster().with(Optional.empty());
- if (stream().map(node -> node.allocation().get().membership().cluster().with(Optional.empty()))
- .anyMatch(clusterSpec -> ! clusterSpec.equals(firstNodeSpec)))
- throw new IllegalStateException("Nodes belong to multiple clusters");
- return firstNodeSpec;
+ ensureSingleCluster();
+ if (isEmpty()) throw new IllegalStateException("No nodes");
+ return first().get().allocation().get().membership().cluster().with(Optional.empty());
}
+ /**
+ * Returns the resources of the nodes of this.
+ *
+ * NOTE: If the nodes do not all have the same values of node resources, a random pick among those node resources
+ * will be returned.
+ *
+ * @throws IllegalStateException if the nodes in this do not all belong to the same cluster
+ */
public ClusterResources toResources() {
+ ensureSingleCluster();
if (isEmpty()) return new ClusterResources(0, 0, NodeResources.unspecified());
return new ClusterResources(size(),
(int)stream().map(node -> node.allocation().get().membership().cluster().group().get())
@@ -210,6 +213,18 @@ public class NodeList extends AbstractFilteringList<Node, NodeList> {
first().get().resources());
}
+ private void ensureSingleCluster() {
+ if (isEmpty()) return;
+
+ if (stream().anyMatch(node -> node.allocation().isEmpty()))
+ throw new IllegalStateException("Some nodes are not allocated to a cluster");
+
+ ClusterSpec firstNodeSpec = first().get().allocation().get().membership().cluster().with(Optional.empty());
+ if (stream().map(node -> node.allocation().get().membership().cluster().with(Optional.empty()))
+ .anyMatch(clusterSpec -> ! clusterSpec.equals(firstNodeSpec)))
+ throw new IllegalStateException("Nodes belong to multiple clusters");
+ }
+
/** Returns the nodes of this as a stream */
public Stream<Node> stream() { return asList().stream(); }