From 65fe9777bea1a3e75b2ada1429da2d242cc6291d Mon Sep 17 00:00:00 2001 From: Harald Musum Date: Thu, 12 Oct 2023 14:56:56 +0200 Subject: Support price calculations with more than 1 app --- .../api/integration/MockPricingController.java | 34 ++++++++++++++++++---- .../integration/pricing/ApplicationResources.java | 16 ++++++++++ .../pricing/PriceInformationApplications.java | 9 ++++++ .../api/integration/pricing/PricingController.java | 10 +++++++ 4 files changed, 63 insertions(+), 6 deletions(-) create mode 100644 controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/pricing/ApplicationResources.java create mode 100644 controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/pricing/PriceInformationApplications.java (limited to 'controller-api') 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 index f72f80155ed..fc1c6b1e28f 100644 --- 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 @@ -3,6 +3,7 @@ package com.yahoo.vespa.hosted.controller.api.integration; import com.yahoo.config.provision.ClusterResources; 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.PricingController; import com.yahoo.vespa.hosted.controller.api.integration.pricing.PricingInfo; @@ -11,17 +12,19 @@ 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.valueOf; public class MockPricingController implements PricingController { + // TODO: Remove when not in use anymore @Override public PriceInformation price(List clusterResources, PricingInfo pricingInfo, Plan plan) { - BigDecimal listPrice = BigDecimal.valueOf(clusterResources.stream() - .mapToDouble(resources -> resources.nodes() * - (resources.nodeResources().vcpu() * 1000 + - resources.nodeResources().memoryGb() * 100 + - resources.nodeResources().diskGb() * 10)) - .sum()); + BigDecimal listPrice = valueOf(clusterResources.stream() + .mapToDouble(resources -> resources.nodes() * + (resources.nodeResources().vcpu() * 1000 + + resources.nodeResources().memoryGb() * 100 + + resources.nodeResources().diskGb() * 10)) + .sum()); BigDecimal supportLevelCost = pricingInfo.supportLevel() == BASIC ? new BigDecimal("-160.00") : new BigDecimal("800.00"); BigDecimal listPriceWithSupport = listPrice.add(supportLevelCost); @@ -32,4 +35,23 @@ public class MockPricingController implements PricingController { return new PriceInformation(listPriceWithSupport, volumeDiscount, committedAmountDiscount, enclaveDiscount, totalAmount); } + @Override + public PriceInformation priceForApplications(List applicationResources, PricingInfo pricingInfo, Plan plan) { + ApplicationResources resources = applicationResources.get(0); + System.out.println(resources); + BigDecimal listPrice = resources.vcpu().multiply(valueOf(1000)) + .add(resources.memoryGb().multiply(valueOf(100))) + .add(resources.diskGb().multiply(valueOf(10))); + + BigDecimal supportLevelCost = pricingInfo.supportLevel() == BASIC ? new BigDecimal("-160.00") : new BigDecimal("800.00"); + BigDecimal listPriceWithSupport = listPrice.add(supportLevelCost); + BigDecimal enclaveDiscount = pricingInfo.enclave() ? new BigDecimal("-15.1234") : BigDecimal.ZERO; + BigDecimal volumeDiscount = new BigDecimal("-5.64315634"); + BigDecimal committedAmountDiscount = new BigDecimal("-1.23"); + BigDecimal totalAmount = listPrice.add(supportLevelCost).add(enclaveDiscount).add(volumeDiscount).add(committedAmountDiscount); + + return new PriceInformation(listPriceWithSupport, volumeDiscount, committedAmountDiscount, enclaveDiscount, totalAmount); + } + + } 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..99ea0febd9d --- /dev/null +++ b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/pricing/ApplicationResources.java @@ -0,0 +1,16 @@ +package com.yahoo.vespa.hosted.controller.api.integration.pricing; + +import java.math.BigDecimal; + +/** + * @param applicationName name of the application + * @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 + */ +public record ApplicationResources(String applicationName, BigDecimal vcpu, BigDecimal memoryGb, BigDecimal diskGb, + BigDecimal gpuMemoryGb) { + +} + diff --git a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/pricing/PriceInformationApplications.java b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/pricing/PriceInformationApplications.java new file mode 100644 index 00000000000..d7da2308a16 --- /dev/null +++ b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/pricing/PriceInformationApplications.java @@ -0,0 +1,9 @@ +// 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; + +public record PriceInformationApplications(BigDecimal listPriceWithSupport, BigDecimal volumeDiscount, BigDecimal committedAmountDiscount, + BigDecimal enclaveDiscount, BigDecimal totalAmount) { + +} 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 index d8186f17796..85d83a32e4c 100644 --- 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 @@ -13,6 +13,16 @@ import java.util.List; */ public interface PricingController { + // TOD: Legacy, will be removed when not in use anymore PriceInformation price(List clusterResources, PricingInfo pricingInfo, Plan plan); + /** + * + * @param applicationResources resources used by an application + * @param pricingInfo pricing info + * @param plan the plan to use for this calculation + * @return a PriceInformation instance + */ + PriceInformation priceForApplications(List applicationResources, PricingInfo pricingInfo, Plan plan); + } -- cgit v1.2.3