aboutsummaryrefslogtreecommitdiffstats
path: root/controller-api
diff options
context:
space:
mode:
authorØyvind Grønnesby <oyving@verizonmedia.com>2020-10-01 12:23:53 +0200
committerØyvind Grønnesby <oyving@verizonmedia.com>2020-10-01 12:23:53 +0200
commite8f8420eab675350e61260578bd10228645c51f1 (patch)
tree6d37b1f22b7ce6717b485f6c9452267fa98e0ec4 /controller-api
parent58a92e118482272de89bb6b9046daaaab00f42ac (diff)
Quota as BigDecimals in the controller
- Added support for BigDecimal flags - Changed internal representation of quota budget to BigDecimal - Changed flag type for TENANT_BUDGET_QUOTA to BigDecimal. Since flag is not in use this should not cause any issues.
Diffstat (limited to 'controller-api')
-rw-r--r--controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/billing/MockBillingController.java2
-rw-r--r--controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/billing/Quota.java53
2 files changed, 29 insertions, 26 deletions
diff --git a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/billing/MockBillingController.java b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/billing/MockBillingController.java
index 5db89ccc656..19dfe0d9dcc 100644
--- a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/billing/MockBillingController.java
+++ b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/billing/MockBillingController.java
@@ -33,7 +33,7 @@ public class MockBillingController implements BillingController {
@Override
public Optional<Quota> getQuota(TenantName tenant, Environment environment) {
- return Optional.of(new Quota(5));
+ return Optional.of(Quota.unlimited().withMaxClusterSize(5));
}
@Override
diff --git a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/billing/Quota.java b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/billing/Quota.java
index 4e1efc1b6d9..511d7bf1d09 100644
--- a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/billing/Quota.java
+++ b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/billing/Quota.java
@@ -1,57 +1,60 @@
// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.hosted.controller.api.integration.billing;
+import java.math.BigDecimal;
import java.util.Objects;
import java.util.Optional;
+import java.util.OptionalInt;
/**
- * Quota information transmitted to the configserver on deploy.
+ * Quota information transmitted to the configserver on deploy. All limits are represented
+ * with an Optional type where the empty optional means unlimited resource use.
*
* @author andreer
* @author ogronnesby
*/
public class Quota {
- private static final Quota UNLIMITED = new Quota(Optional.empty(), Optional.empty());
- private static final Quota ZERO = new Quota(0, 0);
+ private static final Quota UNLIMITED = new Quota(OptionalInt.empty(), Optional.empty());
+ private static final Quota ZERO = new Quota(OptionalInt.of(0), Optional.of(BigDecimal.ZERO));
- private final Optional<Integer> maxClusterSize;
- private final Optional<Integer> budget; // in USD/hr, as calculated by NodeResources
+ private final OptionalInt maxClusterSize;
+ private final Optional<BigDecimal> budget; // in USD/hr, as calculated by NodeResources
- public Quota(int maxClusterSize) {
- this(Optional.of(maxClusterSize), Optional.empty());
- }
-
- public Quota(int maxClusterSize, int dollarsPerHour) {
- this(Optional.of(maxClusterSize), Optional.of(dollarsPerHour));
- }
-
- public Quota(Optional<Integer> maxClusterSize, Optional<Integer> budget) {
+ private Quota(OptionalInt maxClusterSize, Optional<BigDecimal> budget) {
this.maxClusterSize = Objects.requireNonNull(maxClusterSize);
this.budget = Objects.requireNonNull(budget);
}
- public Optional<Integer> maxClusterSize() {
- return maxClusterSize;
+ public Quota withMaxClusterSize(int clusterSize) {
+ return new Quota(OptionalInt.of(clusterSize), budget);
}
- public Optional<Integer> budget() {
- return budget;
+ /** Construct a Quota that allows zero resource usage */
+ public static Quota zero() {
+ return ZERO;
}
- public Quota withMaxClusterSize(int clusterSize) {
- return new Quota(Optional.of(clusterSize), budget);
+ /** Construct a Quota that allows unlimited resource usage */
+ public static Quota unlimited() {
+ return UNLIMITED;
+ }
+
+ public Quota withBudget(BigDecimal budget) {
+ return new Quota(maxClusterSize, Optional.ofNullable(budget));
}
public Quota withBudget(int budget) {
- return new Quota(maxClusterSize, Optional.of(budget));
+ return withBudget(BigDecimal.valueOf(budget));
}
- public static Quota zero() {
- return ZERO;
+ /** Maximum number of nodes in a cluster in a Vespa deployment */
+ public OptionalInt maxClusterSize() {
+ return maxClusterSize;
}
- public static Quota unlimited() {
- return UNLIMITED;
+ /** Maximum $/hour run-rate for the Vespa deployment */
+ public Optional<BigDecimal> budget() {
+ return budget;
}
@Override