diff options
author | Jon Bratseth <bratseth@verizonmedia.com> | 2020-03-24 12:47:27 +0100 |
---|---|---|
committer | Jon Bratseth <bratseth@verizonmedia.com> | 2020-03-24 12:47:27 +0100 |
commit | 273a5429afa90f90c7e9fd9c7a954d0633e2eaf1 (patch) | |
tree | 8bd6d018b14a7020ef6a1faca1bbd8c98f78ae43 /node-repository | |
parent | 17b97e1650314a2cb33235564921ccc62c6f9579 (diff) |
Pass clusterType
Diffstat (limited to 'node-repository')
5 files changed, 25 insertions, 20 deletions
diff --git a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/autoscale/AllocatableClusterResources.java b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/autoscale/AllocatableClusterResources.java index d2fa773a5a2..40af5f43312 100644 --- a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/autoscale/AllocatableClusterResources.java +++ b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/autoscale/AllocatableClusterResources.java @@ -1,6 +1,7 @@ // 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.autoscale; +import com.yahoo.config.provision.ClusterSpec; import com.yahoo.config.provision.Flavor; import com.yahoo.config.provision.NodeResources; import com.yahoo.vespa.hosted.provision.Node; @@ -22,11 +23,14 @@ public class AllocatableClusterResources { private final NodeResources realResources; private final NodeResources advertisedResources; + private final ClusterSpec.Type clusterType; + public AllocatableClusterResources(List<Node> nodes, HostResourcesCalculator calculator) { this.advertisedResources = nodes.get(0).flavor().resources(); this.realResources = calculator.realResourcesOf(nodes.get(0)); this.nodes = nodes.size(); this.groups = (int)nodes.stream().map(node -> node.allocation().get().membership().cluster().group()).distinct().count(); + this.clusterType = nodes.get(0).allocation().get().membership().cluster().type(); } public AllocatableClusterResources(ClusterResources realResources, NodeResources advertisedResources) { @@ -34,6 +38,7 @@ public class AllocatableClusterResources { this.advertisedResources = advertisedResources; this.nodes = realResources.nodes(); this.groups = realResources.groups(); + this.clusterType = realResources.clusterType(); } public AllocatableClusterResources(ClusterResources realResources, Flavor flavor, HostResourcesCalculator calculator) { @@ -41,6 +46,7 @@ public class AllocatableClusterResources { this.advertisedResources = calculator.advertisedResourcesOf(flavor); this.nodes = realResources.nodes(); this.groups = realResources.groups(); + this.clusterType = realResources.clusterType(); } /** @@ -59,6 +65,7 @@ public class AllocatableClusterResources { public int nodes() { return nodes; } public int groups() { return groups; } + public ClusterSpec.Type clusterType() { return clusterType; } @Override public String toString() { diff --git a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/autoscale/Autoscaler.java b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/autoscale/Autoscaler.java index 18d1a4b4ca0..0e70178f71e 100644 --- a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/autoscale/Autoscaler.java +++ b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/autoscale/Autoscaler.java @@ -82,8 +82,7 @@ public class Autoscaler { Optional<AllocatableClusterResources> bestAllocation = findBestAllocation(cpuLoad.get(), memoryLoad.get(), diskLoad.get(), - currentAllocation, - clusterType); + currentAllocation); if (bestAllocation.isEmpty()) return Optional.empty(); if (closeToIdeal(Resource.cpu, cpuLoad.get()) && @@ -96,12 +95,11 @@ public class Autoscaler { } private Optional<AllocatableClusterResources> findBestAllocation(double cpuLoad, double memoryLoad, double diskLoad, - AllocatableClusterResources currentAllocation, - ClusterSpec.Type clusterType) { + AllocatableClusterResources currentAllocation) { Optional<AllocatableClusterResources> bestAllocation = Optional.empty(); for (ResourceIterator i = new ResourceIterator(cpuLoad, memoryLoad, diskLoad, currentAllocation); i.hasNext(); ) { ClusterResources allocation = i.next(); - Optional<AllocatableClusterResources> allocatableResources = toAllocatableResources(allocation, clusterType); + Optional<AllocatableClusterResources> allocatableResources = toAllocatableResources(allocation); if (allocatableResources.isEmpty()) continue; if (bestAllocation.isEmpty() || allocatableResources.get().cost() < bestAllocation.get().cost()) bestAllocation = allocatableResources; @@ -125,9 +123,9 @@ public class Autoscaler { * Returns the smallest allocatable node resources larger than the given node resources, * or empty if none available. */ - private Optional<AllocatableClusterResources> toAllocatableResources(ClusterResources resources, - ClusterSpec.Type clusterType) { - NodeResources nodeResources = nodeResourceLimits.enlargeToLegal(resources.nodeResources(), clusterType); + private Optional<AllocatableClusterResources> toAllocatableResources(ClusterResources resources) { + NodeResources nodeResources = nodeResourceLimits.enlargeToLegal(resources.nodeResources(), + resources.clusterType()); if (allowsHostSharing(nodeRepository.zone().cloud())) { // return the requested resources, or empty if they cannot fit on existing hosts for (Flavor flavor : nodeRepository.getAvailableFlavors().getFlavors()) { diff --git a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/autoscale/ClusterResources.java b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/autoscale/ClusterResources.java index e068b4404d8..ebceba8c97f 100644 --- a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/autoscale/ClusterResources.java +++ b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/autoscale/ClusterResources.java @@ -1,6 +1,7 @@ // 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.autoscale; +import com.yahoo.config.provision.ClusterSpec; import com.yahoo.config.provision.NodeResources; import com.yahoo.vespa.hosted.provision.Node; @@ -19,25 +20,24 @@ public class ClusterResources { /** The resources of each node in the cluster */ private final NodeResources nodeResources; - public ClusterResources(List<Node> nodes) { - this(nodes.size(), - (int)nodes.stream().map(node -> node.allocation().get().membership().cluster().group()).distinct().count(), - nodes.get(0).flavor().resources()); - } + /** The kind of cluster these resources are for */ + private final ClusterSpec.Type clusterType; - public ClusterResources(int nodes, int groups, NodeResources nodeResources) { + public ClusterResources(int nodes, int groups, NodeResources nodeResources, ClusterSpec.Type clusterType) { this.nodes = nodes; this.groups = groups; this.nodeResources = nodeResources; + this.clusterType = clusterType; } /** Returns the total number of allocated nodes (over all groups) */ public int nodes() { return nodes; } public int groups() { return groups; } public NodeResources nodeResources() { return nodeResources; } + public ClusterSpec.Type clusterType() { return clusterType; } public ClusterResources with(NodeResources resources) { - return new ClusterResources(nodes, groups, resources); + return new ClusterResources(nodes, groups, resources, clusterType); } @Override @@ -49,17 +49,18 @@ public class ClusterResources { if (other.nodes != this.nodes) return false; if (other.groups != this.groups) return false; if (other.nodeResources != this.nodeResources) return false; + if (other.clusterType != this.clusterType) return false; return true; } @Override public int hashCode() { - return Objects.hash(nodes, groups, nodeResources); + return Objects.hash(nodes, groups, nodeResources, clusterType); } @Override public String toString() { - return "cluster resources: " + nodes + " * " + nodeResources + (groups > 1 ? " in " + groups + " groups" : ""); + return clusterType + " cluster resources: " + nodes + " * " + nodeResources + (groups > 1 ? " in " + groups + " groups" : ""); } } diff --git a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/autoscale/NodeMetricsDb.java b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/autoscale/NodeMetricsDb.java index c86546a7790..75bc73df5b0 100644 --- a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/autoscale/NodeMetricsDb.java +++ b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/autoscale/NodeMetricsDb.java @@ -11,10 +11,8 @@ import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Objects; -import java.util.Set; import java.util.logging.Logger; import java.util.stream.Collectors; -import java.util.stream.Stream; /** * An in-memory time-series "database" of node metrics. diff --git a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/autoscale/ResourceIterator.java b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/autoscale/ResourceIterator.java index 8294d68aa36..9003ba086f2 100644 --- a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/autoscale/ResourceIterator.java +++ b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/autoscale/ResourceIterator.java @@ -58,7 +58,8 @@ public class ResourceIterator { int nodesWithRedundancy = currentNodes - (singleGroupMode ? 1 : groupSize); ClusterResources next = new ClusterResources(currentNodes, singleGroupMode ? 1 : currentNodes / groupSize, - resourcesFor(nodesWithRedundancy)); + resourcesFor(nodesWithRedundancy), + allocation.clusterType()); currentNodes += nodeIncrement; return next; } |