diff options
author | Harald Musum <musum@yahooinc.com> | 2023-10-13 13:29:05 +0200 |
---|---|---|
committer | Harald Musum <musum@yahooinc.com> | 2023-10-13 13:29:05 +0200 |
commit | 247535e91dee2dbf6fd28484e702d9371ff8892a (patch) | |
tree | 4496876a31def1bf14ea48fa2c60a5211508bcdb /controller-server/src | |
parent | 499b9d9198b90349d07f7519545835950de9403d (diff) |
Test pricing API with 2 apps
Diffstat (limited to 'controller-server/src')
2 files changed, 48 insertions, 3 deletions
diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/pricing/PricingApiHandler.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/pricing/PricingApiHandler.java index 57bde83fd1c..7cff6e951c6 100644 --- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/pricing/PricingApiHandler.java +++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/pricing/PricingApiHandler.java @@ -13,7 +13,6 @@ import com.yahoo.restapi.Path; import com.yahoo.restapi.SlimeJsonResponse; import com.yahoo.slime.Cursor; import com.yahoo.slime.Slime; -import com.yahoo.slime.SlimeUtils; import com.yahoo.text.Text; import com.yahoo.vespa.hosted.controller.Controller; import com.yahoo.vespa.hosted.controller.api.integration.billing.Plan; @@ -263,6 +262,7 @@ public class PricingApiHandler extends ThreadedHttpRequestHandler { applicationPrices(applicationsArray, prices.priceInformationApplications(), priceParameters); var priceInfoArray = cursor.setArray("priceInfo"); + addItem(priceInfoArray, "Enclave", prices.totalPriceInformation().enclaveDiscount()); addItem(priceInfoArray, "Committed spend", prices.totalPriceInformation().committedAmountDiscount()); setBigDecimal(cursor, "totalAmount", prices.totalPriceInformation().totalAmount()); diff --git a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/pricing/PricingApiHandlerTest.java b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/pricing/PricingApiHandlerTest.java index 8fc8fd25384..321e582437a 100644 --- a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/pricing/PricingApiHandlerTest.java +++ b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/pricing/PricingApiHandlerTest.java @@ -141,6 +141,41 @@ public class PricingApiHandlerTest extends ControllerContainerCloudTest { } @Test + void testPricingInfoCommercialEnclave2Apps() { + ContainerTester tester = new ContainerTester(container, responseFiles); + assertEquals(SystemName.Public, tester.controller().system()); + + var request = request("/pricing/v1/pricing?" + urlEncodedPriceInformation2AppsEnclave(COMMERCIAL)); + tester.assertJsonResponse(request, """ + { + "applications": [ + { + "name": "app1", + "priceInfo": [ + {"description": "Commercial support unit price", "amount": "2000.00"}, + {"description": "Enclave", "amount": "-15.12"}, + {"description": "Volume discount", "amount": "-5.64"} + ] + }, + { + "name": "app2", + "priceInfo": [ + {"description": "Commercial support unit price", "amount": "2000.00"}, + {"description": "Enclave", "amount": "-15.12"}, + {"description": "Volume discount", "amount": "-5.64"} + ] + } + ], + "priceInfo": [ + {"description": "Committed spend", "amount": "-1.23"} + ], + "totalAmount": "3957.24" + } + """, + 200); + } + + @Test void testInvalidRequests() { ContainerTester tester = new ContainerTester(container, responseFiles); assertEquals(SystemName.Public, tester.controller().system()); @@ -185,7 +220,7 @@ public class PricingApiHandlerTest extends ControllerContainerCloudTest { * price will be 20000 + 2000 + 200 */ String urlEncodedPriceInformation1App(PricingInfo.SupportLevel supportLevel) { - return "application=" + URLEncoder.encode("name=myapp,vcpu=2,memoryGb=2,diskGb=20,gpuMemoryGb=0", UTF_8) + + return "application=" + URLEncoder.encode("name=app1,vcpu=2,memoryGb=2,diskGb=20,gpuMemoryGb=0", UTF_8) + "&supportLevel=" + supportLevel.name().toLowerCase() + "&committedSpend=100"; } @@ -195,8 +230,18 @@ public class PricingApiHandlerTest extends ControllerContainerCloudTest { * price will be 20000 + 2000 + 200 */ String urlEncodedPriceInformation1AppEnclave(PricingInfo.SupportLevel supportLevel) { - return "application=" + URLEncoder.encode("name=myapp,enclaveVcpu=2,enclaveMemoryGb=2,enclaveDiskGb=20,enclaveGpuMemoryGb=0", UTF_8) + + return "application=" + URLEncoder.encode("name=app1,enclaveVcpu=2,enclaveMemoryGb=2,enclaveDiskGb=20,enclaveGpuMemoryGb=0", UTF_8) + "&supportLevel=" + supportLevel.name().toLowerCase() + "&committedSpend=100"; } + /** + * 2 apps, with 1 cluster (with total resources for all clusters with each having + * 1 node, with 1 vcpu, 1 Gb memory, 10 Gb disk and no GPU + */ + String urlEncodedPriceInformation2AppsEnclave(PricingInfo.SupportLevel supportLevel) { + return "application=" + URLEncoder.encode("name=app1,enclaveVcpu=1,enclaveMemoryGb=1,enclaveDiskGb=10,enclaveGpuMemoryGb=0", UTF_8) + + "&application=" + URLEncoder.encode("name=app2,enclaveVcpu=1,enclaveMemoryGb=1,enclaveDiskGb=10,enclaveGpuMemoryGb=0", UTF_8) + + "&supportLevel=" + supportLevel.name().toLowerCase() + "&committedSpend=0"; + } + } |