summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorValerij Fredriksen <freva@users.noreply.github.com>2023-10-17 15:42:45 +0200
committerGitHub <noreply@github.com>2023-10-17 15:42:45 +0200
commit1d4f18521b1563a83bc600b42ff6e387b320e1db (patch)
tree32b109df8182e59b11cad45fc4adcf74e1d211a0
parent3bcebc707144c199f02c9fd3aac39fb7e7206379 (diff)
parent1b718963178ba76b24a7be0996802322625ecc48 (diff)
Merge pull request #28977 from vespa-engine/freva/allow-no-app
Allow no application resources
-rw-r--r--controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/MockPricingController.java44
-rw-r--r--controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/pricing/PricingApiHandler.java33
-rw-r--r--controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/pricing/PricingApiHandlerTest.java15
3 files changed, 31 insertions, 61 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
index ee0df3adbfb..b451df87727 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
@@ -13,7 +13,6 @@ import java.util.List;
import static com.yahoo.vespa.hosted.controller.api.integration.pricing.PricingInfo.SupportLevel.BASIC;
import static java.math.BigDecimal.ZERO;
-import static java.math.BigDecimal.valueOf;
public class MockPricingController implements PricingController {
@@ -23,34 +22,35 @@ public class MockPricingController implements PricingController {
@Override
public Prices priceForApplications(List<ApplicationResources> applicationResources, PricingInfo pricingInfo, Plan plan) {
- ApplicationResources resources = applicationResources.get(0);
-
- 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))));
+ 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);
+ 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);
- List<PriceInformation> appPrices = applicationResources.stream()
- .map(appResources -> new PriceInformation(listPriceWithSupport,
- volumeDiscount,
- ZERO,
- enclaveDiscount,
- appTotalAmount))
+ return new PriceInformation(listPriceWithSupport,
+ volumeDiscount,
+ ZERO,
+ enclaveDiscount,
+ appTotalAmount);
+ })
.toList();
PriceInformation sum = PriceInformation.sum(appPrices);
- var committedAmountDiscount = new BigDecimal("-0.2");
+ 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 (resources.enclave() && totalAmount.compareTo(new BigDecimal("14.00")) < 0)
+ 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);
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 0a43ec599d5..9a2a57359d7 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
@@ -4,7 +4,6 @@ package com.yahoo.vespa.hosted.controller.restapi.pricing;
import com.yahoo.collections.Pair;
import com.yahoo.component.annotation.Inject;
import com.yahoo.config.provision.ClusterResources;
-import com.yahoo.config.provision.NodeResources;
import com.yahoo.container.jdisc.HttpRequest;
import com.yahoo.container.jdisc.HttpResponse;
import com.yahoo.container.jdisc.ThreadedHttpRequestHandler;
@@ -35,8 +34,6 @@ import java.util.logging.Logger;
import static com.yahoo.jdisc.http.HttpRequest.Method.GET;
import static com.yahoo.restapi.ErrorResponse.methodNotAllowed;
import static com.yahoo.vespa.hosted.controller.api.integration.pricing.PricingInfo.SupportLevel;
-import static java.lang.Double.parseDouble;
-import static java.lang.Integer.parseInt;
import static java.math.BigDecimal.ZERO;
import static java.nio.charset.StandardCharsets.UTF_8;
@@ -116,41 +113,13 @@ public class PricingApiHandler extends ThreadedHttpRequestHandler {
default -> throw new IllegalArgumentException("Unknown query parameter '" + entry.getFirst() + '\'');
}
}
- if (appResources.isEmpty()) throw new IllegalArgumentException("No application resources found in query");
PricingInfo pricingInfo = new PricingInfo(supportLevel, committedSpend);
return new PriceParameters(List.of(), pricingInfo, plan, appResources);
}
- private ClusterResources clusterResources(String resourcesString) {
- List<String> elements = Arrays.stream(resourcesString.split(",")).toList();
-
- var nodes = 0;
- var vcpu = 0d;
- var memoryGb = 0d;
- var diskGb = 0d;
- var gpuMemoryGb = 0d;
-
- for (var element : keysAndValues(elements)) {
- var value = element.getSecond();
- switch (element.getFirst().toLowerCase()) {
- case "nodes" -> nodes = parseInt(value);
- case "vcpu" -> vcpu = parseDouble(value);
- case "memorygb" -> memoryGb = parseDouble(value);
- case "diskgb" -> diskGb = parseDouble(value);
- case "gpumemorygb" -> gpuMemoryGb = parseDouble(value);
- default -> throw new IllegalArgumentException("Unknown resource type '" + element.getFirst() + '\'');
- }
- }
-
- var nodeResources = new NodeResources(vcpu, memoryGb, diskGb, 0); // 0 bandwidth, not used in price calculation
- if (gpuMemoryGb > 0)
- nodeResources = nodeResources.with(new NodeResources.GpuResources(1, gpuMemoryGb));
- return new ClusterResources(nodes, 1, nodeResources);
- }
-
private ApplicationResources applicationResources(String appResourcesString) {
- List<String> elements = Arrays.stream(appResourcesString.split(",")).toList();
+ List<String> elements = List.of(appResourcesString.split(","));
var vcpu = ZERO;
var memoryGb = ZERO;
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 c4b5a771725..f2ce0dfeef2 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
@@ -21,6 +21,12 @@ public class PricingApiHandlerTest extends ControllerContainerCloudTest {
@Test
void testPricingInfoBasic() {
+ tester().assertJsonResponse(request("/pricing/v1/pricing?supportLevel=basic&committedSpend=0"),
+ """
+ { "applications": [ ], "priceInfo": [ ], "totalAmount": "0.00" }
+ """,
+ 200);
+
var request = request("/pricing/v1/pricing?" + urlEncodedPriceInformation1App(BASIC));
tester().assertJsonResponse(request, """
{
@@ -110,10 +116,8 @@ public class PricingApiHandlerTest extends ControllerContainerCloudTest {
]
}
],
- "priceInfo": [
- {"description": "Committed spend", "amount": "-0.20"}
- ],
- "totalAmount": "25.90"
+ "priceInfo": [ ],
+ "totalAmount": "26.10"
}
""",
200);
@@ -128,9 +132,6 @@ public class PricingApiHandlerTest extends ControllerContainerCloudTest {
tester.assertJsonResponse(request("/pricing/v1/pricing?"),
"{\"error-code\":\"BAD_REQUEST\",\"message\":\"Error in query parameter, expected '=' between key and value: ''\"}",
400);
- tester.assertJsonResponse(request("/pricing/v1/pricing?supportLevel=basic&committedSpend=0"),
- "{\"error-code\":\"BAD_REQUEST\",\"message\":\"No application resources found in query\"}",
- 400);
tester.assertJsonResponse(request("/pricing/v1/pricing?supportLevel=basic&committedSpend=0&resources"),
"{\"error-code\":\"BAD_REQUEST\",\"message\":\"Error in query parameter, expected '=' between key and value: 'resources'\"}",
400);