Search in sources :

Example 1 with DeleteTagsResult

use of com.amazonaws.services.ec2.model.DeleteTagsResult 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)

Example 2 with DeleteTagsResult

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

the class EC2ProducerTest method ec2DeleteTagsTest.

@Test
public void ec2DeleteTagsTest() throws Exception {
    mock.expectedMessageCount(1);
    Exchange exchange = template.request("direct:deleteTags", new Processor() {

        @Override
        public void process(Exchange exchange) throws Exception {
            Collection l = new ArrayList();
            l.add("test-1");
            exchange.getIn().setHeader(EC2Constants.INSTANCES_IDS, l);
            Collection tags = new ArrayList();
            tags.add("pacific");
            exchange.getIn().setHeader(EC2Constants.INSTANCES_TAGS, tags);
        }
    });
    assertMockEndpointsSatisfied();
    DeleteTagsResult resultGet = (DeleteTagsResult) exchange.getIn().getBody();
    assertNotNull(resultGet);
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) ArrayList(java.util.ArrayList) Collection(java.util.Collection) DeleteTagsResult(com.amazonaws.services.ec2.model.DeleteTagsResult) Test(org.junit.Test)

Aggregations

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