use of com.vmware.xenon.common.Operation in project photon-model by vmware.
the class TestAWSEnumerationDocumentCountInLongRun method assertNetworkInterfaceLinksAreValid.
private void assertNetworkInterfaceLinksAreValid() {
for (String computeLink : this.computeStateLinks) {
Operation getCompute = Operation.createGet((UriUtils.buildUri(this.host, computeLink))).setReferer(this.host.getUri());
Operation compute = this.host.waitForResponse(getCompute);
if (compute.getStatusCode() == 200) {
ComputeState state = compute.getBody(ComputeState.class);
for (String nicLink : state.networkInterfaceLinks) {
Operation getNic = Operation.createGet((UriUtils.buildUri(this.host, nicLink))).setReferer(this.host.getUri());
Operation nic = this.host.waitForResponse(getNic);
assertEquals("GET on NIC failed.", Operation.STATUS_CODE_OK, nic.getStatusCode());
}
}
}
}
use of com.vmware.xenon.common.Operation in project photon-model by vmware.
the class TestAWSEnumerationDocumentCountInLongRun method verifyResourceDuplicates.
/**
* Verify documents for duplicates after multiple enumerations.
*/
private void verifyResourceDuplicates() {
int total_dup_resource_count = 0;
for (Class resource : resourcesList) {
QueryTask.Query.Builder qBuilder = QueryTask.Query.Builder.create().addKindFieldClause(resource).addFieldClause("endpointLinks.item", this.endpointState.documentSelfLink, QueryTask.QueryTerm.MatchType.TERM, QueryTask.Query.Occurance.MUST_OCCUR);
if (resource.getSimpleName().equals("ComputeState")) {
qBuilder.addFieldClause("type", "VM_GUEST", QueryTask.QueryTerm.MatchType.TERM, QueryTask.Query.Occurance.MUST_OCCUR);
}
QueryTask resourceQt = QueryTask.Builder.createDirectTask().setQuery(qBuilder.build()).addOption(QueryTask.QuerySpecification.QueryOption.EXPAND_CONTENT).addOption(QueryTask.QuerySpecification.QueryOption.TOP_RESULTS).setResultLimit(10000).build();
Operation queryDocuments = QueryUtils.createQueryTaskOperation(this.host, resourceQt, ServiceTypeCluster.INVENTORY_SERVICE).setReferer(this.host.getUri());
Operation queryResponse = this.host.waitForResponse(queryDocuments);
Assert.assertTrue("Error retrieving enumerated documents", queryResponse.getStatusCode() == 200);
QueryTask qt = queryResponse.getBody(QueryTask.class);
Set<String> resourceIdSet = new HashSet<>();
if (qt.results != null && qt.results.documentLinks != null && qt.results.documentLinks.size() > 0) {
this.host.log("Number of %s docs: %d", resource.getSimpleName(), qt.results.documentLinks.size());
for (String resourceDocumentLink : qt.results.documentLinks) {
Object object = qt.results.documents.get(resourceDocumentLink);
ResourceState resourceState = Utils.fromJson(object, ResourceState.class);
String resourceId = resourceState.id;
if (!resourceIdSet.contains(resourceId)) {
resourceIdSet.add(resourceId);
} else {
this.host.log("duplicate %s id = %s, with state: ", resource.getSimpleName(), resourceId, Utils.toJsonHtml(resourceState));
total_dup_resource_count++;
}
}
}
}
assertEquals("Duplicate resources found: ", 0, total_dup_resource_count);
}
use of com.vmware.xenon.common.Operation in project photon-model by vmware.
the class TestAWSCostAdapterService method triggerStatsCollection.
private void triggerStatsCollection(ResourcePoolState pool) {
StatsCollectionTaskState statCollectionState = new StatsCollectionTaskState();
statCollectionState.resourcePoolLink = pool.documentSelfLink;
statCollectionState.statsAdapterReference = UriUtils.buildUri(this.host, AWSCostStatsService.SELF_LINK);
statCollectionState.documentSelfLink = "cost-stats-adapter" + UUID.randomUUID().toString();
statCollectionState.options = EnumSet.of(TaskOption.SELF_DELETE_ON_COMPLETION);
statCollectionState.taskInfo = TaskState.createDirect();
Operation op = Operation.createPost(this.host, StatsCollectionTaskService.FACTORY_LINK).setBody(statCollectionState).setReferer(this.host.getReferer());
this.host.sendAndWaitExpectSuccess(op);
}
use of com.vmware.xenon.common.Operation 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.xenon.common.Operation 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);
}
Aggregations