diff options
author | Øyvind Grønnesby <oyving@verizonmedia.com> | 2021-01-08 09:30:07 +0100 |
---|---|---|
committer | Øyvind Grønnesby <oyving@verizonmedia.com> | 2021-01-08 09:30:07 +0100 |
commit | dffb179172ec88231ad8e4ebd2b36b3437a514f8 (patch) | |
tree | c441a7b23291bacea57bd15f28f6bbc26bfc74b8 | |
parent | fad9a3d1557aa43598ffbed999f1ea20c8b711ac (diff) |
Extract Plan as an interface
We need to talk about plans, quotas, and cost in more places in the code base. To prepare for this
I have extracted Plan as an interface and mad the old enum implement this. Some other interfaces used
by plan have been moved as well.
4 files changed, 106 insertions, 0 deletions
diff --git a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/billing/CostCalculator.java b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/billing/CostCalculator.java new file mode 100644 index 00000000000..7224e6aecdd --- /dev/null +++ b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/billing/CostCalculator.java @@ -0,0 +1,19 @@ +// 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 com.yahoo.config.provision.NodeResources; +import com.yahoo.vespa.hosted.controller.api.integration.resource.CostInfo; +import com.yahoo.vespa.hosted.controller.api.integration.resource.ResourceUsage; + +/** + * @author ogronnesby + */ +public interface CostCalculator { + + /** Calculate the cost for the given usage */ + CostInfo calculate(ResourceUsage usage); + + /** Estimate the cost for the given resources */ + double calculate(NodeResources resources); + +} diff --git a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/billing/Plan.java b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/billing/Plan.java new file mode 100644 index 00000000000..0df7fcefabe --- /dev/null +++ b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/billing/Plan.java @@ -0,0 +1,24 @@ +// 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; + +/** + * A Plan knows about the billing calculations and the default quota for any tenant associated with the Plan. + * The Plan can also enforce transitions from one plan to another. + * + * @author ogronnesby + */ +public interface Plan { + + /** Unique ID for the plan */ + PlanId id(); + + /** A string to be used for display purposes */ + String displayName(); + + /** The cost calculator for this plan */ + CostCalculator calculator(); + + /** The quota for this plan */ + QuotaCalculator quota(); + +} diff --git a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/billing/QuotaCalculator.java b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/billing/QuotaCalculator.java new file mode 100644 index 00000000000..69375969d58 --- /dev/null +++ b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/billing/QuotaCalculator.java @@ -0,0 +1,11 @@ +package com.yahoo.vespa.hosted.controller.api.integration.billing; + +/** + * Calculates the quota. This is used in the context of a {@link Plan}. + * + * @author ogronnesby + */ +public interface QuotaCalculator { + /** Calculate the quota for a given environment */ + Quota calculate(); +} diff --git a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/resource/ResourceUsage.java b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/resource/ResourceUsage.java new file mode 100644 index 00000000000..633a75d070c --- /dev/null +++ b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/resource/ResourceUsage.java @@ -0,0 +1,52 @@ +package com.yahoo.vespa.hosted.controller.api.integration.resource; + +import com.yahoo.config.provision.ApplicationId; +import com.yahoo.config.provision.zone.ZoneId; +import com.yahoo.vespa.hosted.controller.api.integration.billing.Plan; + +import java.math.BigDecimal; + +public class ResourceUsage { + + private final ApplicationId applicationId; + private final ZoneId zoneId; + private final Plan plan; + private final BigDecimal cpuMillis; + private final BigDecimal memoryMillis; + private final BigDecimal diskMillis; + + public ResourceUsage(ApplicationId applicationId, ZoneId zoneId, Plan plan, + BigDecimal cpuMillis, BigDecimal memoryMillis, BigDecimal diskMillis) { + this.applicationId = applicationId; + this.zoneId = zoneId; + this.cpuMillis = cpuMillis; + this.memoryMillis = memoryMillis; + this.diskMillis = diskMillis; + this.plan = plan; + } + + public ApplicationId getApplicationId() { + return applicationId; + } + + public ZoneId getZoneId() { + return zoneId; + } + + public BigDecimal getCpuMillis() { + return cpuMillis; + } + + public BigDecimal getMemoryMillis() { + return memoryMillis; + } + + public BigDecimal getDiskMillis() { + return diskMillis; + } + + public Plan getPlan() { + return plan; + } + +} |