aboutsummaryrefslogtreecommitdiffstats
path: root/controller-server
diff options
context:
space:
mode:
authorØyvind Grønnesby <oyving@yahooinc.com>2022-05-31 17:03:08 +0200
committerGitHub <noreply@github.com>2022-05-31 17:03:08 +0200
commit0b3b4099742306aeb2706e6be7251d66152f12ae (patch)
treefb40d562cd5c2af1a980c0743c3914bf67742b36 /controller-server
parent00e2eae6db19c374a288e239a9df3f96e35cce77 (diff)
parentda46b1496b114ef7d9bb163a56f8f4ddbac2dd16 (diff)
Merge pull request #22808 from vespa-engine/ogronnesby/plan-list-api
Expose all plans in billing API
Diffstat (limited to 'controller-server')
-rw-r--r--controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/billing/BillingApiHandler.java16
-rw-r--r--controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/billing/BillingApiHandlerTest.java7
2 files changed, 23 insertions, 0 deletions
diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/billing/BillingApiHandler.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/billing/BillingApiHandler.java
index 206303adc80..d45e69f781b 100644
--- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/billing/BillingApiHandler.java
+++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/billing/BillingApiHandler.java
@@ -24,6 +24,7 @@ import com.yahoo.vespa.hosted.controller.api.integration.billing.CollectionMetho
import com.yahoo.vespa.hosted.controller.api.integration.billing.InstrumentOwner;
import com.yahoo.vespa.hosted.controller.api.integration.billing.PaymentInstrument;
import com.yahoo.vespa.hosted.controller.api.integration.billing.PlanId;
+import com.yahoo.vespa.hosted.controller.api.integration.billing.PlanRegistry;
import com.yahoo.vespa.hosted.controller.api.role.Role;
import com.yahoo.vespa.hosted.controller.api.role.SecurityContext;
import com.yahoo.vespa.hosted.controller.tenant.Tenant;
@@ -56,11 +57,13 @@ public class BillingApiHandler extends ThreadedHttpRequestHandler {
private final BillingController billingController;
private final ApplicationController applicationController;
private final TenantController tenantController;
+ private final PlanRegistry planRegistry;
public BillingApiHandler(Executor executor,
Controller controller) {
super(executor);
this.billingController = controller.serviceRegistry().billingController();
+ this.planRegistry = controller.serviceRegistry().planRegistry();
this.applicationController = controller.applications();
this.tenantController = controller.tenants();
}
@@ -103,6 +106,7 @@ public class BillingApiHandler extends ThreadedHttpRequestHandler {
if (path.matches("/billing/v1/billing")) return getBillingAllTenants(request.getProperty("until"));
if (path.matches("/billing/v1/invoice/export")) return getAllBills();
if (path.matches("/billing/v1/invoice/tenant/{tenant}/line-item")) return getLineItems(path.get("tenant"));
+ if (path.matches("/billing/v1/plans")) return getPlans();
return ErrorResponse.notFoundError("Nothing at " + path);
}
@@ -295,6 +299,18 @@ public class BillingApiHandler extends ThreadedHttpRequestHandler {
}
}
+ private HttpResponse getPlans() {
+ var slime = new Slime();
+ var root = slime.setObject();
+ var plans = root.setArray("plans");
+ for (var plan : planRegistry.all()) {
+ var p = plans.addObject();
+ p.setString("id", plan.id().value());
+ p.setString("name", plan.displayName());
+ }
+ return new SlimeJsonResponse(slime);
+ }
+
private HttpResponse getLineItems(String tenant) {
var slimeResponse = new Slime();
var root = slimeResponse.setObject();
diff --git a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/billing/BillingApiHandlerTest.java b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/billing/BillingApiHandlerTest.java
index b58e5294f66..c9e86849ed8 100644
--- a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/billing/BillingApiHandlerTest.java
+++ b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/billing/BillingApiHandlerTest.java
@@ -79,6 +79,13 @@ public class BillingApiHandlerTest extends ControllerContainerCloudTest {
}
@Test
+ public void list_plans() {
+ var listPlansRequest = request("/billing/v1/plans", GET)
+ .roles(Role.hostedAccountant());
+ tester.assertResponse(listPlansRequest, "{\"plans\":[{\"id\":\"trial\",\"name\":\"Free Trial - for testing purposes\"},{\"id\":\"paid\",\"name\":\"Paid Plan - for testing purposes\"},{\"id\":\"none\",\"name\":\"None Plan - for testing purposes\"}]}");
+ }
+
+ @Test
public void setting_and_deleting_instrument() {
assertTrue(billingController.getDefaultInstrument(tenant).isEmpty());