Search in sources :

Example 1 with ACCOUNT_IS_AUTO_DISCOVERED

use of com.vmware.photon.controller.model.adapters.awsadapter.AWSConstants.ACCOUNT_IS_AUTO_DISCOVERED in project photon-model by vmware.

the class AWSCostStatsService method createMissingResourcesComputes.

private void createMissingResourcesComputes(AWSCostStatsCreationContext context, AWSCostStatsCreationStages next) {
    String linkedAccountsCsv = context.computeDesc.customProperties.get(AWS_LINKED_ACCOUNT_IDS);
    if (context.isSecondPass || linkedAccountsCsv == null || linkedAccountsCsv.isEmpty() || !isAutoDiscoveryEnabled(context)) {
        context.stage = next;
        handleCostStatsCreationRequest(context);
        return;
    }
    // Following function tells whether the computes of a particular account contain an
    // auto-discovered compute under the primary account's endpoint.
    Function<List<ComputeState>, Boolean> hasAutoDiscoveredCompute = (computes) -> {
        if (CollectionUtils.isEmpty(computes)) {
            return false;
        }
        return computes.stream().filter(c -> c.endpointLinks.contains(context.computeDesc.endpointLink) && Boolean.valueOf(c.customProperties.get(ACCOUNT_IS_AUTO_DISCOVERED))).count() != 0;
    };
    Set<String> existingLinkedAccountIds = context.awsAccountIdToComputeStates.entrySet().stream().filter(e -> hasAutoDiscoveredCompute.apply(e.getValue())).map(e -> e.getKey()).collect(Collectors.toCollection(HashSet::new));
    List<String> missingLinkedAccountIds = Stream.of(linkedAccountsCsv.split(",")).filter(id -> !existingLinkedAccountIds.contains(id)).collect(Collectors.toList());
    if (CollectionUtils.isEmpty(missingLinkedAccountIds)) {
        context.stage = next;
        handleCostStatsCreationRequest(context);
        return;
    }
    AWSMissingResourcesEnumerationService.Request request = new AWSMissingResourcesEnumerationService.Request();
    request.missingLinkedAccountIds = missingLinkedAccountIds;
    request.primaryAccountCompute = context.computeDesc;
    Operation op = Operation.createPost(UriUtils.buildUri(getHost(), AWSMissingResourcesEnumerationService.SELF_LINK)).setBody(request).setCompletion((o, e) -> {
        // Even if the operation fails, we continue with the second pass.
        // The exception might indicate failure for creation of few linked account
        // computes but not all. So we execute the second pass to model the cost of
        // atleast the ones which were created.
        context.stage = AWSCostStatsCreationStages.QUERY_LINKED_ACCOUNTS;
        context.isSecondPass = true;
        context.billMonthToDownload = null;
        context.awsResourceLinksById.clear();
        handleCostStatsCreationRequest(context);
    });
    sendRequest(op);
}
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) AWSMissingResourcesEnumerationService(com.vmware.photon.controller.model.adapters.awsadapter.enumeration.AWSMissingResourcesEnumerationService) ComputeStatsRequest(com.vmware.photon.controller.model.adapterapi.ComputeStatsRequest) GetObjectRequest(com.amazonaws.services.s3.model.GetObjectRequest) List(java.util.List) ArrayList(java.util.ArrayList) Operation(com.vmware.xenon.common.Operation)

Aggregations

ProgressEvent (com.amazonaws.event.ProgressEvent)1 ProgressEventType (com.amazonaws.event.ProgressEventType)1 ProgressListener (com.amazonaws.event.ProgressListener)1 AmazonS3Exception (com.amazonaws.services.s3.model.AmazonS3Exception)1 GetObjectRequest (com.amazonaws.services.s3.model.GetObjectRequest)1 TransferManager (com.amazonaws.services.s3.transfer.TransferManager)1 UriPaths (com.vmware.photon.controller.model.UriPaths)1 ComputeStatsRequest (com.vmware.photon.controller.model.adapterapi.ComputeStatsRequest)1 ComputeStatsResponse (com.vmware.photon.controller.model.adapterapi.ComputeStatsResponse)1 ComputeStats (com.vmware.photon.controller.model.adapterapi.ComputeStatsResponse.ComputeStats)1 AwsAccountDetailDto (com.vmware.photon.controller.model.adapters.aws.dto.AwsAccountDetailDto)1 AwsResourceDetailDto (com.vmware.photon.controller.model.adapters.aws.dto.AwsResourceDetailDto)1 AwsServiceDetailDto (com.vmware.photon.controller.model.adapters.aws.dto.AwsServiceDetailDto)1 ACCOUNT_IS_AUTO_DISCOVERED (com.vmware.photon.controller.model.adapters.awsadapter.AWSConstants.ACCOUNT_IS_AUTO_DISCOVERED)1 AWS_ACCOUNT_BILL_PROCESSED_TIME_MILLIS (com.vmware.photon.controller.model.adapters.awsadapter.AWSConstants.AWS_ACCOUNT_BILL_PROCESSED_TIME_MILLIS)1 AWS_ACCOUNT_ID_KEY (com.vmware.photon.controller.model.adapters.awsadapter.AWSConstants.AWS_ACCOUNT_ID_KEY)1 AWS_LINKED_ACCOUNT_IDS (com.vmware.photon.controller.model.adapters.awsadapter.AWSConstants.AWS_LINKED_ACCOUNT_IDS)1 AwsClientType (com.vmware.photon.controller.model.adapters.awsadapter.AWSConstants.AwsClientType)1 STORAGE_TYPE_EBS (com.vmware.photon.controller.model.adapters.awsadapter.AWSConstants.STORAGE_TYPE_EBS)1 STORAGE_TYPE_S3 (com.vmware.photon.controller.model.adapters.awsadapter.AWSConstants.STORAGE_TYPE_S3)1