Search in sources :

Example 6 with ComputeStats

use of com.vmware.photon.controller.model.adapterapi.ComputeStatsResponse.ComputeStats in project photon-model by vmware.

the class AzureCostHelper method createMonthlyEaAccountCostStats.

static List<ComputeStats> createMonthlyEaAccountCostStats(Map<LocalDate, EaAccountCost> monthlyEaAccountCosts, Map<LocalDate, Double> monthlyTotalCosts, ComputeStateWithDescription computeHostDesc) {
    List<ComputeStats> accountStats = new ArrayList<>();
    String usageCostStatName = AzureCostConstants.USAGE_COST;
    String marketplaceCostStatName = AzureCostConstants.MARKETPLACE_COST;
    String separatelyBilledCostStatName = AzureCostConstants.SEPARATELY_BILLED_COST;
    String costUnit = AzureStatsNormalizer.getNormalizedUnitValue(AzureCostConstants.DEFAULT_CURRENCY_VALUE);
    for (Entry<LocalDate, Double> monthlyTotalCost : monthlyTotalCosts.entrySet()) {
        ComputeStats accountStat = new ComputeStats();
        accountStat.computeLink = computeHostDesc.documentSelfLink;
        accountStat.statValues = new ConcurrentSkipListMap<>();
        LocalDate month = monthlyTotalCost.getKey();
        long timeStamp = adaptMonthToCostTimeStamp(month);
        EaAccountCost eaAccountCost = monthlyEaAccountCosts.get(month);
        ServiceStat usageCostServiceStat = AzureCostHelper.createServiceStat(usageCostStatName, eaAccountCost.monthlyEaAccountUsageCost, costUnit, timeStamp);
        ServiceStat marketplaceCostServiceStat = AzureCostHelper.createServiceStat(marketplaceCostStatName, eaAccountCost.monthlyEaAccountMarketplaceCost, costUnit, timeStamp);
        ServiceStat separatelyBilledCostServiceStat = AzureCostHelper.createServiceStat(separatelyBilledCostStatName, eaAccountCost.monthlyEaAccountSeparatelyBilledCost, costUnit, timeStamp);
        accountStat.statValues.put(usageCostStatName, Collections.singletonList(usageCostServiceStat));
        accountStat.statValues.put(marketplaceCostStatName, Collections.singletonList(marketplaceCostServiceStat));
        accountStat.statValues.put(separatelyBilledCostStatName, Collections.singletonList(separatelyBilledCostServiceStat));
        accountStats.add(accountStat);
    }
    return accountStats;
}
Also used : ServiceStat(com.vmware.xenon.common.ServiceStats.ServiceStat) ComputeStats(com.vmware.photon.controller.model.adapterapi.ComputeStatsResponse.ComputeStats) ArrayList(java.util.ArrayList) EaAccountCost(com.vmware.photon.controller.model.adapters.azure.ea.stats.AzureCostStatsService.EaAccountCost) LocalDate(org.joda.time.LocalDate)

Example 7 with ComputeStats

use of com.vmware.photon.controller.model.adapterapi.ComputeStatsResponse.ComputeStats in project photon-model by vmware.

the class AzureCostHelper method createOldestBillDownloadedStat.

static ComputeStats createOldestBillDownloadedStat(ComputeStateWithDescription computeHostDesc, long billParsedMillis, long currentMonthBillParsedMillis) {
    ComputeStats stats = new ComputeStats();
    stats.computeLink = computeHostDesc.documentSelfLink;
    stats.statValues = new ConcurrentSkipListMap<>();
    stats.addCustomProperty(PhotonModelConstants.CONTAINS_BILL_PROCESSED_TIME_STAT, Boolean.TRUE.toString());
    ServiceStat oldestBillDownloadedStat = AzureCostHelper.createServiceStat(AzureCostConstants.OLDEST_BILL_PROCESSED_MILLIS, billParsedMillis, PhotonModelConstants.UNIT_MILLISECONDS, currentMonthBillParsedMillis);
    stats.statValues.put(oldestBillDownloadedStat.name, Collections.singletonList(oldestBillDownloadedStat));
    return stats;
}
Also used : ServiceStat(com.vmware.xenon.common.ServiceStats.ServiceStat) ComputeStats(com.vmware.photon.controller.model.adapterapi.ComputeStatsResponse.ComputeStats)

Example 8 with ComputeStats

use of com.vmware.photon.controller.model.adapterapi.ComputeStatsResponse.ComputeStats in project photon-model by vmware.

the class AzureCostHelper method createApiKeyExpiresTimeStat.

static ComputeStats createApiKeyExpiresTimeStat(ComputeStateWithDescription computeHostDesc, long keyExpiryTime) {
    ComputeStats accountStats = new ComputeStats();
    accountStats.computeLink = computeHostDesc.documentSelfLink;
    accountStats.statValues = new ConcurrentSkipListMap<>();
    ServiceStat keyExpiryTimeMillis = AzureCostHelper.createServiceStat(AzureCostConstants.EA_ACCOUNT_USAGE_KEY_EXPIRY_TIME_MILLIS, keyExpiryTime, PhotonModelConstants.UNIT_MILLISECONDS, AzureCostHelper.getMillisNow());
    accountStats.statValues.put(keyExpiryTimeMillis.name, Collections.singletonList(keyExpiryTimeMillis));
    return accountStats;
}
Also used : ServiceStat(com.vmware.xenon.common.ServiceStats.ServiceStat) ComputeStats(com.vmware.photon.controller.model.adapterapi.ComputeStatsResponse.ComputeStats)

Example 9 with ComputeStats

use of com.vmware.photon.controller.model.adapterapi.ComputeStatsResponse.ComputeStats 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);
}
Also used : AuthCredentialsServiceState(com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState) Arrays(java.util.Arrays) DateTimeZone(org.joda.time.DateTimeZone) AWS_ACCOUNT_BILL_PROCESSED_TIME_MILLIS(com.vmware.photon.controller.model.adapters.awsadapter.AWSConstants.AWS_ACCOUNT_BILL_PROCESSED_TIME_MILLIS) AWSCsvBillParser(com.vmware.photon.controller.model.adapters.awsadapter.util.AWSCsvBillParser) ServiceTypeCluster(com.vmware.photon.controller.model.util.ClusterUtil.ServiceTypeCluster) QueryTask(com.vmware.xenon.services.common.QueryTask) ServiceDocument(com.vmware.xenon.common.ServiceDocument) ComputeType(com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription.ComputeType) EndpointAllocationTaskService(com.vmware.photon.controller.model.tasks.EndpointAllocationTaskService) SingleResourceStatsCollectionTaskState(com.vmware.photon.controller.model.tasks.monitoring.SingleResourceStatsCollectionTaskService.SingleResourceStatsCollectionTaskState) ProgressListener(com.amazonaws.event.ProgressListener) STORAGE_TYPE_EBS(com.vmware.photon.controller.model.adapters.awsadapter.AWSConstants.STORAGE_TYPE_EBS) Utils(com.vmware.xenon.common.Utils) STORAGE_TYPE_S3(com.vmware.photon.controller.model.adapters.awsadapter.AWSConstants.STORAGE_TYPE_S3) ACCOUNT_IS_AUTO_DISCOVERED(com.vmware.photon.controller.model.adapters.awsadapter.AWSConstants.ACCOUNT_IS_AUTO_DISCOVERED) Map(java.util.Map) URI(java.net.URI) ProgressEventType(com.amazonaws.event.ProgressEventType) AWSMissingResourcesEnumerationService(com.vmware.photon.controller.model.adapters.awsadapter.enumeration.AWSMissingResourcesEnumerationService) Path(java.nio.file.Path) AWSClientManager(com.vmware.photon.controller.model.adapters.awsadapter.util.AWSClientManager) EndpointState(com.vmware.photon.controller.model.resources.EndpointService.EndpointState) PrintWriter(java.io.PrintWriter) ComputeStatsResponse(com.vmware.photon.controller.model.adapterapi.ComputeStatsResponse) ComputeStatsRequest(com.vmware.photon.controller.model.adapterapi.ComputeStatsRequest) StatelessService(com.vmware.xenon.common.StatelessService) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) TaskManager(com.vmware.photon.controller.model.adapters.util.TaskManager) Set(java.util.Set) DiskState(com.vmware.photon.controller.model.resources.DiskService.DiskState) Occurance(com.vmware.xenon.services.common.QueryTask.Query.Occurance) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) AwsServiceDetailDto(com.vmware.photon.controller.model.adapters.aws.dto.AwsServiceDetailDto) Objects(java.util.Objects) List(java.util.List) AWS_LINKED_ACCOUNT_IDS(com.vmware.photon.controller.model.adapters.awsadapter.AWSConstants.AWS_LINKED_ACCOUNT_IDS) Stream(java.util.stream.Stream) UriUtils(com.vmware.xenon.common.UriUtils) Entry(java.util.Map.Entry) QueryOption(com.vmware.xenon.services.common.QueryTask.QuerySpecification.QueryOption) AwsServices(com.vmware.photon.controller.model.adapters.awsadapter.util.AWSCsvBillParser.AwsServices) ResourceMetrics(com.vmware.photon.controller.model.monitoring.ResourceMetricsService.ResourceMetrics) SingleResourceTaskCollectionStage(com.vmware.photon.controller.model.tasks.monitoring.SingleResourceStatsCollectionTaskService.SingleResourceTaskCollectionStage) AwsAccountDetailDto(com.vmware.photon.controller.model.adapters.aws.dto.AwsAccountDetailDto) TransferManager(com.amazonaws.services.s3.transfer.TransferManager) QueryByPages(com.vmware.photon.controller.model.query.QueryUtils.QueryByPages) OperationContext(com.vmware.xenon.common.OperationContext) AWS_ACCOUNT_ID_KEY(com.vmware.photon.controller.model.adapters.awsadapter.AWSConstants.AWS_ACCOUNT_ID_KEY) HashMap(java.util.HashMap) ComputeDescriptionService(com.vmware.photon.controller.model.resources.ComputeDescriptionService) GetObjectRequest(com.amazonaws.services.s3.model.GetObjectRequest) ResourceMetricsService(com.vmware.photon.controller.model.monitoring.ResourceMetricsService) Function(java.util.function.Function) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) Level(java.util.logging.Level) ProgressEvent(com.amazonaws.event.ProgressEvent) HashSet(java.util.HashSet) AuthCredentialsService(com.vmware.xenon.services.common.AuthCredentialsService) Query(com.vmware.xenon.services.common.QueryTask.Query) UriPaths(com.vmware.photon.controller.model.UriPaths) CollectionUtils(org.apache.commons.collections.CollectionUtils) ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) BiConsumer(java.util.function.BiConsumer) ComputeStats(com.vmware.photon.controller.model.adapterapi.ComputeStatsResponse.ComputeStats) AwsClientType(com.vmware.photon.controller.model.adapters.awsadapter.AWSConstants.AwsClientType) StatsUtil(com.vmware.photon.controller.model.tasks.monitoring.StatsUtil) ExecutorService(java.util.concurrent.ExecutorService) AdapterUtils(com.vmware.photon.controller.model.adapters.util.AdapterUtils) AmazonS3Exception(com.amazonaws.services.s3.model.AmazonS3Exception) ResourceState(com.vmware.photon.controller.model.resources.ResourceState) Files(java.nio.file.Files) StringWriter(java.io.StringWriter) Operation(com.vmware.xenon.common.Operation) QueryUtils(com.vmware.photon.controller.model.query.QueryUtils) IOException(java.io.IOException) ServiceStat(com.vmware.xenon.common.ServiceStats.ServiceStat) AwsResourceDetailDto(com.vmware.photon.controller.model.adapters.aws.dto.AwsResourceDetailDto) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) LocalDate(org.joda.time.LocalDate) ConcurrentSkipListMap(java.util.concurrent.ConcurrentSkipListMap) Paths(java.nio.file.Paths) ClusterUtil(com.vmware.photon.controller.model.util.ClusterUtil) AWSStatsNormalizer(com.vmware.photon.controller.model.adapters.awsadapter.util.AWSStatsNormalizer) ComputeStateWithDescription(com.vmware.photon.controller.model.resources.ComputeService.ComputeStateWithDescription) PhotonModelConstants(com.vmware.photon.controller.model.constants.PhotonModelConstants) AWSClientManagerFactory(com.vmware.photon.controller.model.adapters.awsadapter.util.AWSClientManagerFactory) ServiceDocumentDescription(com.vmware.xenon.common.ServiceDocumentDescription) Collections(java.util.Collections) OperationJoin(com.vmware.xenon.common.OperationJoin) PhotonModelUriUtils.createInventoryUri(com.vmware.photon.controller.model.util.PhotonModelUriUtils.createInventoryUri) ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) ServiceStat(com.vmware.xenon.common.ServiceStats.ServiceStat) AwsServiceDetailDto(com.vmware.photon.controller.model.adapters.aws.dto.AwsServiceDetailDto) ComputeStats(com.vmware.photon.controller.model.adapterapi.ComputeStatsResponse.ComputeStats) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ConcurrentSkipListMap(java.util.concurrent.ConcurrentSkipListMap)

Example 10 with ComputeStats

use of com.vmware.photon.controller.model.adapterapi.ComputeStatsResponse.ComputeStats 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)

Aggregations

ComputeStats (com.vmware.photon.controller.model.adapterapi.ComputeStatsResponse.ComputeStats)20 ServiceStat (com.vmware.xenon.common.ServiceStats.ServiceStat)15 ArrayList (java.util.ArrayList)11 SingleResourceStatsCollectionTaskState (com.vmware.photon.controller.model.tasks.monitoring.SingleResourceStatsCollectionTaskService.SingleResourceStatsCollectionTaskState)8 ResourceMetrics (com.vmware.photon.controller.model.monitoring.ResourceMetricsService.ResourceMetrics)7 Operation (com.vmware.xenon.common.Operation)7 QueryTask (com.vmware.xenon.services.common.QueryTask)7 HashMap (java.util.HashMap)7 List (java.util.List)7 Map (java.util.Map)7 LocalDate (org.joda.time.LocalDate)7 ComputeStatsRequest (com.vmware.photon.controller.model.adapterapi.ComputeStatsRequest)6 PhotonModelConstants (com.vmware.photon.controller.model.constants.PhotonModelConstants)6 ServiceDocument (com.vmware.xenon.common.ServiceDocument)6 StatelessService (com.vmware.xenon.common.StatelessService)6 UriUtils (com.vmware.xenon.common.UriUtils)6 Utils (com.vmware.xenon.common.Utils)6 QueryUtils (com.vmware.photon.controller.model.query.QueryUtils)5 ComputeStateWithDescription (com.vmware.photon.controller.model.resources.ComputeService.ComputeStateWithDescription)5 ClusterUtil (com.vmware.photon.controller.model.util.ClusterUtil)5