diff options
author | Jon Bratseth <bratseth@verizonmedia.com> | 2020-03-27 12:57:10 +0100 |
---|---|---|
committer | Jon Bratseth <bratseth@verizonmedia.com> | 2020-03-27 12:57:10 +0100 |
commit | bcaf74cc7cddd26f315ea9c60ceb8a5f9b665168 (patch) | |
tree | e45f781aaedd60fbc95413dd331031be4145556e /node-repository/src/main/java/com/yahoo/vespa/hosted/provision/applications/Application.java | |
parent | e63f7068d3716ef7aa174d6ae7c9a5a5dd754ee3 (diff) |
Maintain application min, max and target resources
Diffstat (limited to 'node-repository/src/main/java/com/yahoo/vespa/hosted/provision/applications/Application.java')
-rw-r--r-- | node-repository/src/main/java/com/yahoo/vespa/hosted/provision/applications/Application.java | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/applications/Application.java b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/applications/Application.java new file mode 100644 index 00000000000..7dd2dc7be17 --- /dev/null +++ b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/applications/Application.java @@ -0,0 +1,37 @@ +// 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.applications; + +import com.yahoo.config.provision.ClusterResources; +import com.yahoo.config.provision.ClusterSpec; +import com.yahoo.transaction.Mutex; + +import java.util.Map; +import java.util.HashMap; +import java.util.Optional; + +/** + * The node repository's view of an application deployment. + * + * This is immutable, and must be locked with the application lock on read-modify-write. + * + * @author bratseth + */ +public class Application { + + private Map<ClusterSpec.Id, Cluster> clusters = new HashMap<>(); + + /** Returns the cluster with the given id or null if none */ + public Cluster cluster(ClusterSpec.Id id) { return clusters.get(id); } + + /** + * Sets the min and max resource limits of the given cluster. + * This will create the cluster with these limits if it does not exist. + * If the cluster has a target which is not inside the new limits, the target is removed. + */ + public void setClusterLimits(ClusterSpec.Id id, ClusterResources min, ClusterResources max, Mutex applicationLock) { + Cluster cluster = clusters.computeIfAbsent(id, clusterId -> new Cluster(min, max, Optional.empty())); + if (cluster.targetResources().isPresent() && ! cluster.targetResources().get().isWithin(min, max)) + clusters.put(id, cluster.withoutTarget()); + } + +} |