diff options
author | Øyvind Grønnesby <oyving@verizonmedia.com> | 2020-08-26 09:02:21 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-08-26 09:02:21 +0200 |
commit | 4746dcd27ad567eb6f00adf773e9ac8fd55ffd35 (patch) | |
tree | c70124061c2fb64397b99b5fd1c42a18897bd793 /config-model-api | |
parent | 1fd041abeebe0fc9749df5dcf9e2649374624786 (diff) |
Quotas in the configuration server (#14088)
* Create a quota JSON encoded parameter
* Propagate quota from PrepareParams to ModelContext.Properties
* Persist quota and read it back
* Check maxClusterSize quota in Validator step
* Default to Quota.empty() in TestProperties
* Javadoc and authors
* Fix parameter type after it was changed on master
Co-authored-by: Andreas Eriksen <andreer@verizonmedia.com>
Diffstat (limited to 'config-model-api')
-rw-r--r-- | config-model-api/src/main/java/com/yahoo/config/model/api/ModelContext.java | 5 | ||||
-rw-r--r-- | config-model-api/src/main/java/com/yahoo/config/model/api/Quota.java | 72 |
2 files changed, 77 insertions, 0 deletions
diff --git a/config-model-api/src/main/java/com/yahoo/config/model/api/ModelContext.java b/config-model-api/src/main/java/com/yahoo/config/model/api/ModelContext.java index 64a2906b1be..413a7dbc62e 100644 --- a/config-model-api/src/main/java/com/yahoo/config/model/api/ModelContext.java +++ b/config-model-api/src/main/java/com/yahoo/config/model/api/ModelContext.java @@ -121,6 +121,11 @@ public interface ModelContext { // TODO(bjorncs): Temporary feature flag default double feedCoreThreadPoolSizeFactor() { return 1.0; } + + default Quota quota() { + return Quota.empty(); + } + } } diff --git a/config-model-api/src/main/java/com/yahoo/config/model/api/Quota.java b/config-model-api/src/main/java/com/yahoo/config/model/api/Quota.java new file mode 100644 index 00000000000..cb600bc0a5e --- /dev/null +++ b/config-model-api/src/main/java/com/yahoo/config/model/api/Quota.java @@ -0,0 +1,72 @@ +// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.config.model.api; + +import com.yahoo.slime.Inspector; +import com.yahoo.slime.Slime; +import com.yahoo.slime.SlimeUtils; + +import java.util.Objects; +import java.util.Optional; + +/** + * Quota for the application deployed. If the application exceeds this quota, deployment will fail. + * + * @author ogronnesby + */ +public class Quota { + private final Optional<Integer> maxClusterSize; + private final Optional<Integer> budget; + + public Quota(Optional<Integer> maybeClusterSize, Optional<Integer> budget) { + this.maxClusterSize = maybeClusterSize; + this.budget = budget; + } + + public static Quota fromSlime(Inspector inspector) { + var clusterSize = SlimeUtils.optionalLong(inspector.field("clusterSize")); + var budget = SlimeUtils.optionalLong(inspector.field("budget")); + return new Quota(clusterSize.map(Long::intValue), budget.map(Long::intValue)); + } + + public Slime toSlime() { + var slime = new Slime(); + var root = slime.setObject(); + maxClusterSize.ifPresent(clusterSize -> root.setLong("clusterSize", clusterSize)); + budget.ifPresent(b -> root.setLong("budget", b)); + return slime; + } + + public static Quota empty() { + return new Quota(Optional.empty(), Optional.empty()); + } + + public Optional<Integer> maxClusterSize() { + return maxClusterSize; + } + + public Optional<Integer> budget() { + return budget; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + Quota quota = (Quota) o; + return Objects.equals(maxClusterSize, quota.maxClusterSize) && + Objects.equals(budget, quota.budget); + } + + @Override + public int hashCode() { + return Objects.hash(maxClusterSize, budget); + } + + @Override + public String toString() { + return "Quota{" + + "maxClusterSize=" + maxClusterSize + + ", budget=" + budget + + '}'; + } +} |