aboutsummaryrefslogtreecommitdiffstats
path: root/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/NodeList.java
diff options
context:
space:
mode:
authorMartin Polden <mpolden@mpolden.no>2021-01-07 10:49:45 +0100
committerMartin Polden <mpolden@mpolden.no>2021-01-07 10:55:03 +0100
commit7471c4fd27a6c5eb764e0eaff78f7aaa2f8d4403 (patch)
tree716ed034e090a9b4c811f48f0d4445d9b710fd05 /node-repository/src/main/java/com/yahoo/vespa/hosted/provision/NodeList.java
parent20f52d23421cd25f1e2e27a17c5e404c55a86ff1 (diff)
Report exclusive switch metric per cluster
Diffstat (limited to 'node-repository/src/main/java/com/yahoo/vespa/hosted/provision/NodeList.java')
-rw-r--r--node-repository/src/main/java/com/yahoo/vespa/hosted/provision/NodeList.java24
1 files changed, 24 insertions, 0 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 5c635551692..b0b61e8a6b2 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
@@ -12,8 +12,10 @@ import com.yahoo.config.provision.NodeType;
import java.util.Comparator;
import java.util.EnumSet;
import java.util.List;
+import java.util.Map;
import java.util.Optional;
import java.util.Set;
+import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;
@@ -213,6 +215,28 @@ public class NodeList extends AbstractFilteringList<Node, NodeList> {
first().get().resources());
}
+ /** Returns the nodes that are allocated on an exclusive network switch within its cluster */
+ public NodeList onExclusiveSwitch(NodeList clusterHosts) {
+ ensureSingleCluster();
+ Map<String, Long> switchCount = clusterHosts.stream()
+ .flatMap(host -> host.switchHostname().stream())
+ .collect(Collectors.groupingBy(Function.identity(),
+ Collectors.counting()));
+ return matching(node -> {
+ Optional<Node> nodeOnSwitch = clusterHosts.parentOf(node);
+ if (node.parentHostname().isPresent()) {
+ if (nodeOnSwitch.isEmpty()) {
+ throw new IllegalArgumentException("Parent of " + node + ", " + node.parentHostname().get() +
+ ", not found in given cluster hosts");
+ }
+ } else {
+ nodeOnSwitch = Optional.of(node);
+ }
+ Optional<String> allocatedSwitch = nodeOnSwitch.flatMap(Node::switchHostname);
+ return allocatedSwitch.isEmpty() || switchCount.get(allocatedSwitch.get()) == 1;
+ });
+ }
+
private void ensureSingleCluster() {
if (isEmpty()) return;