diff options
author | Øyvind Grønnesby <oyving@yahooinc.com> | 2023-10-19 10:56:15 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-10-19 10:56:15 +0200 |
commit | 620be36b13c70d2a265a8d8e60212c74b9d37c1b (patch) | |
tree | baa58287b9b1a38aaf2f62105c9dfe3cbe35cf65 /controller-server/src/main/java | |
parent | 479379d864392f3d6de5c6c78e03214021994d4f (diff) | |
parent | be85900f1756b3f13aafa42b43814178bd9cf1a9 (diff) |
Merge pull request #29018 from vespa-engine/ogronnesby/billing-v2-collection
Add collection method to billing/v2
Diffstat (limited to 'controller-server/src/main/java')
-rw-r--r-- | controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/billing/BillingApiHandlerV2.java | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/billing/BillingApiHandlerV2.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/billing/BillingApiHandlerV2.java index 5b43ede2e22..f32388b388a 100644 --- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/billing/BillingApiHandlerV2.java +++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/billing/BillingApiHandlerV2.java @@ -101,6 +101,9 @@ public class BillingApiHandlerV2 extends RestApiRequestHandler<BillingApiHandler .addRoute(RestApi.route("/billing/v2/accountant/tenant/{tenant}/plan") .get(self::accountantTenantPlan) .post(Slime.class, self::setAccountantTenantPlan)) + .addRoute(RestApi.route("/billing/v2/accountant/tenant/{tenant}/collection") + .get(self::accountantTenantCollection) + .post(Slime.class, self::setAccountantTenantCollection)) .addRoute(RestApi.route("/billing/v2/accountant/bill/{invoice}/export") .put(Slime.class, self::putAccountantInvoiceExport)) .addRoute(RestApi.route("/billing/v2/accountant/plans") @@ -397,6 +400,33 @@ public class BillingApiHandlerV2 extends RestApiRequestHandler<BillingApiHandler return slime; } + private MessageResponse setAccountantTenantCollection(RestApi.RequestContext requestContext, Slime body) { + var tenantName = TenantName.from(requestContext.pathParameters().getStringOrThrow("tenant")); + var tenant = tenants.require(tenantName, CloudTenant.class); + + var collection = CollectionMethod.valueOf(getInspectorFieldOrThrow(body.get(), "collection")); + var result = billing.setCollectionMethod(tenant.name(), collection); + + if (result.isSuccess()) { + return new MessageResponse("Collection: " + collection.name()); + } else { + throw new RestApiException.BadRequest("Could not change collection method: " + result.getErrorMessage()); + } + } + + private Slime accountantTenantCollection(RestApi.RequestContext requestContext) { + var tenantName = TenantName.from(requestContext.pathParameters().getStringOrThrow("tenant")); + var tenant = tenants.require(tenantName, CloudTenant.class); + + var collection = billing.getCollectionMethod(tenant.name()); + + var slime = new Slime(); + var root = slime.setObject(); + root.setString("collection", collection.name()); + + return slime; + } + // --------- INVOICE RENDERING ---------- private void invoicesSummaryToSlime(Cursor slime, List<Bill> bills) { |