diff options
author | Martin Polden <mpolden@mpolden.no> | 2021-05-21 09:47:48 +0200 |
---|---|---|
committer | Martin Polden <mpolden@mpolden.no> | 2021-05-21 10:47:13 +0200 |
commit | b8e9735ff10b38c52b4493862d97b6c03715f04c (patch) | |
tree | 4020cbb6419b94705870af84a97d37562b852ccf /node-repository | |
parent | 21f844e80b416aa011402bb664059b54acb09924 (diff) |
Pull up and reuse ClusterId
Diffstat (limited to 'node-repository')
3 files changed, 62 insertions, 70 deletions
diff --git a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/maintenance/MetricsReporter.java b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/maintenance/MetricsReporter.java index a2e02c15737..85437b3e78a 100644 --- a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/maintenance/MetricsReporter.java +++ b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/maintenance/MetricsReporter.java @@ -19,6 +19,7 @@ import com.yahoo.vespa.hosted.provision.Node.State; import com.yahoo.vespa.hosted.provision.NodeList; import com.yahoo.vespa.hosted.provision.NodeRepository; import com.yahoo.vespa.hosted.provision.node.Allocation; +import com.yahoo.vespa.hosted.provision.node.ClusterId; import com.yahoo.vespa.hosted.provision.node.History; import com.yahoo.vespa.hosted.provision.persistence.CacheStats; import com.yahoo.vespa.orchestrator.Orchestrator; @@ -30,7 +31,6 @@ import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; -import java.util.Objects; import java.util.Optional; import java.util.Set; import java.util.function.Function; @@ -84,11 +84,11 @@ public class MetricsReporter extends NodeRepositoryMaintainer { } private void updateAllocationMetrics(NodeList nodes) { - Map<ClusterKey, List<Node>> byCluster = nodes.stream() - .filter(node -> node.allocation().isPresent()) - .filter(node -> !node.allocation().get().owner().instance().isTester()) - .collect(Collectors.groupingBy(node -> new ClusterKey(node.allocation().get().owner(), node.allocation().get().membership().cluster().id()))); - byCluster.forEach((clusterKey, allocatedNodes) -> { + Map<ClusterId, List<Node>> byCluster = nodes.stream() + .filter(node -> node.allocation().isPresent()) + .filter(node -> !node.allocation().get().owner().instance().isTester()) + .collect(Collectors.groupingBy(node -> new ClusterId(node.allocation().get().owner(), node.allocation().get().membership().cluster().id()))); + byCluster.forEach((clusterId, allocatedNodes) -> { int activeNodes = 0; int nonActiveNodes = 0; for (var node : allocatedNodes) { @@ -104,7 +104,7 @@ public class MetricsReporter extends NodeRepositoryMaintainer { } else { nonActiveFraction = (double) nonActiveNodes / ((double) activeNodes + (double) nonActiveNodes); } - Metric.Context context = getContext(dimensions(clusterKey.application, clusterKey.cluster)); + Metric.Context context = getContext(dimensions(clusterId.application(), clusterId.cluster())); metric.set("nodes.active", activeNodes, context); metric.set("nodes.nonActive", nonActiveNodes, context); metric.set("nodes.nonActiveFraction", nonActiveFraction, context); @@ -112,16 +112,16 @@ public class MetricsReporter extends NodeRepositoryMaintainer { } private void updateExclusiveSwitchMetrics(NodeList nodes) { - Map<ClusterKey, List<Node>> byCluster = nodes.stream() + Map<ClusterId, List<Node>> byCluster = nodes.stream() .filter(node -> node.type() == NodeType.tenant) .filter(node -> node.state() == State.active) .filter(node -> node.allocation().isPresent()) - .collect(Collectors.groupingBy(node -> new ClusterKey(node.allocation().get().owner(), node.allocation().get().membership().cluster().id()))); - byCluster.forEach((clusterKey, clusterNodes) -> { + .collect(Collectors.groupingBy(node -> new ClusterId(node.allocation().get().owner(), node.allocation().get().membership().cluster().id()))); + byCluster.forEach((clusterId, clusterNodes) -> { NodeList clusterHosts = nodes.parentsOf(NodeList.copyOf(clusterNodes)); long nodesOnExclusiveSwitch = NodeList.copyOf(clusterNodes).onExclusiveSwitch(clusterHosts).size(); double exclusiveSwitchRatio = nodesOnExclusiveSwitch / (double) clusterNodes.size(); - metric.set("nodes.exclusiveSwitchFraction", exclusiveSwitchRatio, getContext(dimensions(clusterKey.application, clusterKey.cluster))); + metric.set("nodes.exclusiveSwitchFraction", exclusiveSwitchRatio, getContext(dimensions(clusterId.application(), clusterId.cluster()))); }); } @@ -390,30 +390,4 @@ public class MetricsReporter extends NodeRepositoryMaintainer { .reduce(host.flavor().resources().justNumbers(), NodeResources::subtract); } - private static class ClusterKey { - - private final ApplicationId application; - private final ClusterSpec.Id cluster; - - public ClusterKey(ApplicationId application, ClusterSpec.Id cluster) { - this.application = application; - this.cluster = cluster; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - ClusterKey that = (ClusterKey) o; - return application.equals(that.application) && - cluster.equals(that.cluster); - } - - @Override - public int hashCode() { - return Objects.hash(application, cluster); - } - - } - } diff --git a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/node/ClusterId.java b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/node/ClusterId.java new file mode 100644 index 00000000000..ec9e4dc981b --- /dev/null +++ b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/node/ClusterId.java @@ -0,0 +1,50 @@ +// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.vespa.hosted.provision.node; + +import com.yahoo.config.provision.ApplicationId; +import com.yahoo.config.provision.ClusterSpec; + +import java.util.Objects; + +/** + * Identifies a cluster in an application. + * + * @author mpolden + */ +public class ClusterId { + + private final ApplicationId application; + private final ClusterSpec.Id cluster; + + public ClusterId(ApplicationId application, ClusterSpec.Id cluster) { + this.application = Objects.requireNonNull(application); + this.cluster = Objects.requireNonNull(cluster); + } + + public ApplicationId application() { + return application; + } + + public ClusterSpec.Id cluster() { + return cluster; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + ClusterId that = (ClusterId) o; + return application.equals(that.application) && cluster.equals(that.cluster); + } + + @Override + public int hashCode() { + return Objects.hash(application, cluster); + } + + @Override + public String toString() { + return cluster + " of " + application; + } + +} diff --git a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/os/RebuildingOsUpgrader.java b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/os/RebuildingOsUpgrader.java index 4e401042a67..6030f654a80 100644 --- a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/os/RebuildingOsUpgrader.java +++ b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/os/RebuildingOsUpgrader.java @@ -2,8 +2,6 @@ package com.yahoo.vespa.hosted.provision.os; import com.yahoo.component.Version; -import com.yahoo.config.provision.ApplicationId; -import com.yahoo.config.provision.ClusterSpec; import com.yahoo.config.provision.NodeType; import com.yahoo.vespa.flags.IntFlag; import com.yahoo.vespa.flags.PermanentFlags; @@ -12,6 +10,7 @@ import com.yahoo.vespa.hosted.provision.NodeList; import com.yahoo.vespa.hosted.provision.NodeRepository; import com.yahoo.vespa.hosted.provision.node.Agent; import com.yahoo.vespa.hosted.provision.node.Allocation; +import com.yahoo.vespa.hosted.provision.node.ClusterId; import com.yahoo.vespa.hosted.provision.node.filter.NodeListFilter; import java.time.Instant; @@ -19,7 +18,6 @@ import java.util.ArrayList; import java.util.Collections; import java.util.HashSet; import java.util.List; -import java.util.Objects; import java.util.Optional; import java.util.Set; import java.util.logging.Logger; @@ -116,34 +114,4 @@ public class RebuildingOsUpgrader implements OsUpgrader { throw new IllegalArgumentException(msg); } - private static class ClusterId { - - private final ApplicationId application; - private final ClusterSpec.Id cluster; - - public ClusterId(ApplicationId application, ClusterSpec.Id cluster) { - this.application = Objects.requireNonNull(application); - this.cluster = Objects.requireNonNull(cluster); - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - ClusterId that = (ClusterId) o; - return application.equals(that.application) && cluster.equals(that.cluster); - } - - @Override - public int hashCode() { - return Objects.hash(application, cluster); - } - - @Override - public String toString() { - return cluster + " of " + application; - } - - } - } |