Search in sources :

Example 6 with QueryResultsProcessor

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));
    }
}
Also used : EndpointState(com.vmware.photon.controller.model.resources.EndpointService.EndpointState) QueryResultsProcessor(com.vmware.xenon.common.QueryResultsProcessor) QueryTask(com.vmware.xenon.services.common.QueryTask) AuthCredentialsServiceState(com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState) Query(com.vmware.xenon.services.common.QueryTask.Query) ServiceDocumentQueryResult(com.vmware.xenon.common.ServiceDocumentQueryResult) Test(org.junit.Test)

Example 7 with QueryResultsProcessor

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;
}
Also used : QueryResultsProcessor(com.vmware.xenon.common.QueryResultsProcessor) SnapshotState(com.vmware.photon.controller.model.resources.SnapshotService.SnapshotState) QueryTask(com.vmware.xenon.services.common.QueryTask) Query(com.vmware.xenon.services.common.QueryTask.Query) ArrayList(java.util.ArrayList) TestRequestSender(com.vmware.xenon.common.test.TestRequestSender) ResourceOperation(com.vmware.photon.controller.model.adapters.registry.operations.ResourceOperation) Operation(com.vmware.xenon.common.Operation)

Example 8 with QueryResultsProcessor

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;
}
Also used : QueryResultsProcessor(com.vmware.xenon.common.QueryResultsProcessor) QueryTask(com.vmware.xenon.services.common.QueryTask) SnapshotState(com.vmware.photon.controller.model.resources.SnapshotService.SnapshotState) DeferredResult(com.vmware.xenon.common.DeferredResult)

Example 9 with QueryResultsProcessor

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();
        }
    });
}
Also used : List(java.util.List) StatelessService(com.vmware.xenon.common.StatelessService) Map(java.util.Map) Operation(com.vmware.xenon.common.Operation) UriUtils(com.vmware.xenon.common.UriUtils) QueryTask(com.vmware.xenon.services.common.QueryTask) QueryUtils(com.vmware.photon.controller.model.query.QueryUtils) Collectors(java.util.stream.Collectors) SnapshotService(com.vmware.photon.controller.model.resources.SnapshotService) ArrayList(java.util.ArrayList) QueryResultsProcessor(com.vmware.xenon.common.QueryResultsProcessor) SnapshotService(com.vmware.photon.controller.model.resources.SnapshotService) QueryResultsProcessor(com.vmware.xenon.common.QueryResultsProcessor) QueryTask(com.vmware.xenon.services.common.QueryTask) List(java.util.List) ArrayList(java.util.ArrayList)

Aggregations

QueryResultsProcessor (com.vmware.xenon.common.QueryResultsProcessor)9 QueryTask (com.vmware.xenon.services.common.QueryTask)9 SnapshotState (com.vmware.photon.controller.model.resources.SnapshotService.SnapshotState)5 Operation (com.vmware.xenon.common.Operation)5 ArrayList (java.util.ArrayList)5 Query (com.vmware.xenon.services.common.QueryTask.Query)4 ResourceOperation (com.vmware.photon.controller.model.adapters.registry.operations.ResourceOperation)3 List (java.util.List)3 QueryUtils (com.vmware.photon.controller.model.query.QueryUtils)2 SnapshotService (com.vmware.photon.controller.model.resources.SnapshotService)2 DeferredResult (com.vmware.xenon.common.DeferredResult)2 UriUtils (com.vmware.xenon.common.UriUtils)2 TestRequestSender (com.vmware.xenon.common.test.TestRequestSender)2 AuthCredentialsServiceState (com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState)2 ComputeProperties (com.vmware.photon.controller.model.ComputeProperties)1 IAAS_API_ENABLED (com.vmware.photon.controller.model.UriPaths.IAAS_API_ENABLED)1 ComputeInstanceRequest (com.vmware.photon.controller.model.adapterapi.ComputeInstanceRequest)1 InstanceRequestType (com.vmware.photon.controller.model.adapterapi.ComputeInstanceRequest.InstanceRequestType)1 ResourceRequest (com.vmware.photon.controller.model.adapterapi.ResourceRequest)1 AdapterUtils (com.vmware.photon.controller.model.adapters.util.AdapterUtils)1