Search in sources :

Example 11 with ComputeStats

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

the class AWSCostStatsService method createAccountStats.

protected void createAccountStats(AWSCostStatsCreationContext statsData, LocalDate billMonth, AwsAccountDetailDto awsAccountDetailDto) {
    Consumer<ComputeState> accountStatsProcessor = (accountComputeState) -> {
        ComputeStats accountStats = new ComputeStats();
        accountStats.statValues = new ConcurrentHashMap<>();
        accountStats.computeLink = accountComputeState.documentSelfLink;
        if (isBillUpdated(statsData, awsAccountDetailDto)) {
            logWithContext(statsData, Level.INFO, () -> String.format("Persisting cost of Account: %s (%s) for month: %s", awsAccountDetailDto.id, accountComputeState.documentSelfLink, billMonth));
            ServiceStat costStat = createStat(AWSStatsNormalizer.getNormalizedUnitValue(DIMENSION_CURRENCY_VALUE), AWSStatsNormalizer.getNormalizedStatKeyValue(AWSConstants.COST), awsAccountDetailDto.billProcessedTimeMillis, awsAccountDetailDto.cost);
            accountStats.statValues.put(costStat.name, Collections.singletonList(costStat));
            ServiceStat otherCostsStat = createStat(AWSStatsNormalizer.getNormalizedUnitValue(DIMENSION_CURRENCY_VALUE), AWSConstants.OTHER_CHARGES, awsAccountDetailDto.billProcessedTimeMillis, awsAccountDetailDto.otherCharges);
            accountStats.statValues.put(otherCostsStat.name, Collections.singletonList(otherCostsStat));
            ServiceStat oneTimeChargesStat = createStat(AWSStatsNormalizer.getNormalizedUnitValue(DIMENSION_CURRENCY_VALUE), PhotonModelConstants.ACCOUNT_ONE_TIME_CHARGES, awsAccountDetailDto.billProcessedTimeMillis, awsAccountDetailDto.accountOneTimeCharges);
            accountStats.statValues.put(oneTimeChargesStat.name, Collections.singletonList(oneTimeChargesStat));
        }
        if (!accountStats.statValues.isEmpty()) {
            statsData.statsResponse.statsList.add(accountStats);
        }
    };
    processAccountStats(statsData, billMonth, awsAccountDetailDto, accountStatsProcessor);
    ResourceMetrics prevMarkerMetrics = statsData.accountsMarkersMap.get(awsAccountDetailDto.id);
    if (prevMarkerMetrics != null) {
        prevMarkerMetrics.entries.putAll(transformMapDataTypes(awsAccountDetailDto.lineCountPerInterval));
    }
}
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) ResourceMetrics(com.vmware.photon.controller.model.monitoring.ResourceMetricsService.ResourceMetrics) ComputeStats(com.vmware.photon.controller.model.adapterapi.ComputeStatsResponse.ComputeStats) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 12 with ComputeStats

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

the class VSphereAdapterStatsService method persistStats.

private void persistStats(List<ServiceStat> stats, ComputeStatsRequest statsRequest) {
    ComputeStats cs = new ComputeStats();
    cs.computeLink = statsRequest.resourceReference.toString();
    cs.statValues = new HashMap<>();
    if (stats != null) {
        for (ServiceStat stat : stats) {
            cs.statValues.put(stat.name, Collections.singletonList(stat));
        }
    }
    SingleResourceStatsCollectionTaskState respBody = new SingleResourceStatsCollectionTaskState();
    respBody.statsList = new ArrayList<>();
    respBody.statsList.add(cs);
    respBody.taskStage = SingleResourceTaskCollectionStage.valueOf(statsRequest.nextStage);
    respBody.statsAdapterReference = UriUtils.buildUri(getHost(), SELF_LINK);
    // Verify if this makes sense? These tasks should always be local to deployment?
    this.sendRequest(Operation.createPatch(statsRequest.taskReference).setBody(respBody));
}
Also used : ServiceStat(com.vmware.xenon.common.ServiceStats.ServiceStat) ComputeStats(com.vmware.photon.controller.model.adapterapi.ComputeStatsResponse.ComputeStats) SingleResourceStatsCollectionTaskState(com.vmware.photon.controller.model.tasks.monitoring.SingleResourceStatsCollectionTaskService.SingleResourceStatsCollectionTaskState)

Example 13 with ComputeStats

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

the class MockStatsAdapter method sendBatchResponse.

private void sendBatchResponse(ComputeStatsRequest statsRequest, SingleResourceStatsCollectionTaskState statsResponse, Map<String, List<ServiceStat>> statValues, boolean isFinalBatch) {
    ComputeStats cStat = new ComputeStats();
    cStat.statValues = statValues;
    cStat.computeLink = statsRequest.resourceReference.getPath();
    cStat.addCustomProperty("prop1", "val1");
    statsResponse.statsList = new ArrayList<>();
    statsResponse.statsList.add(cStat);
    statsResponse.taskStage = SingleResourceTaskCollectionStage.valueOf(statsRequest.nextStage);
    statsResponse.statsAdapterReference = UriUtils.buildUri(getHost(), SELF_LINK);
    statsResponse.isFinalBatch = isFinalBatch;
    this.sendRequest(Operation.createPatch(statsRequest.taskReference).setBody(statsResponse));
}
Also used : ComputeStats(com.vmware.photon.controller.model.adapterapi.ComputeStatsResponse.ComputeStats)

Example 14 with ComputeStats

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

the class AWSCostStatsService method createStatsForResource.

private ComputeStats createStatsForResource(String resourceLink, AwsResourceDetailDto resourceDetails) {
    ComputeStats resourceStats = new ComputeStats();
    resourceStats.statValues = new ConcurrentSkipListMap<>();
    resourceStats.computeLink = resourceLink;
    List<ServiceStat> resourceServiceStats = new ArrayList<>();
    String normalizedStatKeyValue = AWSStatsNormalizer.getNormalizedStatKeyValue(AWSConstants.COST);
    for (Entry<Long, Double> cost : resourceDetails.directCosts.entrySet()) {
        ServiceStat resourceStat = createStat(AWSStatsNormalizer.getNormalizedUnitValue(DIMENSION_CURRENCY_VALUE), normalizedStatKeyValue, cost.getKey(), cost.getValue());
        resourceServiceStats.add(resourceStat);
    }
    resourceStats.statValues.put(normalizedStatKeyValue, resourceServiceStats);
    // Create a stat to represent how many hours a resource ran as reserve instance
    String normalizedReservedInstanceStatKey = AWSStatsNormalizer.getNormalizedStatKeyValue(AWSConstants.RESERVED_INSTANCE_DURATION);
    List<ServiceStat> reservedInstanceStats = new ArrayList<>();
    for (Entry<Long, Double> entry : resourceDetails.hoursAsReservedPerDay.entrySet()) {
        ServiceStat resourceStat = createStat(AWSStatsNormalizer.getNormalizedUnitValue(AWSConstants.UNIT_HOURS), normalizedReservedInstanceStatKey, entry.getKey(), entry.getValue());
        reservedInstanceStats.add(resourceStat);
    }
    logFine(() -> String.format("Reserved Instances stats count for %s is %d", resourceLink, reservedInstanceStats.size()));
    if (reservedInstanceStats.size() > 0) {
        resourceStats.statValues.put(normalizedReservedInstanceStatKey, reservedInstanceStats);
    }
    return resourceStats;
}
Also used : ServiceStat(com.vmware.xenon.common.ServiceStats.ServiceStat) ComputeStats(com.vmware.photon.controller.model.adapterapi.ComputeStatsResponse.ComputeStats) ArrayList(java.util.ArrayList)

Example 15 with ComputeStats

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

the class AzureCostStatsService method createComputeStatsForResource.

private ComputeStats createComputeStatsForResource(String resourceLink, AzureResource azureResource) {
    String currencyUnit = AzureStatsNormalizer.getNormalizedUnitValue(AzureCostConstants.DEFAULT_CURRENCY_VALUE);
    String costStatName = AzureStatsNormalizer.getNormalizedStatKeyValue(AzureCostConstants.COST);
    ComputeStats resourceComputeStats = new ComputeStats();
    resourceComputeStats.statValues = new HashMap<>();
    resourceComputeStats.computeLink = resourceLink;
    azureResource.cost.forEach((dayOfMonth, cost) -> {
        List<ServiceStat> vmCostStats = new ArrayList<>();
        ServiceStat vmCostStat = AzureCostHelper.createServiceStat(costStatName, cost, currencyUnit, dayOfMonth);
        vmCostStats.add(vmCostStat);
        resourceComputeStats.statValues.put(costStatName, vmCostStats);
    });
    return resourceComputeStats;
}
Also used : ServiceStat(com.vmware.xenon.common.ServiceStats.ServiceStat) ComputeStats(com.vmware.photon.controller.model.adapterapi.ComputeStatsResponse.ComputeStats) ArrayList(java.util.ArrayList)

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