use of com.vmware.xenon.common.Operation in project photon-model by vmware.
the class AzureComputeHostStorageStatsGatherer method getComputeHost.
private void getComputeHost(AzureStorageStatsDataHolder statsData, StorageMetricsStages next) {
Consumer<Operation> onSuccess = (op) -> {
statsData.computeHostDesc = op.getBody(ComputeService.ComputeStateWithDescription.class);
statsData.stage = next;
handleStorageMetricDiscovery(statsData);
};
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.xenon.common.Operation in project photon-model by vmware.
the class AzureCostStatsService method getEndpointState.
protected void getEndpointState(Context context, Stages next) {
Consumer<Operation> onEndpointSuccess = (op) -> {
context.endpointState = op.getBody(EndpointState.class);
logInfo(() -> String.format("Azure ea cost stats endpoint state link: %s", context.endpointState.documentSelfLink));
getAuth(context, next);
};
URI endpointUri = UriUtils.extendUriWithQuery(UriUtils.buildUri(this.getHost(), context.endpointLink), UriUtils.URI_PARAM_ODATA_EXPAND, Boolean.TRUE.toString());
AdapterUtils.getServiceState(this, endpointUri, onEndpointSuccess, getFailureConsumer(context));
}
use of com.vmware.xenon.common.Operation in project photon-model by vmware.
the class AzureCostStatsService method postStats.
/**
* Send stats for persistence.
* @param context Holds data to be posted for persistence in
* {@code context.statsResponse.statsList}
*/
private void postStats(Context context) {
if (!context.isFinalBatch && context.statsResponse.statsList.size() == 0) {
return;
}
SingleResourceStatsCollectionTaskState respBody = new SingleResourceStatsCollectionTaskState();
respBody.taskStage = SingleResourceTaskCollectionStage.valueOf(context.statsRequest.nextStage);
respBody.statsAdapterReference = UriUtils.buildUri(getHost(), SELF_LINK);
respBody.statsList = context.statsResponse.statsList;
respBody.computeLink = context.computeHostDesc.documentSelfLink;
respBody.isFinalBatch = context.isFinalBatch;
sendRequest(Operation.createPatch(context.statsRequest.taskReference).setBody(respBody).setCompletion((operation, exception) -> {
if (exception != null) {
handleError(context, null, exception, false);
}
}));
context.statsResponse.statsList = new ArrayList<>();
}
use of com.vmware.xenon.common.Operation in project photon-model by vmware.
the class AzureCostStatsService method getServiceMetadata.
private void getServiceMetadata(Context context, Stages next) {
Query.Builder builder = Query.Builder.create();
builder.addKindFieldClause(ResourceMetrics.class);
builder.addCompositeFieldClause(ResourceMetrics.FIELD_NAME_CUSTOM_PROPERTIES, ResourceMetrics.PROPERTY_RESOURCE_LINK, context.computeHostDesc.documentSelfLink);
builder.addCompositeFieldClause(ResourceMetrics.FIELD_NAME_CUSTOM_PROPERTIES, PhotonModelConstants.CONTAINS_BILL_PROCESSED_TIME_STAT, Boolean.TRUE.toString());
QueryTask.Builder queryTaskBuilder = QueryTask.Builder.createDirectTask().addOption(QueryOption.SORT).addOption(QueryOption.TOP_RESULTS).addOption(QueryOption.INCLUDE_ALL_VERSIONS).addOption(QueryOption.EXPAND_CONTENT).orderDescending(ServiceDocument.FIELD_NAME_SELF_LINK, ServiceDocumentDescription.TypeName.STRING).setResultLimit(1).setQuery(builder.build());
if (!AzureCostConstants.SHOULD_REFRESH_INDEX) {
queryTaskBuilder.addOption(QueryOption.DO_NOT_REFRESH);
}
QueryTask queryTask = queryTaskBuilder.build();
queryTask.tenantLinks = context.computeHostDesc.tenantLinks;
Operation queryTaskOp = QueryUtils.createQueryTaskOperation(this, queryTask, ServiceTypeCluster.METRIC_SERVICE).setExpiration(Utils.fromNowMicrosUtc(TimeUnit.SECONDS.toMicros(INTERNAL_REQUEST_TIMEOUT_SECONDS)));
this.sendWithDeferredResult(queryTaskOp, QueryTask.class).whenComplete((response, exception) -> {
if (exception != null) {
handleError(context, Stages.GET_HISTORICAL_COSTS, exception, true);
return;
}
if (response == null || response.results == null || response.results.documents == null) {
context.billProcessedTimeMillis = 0;
return;
}
Collection<Object> values = response.results.documents.values();
if (!values.isEmpty()) {
if (values.iterator().next() == null) {
context.billProcessedTimeMillis = 0;
return;
}
ResourceMetrics rawResourceMetrics = Utils.fromJson(values.iterator().next(), ResourceMetrics.class);
context.billProcessedTimeMillis = rawResourceMetrics.entries.getOrDefault(PhotonModelConstants.CLOUD_ACCOUNT_COST_SYNC_MARKER_MILLIS, 0d).longValue();
context.oldestBillProcessedMillis = rawResourceMetrics.entries.getOrDefault(AzureCostConstants.OLDEST_BILL_PROCESSED_MILLIS, 0d).longValue();
}
context.stage = next;
handleRequest(context);
});
}
use of com.vmware.xenon.common.Operation in project photon-model by vmware.
the class AzureCostStatsService method createSummarizedBillOps.
private List<Operation> createSummarizedBillOps(Context context) {
List<Operation> summarizedBillOps = new ArrayList<>();
if (context.summarizedBillsToGet.isEmpty()) {
// Get the summarized bill only for the current month
context.summarizedBillsToGet.add(AzureCostHelper.getFirstDayOfCurrentMonth());
}
for (LocalDate bill : context.summarizedBillsToGet) {
summarizedBillOps.add(AzureCostHelper.getOldBillOperation(context.auth.privateKeyId, context.auth.privateKey, bill, AzureCostConstants.QUERY_PARAM_BILL_TYPE_VALUE_SUMMARY));
}
context.numberBillsAvailable = Math.min(context.summarizedBillsToGet.size() - 1, AzureCostConstants.NO_OF_MONTHS_TO_GET_PAST_BILLS);
return summarizedBillOps;
}
Aggregations