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));
}
}
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;
}
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());
}
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;
}
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;
}
}
Aggregations