use of com.vmware.xenon.common.QueryResultsProcessor in project photon-model by vmware.
the class TestAWSEndpointService method testCreateAndThenValidate.
@Test
public void testCreateAndThenValidate() throws Throwable {
this.endpointTestsRunner.testCreateAndThenValidate(this.endpointState);
// Tests that EndpointService QueryTasks can use SELECT_LINKS + EXPAND_LINKS
Query query = Builder.create().addKindFieldClause(EndpointState.class).build();
QueryTask queryTask = QueryTask.Builder.createDirectTask().addOptions(EnumSet.of(QueryOption.EXPAND_CONTENT, QueryOption.SELECT_LINKS, QueryOption.EXPAND_LINKS)).addLinkTerm(EndpointState.FIELD_NAME_AUTH_CREDENTIALS_LINK).setQuery(query).build();
this.host.createQueryTaskService(queryTask, false, true, queryTask, null);
ServiceDocumentQueryResult results = queryTask.results;
assertEquals(Long.valueOf(1), results.documentCount);
assertEquals(1, results.selectedLinks.size());
assertEquals(1, results.selectedDocuments.size());
QueryResultsProcessor processor = QueryResultsProcessor.create(results);
for (EndpointState endpoint : processor.documents(EndpointState.class)) {
String authCredentialSelfLink = endpoint.authCredentialsLink;
assertNotNull(authCredentialSelfLink);
assertNotNull(processor.selectedDocument(authCredentialSelfLink, AuthCredentialsServiceState.class));
}
}
use of com.vmware.xenon.common.QueryResultsProcessor in project photon-model by vmware.
the class BaseVSphereAdapterTest method queryAllSnapshotStates.
private List<SnapshotState> queryAllSnapshotStates(String computeReferenceLink) {
List<SnapshotState> snapshotStates = new ArrayList<>();
QueryTask.Query querySnapshot = QueryTask.Query.Builder.create().addKindFieldClause(SnapshotState.class).addFieldClause(SnapshotState.FIELD_NAME_COMPUTE_LINK, computeReferenceLink).build();
QueryTask qTask = QueryTask.Builder.createDirectTask().setQuery(querySnapshot).addOption(QueryTask.QuerySpecification.QueryOption.EXPAND_CONTENT).build();
Operation postOperation = QueryUtils.createQueryTaskOperation(this.host, qTask, ServiceTypeCluster.INVENTORY_SERVICE);
TestRequestSender sender = new TestRequestSender(this.host);
Operation responseOp = sender.sendAndWait(postOperation);
QueryResultsProcessor rp = QueryResultsProcessor.create(responseOp);
if (rp.hasResults()) {
snapshotStates.addAll(rp.streamDocuments(SnapshotState.class).collect(Collectors.toList()));
}
return snapshotStates;
}
use of com.vmware.xenon.common.QueryResultsProcessor in project photon-model by vmware.
the class VSphereAdapterSnapshotService method isLastSnapshotForCompute.
private DeferredResult<Boolean> isLastSnapshotForCompute(SnapshotContext context) {
DeferredResult<Boolean> dr = new DeferredResult<>();
// find if for the compute has only one snapshot (the one which is to be deleted)
QueryTask qTask = getQueryWithFilters(context.snapshotState.computeLink, SnapshotState.FIELD_NAME_COMPUTE_LINK);
QueryUtils.startInventoryQueryTask(this, qTask).whenComplete((o, e) -> {
if (e != null) {
logInfo(String.format("Failure getting snapshot state: %s", Utils.toString(e)));
dr.fail(e);
return;
}
QueryResultsProcessor rp = QueryResultsProcessor.create(o);
List<SnapshotState> snapshotsFinal;
if (!rp.hasResults()) {
dr.complete(Boolean.FALSE);
} else {
snapshotsFinal = rp.streamDocuments(SnapshotState.class).collect(Collectors.toList());
dr.complete(snapshotsFinal.size() == 1);
}
});
return dr;
}
use of com.vmware.xenon.common.QueryResultsProcessor in project photon-model by vmware.
the class VSphereListComputeSnapshotService method handleGet.
@Override
public void handleGet(Operation get) {
Map<String, String> params = UriUtils.parseUriQueryParams(get.getUri());
String computeLink = params.get(QUERY_PARAM_COMPUTE);
if (computeLink == null || computeLink.isEmpty()) {
get.fail(new IllegalArgumentException("'" + QUERY_PARAM_COMPUTE + "' query param is required"));
return;
}
QueryTask.Query snapshotQuery = QueryTask.Query.Builder.create().addKindFieldClause(SnapshotService.SnapshotState.class).addFieldClause(SnapshotService.SnapshotState.FIELD_NAME_COMPUTE_LINK, computeLink).build();
QueryTask qTask = QueryTask.Builder.createDirectTask().setQuery(snapshotQuery).addOption(QueryTask.QuerySpecification.QueryOption.EXPAND_CONTENT).addOption(QueryTask.QuerySpecification.QueryOption.INDEXED_METADATA).build();
QueryUtils.startInventoryQueryTask(this, qTask).thenApply(op -> {
QueryResultsProcessor rp = QueryResultsProcessor.create(op);
List<SnapshotService.SnapshotState> snapshots = new ArrayList<>();
if (rp.hasResults()) {
snapshots = rp.streamDocuments(SnapshotService.SnapshotState.class).collect(Collectors.toList());
}
return snapshots;
}).whenComplete((result, e) -> {
if (e != null) {
get.fail(e);
} else {
get.setBody(result).complete();
}
});
}
Aggregations