aboutsummaryrefslogtreecommitdiffstats
path: root/controller-server
diff options
context:
space:
mode:
authorHarald Musum <musum@yahooinc.com>2023-10-13 15:14:48 +0200
committerHarald Musum <musum@yahooinc.com>2023-10-13 15:14:48 +0200
commit1fe61e8329e25b41576286b24e867f822226c778 (patch)
tree6f293914c7691d74c955616c45ee2dac0dbd13e5 /controller-server
parent4941bdf24e4ab4ac09348f9d50d65bb4d8112c50 (diff)
Remove support for legacy price calculations from API
Diffstat (limited to 'controller-server')
-rw-r--r--controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/pricing/PricingApiHandler.java63
-rw-r--r--controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/pricing/PricingApiHandlerTest.java54
2 files changed, 6 insertions, 111 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 7cff6e951c6..48ddd59e3f2 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
@@ -83,19 +83,8 @@ public class PricingApiHandler extends ThreadedHttpRequestHandler {
private HttpResponse pricing(HttpRequest request) {
String rawQuery = request.getUri().getRawQuery();
var priceParameters = parseQuery(rawQuery);
- boolean isLegacy = priceParameters.appResources() == null;
- if (isLegacy) {
- PriceInformation price = calculateLegacyPrice(priceParameters);
- return legacyResponse(price, priceParameters);
- } else {
- Prices price = calculatePrice(priceParameters);
- return response(price, priceParameters);
- }
- }
-
- private PriceInformation calculateLegacyPrice(PriceParameters priceParameters) {
- var priceCalculator = controller.serviceRegistry().pricingController();
- return priceCalculator.price(priceParameters.clusterResources, priceParameters.pricingInfo, priceParameters.plan);
+ Prices price = calculatePrice(priceParameters);
+ return response(price, priceParameters);
}
private Prices calculatePrice(PriceParameters priceParameters) {
@@ -106,35 +95,7 @@ public class PricingApiHandler extends ThreadedHttpRequestHandler {
private PriceParameters parseQuery(String rawQuery) {
if (rawQuery == null) throw new IllegalArgumentException("No price information found in query");
List<String> elements = Arrays.stream(URLDecoder.decode(rawQuery, UTF_8).split("&")).toList();
-
- if (keysAndValues(elements).stream().map(Pair::getFirst).toList().contains("resources"))
- return parseQueryLegacy(elements);
- else
- return parseQuery(elements);
- }
-
- private PriceParameters parseQueryLegacy(List<String> elements) {
- var supportLevel = SupportLevel.BASIC;
- var enclave = false;
- var committedSpend = ZERO;
- var plan = controller.serviceRegistry().planRegistry().defaultPlan(); // fallback to default plan if not supplied
- List<ClusterResources> clusterResources = new ArrayList<>();
-
- for (Pair<String, String> entry : keysAndValues(elements)) {
- var value = entry.getSecond();
- switch (entry.getFirst().toLowerCase()) {
- case "committedspend" -> committedSpend = new BigDecimal(value);
- case "enclave" -> enclave = Boolean.parseBoolean(value);
- case "planid" -> plan = plan(value).orElseThrow(() -> new IllegalArgumentException("Unknown plan id " + value));
- case "supportlevel" -> supportLevel = SupportLevel.valueOf(value.toUpperCase());
- case "resources" -> clusterResources.add(clusterResources(value));
- default -> throw new IllegalArgumentException("Unknown query parameter '" + entry.getFirst() + '\'');
- }
- }
- if (clusterResources.isEmpty()) throw new IllegalArgumentException("No cluster resources found in query");
-
- PricingInfo pricingInfo = new PricingInfo(enclave, supportLevel, committedSpend.doubleValue());
- return new PriceParameters(clusterResources, pricingInfo, plan, null);
+ return parseQuery(elements);
}
private PriceParameters parseQuery(List<String> elements) {
@@ -157,8 +118,7 @@ public class PricingApiHandler extends ThreadedHttpRequestHandler {
}
if (appResources.isEmpty()) throw new IllegalArgumentException("No application resources found in query");
- // TODO: enclave does not make sense in PricingInfo anymore, remove when legacy method is removed
- PricingInfo pricingInfo = new PricingInfo(false, supportLevel, committedSpend.doubleValue());
+ PricingInfo pricingInfo = new PricingInfo(supportLevel, committedSpend);
return new PriceParameters(List.of(), pricingInfo, plan, appResources);
}
@@ -239,21 +199,6 @@ public class PricingApiHandler extends ThreadedHttpRequestHandler {
return controller.serviceRegistry().planRegistry().plan(element);
}
- private static SlimeJsonResponse legacyResponse(PriceInformation priceInfo, PriceParameters priceParameters) {
- var slime = new Slime();
- Cursor cursor = slime.setObject();
-
- var array = cursor.setArray("priceInfo");
- addItem(array, supportLevelDescription(priceParameters), priceInfo.listPriceWithSupport());
- addItem(array, "Enclave", priceInfo.enclaveDiscount());
- addItem(array, "Volume discount", priceInfo.volumeDiscount());
- addItem(array, "Committed spend", priceInfo.committedAmountDiscount());
-
- setBigDecimal(cursor, "totalAmount", priceInfo.totalAmount());
-
- return new SlimeJsonResponse(slime);
- }
-
private static SlimeJsonResponse response(Prices prices, PriceParameters priceParameters) {
var slime = new Slime();
Cursor cursor = slime.setObject();
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 321e582437a..6262697f0c3 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
@@ -22,25 +22,6 @@ public class PricingApiHandlerTest extends ControllerContainerCloudTest {
private static final String responseFiles = "src/test/java/com/yahoo/vespa/hosted/controller/restapi/pricing/responses/";
@Test
- void testPricingInfoBasicLegacy() {
- ContainerTester tester = new ContainerTester(container, responseFiles);
- assertEquals(SystemName.Public, tester.controller().system());
-
- var request = request("/pricing/v1/pricing?" + urlEncodedPriceInformationLegacy(BASIC, false));
- tester.assertJsonResponse(request, """
- {
- "priceInfo": [
- {"description": "Basic support unit price", "amount": "2240.00"},
- {"description": "Volume discount", "amount": "-5.64"},
- {"description": "Committed spend", "amount": "-1.23"}
- ],
- "totalAmount": "2233.13"
- }
- """,
- 200);
- }
-
- @Test
void testPricingInfoBasic() {
ContainerTester tester = new ContainerTester(container, responseFiles);
assertEquals(SystemName.Public, tester.controller().system());
@@ -94,26 +75,6 @@ public class PricingApiHandlerTest extends ControllerContainerCloudTest {
}
@Test
- void testPricingInfoCommercialEnclaveLegacy() {
- ContainerTester tester = new ContainerTester(container, responseFiles);
- assertEquals(SystemName.Public, tester.controller().system());
-
- var request = request("/pricing/v1/pricing?" + urlEncodedPriceInformationLegacy(COMMERCIAL, true));
- tester.assertJsonResponse(request, """
- {
- "priceInfo": [
- {"description": "Commercial support unit price", "amount": "3200.00"},
- {"description": "Enclave", "amount": "-15.12"},
- {"description": "Volume discount", "amount": "-5.64"},
- {"description": "Committed spend", "amount": "-1.23"}
- ],
- "totalAmount": "3178.00"
- }
- """,
- 200);
- }
-
- @Test
void testPricingInfoCommercialEnclave() {
ContainerTester tester = new ContainerTester(container, responseFiles);
assertEquals(SystemName.Public, tester.controller().system());
@@ -198,23 +159,12 @@ public class PricingApiHandlerTest extends ControllerContainerCloudTest {
tester.assertJsonResponse(request("/pricing/v1/pricing?supportLevel=basic&committedSpend=0&key=value"),
"{\"error-code\":\"BAD_REQUEST\",\"message\":\"Unknown query parameter 'key'\"}",
400);
- tester.assertJsonResponse(request("/pricing/v1/pricing?supportLevel=basic&committedSpend=0&resources=key%3Dvalue"),
- "{\"error-code\":\"BAD_REQUEST\",\"message\":\"Unknown resource type 'key'\"}",
+ tester.assertJsonResponse(request("/pricing/v1/pricing?supportLevel=basic&committedSpend=0&application=key%3Dvalue"),
+ "{\"error-code\":\"BAD_REQUEST\",\"message\":\"Unknown key 'key'\"}",
400);
}
/**
- * 2 clusters, with each having 1 node, with 1 vcpu, 1 Gb memory, 10 Gb disk and no GPU
- * price will be 20000 + 2000 + 200
- */
- String urlEncodedPriceInformationLegacy(PricingInfo.SupportLevel supportLevel, boolean enclave) {
- String resources = URLEncoder.encode("nodes=1,vcpu=1,memoryGb=1,diskGb=10,gpuMemoryGb=0", UTF_8);
- return "supportLevel=" + supportLevel.name().toLowerCase() + "&committedSpend=100&enclave=" + enclave +
- "&resources=" + resources +
- "&resources=" + resources;
- }
-
- /**
* 1 app, with 2 clusters (with total resources for all clusters with each having
* 1 node, with 1 vcpu, 1 Gb memory, 10 Gb disk and no GPU,
* price will be 20000 + 2000 + 200