Search in sources :

Example 1 with AwsResourceDetailDto

use of com.vmware.photon.controller.model.adapters.aws.dto.AwsResourceDetailDto 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);
            }
        }
    }
}
Also used : AwsResourceDetailDto(com.vmware.photon.controller.model.adapters.aws.dto.AwsResourceDetailDto) AwsServiceDetailDto(com.vmware.photon.controller.model.adapters.aws.dto.AwsServiceDetailDto) ComputeStats(com.vmware.photon.controller.model.adapterapi.ComputeStatsResponse.ComputeStats) AwsServices(com.vmware.photon.controller.model.adapters.awsadapter.util.AWSCsvBillParser.AwsServices)

Example 2 with AwsResourceDetailDto

use of com.vmware.photon.controller.model.adapters.aws.dto.AwsResourceDetailDto in project photon-model by vmware.

the class AWSCsvBillParser method createOrGetResourceDetailObject.

private AwsResourceDetailDto createOrGetResourceDetailObject(Map<String, Object> rowMap, AwsServiceDetailDto serviceDetail, String resourceId) {
    AwsResourceDetailDto resourceDetail = serviceDetail.getResourceDetail(resourceId);
    if (resourceDetail == null) {
        resourceDetail = new AwsResourceDetailDto();
        resourceDetail.availabilityZone = ((String) rowMap.get(DetailedCsvHeaders.AVAILABILITY_ZONE));
        resourceDetail.type = "OTHERS";
        serviceDetail.addToResourceDetailMap(resourceId, resourceDetail);
    }
    return resourceDetail;
}
Also used : AwsResourceDetailDto(com.vmware.photon.controller.model.adapters.aws.dto.AwsResourceDetailDto)

Example 3 with AwsResourceDetailDto

use of com.vmware.photon.controller.model.adapters.aws.dto.AwsResourceDetailDto 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);
    }
}
Also used : LocalDateTime(org.joda.time.LocalDateTime) AwsResourceDetailDto(com.vmware.photon.controller.model.adapters.aws.dto.AwsResourceDetailDto) AwsServiceDetailDto(com.vmware.photon.controller.model.adapters.aws.dto.AwsServiceDetailDto) AwsAccountDetailDto(com.vmware.photon.controller.model.adapters.aws.dto.AwsAccountDetailDto)

Aggregations

AwsResourceDetailDto (com.vmware.photon.controller.model.adapters.aws.dto.AwsResourceDetailDto)3 AwsServiceDetailDto (com.vmware.photon.controller.model.adapters.aws.dto.AwsServiceDetailDto)2 ComputeStats (com.vmware.photon.controller.model.adapterapi.ComputeStatsResponse.ComputeStats)1 AwsAccountDetailDto (com.vmware.photon.controller.model.adapters.aws.dto.AwsAccountDetailDto)1 AwsServices (com.vmware.photon.controller.model.adapters.awsadapter.util.AWSCsvBillParser.AwsServices)1 LocalDateTime (org.joda.time.LocalDateTime)1