Search in sources :

Example 1 with DeleteTagsRequest

use of com.amazonaws.services.ec2.model.DeleteTagsRequest in project photon-model by vmware.

the class AWSUtils method unTagResources.

/**
 * Synchronous UnTagging of one or many AWS resources with the provided tags.
 */
public static void unTagResources(AmazonEC2AsyncClient client, Collection<Tag> tags, String... resourceIds) {
    if (isAwsClientMock()) {
        return;
    }
    DeleteTagsRequest req = new DeleteTagsRequest().withTags(tags).withResources(resourceIds);
    client.deleteTags(req);
}
Also used : DeleteTagsRequest(com.amazonaws.services.ec2.model.DeleteTagsRequest)

Example 2 with DeleteTagsRequest

use of com.amazonaws.services.ec2.model.DeleteTagsRequest in project camel by apache.

the class EC2Producer method deleteTags.

private void deleteTags(AmazonEC2Client ec2Client, Exchange exchange) {
    Collection instanceIds;
    Collection tags;
    DeleteTagsRequest request = new DeleteTagsRequest();
    if (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(EC2Constants.INSTANCES_IDS))) {
        instanceIds = exchange.getIn().getHeader(EC2Constants.INSTANCES_IDS, Collection.class);
        request.withResources(instanceIds);
    } else {
        throw new IllegalArgumentException("Instances Ids must be specified");
    }
    if (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(EC2Constants.INSTANCES_TAGS))) {
        tags = exchange.getIn().getHeader(EC2Constants.INSTANCES_TAGS, Collection.class);
        request.withTags(tags);
    } else {
        throw new IllegalArgumentException("Tags must be specified");
    }
    DeleteTagsResult result = new DeleteTagsResult();
    try {
        result = ec2Client.deleteTags(request);
    } catch (AmazonServiceException ase) {
        LOG.trace("Delete tags command returned the error code {}", ase.getErrorCode());
        throw ase;
    }
    LOG.trace("Delete tags [{}] on resources with Ids [{}] ", Arrays.toString(tags.toArray()), Arrays.toString(instanceIds.toArray()));
    Message message = getMessageForResponse(exchange);
    message.setBody(result);
}
Also used : Message(org.apache.camel.Message) AmazonServiceException(com.amazonaws.AmazonServiceException) Collection(java.util.Collection) DeleteTagsResult(com.amazonaws.services.ec2.model.DeleteTagsResult) DeleteTagsRequest(com.amazonaws.services.ec2.model.DeleteTagsRequest)

Aggregations

DeleteTagsRequest (com.amazonaws.services.ec2.model.DeleteTagsRequest)2 AmazonServiceException (com.amazonaws.AmazonServiceException)1 DeleteTagsResult (com.amazonaws.services.ec2.model.DeleteTagsResult)1 Collection (java.util.Collection)1 Message (org.apache.camel.Message)1