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