summaryrefslogtreecommitdiffstats
path: root/node-repository
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@verizonmedia.com>2020-03-04 15:31:19 +0100
committerJon Bratseth <bratseth@verizonmedia.com>2020-03-04 15:31:19 +0100
commit34548b00db9cb5865da3180afc080861ada47e2e (patch)
tree22658f46b95e2fb92f1ffc61c30ffe98b3aba255 /node-repository
parent0e4e9560853d49f9d0a061a7ca8a13ee8f357142 (diff)
Simplify
Diffstat (limited to 'node-repository')
-rw-r--r--node-repository/src/main/java/com/yahoo/vespa/hosted/provision/autoscale/Autoscaler.java21
1 files changed, 9 insertions, 12 deletions
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 443fd0574d4..5986b80f519 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
@@ -140,23 +140,20 @@ public class Autoscaler {
}
else {
// return the cheapest flavor satisfying the target resources, if any
- double bestCost = Double.MAX_VALUE;
- Optional<Flavor> bestFlavor = Optional.empty();
+ Optional<AllocatableClusterResources> best = Optional.empty();
for (Flavor flavor : nodeRepository.getAvailableFlavors().getFlavors()) {
if ( ! flavor.resources().satisfies(resources.nodeResources())) continue;
+
if (flavor.resources().storageType() == NodeResources.StorageType.remote)
flavor = flavor.with(FlavorOverrides.ofDisk(resources.nodeResources().diskGb()));
- if (bestFlavor.isEmpty() || bestCost > costOf(flavor.resources())) {
- bestFlavor = Optional.of(flavor);
- bestCost = costOf(flavor);
- }
+ var candidate = new AllocatableClusterResources(resources.with(flavor.resources()),
+ costOf(flavor) * resources.nodes(),
+ hostResourcesCalculator.availableCapacityOf(flavor.name(), flavor.resources()));
+
+ if (best.isEmpty() || best.get().cost() > costOf(flavor.resources()))
+ best = Optional.of(candidate);
}
- if (bestFlavor.isEmpty())
- return Optional.empty();
- else
- return Optional.of(new AllocatableClusterResources(resources.with(bestFlavor.get().resources()),
- bestCost * resources.nodes(),
- hostResourcesCalculator.availableCapacityOf(bestFlavor.get().name(), bestFlavor.get().resources())));
+ return best;
}
}