Search in sources :

Example 1 with OldEaSummarizedBillElement

use of com.vmware.photon.controller.model.adapters.azure.model.cost.OldEaSummarizedBillElement in project photon-model by vmware.

the class AzureCostStatsService method populatePastAndCurrentMonthsEaAccountCostUsingOldApi.

/**
 * Populates the cost incurred on the overall EA account in the past months.
 * @param context the data holder for the current run
 * @param requestUri the request URI: this is needed to get the correlate corresponding to
 *                   the cost obtained in the response
 * @param summarizedBillElements the response obtained from Azure, contains the account cost
 */
@OldApi
private void populatePastAndCurrentMonthsEaAccountCostUsingOldApi(Context context, String requestUri, OldEaSummarizedBillElement[] summarizedBillElements) {
    // Set the account cost to null (NOT zero) by default. If the cost obtained
    // was NOT a parse-able Double value, we will have null values. NOT setting to zero since
    // genuine zero values will then be unidentifiable; this will
    // help to distinguish unknown values from real zero costs.
    Double accountUsageCost = null;
    Double accountMarketplaceCost = null;
    Double accountSeparatelyBilledCost = null;
    String currency = null;
    LocalDate billMonth = AzureCostHelper.getMonthFromOldRequestUri(requestUri);
    for (OldEaSummarizedBillElement billElement : summarizedBillElements) {
        if (billElement == null) {
            continue;
        }
        billElement = AzureCostHelper.sanitizeSummarizedBillElementUsingOldApi(billElement);
        String serviceCommitment = billElement.serviceCommitment;
        context.currency = AzureCostConstants.DEFAULT_CURRENCY_VALUE;
        if (serviceCommitment == null) {
            continue;
        }
        switch(serviceCommitment) {
            case AzureCostConstants.SERVICE_COMMITMENT_TOTAL_USAGE:
                try {
                    accountUsageCost = Double.valueOf(billElement.amount);
                    if (billElement.currencyCode != null) {
                        currency = billElement.currencyCode.trim();
                    }
                } catch (NumberFormatException numberFormatEx) {
                    OldEaSummarizedBillElement finalBillElement = billElement;
                    logWarning(() -> String.format("Could not convert cost obtained from summarized bill " + "to a double value: %s", finalBillElement));
                }
                break;
            case AzureCostConstants.SERVICE_COMMITMENT_CHARGES_BILLED_SEPARATELY:
                accountSeparatelyBilledCost = getBillElementAmountUsingOldApi(billElement);
                break;
            case AzureCostConstants.SERVICE_COMMITMENT_MARKETPLACE_SERVICE_CHARGES_BILLED_SEPARATELY:
                accountMarketplaceCost = getBillElementAmountUsingOldApi(billElement);
                break;
            default:
                break;
        }
    }
    setEaAccountCosts(context, billMonth, accountUsageCost, accountMarketplaceCost, accountSeparatelyBilledCost);
    context.currency = currency;
}
Also used : OldEaSummarizedBillElement(com.vmware.photon.controller.model.adapters.azure.model.cost.OldEaSummarizedBillElement) AtomicDouble(com.google.common.util.concurrent.AtomicDouble) LocalDate(org.joda.time.LocalDate) OldApi(com.vmware.photon.controller.model.adapters.azure.model.cost.OldApi)

Aggregations

AtomicDouble (com.google.common.util.concurrent.AtomicDouble)1 OldApi (com.vmware.photon.controller.model.adapters.azure.model.cost.OldApi)1 OldEaSummarizedBillElement (com.vmware.photon.controller.model.adapters.azure.model.cost.OldEaSummarizedBillElement)1 LocalDate (org.joda.time.LocalDate)1