use of com.vmware.photon.controller.model.resources.TagService.TagState in project photon-model by vmware.
the class TagGroomerTaskServiceTest method assertUnusedTags.
// unused tags should be external and marked as deleted
private void assertUnusedTags(List<TagState> tags) {
for (TagState unusedTag : tags) {
assertTrue(unusedTag.external);
assertFalse(unusedTag.origins.contains(DISCOVERED.toString()));
assertTrue(unusedTag.deleted);
}
}
use of com.vmware.photon.controller.model.resources.TagService.TagState in project photon-model by vmware.
the class TagGroomerTaskServiceTest method buildTagState.
/**
* Create tagState object
*/
private static TagState buildTagState(String prefix, int k, int v, boolean external, EnumSet<TagOrigin> origin) throws Throwable {
TagService.TagState tag = new TagService.TagState();
tag.key = prefix + Integer.toString(k);
tag.value = prefix + Integer.toString(v);
tag.external = external;
tag.origins.addAll(origin);
tag.deleted = Boolean.FALSE;
return tag;
}
use of com.vmware.photon.controller.model.resources.TagService.TagState in project photon-model by vmware.
the class TagGroomerTaskServiceTest method getTags.
/**
* Query for tagLinks
*/
public List<TagState> getTags(QueryTask queryTask) {
Operation postQuery = Operation.createPost(UriUtils.buildUri(this.host, ServiceUriPaths.CORE_LOCAL_QUERY_TASKS)).setBody(queryTask);
Operation queryResponse = this.host.waitForResponse(postQuery);
if (queryResponse.getStatusCode() != 200) {
return null;
}
QueryTask response = queryResponse.getBody(QueryTask.class);
List<TagState> tagList = new ArrayList<>();
response.results.documents.values().forEach(tagState -> {
TagState ts = Utils.fromJson(tagState, TagState.class);
tagList.add(ts);
});
return tagList;
}
use of com.vmware.photon.controller.model.resources.TagService.TagState 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.photon.controller.model.resources.TagService.TagState 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));
}
}
Aggregations