diff options
author | Ola Aunrønning <ola.aunroe@gmail.com> | 2023-10-20 18:13:27 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-10-20 18:13:27 +0200 |
commit | 16b0ac7203d6433e631de558e30622b297879acb (patch) | |
tree | b1ecbe268a94310302c88b9520d88e08d027622c /controller-api | |
parent | 46bd10fe1fbbbbf388155bf72e73ab26fbd0bfab (diff) |
Revert "Move PricingApiHandler and related code to internal repo"
Diffstat (limited to 'controller-api')
7 files changed, 177 insertions, 0 deletions
diff --git a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/MockPricingController.java b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/MockPricingController.java new file mode 100644 index 00000000000..b451df87727 --- /dev/null +++ b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/MockPricingController.java @@ -0,0 +1,64 @@ +// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.vespa.hosted.controller.api.integration; + +import com.yahoo.vespa.hosted.controller.api.integration.billing.Plan; +import com.yahoo.vespa.hosted.controller.api.integration.pricing.ApplicationResources; +import com.yahoo.vespa.hosted.controller.api.integration.pricing.PriceInformation; +import com.yahoo.vespa.hosted.controller.api.integration.pricing.Prices; +import com.yahoo.vespa.hosted.controller.api.integration.pricing.PricingController; +import com.yahoo.vespa.hosted.controller.api.integration.pricing.PricingInfo; + +import java.math.BigDecimal; +import java.util.List; + +import static com.yahoo.vespa.hosted.controller.api.integration.pricing.PricingInfo.SupportLevel.BASIC; +import static java.math.BigDecimal.ZERO; + +public class MockPricingController implements PricingController { + + private static final BigDecimal cpuCost = new BigDecimal("1.00"); + private static final BigDecimal memoryCost = new BigDecimal("0.10"); + private static final BigDecimal diskCost = new BigDecimal("0.005"); + + @Override + public Prices priceForApplications(List<ApplicationResources> applicationResources, PricingInfo pricingInfo, Plan plan) { + List<PriceInformation> appPrices = applicationResources.stream() + .map(resources -> { + BigDecimal listPrice = resources.vcpu().multiply(cpuCost) + .add(resources.memoryGb().multiply(memoryCost)) + .add(resources.diskGb().multiply(diskCost)) + .add(resources.enclaveVcpu().multiply(cpuCost)) + .add(resources.enclaveMemoryGb().multiply(memoryCost)) + .add(resources.enclaveDiskGb().multiply(diskCost)); + + BigDecimal supportLevelCost = pricingInfo.supportLevel() == BASIC ? new BigDecimal("-1.00") : new BigDecimal("8.00"); + BigDecimal listPriceWithSupport = listPrice.add(supportLevelCost); + BigDecimal enclaveDiscount = isEnclave(resources) ? new BigDecimal("-0.15") : BigDecimal.ZERO; + BigDecimal volumeDiscount = new BigDecimal("-0.1"); + BigDecimal appTotalAmount = listPrice.add(supportLevelCost).add(enclaveDiscount).add(volumeDiscount); + + return new PriceInformation(listPriceWithSupport, + volumeDiscount, + ZERO, + enclaveDiscount, + appTotalAmount); + }) + .toList(); + + PriceInformation sum = PriceInformation.sum(appPrices); + System.out.println(pricingInfo.committedHourlyAmount()); + var committedAmountDiscount = pricingInfo.committedHourlyAmount().compareTo(ZERO) > 0 ? new BigDecimal("-0.2") : ZERO; + var totalAmount = sum.totalAmount().add(committedAmountDiscount); + var enclave = ZERO; + if (applicationResources.stream().anyMatch(ApplicationResources::enclave) && totalAmount.compareTo(new BigDecimal("14.00")) < 0) + enclave = new BigDecimal("14.00").subtract(totalAmount); + var totalPrice = new PriceInformation(ZERO, ZERO, committedAmountDiscount, enclave, totalAmount); + + return new Prices(appPrices, totalPrice); + } + + private static boolean isEnclave(ApplicationResources resources) { + return resources.enclaveVcpu().compareTo(ZERO) > 0; + } + +} diff --git a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/pricing/ApplicationResources.java b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/pricing/ApplicationResources.java new file mode 100644 index 00000000000..106d9ab6bbe --- /dev/null +++ b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/pricing/ApplicationResources.java @@ -0,0 +1,33 @@ +package com.yahoo.vespa.hosted.controller.api.integration.pricing; + +import java.math.BigDecimal; + +import static java.math.BigDecimal.ZERO; + +/** + * @param vcpu vcpus summed over all clusters, instances, zones + * @param memoryGb memory in Gb summed over all clusters, instances, zones + * @param diskGb disk in Gb summed over all clusters, instances, zones + * @param gpuMemoryGb GPU memory in Gb summed over all clusters, instances, zones + * @param enclaveVcpu vcpus summed over all clusters, instances, zones + * @param enclaveMemoryGb memory in Gb summed over all clusters, instances, zones + * @param enclaveDiskGb disk in Gb summed over all clusters, instances, zones + * @param enclaveGpuMemoryGb GPU memory in Gb summed over all clusters, instances, zones + */ +public record ApplicationResources(BigDecimal vcpu, BigDecimal memoryGb, BigDecimal diskGb, + BigDecimal gpuMemoryGb, BigDecimal enclaveVcpu, BigDecimal enclaveMemoryGb, + BigDecimal enclaveDiskGb, BigDecimal enclaveGpuMemoryGb) { + + public static ApplicationResources create(BigDecimal vcpu, BigDecimal memoryGb, + BigDecimal diskGb, BigDecimal gpuMemoryGb) { + return new ApplicationResources(vcpu, memoryGb, diskGb, gpuMemoryGb, ZERO, ZERO, ZERO, ZERO); + } + + public static ApplicationResources createEnclave(BigDecimal vcpu, BigDecimal memoryGb, + BigDecimal diskGb, BigDecimal gpuMemoryGb) { + return new ApplicationResources(ZERO, ZERO, ZERO, ZERO, vcpu, memoryGb, diskGb, gpuMemoryGb); + } + + public boolean enclave() { return enclaveVcpu().compareTo(ZERO) > 0; } + +} diff --git a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/pricing/PriceInformation.java b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/pricing/PriceInformation.java new file mode 100644 index 00000000000..50463553f8e --- /dev/null +++ b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/pricing/PriceInformation.java @@ -0,0 +1,29 @@ +// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.vespa.hosted.controller.api.integration.pricing; + +import java.math.BigDecimal; +import java.util.List; + +import static java.math.BigDecimal.ZERO; + +public record PriceInformation(BigDecimal listPriceWithSupport, BigDecimal volumeDiscount, + BigDecimal committedAmountDiscount, BigDecimal enclaveDiscount, BigDecimal totalAmount) { + + public static PriceInformation empty() { return new PriceInformation(ZERO, ZERO, ZERO, ZERO, ZERO); } + + public static PriceInformation sum(List<PriceInformation> priceInformationList) { + var result = PriceInformation.empty(); + for (var prices : priceInformationList) + result = result.add(prices); + return result; + } + + public PriceInformation add(PriceInformation priceInformation) { + return new PriceInformation(this.listPriceWithSupport().add(priceInformation.listPriceWithSupport()), + this.volumeDiscount().add(priceInformation.volumeDiscount()), + this.committedAmountDiscount().add(priceInformation.committedAmountDiscount()), + this.enclaveDiscount().add(priceInformation.enclaveDiscount()), + this.totalAmount().add(priceInformation.totalAmount())); + } + +} diff --git a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/pricing/Prices.java b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/pricing/Prices.java new file mode 100644 index 00000000000..650a07c51e0 --- /dev/null +++ b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/pricing/Prices.java @@ -0,0 +1,8 @@ +// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.vespa.hosted.controller.api.integration.pricing; + +import java.util.List; + +public record Prices(List<PriceInformation> priceInformationApplications, PriceInformation totalPriceInformation) { + +} diff --git a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/pricing/PricingController.java b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/pricing/PricingController.java new file mode 100644 index 00000000000..7b082932588 --- /dev/null +++ b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/pricing/PricingController.java @@ -0,0 +1,24 @@ +// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.vespa.hosted.controller.api.integration.pricing; + +import com.yahoo.vespa.hosted.controller.api.integration.billing.Plan; + +import java.util.List; + +/** + * A service that calculates price information based on cluster resources, plan, service level etc. + * + * @author hmusum + */ +public interface PricingController { + + /** + * + * @param applicationResources resources used by an application + * @param pricingInfo pricing info + * @param plan the plan to use for this calculation + * @return a PriceInformation instance + */ + Prices priceForApplications(List<ApplicationResources> applicationResources, PricingInfo pricingInfo, Plan plan); + +} diff --git a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/pricing/PricingInfo.java b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/pricing/PricingInfo.java new file mode 100644 index 00000000000..ba6f1939fc5 --- /dev/null +++ b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/pricing/PricingInfo.java @@ -0,0 +1,14 @@ +// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.vespa.hosted.controller.api.integration.pricing; + +import java.math.BigDecimal; + +import static java.math.BigDecimal.ZERO; + +public record PricingInfo(SupportLevel supportLevel, BigDecimal committedHourlyAmount) { + + public enum SupportLevel { BASIC, COMMERCIAL, ENTERPRISE } + + public static PricingInfo empty() { return new PricingInfo(SupportLevel.COMMERCIAL, ZERO); } + +} diff --git a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/pricing/package-info.java b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/pricing/package-info.java new file mode 100644 index 00000000000..649ab2a80f4 --- /dev/null +++ b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/pricing/package-info.java @@ -0,0 +1,5 @@ +// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +@ExportPackage +package com.yahoo.vespa.hosted.controller.api.integration.pricing; + +import com.yahoo.osgi.annotation.ExportPackage; |