use of com.vmware.xenon.services.common.QueryTask in project photon-model by vmware.
the class AzureSubscriptionsEnumerationServiceTest method executQuerySynchronously.
private QueryTask executQuerySynchronously(QueryTask task) throws Throwable {
task.documentExpirationTimeMicros = Utils.fromNowMicrosUtc(TimeUnit.DAYS.toMicros(1));
URI queryTaskUri = this.host.createQueryTaskService(UriUtils.buildUri(this.host.getUri(), ServiceUriPaths.CORE_QUERY_TASKS), task, false, false, task, null);
// Wait for query task to have data
QueryTask queryTaskResponse = null;
Date exp = this.host.getTestExpiration();
while (new Date().before(exp)) {
queryTaskResponse = this.host.getServiceState(null, QueryTask.class, queryTaskUri);
if (queryTaskResponse.results != null && queryTaskResponse.results.documentLinks != null && !queryTaskResponse.results.documentLinks.isEmpty()) {
break;
}
Thread.sleep(100);
}
return queryTaskResponse;
}
use of com.vmware.xenon.services.common.QueryTask in project photon-model by vmware.
the class TestAzureLongRunningEnumeration method getDocumentCount.
/**
* Returns the count of resource documents for given Resource type.
*/
private long getDocumentCount(Class<? extends ServiceDocument> T) {
QueryTask.Query.Builder qBuilder = QueryTask.Query.Builder.create().addKindFieldClause(T);
QueryTask queryTask = QueryTask.Builder.createDirectTask().addOption(QueryTask.QuerySpecification.QueryOption.COUNT).setQuery(qBuilder.build()).build();
this.host.createQueryTaskService(queryTask, false, true, queryTask, null);
return queryTask.results.documentCount;
}
use of com.vmware.xenon.services.common.QueryTask in project photon-model by vmware.
the class TestAzureResourceDeduplication method getDocumentLinks.
private List<String> getDocumentLinks(Class resourceState, String endpointLink) {
QueryTask.Query.Builder qBuilder = QueryTask.Query.Builder.create().addKindFieldClause(resourceState);
if (endpointLink != null && !endpointLink.equals("")) {
qBuilder.addFieldClause(ENDPOINT_LINKS_FIELD_CLAUSE, endpointLink);
} else {
qBuilder.addFieldClause(ENDPOINT_LINKS_FIELD_CLAUSE, "*", QueryTask.QueryTerm.MatchType.WILDCARD, QueryTask.Query.Occurance.MUST_NOT_OCCUR);
}
QueryTask queryTask = QueryTask.Builder.createDirectTask().addOption(QueryTask.QuerySpecification.QueryOption.EXPAND_CONTENT).setQuery(qBuilder.build()).build();
this.host.createQueryTaskService(queryTask, false, true, queryTask, null);
return queryTask.results.documentLinks;
}
use of com.vmware.xenon.services.common.QueryTask in project photon-model by vmware.
the class GCPTestUtil method queryComputeStatesWithPowerState.
/**
* Method to query the number of local compute states with given power state.
* @param host The test service host.
* @param resourcePool The default resource pool.
* @param parentCompute The default compute host.
* @param powerState The given power state.
* @param instanceNames The assumed names of compute states.
*/
private static void queryComputeStatesWithPowerState(VerificationHost host, ResourcePoolState resourcePool, ComputeState parentCompute, PowerState powerState, Set<String> instanceNames) {
Query query = QueryTask.Query.Builder.create().addKindFieldClause(ComputeState.class).addFieldClause(ComputeState.FIELD_NAME_RESOURCE_POOL_LINK, resourcePool.documentSelfLink).addFieldClause(ComputeState.FIELD_NAME_PARENT_LINK, parentCompute.documentSelfLink).build();
QueryTask q = QueryTask.Builder.createDirectTask().addOption(QueryTask.QuerySpecification.QueryOption.EXPAND_CONTENT).setQuery(query).build();
host.sendRequest(QueryUtils.createQueryTaskOperation(host, q, ServiceTypeCluster.INVENTORY_SERVICE).setReferer(host.getUri()).setCompletion((o, e) -> {
if (e != null) {
host.log(Level.WARNING, String.format("Error: %s", e.getMessage()));
return;
}
QueryTask queryTask = o.getBody(QueryTask.class);
if (queryTask.results.documentCount > 0) {
queryTask.results.documents.values().forEach(s -> {
ComputeState computeState = Utils.fromJson(s, ComputeState.class);
if (computeState.powerState == powerState) {
instanceNames.remove(computeState.name);
}
});
}
}));
}
use of com.vmware.xenon.services.common.QueryTask in project photon-model by vmware.
the class ClientUtils method getDatastoresForProfile.
public static void getDatastoresForProfile(Service service, String storagePolicyLink, String endpointLink, List<String> tenantLinks, Consumer<Throwable> failure, Consumer<ServiceDocumentQueryResult> handler) {
QueryTask.Query.Builder builder = QueryTask.Query.Builder.create().addKindFieldClause(StorageDescriptionService.StorageDescription.class);
builder.addCollectionItemClause(StorageDescriptionService.StorageDescription.FIELD_NAME_GROUP_LINKS, storagePolicyLink);
QueryUtils.addEndpointLink(builder, StorageDescriptionService.StorageDescription.class, endpointLink);
QueryUtils.addTenantLinks(builder, getTenantLinks(tenantLinks));
QueryTask task = QueryTask.Builder.createDirectTask().setQuery(builder.build()).build();
task.querySpec.options = EnumSet.of(QueryTask.QuerySpecification.QueryOption.EXPAND_CONTENT);
QueryUtils.startInventoryQueryTask(service, task).whenComplete((queryTask, e) -> {
if (e != null) {
service.getHost().log(Level.WARNING, "Error processing task %s", task.documentSelfLink);
failure.accept(e);
return;
}
handler.accept(queryTask.results);
});
}
Aggregations