Search in sources :

Example 11 with TagState

use of com.vmware.photon.controller.model.resources.TagService.TagState in project photon-model by vmware.

the class TagsUtil method newTagState.

public static TagState newTagState(String key, String value, EnumSet<TagOrigin> origin, List<String> tenantLinks) {
    final TagState tagState = new TagState();
    tagState.key = key == null ? "" : key;
    tagState.value = value == null ? "" : value;
    tagState.origins = origin;
    tagState.deleted = Boolean.FALSE;
    tagState.tenantLinks = tenantLinks;
    tagState.documentSelfLink = TagFactoryService.generateSelfLink(tagState);
    return tagState;
}
Also used : TagState(com.vmware.photon.controller.model.resources.TagService.TagState)

Example 12 with TagState

use of com.vmware.photon.controller.model.resources.TagService.TagState in project photon-model by vmware.

the class TagsUtil method newTagState.

/**
 * TODO Method should get removed - leaving in place to help transition.
 *
 * Generate a new external TagState from provided key and value. TagStates, marked as "external"
 * identify tags which exist on the remote cloud. They will be removed from the local resource's
 * state, in case the corresponding tags is removed from the remote resource. Tags, identified
 * as "local" are not maintained in sync with the tags on the cloud. They are used by the local
 * user to mark local resource states.
 */
public static TagState newTagState(String key, String value, Boolean isExternal, List<String> tenantLinks) {
    final TagState tagState = new TagState();
    tagState.key = key == null ? "" : key;
    tagState.value = value == null ? "" : value;
    tagState.external = isExternal;
    tagState.origins = EnumSet.of(isExternal ? DISCOVERED : SYSTEM);
    tagState.deleted = Boolean.FALSE;
    tagState.tenantLinks = tenantLinks;
    tagState.documentSelfLink = TagFactoryService.generateSelfLink(tagState);
    return tagState;
}
Also used : TagState(com.vmware.photon.controller.model.resources.TagService.TagState)

Example 13 with TagState

use of com.vmware.photon.controller.model.resources.TagService.TagState in project photon-model by vmware.

the class TestAWSImageEnumerationTask method testPrivateImageEnumeration_single.

/*
     * The image that must be returned:
     *
     * https://console.aws.amazon.com/ec2/v2/home?region=us-east-1#Images:visibility=private-images;
     * imageId=ami-caf25eb0;sort=name
     *
     * under prelude_test @ https://537227425989.signin.aws.amazon.com/console
     */
@Test
@Ignore("https://jira-hzn.eng.vmware.com/browse/VCOM-832")
public void testPrivateImageEnumeration_single() throws Throwable {
    Assume.assumeFalse(this.isMock);
    final EndpointState endpointState = createEndpointState();
    kickOffImageEnumeration(endpointState, PRIVATE, AMAZON_PRIVATE_IMAGE_FILTER);
    // Validate 1 image state is CREATED
    ServiceDocumentQueryResult images = queryDocumentsAndAssertExpectedCount(getHost(), 1, ImageService.FACTORY_LINK, EXACT_COUNT);
    ImageState image = Utils.fromJson(images.documents.values().iterator().next(), ImageState.class);
    // Validate created image is correctly populated
    Assert.assertNull("Private image must NOT have endpointType set.", image.endpointType);
    Assert.assertEquals("Private image must have endpointLink set.", endpointState.documentSelfLink, image.endpointLink);
    Assert.assertEquals("Private image must have tenantLinks set.", endpointState.tenantLinks, image.tenantLinks);
    Assert.assertEquals("Private image id is incorrect.", "ami-caf25eb0", image.id);
    Assert.assertEquals("Private image name is incorrect.", "tapestryPipelineServiceTestService", image.name);
    Assert.assertEquals("Private image 'Name' tag is missing.", 1, image.tagLinks.size());
    TagState nameTag = getServiceSynchronously(image.tagLinks.iterator().next(), TagState.class);
    Assert.assertEquals(image.name, nameTag.value);
}
Also used : EndpointState(com.vmware.photon.controller.model.resources.EndpointService.EndpointState) TagState(com.vmware.photon.controller.model.resources.TagService.TagState) ServiceDocumentQueryResult(com.vmware.xenon.common.ServiceDocumentQueryResult) ImageState(com.vmware.photon.controller.model.resources.ImageService.ImageState) Ignore(org.junit.Ignore) BaseModelTest(com.vmware.photon.controller.model.helpers.BaseModelTest) Test(org.junit.Test)

Example 14 with TagState

use of com.vmware.photon.controller.model.resources.TagService.TagState in project photon-model by vmware.

the class VsphereEnumerationHelper method retrieveAttachedTags.

/**
 * Retreives all tags for a MoRef from an endpoint.
 *
 * @return empty list if no tags found, never null
 */
static List<TagState> retrieveAttachedTags(VSphereIncrementalEnumerationService service, VapiConnection endpoint, ManagedObjectReference ref, List<String> tenantLinks) throws IOException, RpcException {
    TaggingClient taggingClient = endpoint.newTaggingClient();
    List<String> tagIds = taggingClient.getAttachedTags(ref);
    List<TagState> res = new ArrayList<>();
    for (String id : tagIds) {
        TagState cached = service.getTagCache().get(id, newTagRetriever(taggingClient));
        if (cached != null) {
            TagState tag = TagsUtil.newTagState(cached.key, cached.value, true, tenantLinks);
            res.add(tag);
        }
    }
    return res;
}
Also used : ArrayList(java.util.ArrayList) TaggingClient(com.vmware.photon.controller.model.adapters.vsphere.vapi.TaggingClient) TagState(com.vmware.photon.controller.model.resources.TagService.TagState)

Example 15 with TagState

use of com.vmware.photon.controller.model.resources.TagService.TagState in project photon-model by vmware.

the class AWSComputeStateCreationAdapterService method createInternalTypeTags.

private void createInternalTypeTags(AWSComputeStateCreationContext context, AWSComputeStateCreationStage next) {
    // Go over the list of internal tags to be created. Find whatever already does not have an
    // associated tag state and create an operation for its creation.
    List<Operation> joinOperations = new ArrayList<>();
    for (String resourceType : internalTagList) {
        TagState typeTag = newTagState(TAG_KEY_TYPE, resourceType, false, context.request.tenantLinks);
        Operation op = Operation.createPost(this, TagService.FACTORY_LINK).setBody(typeTag);
        joinOperations.add(op);
    }
    OperationJoin.create(joinOperations).setCompletion((ops, exs) -> {
        if (exs != null) {
            exs.values().forEach(ex -> logWarning(() -> String.format("Error creating internal tag%s", ex.getMessage())));
            context.creationStage = next;
            handleComputeStateCreateOrUpdate(context);
            return;
        }
        for (String internalTagValue : internalTagList) {
            TagState tagState = newTagState(TAG_KEY_TYPE, internalTagValue, false, context.request.tenantLinks);
            context.internalTagLinksMap.put(tagState.value, new HashSet<>(Arrays.asList(tagState.documentSelfLink)));
        }
        context.creationStage = next;
        handleComputeStateCreateOrUpdate(context);
    }).sendWith(this);
}
Also used : AdapterUtils.createDeleteOperation(com.vmware.photon.controller.model.adapters.util.AdapterUtils.createDeleteOperation) AuthCredentialsServiceState(com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState) Arrays(java.util.Arrays) QueryTask(com.vmware.xenon.services.common.QueryTask) InstanceDescKey(com.vmware.photon.controller.model.adapters.awsadapter.util.AWSEnumerationUtils.InstanceDescKey) AWSEnumerationUtils(com.vmware.photon.controller.model.adapters.awsadapter.util.AWSEnumerationUtils) StringUtils(org.apache.commons.lang3.StringUtils) AWSEnumerationUtils.getKeyForComputeDescriptionFromCD(com.vmware.photon.controller.model.adapters.awsadapter.util.AWSEnumerationUtils.getKeyForComputeDescriptionFromCD) Utils(com.vmware.xenon.common.Utils) Map(java.util.Map) GroupIdentifier(com.amazonaws.services.ec2.model.GroupIdentifier) AdapterUtils.createPatchOperation(com.vmware.photon.controller.model.adapters.util.AdapterUtils.createPatchOperation) URI(java.net.URI) TagsUtil.newTagState(com.vmware.photon.controller.model.adapters.util.TagsUtil.newTagState) AWSClientManager(com.vmware.photon.controller.model.adapters.awsadapter.util.AWSClientManager) ComputeDescription(com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription) NetworkInterfaceState(com.vmware.photon.controller.model.resources.NetworkInterfaceService.NetworkInterfaceState) StatelessService(com.vmware.xenon.common.StatelessService) Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) DiskState(com.vmware.photon.controller.model.resources.DiskService.DiskState) UUID(java.util.UUID) AdapterUtils.getDeletionState(com.vmware.photon.controller.model.adapters.util.AdapterUtils.getDeletionState) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) List(java.util.List) NetworkInterfaceService(com.vmware.photon.controller.model.resources.NetworkInterfaceService) TagService(com.vmware.photon.controller.model.resources.TagService) Tag(com.amazonaws.services.ec2.model.Tag) DeferredResult(com.vmware.xenon.common.DeferredResult) UriUtils(com.vmware.xenon.common.UriUtils) TAG_KEY_TYPE(com.vmware.photon.controller.model.constants.PhotonModelConstants.TAG_KEY_TYPE) ComputeService(com.vmware.photon.controller.model.resources.ComputeService) QueryOption(com.vmware.xenon.services.common.QueryTask.QuerySpecification.QueryOption) AWSEnumerationUtils.mapInstanceToComputeState(com.vmware.photon.controller.model.adapters.awsadapter.util.AWSEnumerationUtils.mapInstanceToComputeState) ZoneData(com.vmware.photon.controller.model.adapters.awsadapter.util.AWSEnumerationUtils.ZoneData) InstanceNetworkInterface(com.amazonaws.services.ec2.model.InstanceNetworkInterface) AWSResourceType.ec2_instance(com.vmware.photon.controller.model.adapters.awsadapter.AWSConstants.AWSResourceType.ec2_instance) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) AWSConstants(com.vmware.photon.controller.model.adapters.awsadapter.AWSConstants) TagState(com.vmware.photon.controller.model.resources.TagService.TagState) AWSResourceType.ec2_net_interface(com.vmware.photon.controller.model.adapters.awsadapter.AWSConstants.AWSResourceType.ec2_net_interface) ServiceStateCollectionUpdateRequest(com.vmware.xenon.common.ServiceStateCollectionUpdateRequest) Query(com.vmware.xenon.services.common.QueryTask.Query) TagsUtil.updateLocalTagStates(com.vmware.photon.controller.model.adapters.util.TagsUtil.updateLocalTagStates) ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) AdapterUtils.createPostOperation(com.vmware.photon.controller.model.adapters.util.AdapterUtils.createPostOperation) AWSEnumerationUtils.getRepresentativeListOfCDsFromInstanceList(com.vmware.photon.controller.model.adapters.awsadapter.util.AWSEnumerationUtils.getRepresentativeListOfCDsFromInstanceList) BiConsumer(java.util.function.BiConsumer) Instance(com.amazonaws.services.ec2.model.Instance) AWSSecurityGroupEnumerationResponse(com.vmware.photon.controller.model.adapters.awsadapter.enumeration.AWSSecurityGroupEnumerationAdapterService.AWSSecurityGroupEnumerationResponse) ResourceState(com.vmware.photon.controller.model.resources.ResourceState) Operation(com.vmware.xenon.common.Operation) QueryUtils(com.vmware.photon.controller.model.query.QueryUtils) AWSNetworkEnumerationResponse(com.vmware.photon.controller.model.adapters.awsadapter.enumeration.AWSNetworkStateEnumerationAdapterService.AWSNetworkEnumerationResponse) TimeUnit(java.util.concurrent.TimeUnit) AWSEnumerationUtils.getCDsRepresentingVMsInLocalSystemCreatedByEnumerationQuery(com.vmware.photon.controller.model.adapters.awsadapter.util.AWSEnumerationUtils.getCDsRepresentingVMsInLocalSystemCreatedByEnumerationQuery) AWSClientManagerFactory(com.vmware.photon.controller.model.adapters.awsadapter.util.AWSClientManagerFactory) Collections(java.util.Collections) AWSUriPaths(com.vmware.photon.controller.model.adapters.awsadapter.AWSUriPaths) OperationJoin(com.vmware.xenon.common.OperationJoin) ArrayList(java.util.ArrayList) AdapterUtils.createDeleteOperation(com.vmware.photon.controller.model.adapters.util.AdapterUtils.createDeleteOperation) AdapterUtils.createPatchOperation(com.vmware.photon.controller.model.adapters.util.AdapterUtils.createPatchOperation) AdapterUtils.createPostOperation(com.vmware.photon.controller.model.adapters.util.AdapterUtils.createPostOperation) Operation(com.vmware.xenon.common.Operation) TagsUtil.newTagState(com.vmware.photon.controller.model.adapters.util.TagsUtil.newTagState) TagState(com.vmware.photon.controller.model.resources.TagService.TagState) HashSet(java.util.HashSet)

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