use of com.vmware.photon.controller.model.resources.TagService.TagState in project photon-model by vmware.
the class AzureComputeEnumerationAdapterService method createNetworkInterfaceInternalTagStates.
/**
* Create internal tag resources for network interfaces.
*/
private void createNetworkInterfaceInternalTagStates(EnumerationContext ctx, ComputeEnumerationSubStages next) {
TagState internalTypeTag = newTagState(PhotonModelConstants.TAG_KEY_TYPE, NETWORK_INTERFACE_TAG_TYPE_VALUE, false, ctx.parentCompute.tenantLinks);
// operation to create tag "type" for network interfaces.
Operation.createPost(this, TagService.FACTORY_LINK).setBody(internalTypeTag).setCompletion((o, e) -> {
if (e != null) {
logSevere("Error creating internal type tag for network interfaces: %s", e.getMessage());
} else {
ctx.nicInternalTagsMap.put(PhotonModelConstants.TAG_KEY_TYPE, NETWORK_INTERFACE_TAG_TYPE_VALUE);
ctx.nicInternalTagLinksSet.add(internalTypeTag.documentSelfLink);
}
ctx.subStage = next;
handleSubStage(ctx);
}).sendWith(this);
}
use of com.vmware.photon.controller.model.resources.TagService.TagState in project photon-model by vmware.
the class TestAWSProvisionTask method createTags.
private Set<TagState> createTags(List<String> tenantLinks, String... keyValue) throws Throwable {
Set<TagState> result = new HashSet<>();
for (int i = 0; i <= keyValue.length - 2; i = i + 2) {
TagState tagState = new TagState();
tagState.tenantLinks = tenantLinks;
tagState.key = keyValue[i];
tagState.value = keyValue[i + 1];
TagState response = TestUtils.doPost(this.host, tagState, TagState.class, UriUtils.buildUri(this.host, TagService.FACTORY_LINK));
result.add(response);
}
return result;
}
use of com.vmware.photon.controller.model.resources.TagService.TagState in project photon-model by vmware.
the class TagGroomerTaskService method markStaleTagsDeleted.
/**
* Mark stale tags as deleted. On completion, process the next batch of tagLinks or complete task.
*/
private void markStaleTagsDeleted(TagDeletionRequest task, SubStage next) {
if (task.tagsMap.isEmpty()) {
if (task.tagsNextPageLink == null) {
task.subStage = SubStage.FINISHED;
} else {
task.subStage = next;
}
sendSelfPatch(task);
return;
}
// Create an update operation for each stale tagState
List<Operation> operations = new ArrayList<>();
for (Map.Entry<String, TagState> entry : task.tagsMap.entrySet()) {
TagState tagToDelete = entry.getValue();
tagToDelete.deleted = Boolean.TRUE;
operations.add(Operation.createPatch(createInventoryUri(this.getHost(), tagToDelete.documentSelfLink)).setBody(tagToDelete).setReferer(this.getUri()));
}
OperationJoin.create(operations).setCompletion((ops, exs) -> {
if (exs != null && !exs.isEmpty()) {
exs.values().forEach(ex -> this.logWarning(() -> String.format("Error: %s", ex.getMessage())));
} else {
task.subStage = next;
sendSelfPatch(task);
}
}).sendWith(this);
}
use of com.vmware.photon.controller.model.resources.TagService.TagState in project photon-model by vmware.
the class TagGroomerTaskServiceTest method createTagStates.
/**
* Create n tagLinks
*/
private List<String> createTagStates(String prefix, int count, boolean external, EnumSet<TagOrigin> origin) throws Throwable {
List<String> tags = new ArrayList<>();
for (int i = 0; i < count; i++) {
TagState tag = buildTagState(prefix, i, i, external, origin);
Operation op = Operation.createPost(UriUtils.buildUri(this.host, TagService.FACTORY_LINK)).setBody(tag);
Operation response = this.host.waitForResponse(op);
if (response.getStatusCode() == Operation.STATUS_CODE_OK) {
tags.add(response.getBody(TagState.class).documentSelfLink);
}
}
return tags;
}
use of com.vmware.photon.controller.model.resources.TagService.TagState in project photon-model by vmware.
the class TagGroomerTaskServiceTest method testTagStateGroomerOnePageOfResults.
/**
* 1. Create multiple tagStates both internal and external
* 2. create different resources some with above tagLinks and some without
* 3. validate groomer task only marks the external tagStates as deleted
*/
@Test
public void testTagStateGroomerOnePageOfResults() throws Throwable {
List<String> usedTags = createTagStates("usedExt-", TAG_COUNT_15, true, EnumSet.of(DISCOVERED));
usedTags.addAll(createTagStates("usedInt-", TAG_COUNT_15, false, EnumSet.of(SYSTEM)));
List<String> unusedTagsExt = createTagStates("unusedExt-", 10, true, EnumSet.of(DISCOVERED));
List<String> unusedTagsInt = createTagStates("unusedInt-", 7, false, EnumSet.of(SYSTEM));
int totalTagsCreated = usedTags.size() + unusedTagsExt.size() + unusedTagsInt.size();
createComputesWithTags(30, usedTags);
createDisksWithTags(30, usedTags);
executeTagsGroomerTask();
QueryTask tagsQT = createTagsQueryTask(false);
List<TagState> tagsAfterGrooming = getTags(tagsQT);
// the only tags returned should be the ones not marked as deleted
assertEquals(totalTagsCreated - unusedTagsExt.size(), tagsAfterGrooming.size());
// assert used tags are marked as deleted
assertUsedTags(tagsAfterGrooming);
tagsQT = createTagsQueryTask(true);
tagsAfterGrooming = getTags(tagsQT);
// the only tags returned should be the 10 external tags that are marked as deleted
assertEquals(unusedTagsExt.size(), tagsAfterGrooming.size());
// assert unused tags are marked as deleted
assertUnusedTags(tagsAfterGrooming);
}
Aggregations