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;
}
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;
}
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);
}
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;
}
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);
}
Aggregations