Search in sources :

Example 6 with TagState

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);
    }
}
Also used : TagState(com.vmware.photon.controller.model.resources.TagService.TagState)

Example 7 with TagState

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;
}
Also used : TagState(com.vmware.photon.controller.model.resources.TagService.TagState) TagService(com.vmware.photon.controller.model.resources.TagService) TagState(com.vmware.photon.controller.model.resources.TagService.TagState)

Example 8 with TagState

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;
}
Also used : QueryTask(com.vmware.xenon.services.common.QueryTask) ArrayList(java.util.ArrayList) Operation(com.vmware.xenon.common.Operation) TagState(com.vmware.photon.controller.model.resources.TagService.TagState)

Example 9 with TagState

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);
    }
}
Also used : Query(com.vmware.xenon.services.common.QueryTask.Query) PhotonModelUtils.createOriginTagQuery(com.vmware.photon.controller.model.resources.util.PhotonModelUtils.createOriginTagQuery) HashMap(java.util.HashMap) AzureTestUtil.randomString(com.vmware.photon.controller.model.adapters.azure.instance.AzureTestUtil.randomString) TagState(com.vmware.photon.controller.model.resources.TagService.TagState) TagsUtil.newTagState(com.vmware.photon.controller.model.adapters.util.TagsUtil.newTagState) NicSpec(com.vmware.photon.controller.model.adapters.azure.instance.AzureTestUtil.AzureNicSpecs.NicSpec)

Example 10 with TagState

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));
    }
}
Also used : Query(com.vmware.xenon.services.common.QueryTask.Query) PhotonModelUtils.createOriginTagQuery(com.vmware.photon.controller.model.resources.util.PhotonModelUtils.createOriginTagQuery) ArrayList(java.util.ArrayList) AzureTestUtil.randomString(com.vmware.photon.controller.model.adapters.azure.instance.AzureTestUtil.randomString) TagState(com.vmware.photon.controller.model.resources.TagService.TagState) TagsUtil.newTagState(com.vmware.photon.controller.model.adapters.util.TagsUtil.newTagState)

Aggregations

TagState (com.vmware.photon.controller.model.resources.TagService.TagState)31 ArrayList (java.util.ArrayList)18 HashMap (java.util.HashMap)18 Operation (com.vmware.xenon.common.Operation)15 Query (com.vmware.xenon.services.common.QueryTask.Query)15 HashSet (java.util.HashSet)14 Map (java.util.Map)14 TagsUtil.newTagState (com.vmware.photon.controller.model.adapters.util.TagsUtil.newTagState)13 Utils (com.vmware.xenon.common.Utils)13 TagService (com.vmware.photon.controller.model.resources.TagService)12 QueryTask (com.vmware.xenon.services.common.QueryTask)12 List (java.util.List)12 Set (java.util.Set)12 StatelessService (com.vmware.xenon.common.StatelessService)11 Collectors (java.util.stream.Collectors)11 DiskState (com.vmware.photon.controller.model.resources.DiskService.DiskState)10 UriUtils (com.vmware.xenon.common.UriUtils)10 PhotonModelConstants (com.vmware.photon.controller.model.constants.PhotonModelConstants)8 QueryUtils (com.vmware.photon.controller.model.query.QueryUtils)8 ResourceState (com.vmware.photon.controller.model.resources.ResourceState)8