diff options
Diffstat (limited to 'controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/BillingReportMaintainer.java')
-rw-r--r-- | controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/BillingReportMaintainer.java | 34 |
1 files changed, 29 insertions, 5 deletions
diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/BillingReportMaintainer.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/BillingReportMaintainer.java index e7ec6675a82..7868c3fe611 100644 --- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/BillingReportMaintainer.java +++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/BillingReportMaintainer.java @@ -1,12 +1,15 @@ -// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.vespa.hosted.controller.maintenance; import com.yahoo.config.provision.SystemName; import com.yahoo.config.provision.TenantName; import com.yahoo.vespa.hosted.controller.Controller; import com.yahoo.vespa.hosted.controller.LockedTenant; +import com.yahoo.vespa.hosted.controller.api.integration.billing.BillStatus; import com.yahoo.vespa.hosted.controller.api.integration.billing.BillingController; +import com.yahoo.vespa.hosted.controller.api.integration.billing.BillingDatabaseClient; import com.yahoo.vespa.hosted.controller.api.integration.billing.BillingReporter; +import com.yahoo.vespa.hosted.controller.api.integration.billing.InvoiceUpdate; import com.yahoo.vespa.hosted.controller.api.integration.billing.Plan; import com.yahoo.vespa.hosted.controller.api.integration.billing.PlanRegistry; import com.yahoo.vespa.hosted.controller.tenant.CloudTenant; @@ -23,18 +26,25 @@ public class BillingReportMaintainer extends ControllerMaintainer { private final BillingReporter reporter; private final BillingController billing; + private final BillingDatabaseClient databaseClient; + private final PlanRegistry plans; public BillingReportMaintainer(Controller controller, Duration interval) { - super(controller, interval, null, Set.of(SystemName.PublicCd)); - this.reporter = controller.serviceRegistry().billingReporter(); - this.billing = controller.serviceRegistry().billingController(); - this.plans = controller.serviceRegistry().planRegistry(); + super(controller, interval, null, Set.of(SystemName.Public, SystemName.PublicCd)); + reporter = controller.serviceRegistry().billingReporter(); + billing = controller.serviceRegistry().billingController(); + databaseClient = controller.serviceRegistry().billingDatabase(); + plans = controller.serviceRegistry().planRegistry(); } @Override protected double maintain() { maintainTenants(); + + var updates = maintainInvoices(); + log.fine("Updated invoices: " + updates); + return 0.0; } @@ -53,6 +63,19 @@ public class BillingReportMaintainer extends ControllerMaintainer { }); } + InvoiceUpdate maintainInvoices() { + var billsNeedingMaintenance = databaseClient.readBills().stream() + .filter(bill -> bill.getExportedId().isPresent()) + .filter(exported -> exported.status() == BillStatus.OPEN) + .toList(); + + var updates = new InvoiceUpdate.Counter(); + for (var bill : billsNeedingMaintenance) { + updates.add(reporter.maintainInvoice(bill)); + } + return updates.finish(); + } + private Map<TenantName, CloudTenant> cloudTenants() { return controller().tenants().asList() .stream() @@ -74,4 +97,5 @@ public class BillingReportMaintainer extends ControllerMaintainer { .flatMap(p -> billing.tenantsWithPlan(tenants, p.id()).stream()) .toList(); } + } |