use of com.vmware.xenon.services.common.QueryTask.QuerySpecification in project photon-model by vmware.
the class LongRunEndToEndAzureStatsAggregation 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 : AzureTestUtil.getMetricNames()) {
QuerySpecification querySpec = new QuerySpecification();
querySpec.query = QueryTask.Query.Builder.create().addKindFieldClause(ResourceMetrics.class).addFieldClause(ServiceDocument.FIELD_NAME_SELF_LINK, UriUtils.buildUriPath(ResourceMetricsService.FACTORY_LINK, computeResourceLink), 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(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(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);
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));
}
}
use of com.vmware.xenon.services.common.QueryTask.QuerySpecification in project photon-model by vmware.
the class TestAWSSetupUtils method deleteVMs.
/**
* Deletes the VM that is present on an endpoint and represented by the passed in ID.
*
* @param documentSelfLink
* @param isMock
* @param host
* @param deleteDocumentOnly
* @throws Throwable
*/
public static void deleteVMs(String documentSelfLink, boolean isMock, VerificationHost host, boolean deleteDocumentOnly) throws Throwable {
ResourceRemovalTaskState deletionState = new ResourceRemovalTaskState();
QuerySpecification resourceQuerySpec = new QueryTask.QuerySpecification();
// query all ComputeState resources for the cluster
resourceQuerySpec.query.setTermPropertyName(ServiceDocument.FIELD_NAME_SELF_LINK).setTermMatchValue(documentSelfLink);
deletionState.resourceQuerySpec = resourceQuerySpec;
deletionState.isMockRequest = isMock;
// Waiting for default request timeout in minutes for the machine to be turned OFF on AWS.
deletionState.documentExpirationTimeMicros = Utils.getNowMicrosUtc() + TimeUnit.MINUTES.toMicros(AWS_VM_REQUEST_TIMEOUT_MINUTES);
if (deleteDocumentOnly) {
deletionState.options = EnumSet.of(TaskOption.DOCUMENT_CHANGES_ONLY);
}
deletionState = TestUtils.doPost(host, deletionState, ResourceRemovalTaskState.class, UriUtils.buildUri(host, ResourceRemovalTaskService.FACTORY_LINK));
ProvisioningUtils.waitForTaskCompletion(host, deletionState.documentSelfLink, ResourceRemovalTaskState.class);
// check that the VMs are gone
ServiceDocumentQueryResult serviceDocumentQueryResult = ProvisioningUtils.queryAllFactoryResources(host, ComputeService.FACTORY_LINK);
List<String> documentLinks = serviceDocumentQueryResult.documentLinks;
assertFalse(documentLinks.contains(documentSelfLink));
}
use of com.vmware.xenon.services.common.QueryTask.QuerySpecification in project photon-model by vmware.
the class TestAWSSetupUtils method deleteVMsOnThisEndpoint.
/**
* A utility method that deletes the VMs on the specified endpoint filtered by the instanceIds
* that are passed in. It expects peerURI and tenantLinks to be populated.
*
* @throws Throwable
*/
public static void deleteVMsOnThisEndpoint(VerificationHost host, URI peerURI, boolean isMock, String parentComputeLink, List<String> instanceIdsToDelete, List<String> tenantLinks) throws Throwable {
host.testStart(1);
ResourceRemovalTaskState deletionState = new ResourceRemovalTaskState();
deletionState.tenantLinks = tenantLinks;
// All AWS Compute States AND Ids in (Ids to delete)
QuerySpecification compositeQuery = new QueryTask.QuerySpecification();
// Document Kind = Compute State AND Parent Compute Link = AWS
QueryTask.Query awsComputeStatesQuery = new QueryTask.Query();
awsComputeStatesQuery = Query.Builder.create().addKindFieldClause(ComputeService.ComputeState.class).addFieldClause(ComputeState.FIELD_NAME_PARENT_LINK, parentComputeLink).build();
compositeQuery.query.addBooleanClause(awsComputeStatesQuery);
if (instanceIdsToDelete != null && instanceIdsToDelete.size() > 0) {
// Instance Ids in List of instance Ids to delete
QueryTask.Query instanceIdFilterParentQuery = new QueryTask.Query();
for (String instanceId : instanceIdsToDelete) {
if (!instanceId.startsWith(AWS_INSTANCE_PREFIX)) {
continue;
}
QueryTask.Query instanceIdFilter = new QueryTask.Query().setTermPropertyName(ComputeState.FIELD_NAME_ID).setTermMatchValue(instanceId);
instanceIdFilter.occurance = QueryTask.Query.Occurance.SHOULD_OCCUR;
instanceIdFilterParentQuery.addBooleanClause(instanceIdFilter);
}
instanceIdFilterParentQuery.occurance = Occurance.MUST_OCCUR;
compositeQuery.query.addBooleanClause(instanceIdFilterParentQuery);
}
deletionState.resourceQuerySpec = compositeQuery;
deletionState.isMockRequest = isMock;
host.send(Operation.createPost(createServiceURI(host, peerURI, ResourceRemovalTaskService.FACTORY_LINK)).setBody(deletionState).setCompletion(host.getCompletion()));
// Re-setting the test timeout value so that it clean up spawned instances even if it has
// timed out based on the original value.
host.setTimeoutSeconds(500);
host.testWait();
}
Aggregations