diff options
author | Øyvind Grønnesby <oyving@verizonmedia.com> | 2021-01-11 11:06:08 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-11 11:06:08 +0100 |
commit | 381e20b7609eb6557168425089a6a5c948c50554 (patch) | |
tree | f247025d44f3b297a2070a121d3d5e55d14bc22f /controller-api | |
parent | 4828fe72bddc270e927993289e558dec64020b17 (diff) | |
parent | dffb179172ec88231ad8e4ebd2b36b3437a514f8 (diff) |
Merge pull request #15958 from vespa-engine/ogronnesby/plan-interface
Extract Plan as an interface
Diffstat (limited to 'controller-api')
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; + } + +} |