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;
}
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;
}
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();
}
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;
}
Aggregations