Search in sources :

Example 26 with TagState

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);
}
Also used : PowerState(com.vmware.photon.controller.model.resources.ComputeService.PowerState) Arrays(java.util.Arrays) ComputeEnumerateResourceRequest(com.vmware.photon.controller.model.adapterapi.ComputeEnumerateResourceRequest) ServiceTypeCluster(com.vmware.photon.controller.model.util.ClusterUtil.ServiceTypeCluster) LifecycleState(com.vmware.photon.controller.model.resources.ComputeService.LifecycleState) DISK_CONTROLLER_NUMBER(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.DISK_CONTROLLER_NUMBER) Action1(rx.functions.Action1) StringUtils(org.apache.commons.lang3.StringUtils) Azure(com.microsoft.azure.management.Azure) Utils(com.vmware.xenon.common.Utils) Pair(org.apache.commons.lang3.tuple.Pair) SubnetState(com.vmware.photon.controller.model.resources.SubnetService.SubnetState) Map(java.util.Map) StorageDescription(com.vmware.photon.controller.model.resources.StorageDescriptionService.StorageDescription) OSDisk(com.microsoft.azure.management.compute.OSDisk) ResourceEnumerationTaskService(com.vmware.photon.controller.model.tasks.ResourceEnumerationTaskService) NetworkInterfaceState(com.vmware.photon.controller.model.resources.NetworkInterfaceService.NetworkInterfaceState) StatelessService(com.vmware.xenon.common.StatelessService) Set(java.util.Set) NetworkInterfaceService(com.vmware.photon.controller.model.resources.NetworkInterfaceService) StorageAccountTypes(com.microsoft.azure.management.compute.StorageAccountTypes) TagService(com.vmware.photon.controller.model.resources.TagService) CompletionHandler(com.vmware.xenon.common.Operation.CompletionHandler) SOURCE_TASK_LINK(com.vmware.photon.controller.model.constants.PhotonModelConstants.SOURCE_TASK_LINK) InstanceViewStatus(com.microsoft.azure.management.compute.InstanceViewStatus) DeferredResult(com.vmware.xenon.common.DeferredResult) UriUtils(com.vmware.xenon.common.UriUtils) ComputeService(com.vmware.photon.controller.model.resources.ComputeService) NumericRange(com.vmware.xenon.services.common.QueryTask.NumericRange) AZURE_DATA_DISK_CACHING(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.AZURE_DATA_DISK_CACHING) ImageReferenceInner(com.microsoft.azure.management.compute.implementation.ImageReferenceInner) VirtualMachinesInner(com.microsoft.azure.management.compute.implementation.VirtualMachinesInner) ComputeDescriptionService(com.vmware.photon.controller.model.resources.ComputeDescriptionService) PhotonModelUtils(com.vmware.photon.controller.model.resources.util.PhotonModelUtils) RegionInfo(com.vmware.photon.controller.model.adapterapi.RegionEnumerationResponse.RegionInfo) TagsUtil(com.vmware.photon.controller.model.adapters.util.TagsUtil) ArrayList(java.util.ArrayList) TagState(com.vmware.photon.controller.model.resources.TagService.TagState) ServiceStateCollectionUpdateRequest(com.vmware.xenon.common.ServiceStateCollectionUpdateRequest) Query(com.vmware.xenon.services.common.QueryTask.Query) EnumerationStages(com.vmware.photon.controller.model.adapters.util.enums.EnumerationStages) OperatingSystemTypes(com.microsoft.azure.management.compute.OperatingSystemTypes) BiConsumer(java.util.function.BiConsumer) AZURE_DIAGNOSTIC_STORAGE_ACCOUNT_LINK(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.AZURE_DIAGNOSTIC_STORAGE_ACCOUNT_LINK) AZURE_STORAGE_ACCOUNT_URI(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.AZURE_STORAGE_ACCOUNT_URI) VirtualMachineInner(com.microsoft.azure.management.compute.implementation.VirtualMachineInner) AdapterUtils(com.vmware.photon.controller.model.adapters.util.AdapterUtils) DataDisk(com.microsoft.azure.management.compute.DataDisk) ResourceState(com.vmware.photon.controller.model.resources.ResourceState) QueryUtils(com.vmware.photon.controller.model.query.QueryUtils) ENVIRONMENT_NAME_AZURE(com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription.ENVIRONMENT_NAME_AZURE) QueryTop(com.vmware.photon.controller.model.query.QueryUtils.QueryTop) CUSTOM_OS_TYPE(com.vmware.photon.controller.model.ComputeProperties.CUSTOM_OS_TYPE) ComputeStateWithDescription(com.vmware.photon.controller.model.resources.ComputeService.ComputeStateWithDescription) PhotonModelConstants(com.vmware.photon.controller.model.constants.PhotonModelConstants) ComputeEnumerateAdapterRequest(com.vmware.photon.controller.model.adapters.util.ComputeEnumerateAdapterRequest) RegionEnumerationResponse(com.vmware.photon.controller.model.adapterapi.RegionEnumerationResponse) QuerySpecification(com.vmware.xenon.services.common.QueryTask.QuerySpecification) PhotonModelUriUtils.createInventoryUri(com.vmware.photon.controller.model.util.PhotonModelUriUtils.createInventoryUri) AuthCredentialsServiceState(com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState) QueryTask(com.vmware.xenon.services.common.QueryTask) AZURE_RESOURCE_GROUP_NAME(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.AZURE_RESOURCE_GROUP_NAME) OSType(com.vmware.photon.controller.model.ComputeProperties.OSType) AzureUriPaths(com.vmware.photon.controller.model.adapters.azure.AzureUriPaths) AZURE_MANAGED_DISK_TYPE(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.AZURE_MANAGED_DISK_TYPE) ComputeType(com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription.ComputeType) AzureSdkClients(com.vmware.photon.controller.model.adapters.azure.utils.AzureSdkClients) AzureUtils.injectOperationContext(com.vmware.photon.controller.model.adapters.azure.utils.AzureUtils.injectOperationContext) CUSTOM_PROP_ENDPOINT_LINK(com.vmware.photon.controller.model.constants.PhotonModelConstants.CUSTOM_PROP_ENDPOINT_LINK) URI(java.net.URI) TagsUtil.newTagState(com.vmware.photon.controller.model.adapters.util.TagsUtil.newTagState) EndpointState(com.vmware.photon.controller.model.resources.EndpointService.EndpointState) AzureConstants(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants) AzureConstants.getQueryResultLimit(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.getQueryResultLimit) ComputeDescription(com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription) Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) DiskState(com.vmware.photon.controller.model.resources.DiskService.DiskState) Occurance(com.vmware.xenon.services.common.QueryTask.Query.Occurance) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) List(java.util.List) AzureUtils(com.vmware.photon.controller.model.adapters.azure.utils.AzureUtils) AzureUtils.getResourceGroupName(com.vmware.photon.controller.model.adapters.azure.utils.AzureUtils.getResourceGroupName) TAG_KEY_TYPE(com.vmware.photon.controller.model.constants.PhotonModelConstants.TAG_KEY_TYPE) Entry(java.util.Map.Entry) NetworkInterfacesInner(com.microsoft.azure.management.network.implementation.NetworkInterfacesInner) QueryOption(com.vmware.xenon.services.common.QueryTask.QuerySpecification.QueryOption) InstanceViewTypes(com.microsoft.azure.management.compute.InstanceViewTypes) TagsUtil.setTagLinksToResourceState(com.vmware.photon.controller.model.adapters.util.TagsUtil.setTagLinksToResourceState) Builder(com.vmware.xenon.services.common.QueryTask.Query.Builder) DiskService(com.vmware.photon.controller.model.resources.DiskService) AzureUtils.isDiskManaged(com.vmware.photon.controller.model.adapters.azure.utils.AzureUtils.isDiskManaged) Default(com.vmware.photon.controller.model.adapters.azure.utils.AzureDeferredResultServiceCallback.Default) QueryByPages(com.vmware.photon.controller.model.query.QueryUtils.QueryByPages) AZURE_OSDISK_CACHING(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.AZURE_OSDISK_CACHING) PublicIPAddress(com.microsoft.azure.management.network.PublicIPAddress) HashMap(java.util.HashMap) HashSet(java.util.HashSet) AuthCredentialsService(com.vmware.xenon.services.common.AuthCredentialsService) TagsUtil.updateLocalTagStates(com.vmware.photon.controller.model.adapters.util.TagsUtil.updateLocalTagStates) ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) EnumerationAction(com.vmware.photon.controller.model.adapterapi.EnumerationAction) AzureResourceType(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.AzureResourceType) ExecutorService(java.util.concurrent.ExecutorService) Iterator(java.util.Iterator) NetworkInterfaceIPConfigurationInner(com.microsoft.azure.management.network.implementation.NetworkInterfaceIPConfigurationInner) Operation(com.vmware.xenon.common.Operation) Page(com.microsoft.azure.Page) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) NetworkInterfaceReferenceInner(com.microsoft.azure.management.compute.implementation.NetworkInterfaceReferenceInner) AzureDeferredResultServiceCallback(com.vmware.photon.controller.model.adapters.azure.utils.AzureDeferredResultServiceCallback) NetworkInterfaceInner(com.microsoft.azure.management.network.implementation.NetworkInterfaceInner) Collections(java.util.Collections) OperationJoin(com.vmware.xenon.common.OperationJoin) RESOURCE_GROUP_NAME(com.vmware.photon.controller.model.ComputeProperties.RESOURCE_GROUP_NAME) TagState(com.vmware.photon.controller.model.resources.TagService.TagState) TagsUtil.newTagState(com.vmware.photon.controller.model.adapters.util.TagsUtil.newTagState)

Example 27 with TagState

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

Example 28 with TagState

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);
}
Also used : Service(com.vmware.xenon.common.Service) PhotonModelUtils.createOriginTagQuery(com.vmware.photon.controller.model.resources.util.PhotonModelUtils.createOriginTagQuery) QueryTask(com.vmware.xenon.services.common.QueryTask) HashMap(java.util.HashMap) SYSTEM(com.vmware.photon.controller.model.resources.TagService.TagState.TagOrigin.SYSTEM) ArrayList(java.util.ArrayList) ServiceUriPaths(com.vmware.xenon.services.common.ServiceUriPaths) HashSet(java.util.HashSet) TagState(com.vmware.photon.controller.model.resources.TagService.TagState) Utils(com.vmware.xenon.common.Utils) USER_DEFINED(com.vmware.photon.controller.model.resources.TagService.TagState.TagOrigin.USER_DEFINED) Query(com.vmware.xenon.services.common.QueryTask.Query) UriPaths(com.vmware.photon.controller.model.UriPaths) TaskFactoryService(com.vmware.xenon.services.common.TaskFactoryService) Map(java.util.Map) PropertyUsageOption(com.vmware.xenon.common.ServiceDocumentDescription.PropertyUsageOption) ResourceState(com.vmware.photon.controller.model.resources.ResourceState) Operation(com.vmware.xenon.common.Operation) QueryUtils(com.vmware.photon.controller.model.query.QueryUtils) Set(java.util.Set) List(java.util.List) QueryOption(com.vmware.xenon.services.common.QueryTask.QuerySpecification.QueryOption) FactoryService(com.vmware.xenon.common.FactoryService) TaskService(com.vmware.xenon.services.common.TaskService) OperationJoin(com.vmware.xenon.common.OperationJoin) DISCOVERED(com.vmware.photon.controller.model.resources.TagService.TagState.TagOrigin.DISCOVERED) PhotonModelUriUtils.createInventoryUri(com.vmware.photon.controller.model.util.PhotonModelUriUtils.createInventoryUri) ArrayList(java.util.ArrayList) Operation(com.vmware.xenon.common.Operation) HashMap(java.util.HashMap) Map(java.util.Map) TagState(com.vmware.photon.controller.model.resources.TagService.TagState)

Example 29 with TagState

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

Example 30 with TagState

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

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