use of com.vmware.photon.controller.model.adapters.aws.dto.AwsServiceDetailDto in project photon-model by vmware.
the class AWSCostStatsService method insertEC2ServiceDetail.
private void insertEC2ServiceDetail(AwsAccountDetailDto awsAccountDetailDto) {
AwsServiceDetailDto vm = awsAccountDetailDto.serviceDetailsMap.get(AwsServices.EC2_Instance_Usage.getName());
AwsServiceDetailDto ebs = awsAccountDetailDto.serviceDetailsMap.get(AwsServices.EC2_EBS.getName());
AwsServiceDetailDto others = awsAccountDetailDto.serviceDetailsMap.get(AwsServices.EC2_Others.getName());
AwsServiceDetailDto ec2ServiceDetail = new AwsServiceDetailDto();
ec2ServiceDetail.id = AwsServices.EC2.getName();
ec2ServiceDetail.type = AwsServices.getTypeByName(AwsServices.EC2.getName()).toString();
ec2ServiceDetail.directCosts = Stream.of(vm, ebs, others).filter(Objects::nonNull).map(dto -> dto.directCosts.entrySet()).flatMap(Set::stream).collect(Collectors.toMap(Entry::getKey, Entry::getValue, Double::sum));
ec2ServiceDetail.otherCosts = Stream.of(vm, ebs, others).filter(Objects::nonNull).map(dto -> dto.otherCosts.entrySet()).flatMap(Set::stream).collect(Collectors.toMap(Entry::getKey, Entry::getValue, Double::sum));
ec2ServiceDetail.remainingCosts = Stream.of(vm, ebs, others).filter(Objects::nonNull).map(dto -> dto.remainingCosts.entrySet()).flatMap(Set::stream).collect(Collectors.toMap(Entry::getKey, Entry::getValue, Double::sum));
ec2ServiceDetail.reservedRecurringCosts = Stream.of(vm, ebs, others).filter(Objects::nonNull).map(dto -> dto.reservedRecurringCosts.entrySet()).flatMap(Set::stream).collect(Collectors.toMap(Entry::getKey, Entry::getValue, Double::sum));
awsAccountDetailDto.serviceDetailsMap.put(AwsServices.EC2.getName(), ec2ServiceDetail);
}
use of com.vmware.photon.controller.model.adapters.aws.dto.AwsServiceDetailDto in project photon-model by vmware.
the class AWSCostStatsService method createServiceStatsForAccount.
protected void createServiceStatsForAccount(AWSCostStatsCreationContext statsData, LocalDate billMonth, AwsAccountDetailDto awsAccountDetailDto) {
Consumer<ComputeState> serviceStatsProcessor = (accountComputeState) -> {
ComputeStats awsServiceStats = new ComputeStats();
awsServiceStats.statValues = new ConcurrentHashMap<>();
awsServiceStats.computeLink = accountComputeState.documentSelfLink;
awsServiceStats.addCustomProperty(PhotonModelConstants.DOES_CONTAIN_SERVICE_STATS, Boolean.TRUE.toString());
for (AwsServiceDetailDto serviceDetailDto : awsAccountDetailDto.serviceDetailsMap.values()) {
Map<String, List<ServiceStat>> statsForAwsService = createStatsForAwsService(serviceDetailDto);
awsServiceStats.statValues.putAll(statsForAwsService);
}
if (!awsServiceStats.statValues.isEmpty()) {
statsData.statsResponse.statsList.add(awsServiceStats);
}
};
insertEC2ServiceDetail(awsAccountDetailDto);
processAccountStats(statsData, billMonth, awsAccountDetailDto, serviceStatsProcessor);
}
use of com.vmware.photon.controller.model.adapters.aws.dto.AwsServiceDetailDto in project photon-model by vmware.
the class AWSCostStatsService method createResourceStatsForAccount.
protected void createResourceStatsForAccount(AWSCostStatsCreationContext statsData, AwsAccountDetailDto awsAccountDetailDto) {
Map<String, AwsServiceDetailDto> serviceDetails = awsAccountDetailDto.serviceDetailsMap;
List<AwsServices> supportedServices = Arrays.asList(AwsServices.EC2_Instance_Usage, AwsServices.EC2_EBS, AwsServices.S3);
for (String service : serviceDetails.keySet()) {
if (!supportedServices.contains(AwsServices.getByName(service))) {
continue;
}
Map<String, AwsResourceDetailDto> resourceDetailsMap = serviceDetails.get(service).resourceDetailsMap;
if (resourceDetailsMap == null) {
continue;
}
for (Entry<String, AwsResourceDetailDto> entry : resourceDetailsMap.entrySet()) {
String resourceId = entry.getKey();
AwsResourceDetailDto resourceDetails = entry.getValue();
if ((resourceDetails == null) || (resourceDetails.directCosts == null)) {
continue;
}
Set<String> resourceLinks = statsData.awsResourceLinksById.getOrDefault(resourceId, Collections.emptySet());
for (String resourceStateLink : resourceLinks) {
ComputeStats resourceStats = createStatsForResource(resourceStateLink, resourceDetails);
statsData.statsResponse.statsList.add(resourceStats);
}
}
}
}
use of com.vmware.photon.controller.model.adapters.aws.dto.AwsServiceDetailDto in project photon-model by vmware.
the class AWSCsvBillParser method createOrGetServiceDetailObject.
private AwsServiceDetailDto createOrGetServiceDetailObject(AwsAccountDetailDto accountDetails, String serviceName, String resourceId) {
if (serviceName != null && serviceName.contains(AwsServices.EC2.getName())) {
if (resourceId != null && resourceId.startsWith(AWS_INSTANCE_ID_PREFIX)) {
serviceName = AwsServices.EC2_Instance_Usage.getName();
} else if (resourceId != null && resourceId.startsWith(AWS_VOLUME_ID_PREFIX)) {
serviceName = AwsServices.EC2_EBS.getName();
} else {
serviceName = AwsServices.EC2_Others.getName();
}
}
AwsServiceDetailDto serviceDetail = accountDetails.fetchServiceDetail(serviceName);
/*
* If the service is not present, add the service and its details from
* the bill
*/
if (serviceDetail == null && serviceName != null && !serviceName.isEmpty()) {
serviceDetail = new AwsServiceDetailDto();
serviceDetail.id = serviceName;
serviceDetail.type = AwsServices.getTypeByName(serviceName).toString();
accountDetails.addToServiceDetailsMap(serviceName, serviceDetail);
}
return serviceDetail;
}
use of com.vmware.photon.controller.model.adapters.aws.dto.AwsServiceDetailDto in project photon-model by vmware.
the class AWSCsvBillParser method readSummaryRow.
private void readSummaryRow(Map<String, Object> rowMap, String linkedAccountId, String productName, Map<String, AwsAccountDetailDto> accountDetails, Collection<String> ignorableInvoiceCharge) {
AwsAccountDetailDto awsAccountDetail;
if (linkedAccountId == null || linkedAccountId.length() == 0) {
// The AccountId is not obtained from LinkedAccountId in case of
// non-consolidated bills and has to be fetched from PayerAccountId
// column from the bill file
awsAccountDetail = createOrGetAccountDetailObject(accountDetails, getStringFieldValue(rowMap, DetailedCsvHeaders.PAYER_ACCOUNT_ID));
} else {
awsAccountDetail = createOrGetAccountDetailObject(accountDetails, linkedAccountId);
}
String lineInvoiceId = getStringFieldValue(rowMap, DetailedCsvHeaders.INVOICE_ID);
Double resourceCost = getResourceCost(rowMap);
if (matchFieldValue(rowMap, DetailedCsvHeaders.RECORD_TYPE, DetailedCsvHeaders.LINE_ITEM)) {
LocalDateTime usageStartTimeFromCsv = (LocalDateTime) rowMap.get(DetailedCsvHeaders.USAGE_START_DATE);
Long millisForBillHour = getMillisForHour(usageStartTimeFromCsv);
AwsServiceDetailDto serviceDetail = createOrGetServiceDetailObject(awsAccountDetail, productName, null);
if (serviceDetail != null && millisForBillHour != null) {
if (matchFieldValue(rowMap, DetailedCsvHeaders.OPERATION, RUN_INSTANCES)) {
serviceDetail.addToReservedRecurringCosts(millisForBillHour, resourceCost);
return;
}
serviceDetail.addToRemainingCosts(millisForBillHour, resourceCost);
if (StringUtils.isNotEmpty(lineInvoiceId) && StringUtils.isNotEmpty(this.billInvoiceId) && !StringUtils.equals(lineInvoiceId, this.billInvoiceId)) {
// service subscriptions/renewals
awsAccountDetail.accountOneTimeCharges += resourceCost;
ignorableInvoiceCharge.add(lineInvoiceId);
}
return;
}
awsAccountDetail.otherCharges += resourceCost;
} else if (matchFieldValue(rowMap, DetailedCsvHeaders.RECORD_TYPE, ACCOUNT_TOTAL)) {
// If the RecordType is AccountTotal, this is the account monthly cost for consolidated bills
awsAccountDetail.cost = resourceCost;
} else if (matchFieldValue(rowMap, DetailedCsvHeaders.RECORD_TYPE, INVOICE_TOTAL)) {
// ie, for primary accounts with no linked accounts
if (!ignorableInvoiceCharge.contains(lineInvoiceId)) {
awsAccountDetail.cost = resourceCost;
}
}
}
Aggregations