com.amazonaws.services.ec2.model.TagDescription Java Examples

The following examples show how to use com.amazonaws.services.ec2.model.TagDescription. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ResourceTaggingManager.java    From pacbot with Apache License 2.0 6 votes vote down vote up
/**
 *
 * @param resourceId
 * @param clientMap
 * @return
 */
private String getEC2PacManTagValue(String resourceId, Map<String, Object> clientMap) {
    AmazonEC2 ec2Client = (AmazonEC2) clientMap.get("client");
    DescribeTagsRequest describeTagsRequest = new DescribeTagsRequest();
    Filter filter = new Filter("resource-id");
    filter.setValues(Arrays.asList(resourceId));
    describeTagsRequest.setFilters(Arrays.asList(filter));
    DescribeTagsResult describeTagsResult = ec2Client.describeTags(describeTagsRequest);
    List<TagDescription> descriptions = describeTagsResult.getTags();
    TagDescription tagDescription = null;
    Optional<TagDescription> optional = descriptions.stream()
            .filter(obj -> obj.getKey().equals(PacmanSdkConstants.PACMAN_AUTO_FIX_TAG_NAME)).findAny();
    if (optional.isPresent()) {
        tagDescription = optional.get();
    } else {
        return null;
    }
    return tagDescription.getValue();
}
 
Example #2
Source File: ResourceTaggingManager.java    From pacbot with Apache License 2.0 6 votes vote down vote up
/**
 * get the value of pacman tag from app elb
 * @param resourceId
 * @param clientMap
 * @return
 */
private String getAppElbPacManTagValue(String resourceId, Map<String, Object> clientMap) {

    try{
        AmazonElasticLoadBalancingClient client = (AmazonElasticLoadBalancingClient) clientMap.get(PacmanSdkConstants.CLIENT);
        com.amazonaws.services.elasticloadbalancingv2.model.DescribeTagsRequest describeTagsRequest =   new com.amazonaws.services.elasticloadbalancingv2.model.DescribeTagsRequest();
        describeTagsRequest.withResourceArns(resourceId);
        com.amazonaws.services.elasticloadbalancingv2.model.DescribeTagsResult describeTagsResult = client.describeTags(describeTagsRequest);
        List<com.amazonaws.services.elasticloadbalancingv2.model.TagDescription> descriptions = describeTagsResult.getTagDescriptions();
        com.amazonaws.services.elasticloadbalancingv2.model.Tag tag=null;
        Optional<com.amazonaws.services.elasticloadbalancingv2.model.Tag> optional=null;;
        if(descriptions!=null && descriptions.size()>0){
             optional = descriptions.get(0).getTags().stream()
            .filter(obj -> obj.getKey().equals(CommonUtils.getPropValue(PacmanSdkConstants.PACMAN_AUTO_FIX_TAG_NAME))).findAny();
        }
        if (optional.isPresent()) {
            tag = optional.get();
        } else {
            return null;
        }
        return tag.getValue();
    }catch (Exception e) {
        logger.error("error whiel getting pacman tag valye for " + resourceId,e);
        return null;
    }
}
 
Example #3
Source File: TaupageExpirationTimeProviderImpl.java    From fullstop with Apache License 2.0 6 votes vote down vote up
@Override
@Cacheable(cacheNames = "ami-expiration-time", cacheManager = "oneMinuteTTLCacheManager")
public ZonedDateTime getExpirationTime(String regionName, String imageOwner, String imageId) {
    // tags are only visible in the owning account of the image
    final AmazonEC2Client ec2 = clientProvider.getClient(AmazonEC2Client.class, imageOwner,
            Region.getRegion(Regions.fromName(regionName)));
    final DescribeTagsRequest tagsRequest = new DescribeTagsRequest().withFilters(
            new Filter("resource-id").withValues(imageId),
            new Filter("resource-type").withValues("image"),
            new Filter("key").withValues(TAG_KEY));
    return ec2.describeTags(tagsRequest).getTags().stream()
            .findFirst()
            .map(TagDescription::getValue)
            .map(value -> ZonedDateTime.parse(value, ISO_DATE_TIME))
            .orElse(null);
}
 
Example #4
Source File: TaupageExpirationTimeProviderImplTest.java    From fullstop with Apache License 2.0 6 votes vote down vote up
@Test
public void getExpirationTime() {
    final DescribeTagsResult response = new DescribeTagsResult()
            .withTags(new TagDescription()
                    .withResourceType("image")
                    .withResourceId(IMAGE_ID)
                    .withKey(TaupageExpirationTimeProviderImpl.TAG_KEY)
                    .withValue("2018-06-20T03:00:00+02:00"));

    when(mockEC2Client.describeTags(any(DescribeTagsRequest.class))).thenReturn(response);

    final ZonedDateTime result = expirationTimeProvider.getExpirationTime(REGION_NAME, IMAGE_OWNER, IMAGE_ID);
    assertThat(result).isEqualTo(ZonedDateTime.of(2018, 6, 20, 3, 0, 0, 0, ZoneOffset.ofHours(2)));

    verify(mockClientProvider).getClient(eq(AmazonEC2Client.class), eq(IMAGE_OWNER), eq(getRegion(fromName(REGION_NAME))));
    verify(mockEC2Client).describeTags(
            eq(new DescribeTagsRequest().withFilters(
                    new Filter("resource-id").withValues(IMAGE_ID),
                    new Filter("resource-type").withValues("image"),
                    new Filter("key").withValues(TaupageExpirationTimeProviderImpl.TAG_KEY))));
}
 
Example #5
Source File: AmazonEc2InstanceUserTagsFactoryBean.java    From spring-cloud-aws with Apache License 2.0 6 votes vote down vote up
@Override
protected Map<String, String> createInstance() throws Exception {
	LinkedHashMap<String, String> properties = new LinkedHashMap<>();
	DescribeTagsResult tags = this.amazonEc2
			.describeTags(
					new DescribeTagsRequest()
							.withFilters(
									new Filter("resource-id",
											Collections.singletonList(this.idProvider
													.getCurrentInstanceId())),
									new Filter("resource-type",
											Collections.singletonList("instance"))));
	for (TagDescription tag : tags.getTags()) {
		properties.put(tag.getKey(), tag.getValue());
	}
	return properties;
}
 
Example #6
Source File: Ec2NetworkTest.java    From aws-mock with MIT License 6 votes vote down vote up
/**
 * Test delete Tags.
 */
@Test(timeout = TIMEOUT_LEVEL1)
public final void describerTagsTest() {
    log.info("Describe Tags test");
    createTagsTest();
    
    List<TagDescription> tagsDesc = getTags();
    Assert.assertNotNull("tag Desc should not be null", tagsDesc);
    
    Collection<String> resources = new ArrayList<String>();
    Collection<Tag> tags = new ArrayList<Tag>();
    
    for(TagDescription tagDesc : tagsDesc)
    {
        Tag tag = new Tag();
        tag.setKey(tagDesc.getKey());
        tag.setValue(tagDesc.getValue());
        tags.add(tag);
        
        resources.add(tagDesc.getResourceId());
    }
    
    Assert.assertTrue("Tags should be created.", deleteTags(resources, tags));
}
 
Example #7
Source File: ResourceTaggingManagerTest.java    From pacbot with Apache License 2.0 5 votes vote down vote up
/**
 * Gets the tag descriptions.
 *
 */
private List<TagDescription> getTagDescriptions() {
	List<TagDescription> dists = Lists.newArrayList();
	TagDescription dist = new TagDescription();
	dist.setKey("key");
	dist.setResourceId("resourceId");
	dist.setResourceType("resourceType");
	dist.setResourceType("resourceType");
	dist.setValue("value");
	dists.add(dist);
	return dists;
}
 
Example #8
Source File: AmazonEc2InstanceUserTagsFactoryBeanTest.java    From spring-cloud-aws with Apache License 2.0 5 votes vote down vote up
@Test
void getObject_userTagDataAvailable_objectContainsAllAvailableKeys()
		throws Exception {
	// Arrange
	AmazonEC2 amazonEC2 = mock(AmazonEC2.class);

	InstanceIdProvider instanceIdProvider = mock(InstanceIdProvider.class);
	when(instanceIdProvider.getCurrentInstanceId()).thenReturn("1234567890");

	DescribeTagsRequest describeTagsRequest = new DescribeTagsRequest().withFilters(
			new Filter("resource-id", Collections.singletonList("1234567890")),
			new Filter("resource-type", Collections.singletonList("instance")));

	DescribeTagsResult describeTagsResult = new DescribeTagsResult().withTags(
			new TagDescription().withKey("keyA")
					.withResourceType(ResourceType.Instance).withValue("valueA"),
			new TagDescription().withKey("keyB")
					.withResourceType(ResourceType.Instance).withValue("valueB"));

	when(amazonEC2.describeTags(describeTagsRequest)).thenReturn(describeTagsResult);

	AmazonEc2InstanceUserTagsFactoryBean amazonEc2InstanceUserTagsFactoryBean = new AmazonEc2InstanceUserTagsFactoryBean(
			amazonEC2, instanceIdProvider);

	// Act
	amazonEc2InstanceUserTagsFactoryBean.afterPropertiesSet();
	Map<String, String> resultMap = amazonEc2InstanceUserTagsFactoryBean.getObject();

	// Assert
	assertThat(resultMap.get("keyA")).isEqualTo("valueA");
	assertThat(resultMap.get("keyB")).isEqualTo("valueB");
	assertThat(resultMap.containsKey("keyC")).isFalse();
}
 
Example #9
Source File: BaseTest.java    From aws-mock with MIT License 5 votes vote down vote up
/**
 * Describe Tags.
 * @return TagsDescription
 */
protected final List<TagDescription> getTags() {
    DescribeTagsResult result = amazonEC2Client.describeTags();
    List<TagDescription> tagsDesc = null;
    
    if (result != null) {
        
        tagsDesc = result.getTags();
    }

    return tagsDesc;
}