use of com.vmware.xenon.services.common.QueryTask in project photon-model by vmware.
the class TestVSphereEnumerationTask method findRandomVm.
private ComputeState findRandomVm() throws InterruptedException, TimeoutException, ExecutionException {
Query q = Query.Builder.create().addCompositeFieldClause(ComputeState.FIELD_NAME_CUSTOM_PROPERTIES, CustomProperties.TYPE, VimNames.TYPE_VM).addKindFieldClause(ComputeState.class).build();
QueryTask qt = QueryTask.Builder.createDirectTask().setQuery(q).addOption(QueryOption.EXPAND_CONTENT).build();
Operation op = QueryUtils.createQueryTaskOperation(this.host, qt, ServiceTypeCluster.INVENTORY_SERVICE);
QueryTask result = this.host.waitForResponse(op).getBody(QueryTask.class);
Object firstResult = result.results.documents.values().iterator().next();
return Utils.fromJson(firstResult, ComputeState.class);
}
use of com.vmware.xenon.services.common.QueryTask in project photon-model by vmware.
the class TestVSphereEnumerationTask method verifyCIGapForComputeResource.
private void verifyCIGapForComputeResource() {
Query.Builder builder = Query.Builder.create().addKindFieldClause(ComputeState.class).addCompositeFieldClause(ComputeState.FIELD_NAME_CUSTOM_PROPERTIES, CustomProperties.TYPE, VimNames.TYPE_CLUSTER_COMPUTE_RESOURCE);
QueryTask task = QueryTask.Builder.createDirectTask().setQuery(builder.build()).build();
withTaskResults(task, result -> {
if (result.documentLinks.isEmpty()) {
assertTrue("Could not enumerate Compute Cluster Resource", !result.documentLinks.isEmpty());
} else {
int randInt = getRandomIntWithinBounds(result.documentCount.intValue());
ComputeState sd = Utils.fromJson(result.documents.get(result.documentLinks.get(randInt)), ComputeState.class);
assertNotNull(sd.customProperties.get(CustomProperties.CR_VSAN_CONFIG_ID), sd.customProperties.get(CustomProperties.CR_VSAN_CONFIG_ID));
assertNotNull(sd.customProperties.get(CustomProperties.CR_IS_VSAN_ENABLED), sd.customProperties.get(CustomProperties.CR_IS_VSAN_ENABLED));
}
});
}
use of com.vmware.xenon.services.common.QueryTask in project photon-model by vmware.
the class ResourceGroomerTaskServiceTest method getComputeCount.
/**
* Query count of computes with all given endpointLinks in a set and tenantLink.
*/
public long getComputeCount(Set<String> endpointLinks, String tenantLink) {
Query.Builder query = Query.Builder.create().addCollectionItemClause(ResourceState.FIELD_NAME_TENANT_LINKS, tenantLink);
for (String endpointLink : endpointLinks) {
query.addCollectionItemClause(ResourceState.FIELD_NAME_ENDPOINT_LINKS, endpointLink);
}
QueryTask queryTask = QueryTask.Builder.createDirectTask().setQuery(query.build()).addOption(QueryOption.COUNT).build();
Operation postQuery = Operation.createPost(UriUtils.buildUri(this.host, ServiceUriPaths.CORE_LOCAL_QUERY_TASKS)).setBody(queryTask).setReferer(this.host.getUri());
Operation queryResponse = this.host.waitForResponse(postQuery);
if (queryResponse.getStatusCode() != 200) {
return -1;
}
QueryTask response = queryResponse.getBody(QueryTask.class);
return response.results.documentCount;
}
use of com.vmware.xenon.services.common.QueryTask in project photon-model by vmware.
the class ResourceGroomerTaskServiceTest method getComputeCount.
/**
* Query count of computes with all given endpointLinks in a set and tenantLink.
*/
public long getComputeCount(String endpointLink, String tenantLink) {
Query.Builder query = Query.Builder.create().addFieldClause(ResourceState.FIELD_NAME_ENDPOINT_LINK, endpointLink).addCollectionItemClause(ResourceState.FIELD_NAME_TENANT_LINKS, tenantLink);
QueryTask queryTask = QueryTask.Builder.createDirectTask().setQuery(query.build()).addOption(QueryOption.COUNT).build();
Operation postQuery = Operation.createPost(UriUtils.buildUri(this.host, ServiceUriPaths.CORE_LOCAL_QUERY_TASKS)).setBody(queryTask).setReferer(this.host.getUri());
Operation queryResponse = this.host.waitForResponse(postQuery);
if (queryResponse.getStatusCode() != 200) {
return -1;
}
QueryTask response = queryResponse.getBody(QueryTask.class);
return response.results.documentCount;
}
use of com.vmware.xenon.services.common.QueryTask in project photon-model by vmware.
the class StatsCollectionTaskServiceTest method getResourceMetrics.
/**
* Queries all ResourceMetric documents with the prefix provided.
* Sorts the documents by documentSelfLink.
* Returns the first document.
*/
private ResourceMetrics getResourceMetrics(VerificationHost host, 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, TypeName.STRING).setQuery(Query.Builder.create().addKindFieldClause(ResourceMetrics.class).addCompositeFieldClause(ResourceMetrics.FIELD_NAME_CUSTOM_PROPERTIES, ResourceMetrics.PROPERTY_RESOURCE_LINK, resourceLink).addRangeClause(QuerySpecification.buildCompositeFieldName(ResourceMetrics.FIELD_NAME_ENTRIES, metricKey), NumericRange.createDoubleRange(Double.MIN_VALUE, Double.MAX_VALUE, true, true)).build()).build();
host.createQueryTaskService(qt, false, true, qt, null);
String documentLink = qt.results.documentLinks.get(0);
ResourceMetrics resourceMetric = Utils.fromJson(qt.results.documents.get(documentLink), ResourceMetrics.class);
return resourceMetric;
}
Aggregations