Search in sources :

Example 1 with Instance

use of com.amazonaws.services.ec2.model.Instance in project camel by apache.

the class EC2ComponentSpringTest method createAndRunInstances.

@Test
public void createAndRunInstances() {
    Exchange exchange = template.request("direct:createAndRun", new Processor() {

        public void process(Exchange exchange) throws Exception {
            exchange.getIn().setHeader(EC2Constants.OPERATION, EC2Operations.createAndRunInstances);
            exchange.getIn().setHeader(EC2Constants.IMAGE_ID, "test-1");
            exchange.getIn().setHeader(EC2Constants.INSTANCE_TYPE, InstanceType.T2Micro);
            exchange.getIn().setHeader(EC2Constants.INSTANCE_MIN_COUNT, 1);
            exchange.getIn().setHeader(EC2Constants.INSTANCE_MAX_COUNT, 1);
        }
    });
    RunInstancesResult resultGet = (RunInstancesResult) exchange.getOut().getBody();
    assertEquals(resultGet.getReservation().getInstances().get(0).getImageId(), "test-1");
    assertEquals(resultGet.getReservation().getInstances().get(0).getInstanceType(), InstanceType.T2Micro.toString());
    assertEquals(resultGet.getReservation().getInstances().get(0).getInstanceId(), "instance-1");
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) RunInstancesResult(com.amazonaws.services.ec2.model.RunInstancesResult) Test(org.junit.Test)

Example 2 with Instance

use of com.amazonaws.services.ec2.model.Instance in project camel by apache.

the class EC2ComponentSpringTest method ec2DescribeSpecificInstancesTest.

@Test
public void ec2DescribeSpecificInstancesTest() throws Exception {
    Exchange exchange = template.request("direct:describe", new Processor() {

        @Override
        public void process(Exchange exchange) throws Exception {
            Collection l = new ArrayList();
            l.add("instance-1");
            exchange.getIn().setHeader(EC2Constants.INSTANCES_IDS, l);
        }
    });
    DescribeInstancesResult resultGet = (DescribeInstancesResult) exchange.getOut().getBody();
    assertEquals(resultGet.getReservations().size(), 1);
    assertEquals(resultGet.getReservations().get(0).getInstances().size(), 1);
}
Also used : Exchange(org.apache.camel.Exchange) DescribeInstancesResult(com.amazonaws.services.ec2.model.DescribeInstancesResult) Processor(org.apache.camel.Processor) ArrayList(java.util.ArrayList) Collection(java.util.Collection) Test(org.junit.Test)

Example 3 with Instance

use of com.amazonaws.services.ec2.model.Instance in project camel by apache.

the class EC2ProducerTest method ec2CreateAndRunTest.

@Test
public void ec2CreateAndRunTest() throws Exception {
    mock.expectedMessageCount(1);
    Exchange exchange = template.request("direct:createAndRun", new Processor() {

        @Override
        public void process(Exchange exchange) throws Exception {
            exchange.getIn().setHeader(EC2Constants.OPERATION, EC2Operations.createAndRunInstances);
            exchange.getIn().setHeader(EC2Constants.IMAGE_ID, "test-1");
            exchange.getIn().setHeader(EC2Constants.INSTANCE_TYPE, InstanceType.T2Micro);
            exchange.getIn().setHeader(EC2Constants.INSTANCE_MIN_COUNT, 1);
            exchange.getIn().setHeader(EC2Constants.INSTANCE_MAX_COUNT, 1);
        }
    });
    assertMockEndpointsSatisfied();
    RunInstancesResult resultGet = (RunInstancesResult) exchange.getIn().getBody();
    assertEquals(resultGet.getReservation().getInstances().get(0).getImageId(), "test-1");
    assertEquals(resultGet.getReservation().getInstances().get(0).getInstanceType(), InstanceType.T2Micro.toString());
    assertEquals(resultGet.getReservation().getInstances().get(0).getInstanceId(), "instance-1");
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) RunInstancesResult(com.amazonaws.services.ec2.model.RunInstancesResult) Test(org.junit.Test)

Example 4 with Instance

use of com.amazonaws.services.ec2.model.Instance in project camel by apache.

the class EC2ProducerTest method ec2CreateAndRunTestWithKeyPair.

@Test
public void ec2CreateAndRunTestWithKeyPair() throws Exception {
    mock.expectedMessageCount(1);
    Exchange exchange = template.request("direct:createAndRun", new Processor() {

        @Override
        public void process(Exchange exchange) throws Exception {
            exchange.getIn().setHeader(EC2Constants.OPERATION, EC2Operations.createAndRunInstances);
            exchange.getIn().setHeader(EC2Constants.IMAGE_ID, "test-1");
            exchange.getIn().setHeader(EC2Constants.INSTANCE_TYPE, InstanceType.T2Micro);
            exchange.getIn().setHeader(EC2Constants.INSTANCE_MIN_COUNT, 1);
            exchange.getIn().setHeader(EC2Constants.INSTANCE_MAX_COUNT, 1);
            exchange.getIn().setHeader(EC2Constants.INSTANCES_KEY_PAIR, "keypair-1");
        }
    });
    assertMockEndpointsSatisfied();
    RunInstancesResult resultGet = (RunInstancesResult) exchange.getIn().getBody();
    assertEquals(resultGet.getReservation().getInstances().get(0).getImageId(), "test-1");
    assertEquals(resultGet.getReservation().getInstances().get(0).getInstanceType(), InstanceType.T2Micro.toString());
    assertEquals(resultGet.getReservation().getInstances().get(0).getInstanceId(), "instance-1");
    assertEquals(resultGet.getReservation().getInstances().get(0).getSecurityGroups().size(), 2);
    assertEquals(resultGet.getReservation().getInstances().get(0).getSecurityGroups().get(0).getGroupId(), "id-3");
    assertEquals(resultGet.getReservation().getInstances().get(0).getSecurityGroups().get(1).getGroupId(), "id-4");
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) RunInstancesResult(com.amazonaws.services.ec2.model.RunInstancesResult) Test(org.junit.Test)

Example 5 with Instance

use of com.amazonaws.services.ec2.model.Instance in project camel by apache.

the class EC2ProducerTest method ec2CreateAndRunTestWithSecurityGroups.

@Test
public void ec2CreateAndRunTestWithSecurityGroups() throws Exception {
    mock.expectedMessageCount(1);
    Exchange exchange = template.request("direct:createAndRun", new Processor() {

        @Override
        public void process(Exchange exchange) throws Exception {
            exchange.getIn().setHeader(EC2Constants.OPERATION, EC2Operations.createAndRunInstances);
            exchange.getIn().setHeader(EC2Constants.IMAGE_ID, "test-1");
            exchange.getIn().setHeader(EC2Constants.INSTANCE_TYPE, InstanceType.T2Micro);
            exchange.getIn().setHeader(EC2Constants.INSTANCE_MIN_COUNT, 1);
            exchange.getIn().setHeader(EC2Constants.INSTANCE_MAX_COUNT, 1);
            Collection<String> secGroups = new ArrayList<String>();
            secGroups.add("secgroup-1");
            secGroups.add("secgroup-2");
            exchange.getIn().setHeader(EC2Constants.INSTANCE_SECURITY_GROUPS, secGroups);
        }
    });
    assertMockEndpointsSatisfied();
    RunInstancesResult resultGet = (RunInstancesResult) exchange.getIn().getBody();
    assertEquals(resultGet.getReservation().getInstances().get(0).getImageId(), "test-1");
    assertEquals(resultGet.getReservation().getInstances().get(0).getInstanceType(), InstanceType.T2Micro.toString());
    assertEquals(resultGet.getReservation().getInstances().get(0).getInstanceId(), "instance-1");
    assertEquals(resultGet.getReservation().getInstances().get(0).getSecurityGroups().size(), 2);
    assertEquals(resultGet.getReservation().getInstances().get(0).getSecurityGroups().get(0).getGroupId(), "id-1");
    assertEquals(resultGet.getReservation().getInstances().get(0).getSecurityGroups().get(1).getGroupId(), "id-2");
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) RunInstancesResult(com.amazonaws.services.ec2.model.RunInstancesResult) Collection(java.util.Collection) Test(org.junit.Test)

Aggregations

Instance (com.amazonaws.services.ec2.model.Instance)33 AmazonEC2 (com.amazonaws.services.ec2.AmazonEC2)20 Reservation (com.amazonaws.services.ec2.model.Reservation)15 DescribeInstancesResult (com.amazonaws.services.ec2.model.DescribeInstancesResult)12 RunInstancesResult (com.amazonaws.services.ec2.model.RunInstancesResult)11 Test (org.junit.Test)10 AmazonEC2Client (com.amazonaws.services.ec2.AmazonEC2Client)7 DescribeInstancesRequest (com.amazonaws.services.ec2.model.DescribeInstancesRequest)7 Filter (com.amazonaws.services.ec2.model.Filter)7 Tag (com.amazonaws.services.ec2.model.Tag)7 AWSClient (com.netflix.simianarmy.client.aws.AWSClient)7 Exchange (org.apache.camel.Exchange)7 Processor (org.apache.camel.Processor)7 AmazonServiceException (com.amazonaws.AmazonServiceException)6 ArrayList (java.util.ArrayList)6 LinkedList (java.util.LinkedList)6 AWSCredentials (com.amazonaws.auth.AWSCredentials)5 PropertiesCredentials (com.amazonaws.auth.PropertiesCredentials)5 AutoScalingInstanceDetails (com.amazonaws.services.autoscaling.model.AutoScalingInstanceDetails)5 RunInstancesRequest (com.amazonaws.services.ec2.model.RunInstancesRequest)5