use of com.amazonaws.services.ec2.model.DescribeInstanceStatusResult 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.model.DescribeInstanceStatusResult in project camel by apache.
the class EC2ComponentSpringTest method ec2DescribeStatusSpecificInstancesTest.
@Test
public void ec2DescribeStatusSpecificInstancesTest() throws Exception {
Exchange exchange = template.request("direct:describeStatus", 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);
}
});
assertMockEndpointsSatisfied();
DescribeInstanceStatusResult resultGet = (DescribeInstanceStatusResult) exchange.getOut().getBody();
assertEquals(resultGet.getInstanceStatuses().size(), 1);
assertEquals(resultGet.getInstanceStatuses().get(0).getInstanceState().getName(), InstanceStateName.Running.toString());
}
use of com.amazonaws.services.ec2.model.DescribeInstanceStatusResult in project camel by apache.
the class EC2ProducerTest method ec2DescribeInstancesStatusTest.
@Test
public void ec2DescribeInstancesStatusTest() throws Exception {
mock.expectedMessageCount(1);
Exchange exchange = template.request("direct:describeStatus", new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
}
});
assertMockEndpointsSatisfied();
DescribeInstanceStatusResult resultGet = (DescribeInstanceStatusResult) exchange.getIn().getBody();
assertEquals(resultGet.getInstanceStatuses().size(), 2);
}
use of com.amazonaws.services.ec2.model.DescribeInstanceStatusResult in project camel by apache.
the class EC2ProducerTest method ec2DescribeStatusSpecificInstancesTest.
@Test
public void ec2DescribeStatusSpecificInstancesTest() throws Exception {
mock.expectedMessageCount(1);
Exchange exchange = template.request("direct:describeStatus", 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);
}
});
assertMockEndpointsSatisfied();
DescribeInstanceStatusResult resultGet = (DescribeInstanceStatusResult) exchange.getIn().getBody();
assertEquals(resultGet.getInstanceStatuses().size(), 1);
assertEquals(resultGet.getInstanceStatuses().get(0).getInstanceState().getName(), InstanceStateName.Running.toString());
}
use of com.amazonaws.services.ec2.model.DescribeInstanceStatusResult in project camel by apache.
the class AmazonEC2ClientMock method describeInstanceStatus.
@Override
public DescribeInstanceStatusResult describeInstanceStatus(DescribeInstanceStatusRequest describeInstanceStatusRequest) {
DescribeInstanceStatusResult result = new DescribeInstanceStatusResult();
Collection<InstanceStatus> instanceStatuses = new ArrayList();
if (describeInstanceStatusRequest.getInstanceIds().isEmpty()) {
InstanceStatus status = new InstanceStatus();
status.setInstanceId("test-1");
status.setInstanceState(new InstanceState().withName(InstanceStateName.Running));
instanceStatuses.add(status);
status.setInstanceId("test-2");
status.setInstanceState(new InstanceState().withName(InstanceStateName.Stopped));
instanceStatuses.add(status);
} else {
if (describeInstanceStatusRequest.getInstanceIds().contains("test-1")) {
InstanceStatus status = new InstanceStatus();
status.setInstanceId("test-1");
status.setInstanceState(new InstanceState().withName(InstanceStateName.Running));
instanceStatuses.add(status);
}
if (describeInstanceStatusRequest.getInstanceIds().contains("test-2")) {
InstanceStatus status = new InstanceStatus();
status.setInstanceId("test-2");
status.setInstanceState(new InstanceState().withName(InstanceStateName.Stopped));
instanceStatuses.add(status);
}
}
result.setInstanceStatuses(instanceStatuses);
return result;
}
Aggregations