Example usage for com.amazonaws.services.ec2.model DescribeTagsRequest withFilters

List of usage examples for com.amazonaws.services.ec2.model DescribeTagsRequest withFilters

Introduction

In this page you can find the example usage for com.amazonaws.services.ec2.model DescribeTagsRequest withFilters.

Prototype


public DescribeTagsRequest withFilters(java.util.Collection<Filter> filters) 

Source Link

Document

The filters.

Usage

From source file:org.cloudifysource.esc.driver.provisioning.privateEc2.PrivateEC2CloudifyDriver.java

License:Open Source License

private String createNewName(final TagResourceType resourceType, final String prefix)
        throws CloudProvisioningException {
    String newName = null;/*from w ww .  java 2  s  . c  om*/
    int attempts = 0;
    boolean foundFreeName = false;

    while (attempts < MAX_SERVERS_LIMIT) {
        // counter = (counter + 1) % MAX_SERVERS_LIMIT;
        ++attempts;

        switch (resourceType) {
        case INSTANCE:
            newName = prefix + counter.incrementAndGet();
            break;
        case VOLUME:
            newName = prefix + volumeCounter.incrementAndGet();
            break;
        default:
            // not possible
            throw new CloudProvisioningException("ResourceType not supported");
        }

        // verifying this server name is not already used
        final DescribeTagsRequest tagRequest = new DescribeTagsRequest();
        tagRequest.withFilters(new Filter("resource-type", Arrays.asList(resourceType.getValue())));
        tagRequest.withFilters(new Filter("value", Arrays.asList(newName)));
        final DescribeTagsResult describeTags = ec2.describeTags(tagRequest);
        final List<TagDescription> tags = describeTags.getTags();
        if (tags == null || tags.isEmpty()) {
            foundFreeName = true;
            break;
        }
    }

    if (!foundFreeName) {
        throw new CloudProvisioningException(
                "Number of servers has exceeded allowed server limit (" + MAX_SERVERS_LIMIT + ")");
    }
    return newName;
}