diff options
author | Øyvind Grønnesby <oyving@verizonmedia.com> | 2021-05-10 11:54:24 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-05-10 11:54:24 +0200 |
commit | 257e0e2fca7b0ff0a15210909116162c925a11b7 (patch) | |
tree | 6ca33a074cd23221e0d9908764b9065115732d79 /controller-api | |
parent | 0e795977b2072d5504b1a45adffa7d2bdfed7fc2 (diff) | |
parent | 93cbea53ec4aac9861d1f64182d04f3e6d4ee2f2 (diff) |
Merge pull request #17748 from vespa-engine/ogronnesby/billing-api-v2
Some API changes for Billing API
Diffstat (limited to 'controller-api')
4 files changed, 27 insertions, 8 deletions
diff --git a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/billing/Invoice.java b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/billing/Invoice.java index 39d974378b4..f8ef2958f63 100644 --- a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/billing/Invoice.java +++ b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/billing/Invoice.java @@ -6,6 +6,8 @@ import com.yahoo.config.provision.TenantName; import com.yahoo.config.provision.zone.ZoneId; import java.math.BigDecimal; +import java.time.Clock; +import java.time.ZoneOffset; import java.time.ZonedDateTime; import java.util.List; import java.util.Map; @@ -325,9 +327,10 @@ public class Invoice { this.history = history; } - public static StatusHistory open() { + public static StatusHistory open(Clock clock) { + var now = clock.instant().atZone(ZoneOffset.UTC); return new StatusHistory( - new TreeMap<>(Map.of(ZonedDateTime.now(), "OPEN")) + new TreeMap<>(Map.of(now, "OPEN")) ); } diff --git a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/billing/MockBillingController.java b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/billing/MockBillingController.java index b24d532d4a3..535f344d352 100644 --- a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/billing/MockBillingController.java +++ b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/billing/MockBillingController.java @@ -5,7 +5,9 @@ import com.yahoo.config.provision.TenantName; import com.yahoo.vespa.hosted.controller.api.integration.user.User; import java.math.BigDecimal; +import java.time.Clock; import java.time.LocalDate; +import java.time.ZoneOffset; import java.time.ZonedDateTime; import java.util.ArrayList; import java.util.Collection; @@ -21,6 +23,7 @@ import java.util.stream.Collectors; */ public class MockBillingController implements BillingController { + private final Clock clock; Map<TenantName, PlanId> plans = new HashMap<>(); Map<TenantName, PaymentInstrument> activeInstruments = new HashMap<>(); Map<TenantName, List<Invoice>> committedInvoices = new HashMap<>(); @@ -28,6 +31,10 @@ public class MockBillingController implements BillingController { Map<TenantName, List<Invoice.LineItem>> unusedLineItems = new HashMap<>(); Map<TenantName, CollectionMethod> collectionMethod = new HashMap<>(); + public MockBillingController(Clock clock) { + this.clock = clock; + } + @Override public PlanId getPlan(TenantName tenant) { return plans.getOrDefault(tenant, PlanId.from("trial")); @@ -63,7 +70,7 @@ public class MockBillingController implements BillingController { .add(new Invoice( invoiceId, tenant, - Invoice.StatusHistory.open(), + Invoice.StatusHistory.open(clock), List.of(), startTime, endTime @@ -104,10 +111,11 @@ public class MockBillingController implements BillingController { @Override public void updateInvoiceStatus(Invoice.Id invoiceId, String agent, String status) { + var now = clock.instant().atZone(ZoneOffset.UTC); committedInvoices.values().stream() .flatMap(List::stream) .filter(invoice -> invoiceId.equals(invoice.id())) - .forEach(invoice -> invoice.statusHistory().history.put(ZonedDateTime.now(), status)); + .forEach(invoice -> invoice.statusHistory().history.put(now, status)); } @Override @@ -192,6 +200,8 @@ public class MockBillingController implements BillingController { } private Invoice emptyInvoice() { - return new Invoice(Invoice.Id.of("empty"), TenantName.defaultName(), Invoice.StatusHistory.open(), List.of(), ZonedDateTime.now(), ZonedDateTime.now()); + var start = clock.instant().atZone(ZoneOffset.UTC); + var end = clock.instant().atZone(ZoneOffset.UTC); + return new Invoice(Invoice.Id.of("empty"), TenantName.defaultName(), Invoice.StatusHistory.open(clock), List.of(), start, end); } } diff --git a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/role/PathGroup.java b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/role/PathGroup.java index d052a000860..9f6c0a79455 100644 --- a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/role/PathGroup.java +++ b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/role/PathGroup.java @@ -78,6 +78,11 @@ enum PathGroup { billingList(Matcher.tenant, "/billing/v1/tenant/{tenant}/billing/{*}"), + billing(Matcher.tenant, + "/billing/v2/tenant/{tenant}/{*}"), + + accountant("/billing/v2/accountant/{*}"), + applicationKeys(Matcher.tenant, Matcher.application, "/application/v4/tenant/{tenant}/application/{application}/key/"), @@ -283,6 +288,7 @@ enum PathGroup { PathGroup.billingInstrument, PathGroup.billingList, PathGroup.billingPlan, + PathGroup.billing, PathGroup.hostedAccountant ); } diff --git a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/role/Policy.java b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/role/Policy.java index b48e786c178..ee5f1d806ab 100644 --- a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/role/Policy.java +++ b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/role/Policy.java @@ -174,7 +174,7 @@ enum Policy { /** Ability to update tenant payment instrument */ planUpdate(Privilege.grant(Action.update) - .on(PathGroup.billingPlan) + .on(PathGroup.billingPlan, PathGroup.billing) .in(SystemName.PublicCd, SystemName.Public)), /** Ability to update tenant collection method */ @@ -185,12 +185,12 @@ enum Policy { /** Read the generated bills */ billingInformationRead(Privilege.grant(Action.read) - .on(PathGroup.billingList) + .on(PathGroup.billingList, PathGroup.billing) .in(SystemName.PublicCd, SystemName.Public)), /** Invoice management */ hostedAccountant(Privilege.grant(Action.all()) - .on(PathGroup.hostedAccountant) + .on(PathGroup.hostedAccountant, PathGroup.accountant) .in(SystemName.PublicCd, SystemName.Public)), /** Listing endpoint certificate request info */ |