Search in sources :

Example 1 with OldApi

use of com.vmware.photon.controller.model.adapters.azure.model.cost.OldApi 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)

Example 2 with OldApi

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

the class AzureCostHelper method getOldBillOperation.

@OldApi
static Operation getOldBillOperation(String enrollmentNumber, String accessToken, LocalDate billMonthToDownload, String billType) {
    String baseUri = AdapterUriUtil.expandUriPathTemplate(AzureCostConstants.OLD_EA_USAGE_REPORT, enrollmentNumber);
    // Get the summarized bill in JSON format and detailed bill in CSV format.
    String billFormat = billType.equals(AzureCostConstants.QUERY_PARAM_BILL_TYPE_VALUE_DETAILED) ? AzureCostConstants.QUERY_PARAM_RESPONSE_FORMAT_VALUE_CSV : AzureCostConstants.QUERY_PARAM_RESPONSE_FORMAT_VALUE_JSON;
    String dateInBillingApiExpectedFormat = getDateInBillingApiFormat(billMonthToDownload);
    URI uri = UriUtils.extendUriWithQuery(UriUtils.buildUri(baseUri), AzureCostConstants.QUERY_PARAM_BILL_MONTH, dateInBillingApiExpectedFormat, AzureCostConstants.QUERY_PARAM_BILL_TYPE, billType, AzureCostConstants.QUERY_PARAM_RESPONSE_FORMAT, billFormat);
    logger.info(String.format("Request: %s", uri.toString()));
    Operation operation = Operation.createGet(uri);
    addDefaultRequestHeaders(operation, accessToken);
    // Retry thrice on failure.
    operation = operation.setRetryCount(3);
    operation = setExpirationForExternalRequests(operation);
    return operation;
}
Also used : Operation(com.vmware.xenon.common.Operation) URI(java.net.URI) OldApi(com.vmware.photon.controller.model.adapters.azure.model.cost.OldApi)

Example 3 with OldApi

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

the class AzureCostHelper method getOldDetailedBillRequest.

@OldApi
static Request getOldDetailedBillRequest(String enrollmentNumber, String accessToken, LocalDate billMonthToDownload) {
    String baseUri = AdapterUriUtil.expandUriPathTemplate(AzureCostConstants.OLD_EA_USAGE_REPORT, enrollmentNumber);
    String dateInBillingApiExpectedFormat = getDateInBillingApiFormat(billMonthToDownload);
    URI uri = UriUtils.extendUriWithQuery(UriUtils.buildUri(baseUri), AzureCostConstants.QUERY_PARAM_BILL_MONTH, dateInBillingApiExpectedFormat, AzureCostConstants.QUERY_PARAM_BILL_TYPE, AzureCostConstants.QUERY_PARAM_BILL_TYPE_VALUE_DETAILED, AzureCostConstants.QUERY_PARAM_RESPONSE_FORMAT, AzureCostConstants.QUERY_PARAM_RESPONSE_FORMAT_VALUE_CSV);
    return new Request.Builder().url(uri.toString()).addHeader(Operation.AUTHORIZATION_HEADER, AzureConstants.AUTH_HEADER_BEARER_PREFIX + accessToken).addHeader(AzureCostConstants.API_VERSION_HEADER, AzureCostConstants.API_VERSION_HEADER_VALUE).build();
}
Also used : URI(java.net.URI) OldApi(com.vmware.photon.controller.model.adapters.azure.model.cost.OldApi)

Example 4 with OldApi

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

the class AzureCostHelper method getOldBillAvailableMonths.

@OldApi
static Operation getOldBillAvailableMonths(String enrollmentNumber, String accessToken) {
    String baseUri = AdapterUriUtil.expandUriPathTemplate(AzureCostConstants.OLD_EA_BILL_AVAILABLE_MONTHS, enrollmentNumber);
    // Get the summarized bill in JSON format and detailed bill in CSV format.
    URI uri = UriUtils.extendUriWithQuery(UriUtils.buildUri(baseUri));
    logger.info(String.format("Request: %s", uri.toString()));
    Operation operation = Operation.createGet(uri);
    addDefaultRequestHeaders(operation, accessToken);
    // Retry thrice on failure.
    operation = operation.setRetryCount(3);
    operation = setExpirationForExternalRequests(operation);
    return operation;
}
Also used : Operation(com.vmware.xenon.common.Operation) URI(java.net.URI) OldApi(com.vmware.photon.controller.model.adapters.azure.model.cost.OldApi)

Aggregations

OldApi (com.vmware.photon.controller.model.adapters.azure.model.cost.OldApi)4 URI (java.net.URI)3 Operation (com.vmware.xenon.common.Operation)2 AtomicDouble (com.google.common.util.concurrent.AtomicDouble)1 OldEaSummarizedBillElement (com.vmware.photon.controller.model.adapters.azure.model.cost.OldEaSummarizedBillElement)1 LocalDate (org.joda.time.LocalDate)1