diff options
author | Harald Musum <musum@yahooinc.com> | 2023-10-20 14:36:41 +0200 |
---|---|---|
committer | Harald Musum <musum@yahooinc.com> | 2023-10-21 07:54:25 +0200 |
commit | 72ce49c81b93126a1136f2a4bcb8b7a76a5ca013 (patch) | |
tree | 37c8e940004f64ac2fa0fe538749f36ce354db8b /controller-api | |
parent | 80d99d306cdf46eed3ff41ab5783b9f3a5dcf5df (diff) |
Move PricingApiHandler and related code to internal repo
Diffstat (limited to 'controller-api')
7 files changed, 0 insertions, 177 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 deleted file mode 100644 index b451df87727..00000000000 --- a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/MockPricingController.java +++ /dev/null @@ -1,64 +0,0 @@ -// 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 deleted file mode 100644 index 106d9ab6bbe..00000000000 --- a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/pricing/ApplicationResources.java +++ /dev/null @@ -1,33 +0,0 @@ -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 deleted file mode 100644 index 50463553f8e..00000000000 --- a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/pricing/PriceInformation.java +++ /dev/null @@ -1,29 +0,0 @@ -// 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 deleted file mode 100644 index 650a07c51e0..00000000000 --- a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/pricing/Prices.java +++ /dev/null @@ -1,8 +0,0 @@ -// 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 deleted file mode 100644 index 7b082932588..00000000000 --- a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/pricing/PricingController.java +++ /dev/null @@ -1,24 +0,0 @@ -// 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 deleted file mode 100644 index ba6f1939fc5..00000000000 --- a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/pricing/PricingInfo.java +++ /dev/null @@ -1,14 +0,0 @@ -// 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 deleted file mode 100644 index 649ab2a80f4..00000000000 --- a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/pricing/package-info.java +++ /dev/null @@ -1,5 +0,0 @@ -// 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; |