use of com.vmware.photon.controller.model.adapters.aws.dto.AwsAccountDetailDto in project photon-model by vmware.
the class AWSCsvBillParser method createOrGetAccountDetailObject.
private AwsAccountDetailDto createOrGetAccountDetailObject(Map<String, AwsAccountDetailDto> monthlyBill, final String linkedAccountId) {
AwsAccountDetailDto accountDetails = monthlyBill.get(linkedAccountId);
if (accountDetails == null) {
accountDetails = new AwsAccountDetailDto();
accountDetails.id = linkedAccountId;
monthlyBill.put(linkedAccountId, accountDetails);
}
return accountDetails;
}
use of com.vmware.photon.controller.model.adapters.aws.dto.AwsAccountDetailDto in project photon-model by vmware.
the class AWSCsvBillParser method readRow.
/**
* This method reads each row of the AWS bill file, ignores the values that
* are not required, creates or updates the corresponding entry in
* monthlyBill Map.
*/
private void readRow(Map<String, Object> rowMap, Map<String, AwsAccountDetailDto> monthlyBill, List<String> tagHeaders, Collection<String> ignorableInvoiceCharge, Set<String> configuredAccounts) {
final String linkedAccountId = getStringFieldValue(rowMap, DetailedCsvHeaders.LINKED_ACCOUNT_ID);
String serviceName = getStringFieldValue(rowMap, DetailedCsvHeaders.PRODUCT_NAME);
String subscriptionId = getStringFieldValue(rowMap, DetailedCsvHeaders.SUBSCRIPTION_ID);
// Summary Row: For all rows except summary rows this is not null.
if (subscriptionId == null || subscriptionId.length() == 0 || serviceName == null || serviceName.length() == 0) {
// Reads the summary lines in bill file, which consists of the
// account cost and puts it in the monthly bill map
readSummaryRow(rowMap, linkedAccountId, serviceName, monthlyBill, ignorableInvoiceCharge);
return;
}
// ------------------------------------------------------------------------------------
// Check if the account corresponding to this row is configured in the system.
// If not, we skip holding related information in memory.
AwsAccountDetailDto accountDetails = createOrGetAccountDetailObject(monthlyBill, linkedAccountId);
if (!configuredAccounts.contains(linkedAccountId)) {
return;
}
// Non-summary rows.
if (this.billInvoiceId == null) {
this.billInvoiceId = getStringFieldValue(rowMap, DetailedCsvHeaders.INVOICE_ID);
}
LocalDateTime usageStartTimeFromCsv = (LocalDateTime) rowMap.get(DetailedCsvHeaders.USAGE_START_DATE);
Long millisForBillHour = getMillisForHour(usageStartTimeFromCsv);
boolean isRowMarkedAsReserved = isRowReservedInstanceRecurringCost(rowMap);
// for previous months.
if (millisForBillHour == null || (millisForBillHour >= this.monthStartMillis)) {
String resourceId = getStringFieldValue(rowMap, DetailedCsvHeaders.RESOURCE_ID);
AwsServiceDetailDto serviceDetail = createOrGetServiceDetailObject(accountDetails, serviceName, resourceId);
Double resourceCost = getResourceCost(rowMap);
// (recurring charges for reserved instance)or sign up charges(which we have to ignore)}
if (resourceId == null || resourceId.length() == 0) {
// day, otherwise set it as common for month, can divide later for all days
if (millisForBillHour != null) {
if (isRowMarkedAsReserved && matchFieldValue(rowMap, DetailedCsvHeaders.OPERATION, RUN_INSTANCES)) {
serviceDetail.addToReservedRecurringCosts(millisForBillHour, resourceCost);
} else {
serviceDetail.addToOtherCosts(millisForBillHour, resourceCost);
// Adding zero as direct cost for this entity to allow
// populating this as a resource while getting services
serviceDetail.addToDirectCosts(millisForBillHour, 0d);
}
}
} else {
if (millisForBillHour != null) {
serviceDetail.addToDirectCosts(millisForBillHour, resourceCost);
// currently we need only EC2 instances,volumes and s3 buckets
if (resourceId.startsWith(AWS_INSTANCE_ID_PREFIX) || resourceId.startsWith(AWS_VOLUME_ID_PREFIX) || AwsServices.S3.getName().equalsIgnoreCase(serviceName)) {
AwsResourceDetailDto resourceDetail = createOrGetResourceDetailObject(rowMap, serviceDetail, resourceId);
resourceDetail.addToDirectCosts(millisForBillHour, resourceCost);
setLatestResourceValues(rowMap, tagHeaders, resourceDetail);
}
}
}
}
if (millisForBillHour != null && millisForBillHour > accountDetails.billProcessedTimeMillis && millisForBillHour < System.currentTimeMillis()) {
accountDetails.billProcessedTimeMillis = millisForBillHour;
}
// update the line count of the account to whom this row belongs to
if (millisForBillHour != null) {
LocalDateTime usageEndTimeFromCsv = (LocalDateTime) rowMap.get(DetailedCsvHeaders.USAGE_END_DATE);
Long endMillisForBillHour = getMillisForHour(usageEndTimeFromCsv);
String interval = createInterval(millisForBillHour, endMillisForBillHour);
Integer currentLineCount = accountDetails.lineCountPerInterval.getOrDefault(interval, 0);
accountDetails.lineCountPerInterval.put(interval, currentLineCount + 1);
}
}
Aggregations