use of com.amazonaws.services.ec2.AmazonEC2Client in project camel by apache.
the class EC2Producer method stopInstances.
private void stopInstances(AmazonEC2Client ec2Client, Exchange exchange) {
Collection instanceIds;
StopInstancesRequest request = new StopInstancesRequest();
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");
}
StopInstancesResult result;
try {
result = ec2Client.stopInstances(request);
} catch (AmazonServiceException ase) {
LOG.trace("Stop Instances command returned the error code {}", ase.getErrorCode());
throw ase;
}
LOG.trace("Stopping instances with Ids [{}] ", Arrays.toString(instanceIds.toArray()));
Message message = getMessageForResponse(exchange);
message.setBody(result);
}
use of com.amazonaws.services.ec2.AmazonEC2Client 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 com.amazonaws.services.ec2.AmazonEC2Client 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 com.amazonaws.services.ec2.AmazonEC2Client 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 com.amazonaws.services.ec2.AmazonEC2Client in project camel by apache.
the class EC2Endpoint method createEc2Client.
AmazonEC2Client createEc2Client() {
AmazonEC2Client client = null;
ClientConfiguration clientConfiguration = null;
boolean isClientConfigFound = false;
if (ObjectHelper.isNotEmpty(configuration.getProxyHost()) && ObjectHelper.isNotEmpty(configuration.getProxyPort())) {
clientConfiguration = new ClientConfiguration();
clientConfiguration.setProxyHost(configuration.getProxyHost());
clientConfiguration.setProxyPort(configuration.getProxyPort());
isClientConfigFound = true;
}
if (configuration.getAccessKey() != null && configuration.getSecretKey() != null) {
AWSCredentials credentials = new BasicAWSCredentials(configuration.getAccessKey(), configuration.getSecretKey());
if (isClientConfigFound) {
client = new AmazonEC2Client(credentials, clientConfiguration);
} else {
client = new AmazonEC2Client(credentials);
}
} else {
if (isClientConfigFound) {
client = new AmazonEC2Client();
} else {
client = new AmazonEC2Client(clientConfiguration);
}
}
return client;
}
Aggregations