Search in sources :

Example 81 with QueryTask

use of com.vmware.xenon.services.common.QueryTask 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 82 with QueryTask

use of com.vmware.xenon.services.common.QueryTask in project photon-model by vmware.

the class AWSNetworkUtils method createQueryToGetExistingStatesFilteredByDiscoveredIds.

private static QueryTask createQueryToGetExistingStatesFilteredByDiscoveredIds(Class<? extends ResourceState> stateClass, Set<String> stateIds, String computeHostLink, String endpointLink, String regionId, List<String> tenantLinks) {
    Query.Builder queryBuilder = Query.Builder.create().addKindFieldClause(stateClass).addInClause(ResourceState.FIELD_NAME_ID, stateIds);
    queryBuilder.addFieldClause(ResourceState.FIELD_NAME_COMPUTE_HOST_LINK, computeHostLink);
    if (regionId != null) {
        queryBuilder.addFieldClause(ResourceState.FIELD_NAME_REGION_ID, regionId);
    }
    if (tenantLinks != null && !tenantLinks.isEmpty()) {
        queryBuilder.addInCollectionItemClause(ResourceState.FIELD_NAME_TENANT_LINKS, tenantLinks);
    }
    QueryTask queryTask = QueryTask.Builder.createDirectTask().addOption(QueryOption.EXPAND_CONTENT).addOption(QueryOption.INDEXED_METADATA).addOption(QueryOption.TOP_RESULTS).setQuery(queryBuilder.build()).setResultLimit(AWS_NETWORK_QUERY_RESULT_LIMIT).build();
    queryTask.tenantLinks = tenantLinks;
    return queryTask;
}
Also used : QueryTask(com.vmware.xenon.services.common.QueryTask) Query(com.vmware.xenon.services.common.QueryTask.Query)

Example 83 with QueryTask

use of com.vmware.xenon.services.common.QueryTask in project photon-model by vmware.

the class PhotonModelAdaptersRegistryServiceTest method testGetByEndpointType.

@Test
public void testGetByEndpointType() throws Exception {
    String k1 = "k1";
    String k2 = "k2";
    String k3 = "k3";
    PhotonModelAdapterConfig config1 = getPhotonModelAdapterConfig("testGetByEndpointType-1", "Test Get By Endpoint Type 1", "testGetByEndpointType-1.png", k1, k3);
    Operation registerOp1 = Operation.createPost(super.host, PhotonModelAdaptersRegistryService.FACTORY_LINK).setBody(config1);
    super.host.waitForResponse(registerOp1);
    PhotonModelAdapterConfig config2 = getPhotonModelAdapterConfig("testGetByEndpointType-2", "Test Get By Endpoint Type 2", "testGetByEndpointType-2.png", k2, k3);
    Operation registerOp2 = Operation.createPost(super.host, PhotonModelAdaptersRegistryService.FACTORY_LINK).setBody(config2);
    super.host.waitForResponse(registerOp2);
    Query query = Query.Builder.create().addKindFieldClause(PhotonModelAdapterConfig.class).addFieldClause(QuerySpecification.buildCompositeFieldName(PhotonModelAdapterConfig.FIELD_NAME_ADAPTER_ENDPOINTS, k2), "*", MatchType.WILDCARD).build();
    QueryTask queryTask = QueryTask.Builder.createDirectTask().addOption(QueryOption.EXPAND_CONTENT).setQuery(query).build();
    Operation queryOp = Operation.createPost(super.host, ServiceUriPaths.CORE_QUERY_TASKS).setReferer(getClass().getSimpleName()).setBody(queryTask);
    Operation response = super.host.waitForResponse(queryOp);
    QueryTask qTask = response.getBody(QueryTask.class);
    Collection<Object> values = qTask.results.documents.values();
    Assert.assertEquals(1, values.size());
    JsonObject k2Config = (JsonObject) values.iterator().next();
    Assert.assertEquals(config2.id, k2Config.getAsJsonPrimitive(PhotonModelAdapterConfig.FIELD_NAME_ID).getAsString());
}
Also used : QueryTask(com.vmware.xenon.services.common.QueryTask) Query(com.vmware.xenon.services.common.QueryTask.Query) JsonObject(com.google.gson.JsonObject) JsonObject(com.google.gson.JsonObject) Operation(com.vmware.xenon.common.Operation) PhotonModelAdapterConfig(com.vmware.photon.controller.model.adapters.registry.PhotonModelAdaptersRegistryService.PhotonModelAdapterConfig) Test(org.junit.Test)

Example 84 with QueryTask

use of com.vmware.xenon.services.common.QueryTask 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 85 with QueryTask

use of com.vmware.xenon.services.common.QueryTask in project photon-model by vmware.

the class TestVSpherePortgroupProvisioning method findDvs.

protected String findDvs(String name) throws Throwable {
    Query q = Query.Builder.create().addKindFieldClause(NetworkState.class).addCompositeFieldClause(NetworkState.FIELD_NAME_CUSTOM_PROPERTIES, CustomProperties.TYPE, VimNames.TYPE_DVS).addFieldClause(NetworkState.FIELD_NAME_NAME, name).build();
    QueryTask task = QueryTask.Builder.createDirectTask().setQuery(q).build();
    Operation op = QueryUtils.createQueryTaskOperation(this.host, task, ServiceTypeCluster.INVENTORY_SERVICE);
    Operation result = this.host.waitForResponse(op);
    try {
        return result.getBody(QueryTask.class).results.documentLinks.get(0);
    } catch (Exception e) {
        Assert.fail(e.getMessage());
        return null;
    }
}
Also used : QueryTask(com.vmware.xenon.services.common.QueryTask) Query(com.vmware.xenon.services.common.QueryTask.Query) NetworkState(com.vmware.photon.controller.model.resources.NetworkService.NetworkState) Operation(com.vmware.xenon.common.Operation)

Aggregations

QueryTask (com.vmware.xenon.services.common.QueryTask)147 Query (com.vmware.xenon.services.common.QueryTask.Query)62 Operation (com.vmware.xenon.common.Operation)61 ComputeState (com.vmware.photon.controller.model.resources.ComputeService.ComputeState)39 ArrayList (java.util.ArrayList)26 QueryUtils (com.vmware.photon.controller.model.query.QueryUtils)20 List (java.util.List)20 ResourceMetrics (com.vmware.photon.controller.model.monitoring.ResourceMetricsService.ResourceMetrics)19 UriUtils (com.vmware.xenon.common.UriUtils)18 Utils (com.vmware.xenon.common.Utils)17 HashSet (java.util.HashSet)16 HashMap (java.util.HashMap)14 QueryOption (com.vmware.xenon.services.common.QueryTask.QuerySpecification.QueryOption)12 TimeUnit (java.util.concurrent.TimeUnit)12 ComputeEnumerateResourceRequest (com.vmware.photon.controller.model.adapterapi.ComputeEnumerateResourceRequest)11 AdapterUtils (com.vmware.photon.controller.model.adapters.util.AdapterUtils)11 ComputeDescription (com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription)11 ServiceTypeCluster (com.vmware.photon.controller.model.util.ClusterUtil.ServiceTypeCluster)11 URI (java.net.URI)11 Set (java.util.Set)11