aboutsummaryrefslogtreecommitdiffstats
path: root/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/billing/BillingController.java
blob: dcd1a057f4915c6a8b2bbe4d68d295d0ad4e8f40 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
// 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.api.integration.billing;

import com.yahoo.config.provision.TenantName;
import com.yahoo.vespa.hosted.controller.tenant.TaxId;

import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.ZonedDateTime;
import java.util.List;
import java.util.Map;
import java.util.Optional;

/**
 * A service that controls creation of bills based on the resource usage of a tenant, controls the quota for a
 * tenant, and controls the plan the tenant is on.
 *
 * @author ogronnesby
 * @author olaa
 */
public interface BillingController {

    /**
     * Get the plan ID for the given tenant.
     * This method will not fail if the tenant does not exist, it will return the default plan for that tenant instead.
     */
    PlanId getPlan(TenantName tenant);

    /**
     * Return the list of tenants with the given plan.
     * @param existing All existing tenants in the system
     * @param planId The ID of the plan to filter existing tenants on.
     * @return The tenants that have the given plan.
     */
    List<TenantName> tenantsWithPlan(List<TenantName> existing, PlanId planId);

    /**
     * The quota for the given tenant.
     * This method will return default quota for tenants that do not exist.
     */
    Quota getQuota(TenantName tenant);

    /**
     * Set the plan for the current tenant.  Checks some pre-conditions to see if the tenant is eligible for the
     * given plan.
     * @param tenant The name of the tenant.
     * @param planId The ID of the plan to change to.
     * @param hasDeployments Does the tenant have active deployments.
     * @param isAccountant Is it the hosted accountant that is doing the operation
     * @return String containing error message if something went wrong. Empty otherwise
     */
    PlanResult setPlan(TenantName tenant, PlanId planId, boolean hasDeployments, boolean isAccountant);

    /**
     * Create a bill of unbilled use for the given tenant in the given time period.
     * @param tenant The name of the tenant.
     * @param startTime The start of the billing period
     * @param endTime The end of the billing period
     * @param agent The agent that creates the bill
     * @return The ID of the new bill.
     */
    Bill.Id createBillForPeriod(TenantName tenant, ZonedDateTime startTime, ZonedDateTime endTime, String agent);

    /**
     * Create an unpersisted bill of unbilled use for the given tenant from the end of last bill until the given date.
     * This is used to show "unbilled use" in the Console.
     * @param tenant The name of the tenant.
     * @param until The end date of the unbilled use period.
     * @return A bill with the resource use and cost.
     */
    Bill createUncommittedBill(TenantName tenant, LocalDate until);

    /** Run {createUncommittedBill} for all tenants with unbilled use */
    Map<TenantName, Bill> createUncommittedBills(LocalDate until);

    /** Get line items that have been manually added to a tenant, but is not yet part of a bill */
    List<Bill.LineItem> getUnusedLineItems(TenantName tenant);

    /** Add a line item to the given bill */
    void addLineItem(TenantName tenant, String description, BigDecimal amount, Optional<Bill.Id> billId, String agent);

    /** Delete a line item - only available for unused line items */
    void deleteLineItem(String lineItemId);

    /** Get all bills for the given tenant */
    List<Bill> getBillsForTenant(TenantName tenant);

    /** Get the bill with the given id */
    Bill getBill(Bill.Id billId);

    /** Get the bill collection method for the given tenant */
    default CollectionMethod getCollectionMethod(TenantName tenant) {
        return CollectionMethod.NONE;
    }

    /** Set the bill collection method for the given tenant */
    default CollectionResult setCollectionMethod(TenantName tenant, CollectionMethod method) {
        return CollectionResult.error("Method not implemented");
    }

    /** Test if the number of tenants with the given plan is under the given limit */
    default boolean tenantsWithPlanUnderLimit(Plan plan, int limit) {
        return true;
    }

    default void updateCache(List<TenantName> tenants) {}

    /** Get the list of countries that are accepted */
    AcceptedCountries getAcceptedCountries();

    /** Validation of tax id */
    void validateTaxId(TaxId id) throws IllegalArgumentException;

}