use of com.vmware.xenon.services.common.QueryTask.Query in project photon-model by vmware.
the class TestAzureEnumerationTask method getSubnetStates.
/**
* Get all SubnetStates within passed NetworkState. In other words, get all subnet states that
* refer the network state passed.
*/
// TODO : Duplicated from AWS TestUtils. Please advice where to put common test utils
public static List<SubnetState> getSubnetStates(VerificationHost host, NetworkState networkState) {
Query queryForReferrers = QueryUtils.queryForReferrers(networkState.documentSelfLink, SubnetState.class, SubnetState.FIELD_NAME_NETWORK_LINK);
QueryByPages<SubnetState> querySubnetStatesReferrers = new QueryByPages<>(host, queryForReferrers, SubnetState.class, networkState.tenantLinks, networkState.endpointLink);
DeferredResult<List<SubnetState>> subnetDR = querySubnetStatesReferrers.collectDocuments(Collectors.toList());
return waitToComplete(subnetDR);
}
use of com.vmware.xenon.services.common.QueryTask.Query in project photon-model by vmware.
the class TestAzureEnumerationTask method assertRemoteResources.
// Assert that remote resources are enumerated and exists locally.
private void assertRemoteResources() {
assertResourceExists(this.host, NetworkService.FACTORY_LINK, NIC_SPEC.network.name, true);
for (NicSpec nicSpec : NIC_SPEC.nicSpecs) {
assertResourceExists(this.host, SubnetService.FACTORY_LINK, nicSpec.getSubnetSpec().name, true);
}
assertResourceExists(this.host, ResourceGroupService.FACTORY_LINK, azureVMName, true);
assertResourceExists(this.host, SecurityGroupService.FACTORY_LINK, AZURE_SECURITY_GROUP_NAME + "-" + azureVMName, true);
assertResourceExists(this.host, StorageDescriptionService.FACTORY_LINK, (azureVMName + "sa").replace("-", ""), true);
assertDiskExist(this.host, DiskService.FACTORY_LINK, azureVMName + "-boot-disk", true);
validateDiskInternalTag(this.host);
// Tags
final Map<String, String> expectedTags = new HashMap<>();
expectedTags.put(NETWORK_TAG_KEY_PREFIX + azureVMName, NETWORK_TAG_VALUE);
expectedTags.put(VM_TAG_KEY_PREFIX + azureVMName, VM_TAG_VALUE);
expectedTags.put(SG_TAG_KEY_PREFIX + azureVMName, SG_TAG_VALUE);
final List<String> keysToLowerCase = expectedTags.keySet().stream().map(String::toLowerCase).collect(Collectors.toList());
Query query = Query.Builder.create().addKindFieldClause(TagState.class).addInClause(TagState.FIELD_NAME_KEY, keysToLowerCase).build();
Map<String, Query.Occurance> origin = new HashMap<>();
origin.put(DISCOVERED.toString(), Query.Occurance.MUST_OCCUR);
origin.put(SYSTEM.toString(), Query.Occurance.MUST_NOT_OCCUR);
origin.put(USER_DEFINED.toString(), Query.Occurance.MUST_NOT_OCCUR);
Query externalQuery = createOriginTagQuery(Boolean.TRUE, origin);
query.addBooleanClause(externalQuery);
QueryStrategy<TagState> queryLocalTags = new QueryTop<>(getHost(), query, TagState.class, null).setMaxResultsLimit(expectedTags.size() + 1);
List<TagState> tagStates = waitToComplete(queryLocalTags.collectDocuments(Collectors.toList()));
this.host.log(Level.INFO, "external tag states discovered: " + tagStates.size());
if (!AzureUtils.isAzureClientMock()) {
assertEquals("TagStates were not discovered.", expectedTags.size(), tagStates.size());
}
for (TagState tag : tagStates) {
assertEquals(expectedTags.get(tag.key), tag.value);
}
}
use of com.vmware.xenon.services.common.QueryTask.Query in project photon-model by vmware.
the class TestAzureEnumerationTask method assertInternalTagResources.
/**
* Verify internal tags are created.
*/
private void assertInternalTagResources() {
final List<String> expectedTagValues = new ArrayList<>();
expectedTagValues.add(NETWORK_TAG_TYPE_VALUE);
expectedTagValues.add(SUBNET_TAG_TYPE_VALUE);
expectedTagValues.add(NETWORK_INTERFACE_TAG_TYPE_VALUE);
Query query = Query.Builder.create().addKindFieldClause(TagState.class).addFieldClause(TagState.FIELD_NAME_KEY, PhotonModelConstants.TAG_KEY_TYPE).build();
Query externalQuery = new Query().setTermPropertyName(TagState.FIELD_NAME_EXTERNAL).setTermMatchValue(Boolean.FALSE.toString());
externalQuery.occurance = Query.Occurance.SHOULD_OCCUR;
Query originQuery = new Query().addBooleanClause(Query.Builder.create().addCollectionItemClause(TagState.FIELD_NAME_ORIGIN, DISCOVERED.toString(), Query.Occurance.SHOULD_OCCUR).addCollectionItemClause(TagState.FIELD_NAME_ORIGIN, SYSTEM.toString(), Query.Occurance.SHOULD_OCCUR).addCollectionItemClause(TagState.FIELD_NAME_ORIGIN, USER_DEFINED.toString(), Query.Occurance.MUST_NOT_OCCUR).build()).setOccurance(Query.Occurance.SHOULD_OCCUR);
Query originOrExternalQuery = new Query().addBooleanClause(externalQuery).addBooleanClause(originQuery).setOccurance(Query.Occurance.MUST_OCCUR);
query.addBooleanClause(originOrExternalQuery);
QueryStrategy<TagState> queryLocalTags = new QueryTop<>(getHost(), query, TagState.class, null).setMaxResultsLimit(20);
List<TagState> tagStates = waitToComplete(queryLocalTags.collectDocuments(Collectors.toList()));
this.host.log(Level.INFO, "internal tag states discovered: " + tagStates.size());
assertTrue(tagStates.size() >= 3);
final List<String> actualTagValues = new ArrayList<>();
for (TagState tag : tagStates) {
assertNotNull(tag);
actualTagValues.add(tag.value);
}
// assert check if every expected tag value is present in actual values list.
for (String tagValue : expectedTagValues) {
assertTrue(actualTagValues.contains(tagValue));
actualTagValues.remove(tagValue);
}
// verify tag values no more exist in list that verifies duplicate tags are not created
for (String tagValue : expectedTagValues) {
assertFalse(actualTagValues.contains(tagValue));
}
}
use of com.vmware.xenon.services.common.QueryTask.Query in project photon-model by vmware.
the class EndpointAdapterUtils method getEndpointLinks.
private static DeferredResult<List<String>> getEndpointLinks(ServiceHost host, Query endpointQuery, List<String> credentialsLinks, String endpointType, List<String> queryTaskTenantLinks) {
if (credentialsLinks.isEmpty()) {
return DeferredResult.completed(Collections.emptyList());
}
Query.Builder qBuilder = Builder.create().addKindFieldClause(EndpointState.class).addFieldClause(EndpointState.FIELD_NAME_ENDPOINT_TYPE, endpointType).addInClause(EndpointState.FIELD_NAME_AUTH_CREDENTIALS_LINK, credentialsLinks);
if (endpointQuery != null) {
qBuilder.addClause(endpointQuery);
}
QueryTop<EndpointState> queryEndpoints = new QueryTop<>(host, qBuilder.build(), EndpointState.class, queryTaskTenantLinks).setQueryTaskTenantLinks(queryTaskTenantLinks).setMaxResultsLimit(1);
queryEndpoints.setClusterType(INVENTORY_SERVICE);
return queryEndpoints.collectLinks(Collectors.toList());
}
use of com.vmware.xenon.services.common.QueryTask.Query in project photon-model by vmware.
the class EndpointAdapterUtils method getAuthLinks.
private static DeferredResult<List<String>> getAuthLinks(ServiceHost host, Query authQuery, List<String> queryTaskTenantLinks) {
Query.Builder authQueryBuilder = Builder.create().addKindFieldClause(AuthCredentialsServiceState.class);
if (authQuery != null) {
authQueryBuilder.addClause(authQuery);
}
QueryTop<AuthCredentialsServiceState> queryAuth = new QueryTop<>(host, authQueryBuilder.build(), AuthCredentialsServiceState.class, queryTaskTenantLinks).setQueryTaskTenantLinks(queryTaskTenantLinks);
queryAuth.setClusterType(INVENTORY_SERVICE);
return queryAuth.collectLinks(Collectors.toList());
}
Aggregations