use of org.apache.camel.Message in project camel by apache.
the class EC2Producer method startInstances.
private void startInstances(AmazonEC2Client ec2Client, Exchange exchange) {
Collection instanceIds;
StartInstancesRequest request = new StartInstancesRequest();
if (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(EC2Constants.INSTANCES_IDS))) {
instanceIds = exchange.getIn().getHeader(EC2Constants.INSTANCES_IDS, Collection.class);
request.withInstanceIds(instanceIds);
} else {
throw new IllegalArgumentException("Instances Ids must be specified");
}
StartInstancesResult result;
try {
result = ec2Client.startInstances(request);
} catch (AmazonServiceException ase) {
LOG.trace("Start Instances command returned the error code {}", ase.getErrorCode());
throw ase;
}
LOG.trace("Starting instances with Ids [{}] ", Arrays.toString(instanceIds.toArray()));
Message message = getMessageForResponse(exchange);
message.setBody(result);
}
use of org.apache.camel.Message in project camel by apache.
the class EC2Producer method createTags.
private void createTags(AmazonEC2Client ec2Client, Exchange exchange) {
Collection instanceIds;
Collection tags;
CreateTagsRequest request = new CreateTagsRequest();
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");
}
CreateTagsResult result = new CreateTagsResult();
try {
result = ec2Client.createTags(request);
} catch (AmazonServiceException ase) {
LOG.trace("Create tags command returned the error code {}", ase.getErrorCode());
throw ase;
}
LOG.trace("Created tags [{}] on resources with Ids [{}] ", Arrays.toString(tags.toArray()), Arrays.toString(instanceIds.toArray()));
Message message = getMessageForResponse(exchange);
message.setBody(result);
}
use of org.apache.camel.Message in project camel by apache.
the class EC2Producer method describeInstancesStatus.
private void describeInstancesStatus(AmazonEC2Client ec2Client, Exchange exchange) {
Collection instanceIds;
DescribeInstanceStatusRequest request = new DescribeInstanceStatusRequest();
if (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(EC2Constants.INSTANCES_IDS))) {
instanceIds = exchange.getIn().getHeader(EC2Constants.INSTANCES_IDS, Collection.class);
request.withInstanceIds(instanceIds);
}
DescribeInstanceStatusResult result;
try {
result = ec2Client.describeInstanceStatus(request);
} catch (AmazonServiceException ase) {
LOG.trace("Describe Instances Status command returned the error code {}", ase.getErrorCode());
throw ase;
}
Message message = getMessageForResponse(exchange);
message.setBody(result);
}
use of org.apache.camel.Message in project camel by apache.
the class DescribeTableCommand method execute.
@Override
public void execute() {
DescribeTableResult result = ddbClient.describeTable(new DescribeTableRequest().withTableName(determineTableName()));
Message msg = getMessageForResponse(exchange);
msg.setHeader(DdbConstants.TABLE_NAME, result.getTable().getTableName());
msg.setHeader(DdbConstants.TABLE_STATUS, result.getTable().getTableStatus());
msg.setHeader(DdbConstants.CREATION_DATE, result.getTable().getCreationDateTime());
msg.setHeader(DdbConstants.ITEM_COUNT, result.getTable().getItemCount());
msg.setHeader(DdbConstants.KEY_SCHEMA, result.getTable().getKeySchema());
msg.setHeader(DdbConstants.READ_CAPACITY, result.getTable().getProvisionedThroughput().getReadCapacityUnits());
msg.setHeader(DdbConstants.WRITE_CAPACITY, result.getTable().getProvisionedThroughput().getWriteCapacityUnits());
msg.setHeader(DdbConstants.TABLE_SIZE, result.getTable().getTableSizeBytes());
}
use of org.apache.camel.Message in project camel by apache.
the class AwsExchangeUtil method getMessageForResponse.
public static Message getMessageForResponse(final Exchange exchange) {
if (exchange.getPattern().isOutCapable()) {
Message out = exchange.getOut();
out.copyFrom(exchange.getIn());
return out;
}
return exchange.getIn();
}
Aggregations