Search in sources :

Example 1 with DescribeInstanceStatusRequest

use of com.amazonaws.services.ec2.model.DescribeInstanceStatusRequest 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);
}
Also used : DescribeInstanceStatusResult(com.amazonaws.services.ec2.model.DescribeInstanceStatusResult) Message(org.apache.camel.Message) DescribeInstanceStatusRequest(com.amazonaws.services.ec2.model.DescribeInstanceStatusRequest) AmazonServiceException(com.amazonaws.AmazonServiceException) Collection(java.util.Collection)

Example 2 with DescribeInstanceStatusRequest

use of com.amazonaws.services.ec2.model.DescribeInstanceStatusRequest 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;
}
Also used : DescribeInstanceStatusResult(com.amazonaws.services.ec2.model.DescribeInstanceStatusResult) InstanceState(com.amazonaws.services.ec2.model.InstanceState) InstanceStatus(com.amazonaws.services.ec2.model.InstanceStatus) ArrayList(java.util.ArrayList)

Aggregations

DescribeInstanceStatusResult (com.amazonaws.services.ec2.model.DescribeInstanceStatusResult)2 AmazonServiceException (com.amazonaws.AmazonServiceException)1 DescribeInstanceStatusRequest (com.amazonaws.services.ec2.model.DescribeInstanceStatusRequest)1 InstanceState (com.amazonaws.services.ec2.model.InstanceState)1 InstanceStatus (com.amazonaws.services.ec2.model.InstanceStatus)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Message (org.apache.camel.Message)1