summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@oath.com>2020-04-24 14:32:14 +0200
committerGitHub <noreply@github.com>2020-04-24 14:32:14 +0200
commit689e1cc264a556196ada763a3f6727e8d80ee1b4 (patch)
treef748a191aeac53337591b6c2c9b4117241f89683
parent43e1abc79588e593262796909d85f3419a78e1ac (diff)
parentfd31eb82f85582bc7563a9fc03b77e2d03879c9c (diff)
Merge pull request #13057 from vespa-engine/bratseth/clear-outdated-suggestions
Clear outdated suggestions
-rw-r--r--node-repository/src/main/java/com/yahoo/vespa/hosted/provision/maintenance/ScalingSuggestionsMaintainer.java31
1 files changed, 21 insertions, 10 deletions
diff --git a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/maintenance/ScalingSuggestionsMaintainer.java b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/maintenance/ScalingSuggestionsMaintainer.java
index f80f2d11753..985c5c7d1a7 100644
--- a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/maintenance/ScalingSuggestionsMaintainer.java
+++ b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/maintenance/ScalingSuggestionsMaintainer.java
@@ -50,23 +50,34 @@ public class ScalingSuggestionsMaintainer extends Maintainer {
suggest(application, clusterId, clusterNodes));
}
+ private Applications applications() {
+ return nodeRepository().applications();
+ }
+
private void suggest(ApplicationId applicationId,
ClusterSpec.Id clusterId,
List<Node> clusterNodes) {
- Applications applications = nodeRepository().applications();
- Application application = applications.get(applicationId).orElse(new Application(applicationId));
- Cluster cluster = application.clusters().get(clusterId);
- if (cluster == null) return;
- Optional<AllocatableClusterResources> target = autoscaler.suggest(cluster, clusterNodes);
- if (target.isEmpty()) return;
- ClusterResources suggestion = target.get().toAdvertisedClusterResources();
-
+ Application application = applications().get(applicationId).orElse(new Application(applicationId));
+ Optional<Cluster> cluster = application.cluster(clusterId);
+ if (cluster.isEmpty()) return;
+ Optional<AllocatableClusterResources> suggestion = autoscaler.suggest(cluster.get(), clusterNodes);
try (Mutex lock = nodeRepository().lock(applicationId)) {
- applications.get(applicationId).ifPresent(a -> a.cluster(clusterId).ifPresent(c ->
- applications.put(a.with(c.withSuggested(suggestion)), lock)));
+ applications().get(applicationId).ifPresent(a -> storeSuggestion(suggestion, clusterId, a, lock));
}
}
+ private void storeSuggestion(Optional<AllocatableClusterResources> suggestion,
+ ClusterSpec.Id clusterId,
+ Application application,
+ Mutex lock) {
+ Optional<Cluster> cluster = application.cluster(clusterId);
+ if (cluster.isEmpty()) return;
+ if (suggestion.isPresent())
+ applications().put(application.with(cluster.get().withSuggested(suggestion.get().toAdvertisedClusterResources())), lock);
+ else
+ applications().put(application.with(cluster.get().withoutSuggested()), lock);
+ }
+
private Map<ClusterSpec.Id, List<Node>> nodesByCluster(List<Node> applicationNodes) {
return applicationNodes.stream().collect(Collectors.groupingBy(n -> n.allocation().get().membership().cluster().id()));
}