use of com.vmware.xenon.services.common.QueryTask in project photon-model by vmware.
the class LongRunEndToEndStatsAggregationTest method verifyTimeBinMetrics.
/**
* Performs check to verify time bin metrics are available for every compute resource and also
* checks the occurrence of estimated charges for one of the resource metrics.
*/
private void verifyTimeBinMetrics(ServiceDocumentQueryResult res) {
List<Object> results = new ArrayList<>();
for (String computeResourceLink : res.documentLinks) {
for (String metricName : TestAWSSetupUtils.getMetricNames()) {
QueryTask.QuerySpecification querySpec = new QueryTask.QuerySpecification();
querySpec.query = QueryTask.Query.Builder.create().addKindFieldClause(ResourceMetrics.class).addFieldClause(ServiceDocument.FIELD_NAME_SELF_LINK, UriUtils.buildUriPath(ResourceMetricsService.FACTORY_LINK, computeResourceLink), QueryTask.QueryTerm.MatchType.PREFIX).addRangeClause(QuerySpecification.buildCompositeFieldName(ResourceMetrics.FIELD_NAME_ENTRIES, metricName), NumericRange.createDoubleRange(0.0, Double.MAX_VALUE, true, true)).build();
QueryTask qt = QueryTask.Builder.createDirectTask().addOption(QueryTask.QuerySpecification.QueryOption.TOP_RESULTS).addOption(QueryTask.QuerySpecification.QueryOption.INCLUDE_ALL_VERSIONS).setResultLimit(1).addOption(QueryTask.QuerySpecification.QueryOption.EXPAND_CONTENT).addOption(QueryTask.QuerySpecification.QueryOption.SORT).orderDescending(ServiceDocument.FIELD_NAME_SELF_LINK, ServiceDocumentDescription.TypeName.STRING).setQuery(querySpec.query).build();
this.host.createQueryTaskService(qt, false, true, qt, null);
if (qt.results.documentLinks.size() > 0 && qt.results.documentLinks.get(0) != null) {
results.add(qt.results.documents.get(qt.results.documentLinks.get(0)));
}
}
}
long expectedExpirationTime = Utils.getNowMicrosUtc() + TimeUnit.DAYS.toMicros(DEFAULT_RETENTION_LIMIT_DAYS);
boolean estimatedChargeFound = false;
for (Object aggrDocument : results) {
ResourceMetrics aggrMetric = Utils.fromJson(aggrDocument, ResourceMetrics.class);
// Make sure all the documents have expiration time set.
assertTrue("Expiration time is not correctly set.", aggrMetric.documentExpirationTimeMicros < expectedExpirationTime);
// The assertion here checks whether we are aggregating only on latest value. To
// that effect, here is the breakdown for the check:
// count = num of resources: one value for each resource
// sum = null: not specified in the aggregate type set
assertNotNull("Value is not set", aggrMetric.entries.get(0));
}
assertTrue(estimatedChargeFound);
}
use of com.vmware.xenon.services.common.QueryTask in project photon-model by vmware.
the class LongRunEndToEndStatsCollectionTest method getResourceMetrics.
/**
* Method returns ResourceMetrics collected during stats collection for a resource endpoint
* for the given resource metric key.
*/
private ResourceMetrics getResourceMetrics(String resourceLink, String metricKey) {
QueryTask qt = QueryTask.Builder.createDirectTask().addOption(QueryOption.TOP_RESULTS).addOption(QueryOption.INCLUDE_ALL_VERSIONS).setResultLimit(1).addOption(QueryOption.EXPAND_CONTENT).addOption(QueryOption.SORT).orderDescending(ServiceDocument.FIELD_NAME_SELF_LINK, ServiceDocumentDescription.TypeName.STRING).setQuery(QueryTask.Query.Builder.create().addKindFieldClause(ResourceMetrics.class).addFieldClause(ServiceDocument.FIELD_NAME_SELF_LINK, UriUtils.buildUriPath(ResourceMetricsService.FACTORY_LINK, UriUtils.getLastPathSegment(resourceLink)), QueryTask.QueryTerm.MatchType.PREFIX).addRangeClause(QueryTask.QuerySpecification.buildCompositeFieldName(ResourceMetrics.FIELD_NAME_ENTRIES, metricKey), QueryTask.NumericRange.createDoubleRange(0.0, Double.MAX_VALUE, true, true)).build()).build();
this.host.createQueryTaskService(qt, false, true, qt, null);
ResourceMetrics resourceMetric = null;
if (qt.results.documentLinks.size() > 0) {
String documentLink = qt.results.documentLinks.get(0);
resourceMetric = Utils.fromJson(qt.results.documents.get(documentLink), ResourceMetrics.class);
}
return resourceMetric;
}
use of com.vmware.xenon.services.common.QueryTask in project photon-model by vmware.
the class TestAWSEnumerationDocumentCountInLongRun method storeDocumentLinksFromComputeStates.
/**
* Gets and stores resource pool links and network interface links by querying
* given instance IDs.
* @param instanceIdList List of instance IDs provisioned by the test
*/
private void storeDocumentLinksFromComputeStates(List<String> instanceIdList) {
// Query to get all compute state documents associated with list of instance IDs.
QueryTask.Query computeStateQuery = QueryTask.Query.Builder.create().addKindFieldClause(ComputeState.class).addInClause(ComputeState.FIELD_NAME_ID, instanceIdList).build();
QueryTask q = QueryTask.Builder.createDirectTask().setQuery(computeStateQuery).addOption(QueryTask.QuerySpecification.QueryOption.EXPAND_CONTENT).build();
Operation queryComputeState = QueryUtils.createQueryTaskOperation(this.host, q, ServiceTypeCluster.INVENTORY_SERVICE).setReferer(this.host.getUri());
Operation queryResponse = this.host.waitForResponse(queryComputeState);
Assert.assertTrue("Error retrieving compute states", queryResponse.getStatusCode() == 200);
QueryTask qt = queryResponse.getBody(QueryTask.class);
// Store all compute links
this.computeStateLinks.addAll(qt.results.documentLinks);
// Store resource pool links and network links from all compute states.
for (String documentLink : this.computeStateLinks) {
ComputeState cs = Utils.fromJson(qt.results.documents.get(documentLink), ComputeState.class);
this.resourcePoolLinks.add(cs.resourcePoolLink);
this.networkInterfaceLinks.addAll(cs.networkInterfaceLinks);
}
}
use of com.vmware.xenon.services.common.QueryTask in project photon-model by vmware.
the class AWSComputeDescriptionEnumerationAdapterService method getLocalComputeDescriptions.
/**
* Get all the compute descriptions already in the system and filtered by
* - Supported Children (Docker Container)
* - Environment name(AWS),
* - Name (instance type),
* - ZoneId(placement).
* - Endpoint link
*/
private void getLocalComputeDescriptions(AWSComputeDescriptionCreationServiceContext context, AWSComputeDescCreationStage next) {
QueryTask queryTask = getCDsRepresentingVMsInLocalSystemCreatedByEnumerationQuery(context.representativeComputeDescriptionSet, context.cdState.tenantLinks, context.cdState.regionId, context.cdState.parentComputeLink, context.cdState.endpointLink);
// create the query to find an existing compute description
QueryUtils.startInventoryQueryTask(this, queryTask).whenComplete((qrt, e) -> {
if (e != null) {
logWarning(() -> String.format("Failure retrieving query results: %s", e.toString()));
finishWithFailure(context, e);
return;
}
if (qrt != null && qrt.results.documentCount > 0) {
for (Object s : qrt.results.documents.values()) {
ComputeDescription localComputeDescription = Utils.fromJson(s, ComputeDescription.class);
context.localComputeDescriptionMap.put(getKeyForComputeDescriptionFromCD(localComputeDescription), localComputeDescription);
}
logFine(() -> String.format("%d compute descriptions found", context.localComputeDescriptionMap.size()));
} else {
logFine(() -> "No compute descriptions found");
}
context.creationStage = next;
handleComputeDescriptionCreation(context);
});
}
use of com.vmware.xenon.services.common.QueryTask in project photon-model by vmware.
the class AWSComputeStateCreationAdapterService method getRelatedComputeDescriptions.
/**
* Looks up the compute descriptions associated with the compute states to be created in the
* system.
*/
private void getRelatedComputeDescriptions(AWSComputeStateCreationContext context, AWSComputeStateCreationStage next) {
// Get the related compute descriptions for all the compute states are to be updated and
// created.
Set<InstanceDescKey> representativeCDSet = getRepresentativeListOfCDsFromInstanceList(context.request.instancesToBeCreated, context.request.zones);
representativeCDSet.addAll(getRepresentativeListOfCDsFromInstanceList(context.request.instancesToBeUpdated.values(), context.request.zones));
if (representativeCDSet.isEmpty()) {
context.creationStage = next;
handleComputeStateCreateOrUpdate(context);
return;
}
QueryTask queryTask = getCDsRepresentingVMsInLocalSystemCreatedByEnumerationQuery(representativeCDSet, context.request.tenantLinks, context.request.regionId, context.request.parentComputeLink, context.request.endpointLink);
queryTask.documentExpirationTimeMicros = Utils.getNowMicrosUtc() + QUERY_TASK_EXPIRY_MICROS;
// create the query to find an existing compute description
QueryUtils.startInventoryQueryTask(this, queryTask).whenComplete((qrt, e) -> {
if (e != null) {
logWarning(() -> String.format("Failure retrieving query results: %s", e.toString()));
finishWithFailure(context, e);
return;
}
if (qrt != null && qrt.results.documentCount > 0) {
for (Object s : qrt.results.documents.values()) {
ComputeDescription localComputeDescription = Utils.fromJson(s, ComputeDescription.class);
context.computeDescriptionMap.put(getKeyForComputeDescriptionFromCD(localComputeDescription), localComputeDescription.documentSelfLink);
}
logFine(() -> String.format("%d compute descriptions found", context.computeDescriptionMap.size()));
} else {
logFine(() -> "No compute descriptions found");
}
context.creationStage = next;
handleComputeStateCreateOrUpdate(context);
});
}
Aggregations