diff options
author | Øyvind Grønnesby <oyving@verizonmedia.com> | 2020-11-18 17:18:19 +0100 |
---|---|---|
committer | Øyvind Grønnesby <oyving@verizonmedia.com> | 2020-11-18 17:18:19 +0100 |
commit | 6b0237fcb35de3d74ca3c362cddfe3cdfde77a23 (patch) | |
tree | 5acde8fea2b6e2bc0b16f28239c6671a3bd186f9 /controller-server | |
parent | 804b5ea7d3822847d2b732c79fd35a5eceba15b4 (diff) |
List _all_ tenants in all tenant view
Previously we only listed tenants with usage data, but now we list
all tenants regardless of their usage.
Diffstat (limited to 'controller-server')
3 files changed, 36 insertions, 22 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 199eee6d0c9..8b0c2febe46 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 @@ -18,12 +18,14 @@ import com.yahoo.slime.Slime; import com.yahoo.slime.SlimeUtils; import com.yahoo.vespa.hosted.controller.ApplicationController; import com.yahoo.vespa.hosted.controller.Controller; +import com.yahoo.vespa.hosted.controller.TenantController; import com.yahoo.vespa.hosted.controller.api.integration.billing.CollectionMethod; import com.yahoo.vespa.hosted.controller.api.integration.billing.PaymentInstrument; import com.yahoo.vespa.hosted.controller.api.integration.billing.Invoice; import com.yahoo.vespa.hosted.controller.api.integration.billing.InstrumentOwner; import com.yahoo.vespa.hosted.controller.api.integration.billing.BillingController; import com.yahoo.vespa.hosted.controller.api.integration.billing.PlanId; +import com.yahoo.vespa.hosted.controller.tenant.Tenant; import com.yahoo.yolean.Exceptions; import javax.ws.rs.BadRequestException; @@ -37,6 +39,7 @@ import java.time.ZoneId; import java.time.ZonedDateTime; import java.time.format.DateTimeFormatter; import java.time.format.DateTimeParseException; +import java.util.Comparator; import java.util.List; import java.util.Optional; import java.util.concurrent.Executor; @@ -53,6 +56,7 @@ public class BillingApiHandler extends LoggingRequestHandler { private final BillingController billingController; private final ApplicationController applicationController; + private final TenantController tenantController; public BillingApiHandler(Executor executor, AccessLog accessLog, @@ -60,6 +64,7 @@ public class BillingApiHandler extends LoggingRequestHandler { super(executor, accessLog); this.billingController = controller.serviceRegistry().billingController(); this.applicationController = controller.applications(); + this.tenantController = controller.tenants(); } @Override @@ -175,15 +180,16 @@ public class BillingApiHandler extends LoggingRequestHandler { root.setString("until", untilDate.format(DateTimeFormatter.ISO_DATE)); var tenants = root.setArray("tenants"); - uncommittedInvoices.forEach((tenant, invoice) -> { + tenantController.asList().stream().sorted(Comparator.comparing(Tenant::name)).forEach(tenant -> { + var invoice = uncommittedInvoices.get(tenant.name()); var tc = tenants.addObject(); - tc.setString("tenant", tenant.value()); - getPlanForTenant(tc, tenant); - getCollectionForTenant(tc, tenant); + tc.setString("tenant", tenant.name().value()); + getPlanForTenant(tc, tenant.name()); + getCollectionForTenant(tc, tenant.name()); renderCurrentUsage(tc.setObject("current"), invoice); - renderAdditionalItems(tc.setObject("additional").setArray("items"), billingController.getUnusedLineItems(tenant)); + renderAdditionalItems(tc.setObject("additional").setArray("items"), billingController.getUnusedLineItems(tenant.name())); - billingController.getDefaultInstrument(tenant).ifPresent(card -> + billingController.getDefaultInstrument(tenant.name()).ifPresent(card -> renderInstrument(tc.setObject("payment"), card) ); }); 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 8493250d9a3..1d0f0935c05 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 @@ -2,6 +2,7 @@ package com.yahoo.vespa.hosted.controller.restapi.billing; import com.yahoo.config.provision.SystemName; import com.yahoo.config.provision.TenantName; +import com.yahoo.vespa.hosted.controller.ControllerTester; import com.yahoo.vespa.hosted.controller.api.integration.billing.CollectionMethod; import com.yahoo.vespa.hosted.controller.api.integration.billing.Invoice; import com.yahoo.vespa.hosted.controller.api.integration.billing.MockBillingController; @@ -9,12 +10,17 @@ import com.yahoo.vespa.hosted.controller.api.integration.billing.PlanId; import com.yahoo.vespa.hosted.controller.api.role.Role; import com.yahoo.vespa.hosted.controller.restapi.ContainerTester; import com.yahoo.vespa.hosted.controller.restapi.ControllerContainerCloudTest; +import com.yahoo.vespa.hosted.controller.security.Auth0Credentials; +import com.yahoo.vespa.hosted.controller.security.CloudTenantSpec; +import com.yahoo.vespa.hosted.controller.security.Credentials; +import com.yahoo.vespa.hosted.controller.security.TenantSpec; import org.junit.Assert; import org.junit.Before; import org.junit.Test; import java.io.File; import java.math.BigDecimal; +import java.security.Principal; import java.time.LocalDate; import java.time.ZoneId; import java.time.ZonedDateTime; @@ -165,6 +171,9 @@ public class BillingApiHandlerTest extends ControllerContainerCloudTest { @Test public void list_all_uninvoiced_items() { + tester.controller().tenants().create(new CloudTenantSpec(tenant, ""), new Auth0Credentials(() -> "foo", Set.of(Role.hostedOperator()))); + tester.controller().tenants().create(new CloudTenantSpec(tenant2, ""), new Auth0Credentials(() -> "foo", Set.of(Role.hostedOperator()))); + var invoice = createInvoice(); billingController.setPlan(tenant, PlanId.from("some-plan"), true); billingController.setPlan(tenant2, PlanId.from("some-plan"), true); @@ -172,7 +181,6 @@ public class BillingApiHandlerTest extends ControllerContainerCloudTest { billingController.addLineItem(tenant, "support", new BigDecimal("42"), "Smith"); billingController.addInvoice(tenant2, invoice, false); - var request = request("/billing/v1/billing?until=2020-05-28").roles(financeAdmin); tester.assertResponse(request, new File("billing-all-tenants")); diff --git a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/billing/responses/billing-all-tenants b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/billing/responses/billing-all-tenants index 81868a44e57..5c61dc6e86e 100644 --- a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/billing/responses/billing-all-tenants +++ b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/billing/responses/billing-all-tenants @@ -2,7 +2,7 @@ "until":"2020-05-28", "tenants":[ { - "tenant":"tenant2", + "tenant":"tenant1", "plan":"some-plan", "planName":"Plan with id: some-plan", "collection": "AUTO", @@ -20,10 +20,21 @@ } ] }, - "additional":{"items":[]} + "additional": + { + "items":[ + { + "id":"line-item-id", + "description":"support", + "amount":"42.00", + "plan":"some-plan", + "planName":"Plan with id: some-plan" + } + ] + } }, { - "tenant":"tenant1", + "tenant":"tenant2", "plan":"some-plan", "planName":"Plan with id: some-plan", "collection": "AUTO", @@ -41,18 +52,7 @@ } ] }, - "additional": - { - "items":[ - { - "id":"line-item-id", - "description":"support", - "amount":"42.00", - "plan":"some-plan", - "planName":"Plan with id: some-plan" - } - ] - } + "additional":{"items":[]} } ] }
\ No newline at end of file |