use of com.vmware.photon.controller.model.adapters.awsadapter.AWSConstants.AWS_ACCOUNT_ID_KEY in project photon-model by vmware.
the class AWSCostStatsService method getAccountDescription.
protected void getAccountDescription(AWSCostStatsCreationContext statsData, AWSCostStatsCreationStages next) {
Consumer<Operation> onSuccess = (op) -> {
ComputeStateWithDescription compute = op.getBody(ComputeStateWithDescription.class);
statsData.computeDesc = compute;
inferEndpointLink(statsData);
String accountId = AWSUtils.isAwsS3Proxy() ? "mock" : compute.customProperties.get(AWS_ACCOUNT_ID_KEY);
if (compute.type != ComputeType.ENDPOINT_HOST || compute.parentLink != null || compute.endpointLink == null || accountId == null || CollectionUtils.isEmpty(compute.endpointLinks)) {
logWithContext(statsData, Level.SEVERE, () -> "Malformed Root Compute.");
postAccumulatedCostStats(statsData, true);
return;
}
statsData.accountId = accountId;
statsData.awsAccountIdToComputeStates.put(accountId, Collections.singletonList(compute));
getEndpointState(statsData, next);
};
URI computeUri = UriUtils.extendUriWithQuery(statsData.statsRequest.resourceReference, UriUtils.URI_PARAM_ODATA_EXPAND, Boolean.TRUE.toString());
AdapterUtils.getServiceState(this, computeUri, onSuccess, getFailureConsumer(statsData));
}
use of com.vmware.photon.controller.model.adapters.awsadapter.AWSConstants.AWS_ACCOUNT_ID_KEY in project photon-model by vmware.
the class AWSCostStatsService method getMarkerMetricsOp.
private Operation getMarkerMetricsOp(AWSCostStatsCreationContext context, ComputeState accComputeState) {
QueryTask qTask = getQueryTaskForMetric(accComputeState);
Operation.CompletionHandler completionHandler = (operation, exception) -> {
if (exception != null) {
logWarning(() -> String.format("Failed to get bill processed time for account: %s", accComputeState.documentSelfLink));
getFailureConsumer(context).accept(exception);
return;
}
QueryTask body = operation.getBody(QueryTask.class);
String accountId = accComputeState.customProperties.get(AWS_ACCOUNT_ID_KEY);
if (body.results.documentCount == 0) {
ResourceMetrics markerMetrics = new ResourceMetrics();
markerMetrics.timestampMicrosUtc = getCurrentMonthStartTimeMicros();
markerMetrics.entries = new HashMap<>();
markerMetrics.entries.put(AWSConstants.AWS_ACCOUNT_BILL_PROCESSED_TIME_MILLIS, 0d);
markerMetrics.documentSelfLink = StatsUtil.getMetricKey(accComputeState.documentSelfLink, Utils.getNowMicrosUtc());
context.accountsMarkersMap.put(accountId, markerMetrics);
} else {
ResourceMetrics markerMetrics = body.results.documents.values().stream().map(o -> Utils.fromJson(o, ResourceMetrics.class)).collect(Collectors.toList()).get(0);
context.accountsMarkersMap.putIfAbsent(accountId, markerMetrics);
}
};
return QueryUtils.createQueryTaskOperation(this, qTask, ServiceTypeCluster.METRIC_SERVICE).setExpiration(Utils.fromNowMicrosUtc(TimeUnit.SECONDS.toMicros(INTERNAL_REQUEST_TIMEOUT_SECONDS))).setCompletion(completionHandler);
}
use of com.vmware.photon.controller.model.adapters.awsadapter.AWSConstants.AWS_ACCOUNT_ID_KEY in project photon-model by vmware.
the class AWSCostStatsService method createQueryForComputeStatesByAccount.
/**
* Method creates a query operation to get the compute states corresponding to the specified account ID.
* The list of the resultant compute states is then passed to the specified handler for processing.
*
* @param context
* @param accountId
* @param queryResultConsumer
* @return operation object representing the query
*/
protected Operation createQueryForComputeStatesByAccount(AWSCostStatsCreationContext context, String accountId, Consumer<List<ComputeState>> queryResultConsumer) {
Query awsAccountsQuery = Query.Builder.create().addKindFieldClause(ComputeState.class).addFieldClause(ComputeState.FIELD_NAME_TYPE, ComputeType.ENDPOINT_HOST).addCompositeFieldClause(ComputeState.FIELD_NAME_CUSTOM_PROPERTIES, EndpointAllocationTaskService.CUSTOM_PROP_ENPOINT_TYPE, PhotonModelConstants.EndpointType.aws.name()).addCompositeFieldClause(ComputeState.FIELD_NAME_CUSTOM_PROPERTIES, AWS_ACCOUNT_ID_KEY, accountId).addInCollectionItemClause(ComputeState.FIELD_NAME_TENANT_LINKS, context.computeDesc.tenantLinks).build();
QueryTask queryTask = QueryTask.Builder.createDirectTask().addOption(QueryOption.EXPAND_CONTENT).setQuery(awsAccountsQuery).build();
queryTask.setDirect(true);
queryTask.tenantLinks = context.computeDesc.tenantLinks;
return QueryUtils.createQueryTaskOperation(this, queryTask, ServiceTypeCluster.INVENTORY_SERVICE).setCompletion((o, e) -> {
if (e != null) {
getFailureConsumer(context).accept(e);
return;
}
QueryTask responseTask = o.getBody(QueryTask.class);
List<ComputeState> accountComputeStates = responseTask.results.documents.values().stream().map(s -> Utils.fromJson(s, ComputeState.class)).filter(cs -> cs.parentLink == null && cs.endpointLink != null && !CollectionUtils.isEmpty(cs.endpointLinks)).collect(Collectors.toList());
queryResultConsumer.accept(accountComputeStates);
});
}
Aggregations