camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From acosent...@apache.org
Subject [3/3] camel git commit: CAMEL-8882: Camel-AWS EC2: Add options to Run Instance command, add keyPair header
Date Thu, 18 Jun 2015 15:36:38 GMT
CAMEL-8882: Camel-AWS EC2: Add options to Run Instance command, add keyPair header


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/409a039e
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/409a039e
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/409a039e

Branch: refs/heads/master
Commit: 409a039e3cf886b4e2005f5d691367582aaaf5f3
Parents: fc38b2e
Author: Andrea Cosentino <ancosen@gmail.com>
Authored: Thu Jun 18 10:15:33 2015 +0200
Committer: Andrea Cosentino <ancosen@gmail.com>
Committed: Thu Jun 18 17:33:22 2015 +0200

----------------------------------------------------------------------
 .../camel/component/aws/ec2/EC2Constants.java   |  1 +
 .../camel/component/aws/ec2/EC2Producer.java    |  5 +++
 .../component/aws/ec2/AmazonEC2ClientMock.java  | 39 ++++++++++++++------
 .../aws/ec2/EC2ComponentSpringTest.java         | 24 ++++++++++++
 .../component/aws/ec2/EC2ProducerTest.java      | 27 ++++++++++++++
 5 files changed, 85 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/409a039e/components/camel-aws/src/main/java/org/apache/camel/component/aws/ec2/EC2Constants.java
----------------------------------------------------------------------
diff --git a/components/camel-aws/src/main/java/org/apache/camel/component/aws/ec2/EC2Constants.java
b/components/camel-aws/src/main/java/org/apache/camel/component/aws/ec2/EC2Constants.java
index 611e513..c0e95dc 100644
--- a/components/camel-aws/src/main/java/org/apache/camel/component/aws/ec2/EC2Constants.java
+++ b/components/camel-aws/src/main/java/org/apache/camel/component/aws/ec2/EC2Constants.java
@@ -32,4 +32,5 @@ public interface EC2Constants {
     String INSTANCE_EBS_OPTIMIZED   = "CamelAwsEC2InstanceEbsOptimized";
     String INSTANCE_SECURITY_GROUPS = "CamelAwsEC2InstanceSecurityGroups";
     String INSTANCES_IDS            = "CamelAwsEC2InstancesIds";
+    String INSTANCES_KEY_PAIR       = "CamelAwsEC2InstancesKeyPair";
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/409a039e/components/camel-aws/src/main/java/org/apache/camel/component/aws/ec2/EC2Producer.java
----------------------------------------------------------------------
diff --git a/components/camel-aws/src/main/java/org/apache/camel/component/aws/ec2/EC2Producer.java
b/components/camel-aws/src/main/java/org/apache/camel/component/aws/ec2/EC2Producer.java
index fd11c68..dff573d 100644
--- a/components/camel-aws/src/main/java/org/apache/camel/component/aws/ec2/EC2Producer.java
+++ b/components/camel-aws/src/main/java/org/apache/camel/component/aws/ec2/EC2Producer.java
@@ -124,6 +124,7 @@ public class EC2Producer extends DefaultProducer {
         String kernelId;
         boolean ebsOptimized;
         Collection securityGroups;
+        String keyName;
         RunInstancesRequest request = new RunInstancesRequest();
         if (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(EC2Constants.IMAGE_ID))) {
             ami = exchange.getIn().getHeader(EC2Constants.IMAGE_ID, String.class);
@@ -165,6 +166,10 @@ public class EC2Producer extends DefaultProducer {
             securityGroups = exchange.getIn().getHeader(EC2Constants.INSTANCE_SECURITY_GROUPS,
Collection.class);
             request.withSecurityGroups(securityGroups);
         }
+        if (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(EC2Constants.INSTANCES_KEY_PAIR)))
{
+            keyName = exchange.getIn().getHeader(EC2Constants.INSTANCES_KEY_PAIR, String.class);
+            request.withKeyName(keyName);
+        }
         RunInstancesResult result;
         try {
             result = ec2Client.runInstances(request);

http://git-wip-us.apache.org/repos/asf/camel/blob/409a039e/components/camel-aws/src/test/java/org/apache/camel/component/aws/ec2/AmazonEC2ClientMock.java
----------------------------------------------------------------------
diff --git a/components/camel-aws/src/test/java/org/apache/camel/component/aws/ec2/AmazonEC2ClientMock.java
b/components/camel-aws/src/test/java/org/apache/camel/component/aws/ec2/AmazonEC2ClientMock.java
index b714ebe..80572c1 100644
--- a/components/camel-aws/src/test/java/org/apache/camel/component/aws/ec2/AmazonEC2ClientMock.java
+++ b/components/camel-aws/src/test/java/org/apache/camel/component/aws/ec2/AmazonEC2ClientMock.java
@@ -52,6 +52,8 @@ import com.amazonaws.services.ec2.model.TerminateInstancesResult;
 import com.amazonaws.services.ec2.model.UnmonitorInstancesRequest;
 import com.amazonaws.services.ec2.model.UnmonitorInstancesResult;
 
+import org.apache.camel.util.ObjectHelper;
+
 public class AmazonEC2ClientMock extends AmazonEC2Client {
 
     public AmazonEC2ClientMock() {
@@ -71,17 +73,32 @@ public class AmazonEC2ClientMock extends AmazonEC2Client {
             ins.setImageId(runInstancesRequest.getImageId());
             ins.setInstanceType(runInstancesRequest.getInstanceType());
             ins.setInstanceId("instance-1");
-            if (runInstancesRequest.getSecurityGroups().contains("secgroup-1") &&
runInstancesRequest.getSecurityGroups().contains("secgroup-2")) {
-                GroupIdentifier id1 = new GroupIdentifier();
-                id1.setGroupId("id-1");
-                id1.setGroupName("secgroup-1");
-                GroupIdentifier id2 = new GroupIdentifier();
-                id2.setGroupId("id-2");
-                id2.setGroupName("secgroup-2");
-                Collection secGroups = new ArrayList<GroupIdentifier>();
-                secGroups.add(id1);
-                secGroups.add(id2);
-                ins.setSecurityGroups(secGroups);
+            if (ObjectHelper.isNotEmpty(runInstancesRequest.getSecurityGroups()) &&
ObjectHelper.isNotEmpty(runInstancesRequest.getSecurityGroups())) {
+                if (runInstancesRequest.getSecurityGroups().contains("secgroup-1") &&
runInstancesRequest.getSecurityGroups().contains("secgroup-2")) {
+                    GroupIdentifier id1 = new GroupIdentifier();
+                    id1.setGroupId("id-1");
+                    id1.setGroupName("secgroup-1");
+                    GroupIdentifier id2 = new GroupIdentifier();
+                    id2.setGroupId("id-2");
+                    id2.setGroupName("secgroup-2");
+                    Collection secGroups = new ArrayList<GroupIdentifier>();
+                    secGroups.add(id1);
+                    secGroups.add(id2);
+                    ins.setSecurityGroups(secGroups);
+                } else if (ObjectHelper.isNotEmpty(runInstancesRequest.getKeyName())) {
+                    if (ObjectHelper.isNotEmpty(runInstancesRequest.getKeyName().contains("keypair-1")))
{
+                        GroupIdentifier id1 = new GroupIdentifier();
+                        id1.setGroupId("id-3");
+                        id1.setGroupName("secgroup-3");
+                        GroupIdentifier id2 = new GroupIdentifier();
+                        id2.setGroupId("id-4");
+                        id2.setGroupName("secgroup-4");
+                        Collection secGroups = new ArrayList<GroupIdentifier>();
+                        secGroups.add(id1);
+                        secGroups.add(id2);
+                        ins.setSecurityGroups(secGroups);
+                    }
+                }
             }
             instances.add(ins);
             res.setInstances(instances);

http://git-wip-us.apache.org/repos/asf/camel/blob/409a039e/components/camel-aws/src/test/java/org/apache/camel/component/aws/ec2/EC2ComponentSpringTest.java
----------------------------------------------------------------------
diff --git a/components/camel-aws/src/test/java/org/apache/camel/component/aws/ec2/EC2ComponentSpringTest.java
b/components/camel-aws/src/test/java/org/apache/camel/component/aws/ec2/EC2ComponentSpringTest.java
index 5457a9c..849bf2d 100644
--- a/components/camel-aws/src/test/java/org/apache/camel/component/aws/ec2/EC2ComponentSpringTest.java
+++ b/components/camel-aws/src/test/java/org/apache/camel/component/aws/ec2/EC2ComponentSpringTest.java
@@ -71,6 +71,30 @@ public class EC2ComponentSpringTest extends CamelSpringTestSupport {
     }
     
     @Test
+    public void ec2CreateAndRunTestWithKeyPair() throws Exception {
+
+        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");
+            }
+        });
+        
+        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");
+    }
+    
+    @Test
     public void startInstances() {
         
         Exchange exchange = template.request("direct:start", new Processor() {

http://git-wip-us.apache.org/repos/asf/camel/blob/409a039e/components/camel-aws/src/test/java/org/apache/camel/component/aws/ec2/EC2ProducerTest.java
----------------------------------------------------------------------
diff --git a/components/camel-aws/src/test/java/org/apache/camel/component/aws/ec2/EC2ProducerTest.java
b/components/camel-aws/src/test/java/org/apache/camel/component/aws/ec2/EC2ProducerTest.java
index 4c48191..2e53781 100644
--- a/components/camel-aws/src/test/java/org/apache/camel/component/aws/ec2/EC2ProducerTest.java
+++ b/components/camel-aws/src/test/java/org/apache/camel/component/aws/ec2/EC2ProducerTest.java
@@ -99,6 +99,33 @@ public class EC2ProducerTest extends CamelTestSupport {
     }
     
     @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");
+    }
+    
+    @Test
     public void ec2CreateAndRunKoTest() throws Exception {
 
         mock.expectedMessageCount(0);


Mime
View raw message