Search in sources :

Example 1 with DescribeInstanceStatusResult

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

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());
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) DescribeInstanceStatusResult(com.amazonaws.services.ec2.model.DescribeInstanceStatusResult) ArrayList(java.util.ArrayList) Collection(java.util.Collection) Test(org.junit.Test)

Example 3 with DescribeInstanceStatusResult

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);
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) DescribeInstanceStatusResult(com.amazonaws.services.ec2.model.DescribeInstanceStatusResult) Test(org.junit.Test)

Example 4 with DescribeInstanceStatusResult

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());
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) DescribeInstanceStatusResult(com.amazonaws.services.ec2.model.DescribeInstanceStatusResult) ArrayList(java.util.ArrayList) Collection(java.util.Collection) Test(org.junit.Test)

Example 5 with DescribeInstanceStatusResult

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;
}
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)5 ArrayList (java.util.ArrayList)3 Collection (java.util.Collection)3 Exchange (org.apache.camel.Exchange)3 Processor (org.apache.camel.Processor)3 Test (org.junit.Test)3 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 Message (org.apache.camel.Message)1