camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From acosent...@apache.org
Subject camel git commit: CAMEL-8840 Camel-AWS EC2: Add Security Groups support when creating and running instances
Date Sun, 07 Jun 2015 10:16:06 GMT
Repository: camel
Updated Branches:
  refs/heads/master 59b0a721d -> 39f04d446


CAMEL-8840 Camel-AWS EC2: Add Security Groups support when creating and running instances


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

Branch: refs/heads/master
Commit: 39f04d4463ef5b36dc55fc04153036a879b9fb63
Parents: 59b0a72
Author: Andrea Cosentino <ancosen@gmail.com>
Authored: Sun Jun 7 12:12:44 2015 +0200
Committer: Andrea Cosentino <ancosen@gmail.com>
Committed: Sun Jun 7 12:12:44 2015 +0200

----------------------------------------------------------------------
 .../camel/component/aws/ec2/EC2Constants.java   | 19 +++++++------
 .../camel/component/aws/ec2/EC2Producer.java    |  6 ++++
 .../component/aws/ec2/AmazonEC2ClientMock.java  | 13 +++++++++
 .../component/aws/ec2/EC2ProducerTest.java      | 30 ++++++++++++++++++++
 .../EC2ComponentIntegrationTest.java            | 17 +++++++++++
 5 files changed, 76 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/39f04d44/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 a929e44..611e513 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
@@ -22,13 +22,14 @@ package org.apache.camel.component.aws.ec2;
  */
 public interface EC2Constants {
 
-    String IMAGE_ID                = "CamelAwsEC2ImageId";
-    String INSTANCE_TYPE           = "CamelAwsEC2InstanceType";
-    String OPERATION               = "CamelAwsEC2Operation";
-    String INSTANCE_MIN_COUNT      = "CamelAwsEC2InstanceMinCount";
-    String INSTANCE_MAX_COUNT      = "CamelAwsEC2InstanceMaxCount";
-    String INSTANCE_MONITORING     = "CamelAwsEC2InstanceMonitoring";
-    String INSTANCE_KERNEL_ID      = "CamelAwsEC2InstanceKernelId";
-    String INSTANCE_EBS_OPTIMIZED  = "CamelAwsEC2InstanceEbsOptimized";
-    String INSTANCES_IDS           = "CamelAwsEC2InstancesIds";
+    String IMAGE_ID                 = "CamelAwsEC2ImageId";
+    String INSTANCE_TYPE            = "CamelAwsEC2InstanceType";
+    String OPERATION                = "CamelAwsEC2Operation";
+    String INSTANCE_MIN_COUNT       = "CamelAwsEC2InstanceMinCount";
+    String INSTANCE_MAX_COUNT       = "CamelAwsEC2InstanceMaxCount";
+    String INSTANCE_MONITORING      = "CamelAwsEC2InstanceMonitoring";
+    String INSTANCE_KERNEL_ID       = "CamelAwsEC2InstanceKernelId";
+    String INSTANCE_EBS_OPTIMIZED   = "CamelAwsEC2InstanceEbsOptimized";
+    String INSTANCE_SECURITY_GROUPS = "CamelAwsEC2InstanceSecurityGroups";
+    String INSTANCES_IDS            = "CamelAwsEC2InstancesIds";
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/39f04d44/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 3e9a0bc..1a0f913 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
@@ -31,6 +31,7 @@ import com.amazonaws.services.ec2.model.StopInstancesRequest;
 import com.amazonaws.services.ec2.model.StopInstancesResult;
 import com.amazonaws.services.ec2.model.TerminateInstancesRequest;
 import com.amazonaws.services.ec2.model.TerminateInstancesResult;
+import com.amazonaws.services.opsworks.model.StartInstanceRequest;
 
 import org.apache.camel.Endpoint;
 import org.apache.camel.Exchange;
@@ -104,6 +105,7 @@ public class EC2Producer extends DefaultProducer {
         boolean monitoring;
         String kernelId;
         boolean ebsOptimized;
+        Collection securityGroups;
         RunInstancesRequest request = new RunInstancesRequest();
         if (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(EC2Constants.IMAGE_ID))) {
             ami = exchange.getIn().getHeader(EC2Constants.IMAGE_ID, String.class);
@@ -141,6 +143,10 @@ public class EC2Producer extends DefaultProducer {
             ebsOptimized = exchange.getIn().getHeader(EC2Constants.INSTANCE_EBS_OPTIMIZED,
Boolean.class);
             request.withEbsOptimized(ebsOptimized);
         }
+        if (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(EC2Constants.INSTANCE_SECURITY_GROUPS)))
{
+            securityGroups = exchange.getIn().getHeader(EC2Constants.INSTANCE_SECURITY_GROUPS,
Collection.class);
+            request.withSecurityGroups(securityGroups);
+        }
         RunInstancesResult result;
         try {
             result = ec2Client.runInstances(request);

http://git-wip-us.apache.org/repos/asf/camel/blob/39f04d44/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 25c7e27..ec65ad0 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
@@ -24,6 +24,7 @@ import com.amazonaws.auth.BasicAWSCredentials;
 import com.amazonaws.services.ec2.AmazonEC2Client;
 import com.amazonaws.services.ec2.model.DescribeInstancesRequest;
 import com.amazonaws.services.ec2.model.DescribeInstancesResult;
+import com.amazonaws.services.ec2.model.GroupIdentifier;
 import com.amazonaws.services.ec2.model.Instance;
 import com.amazonaws.services.ec2.model.InstanceState;
 import com.amazonaws.services.ec2.model.InstanceStateChange;
@@ -58,6 +59,18 @@ 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);
+            }
             instances.add(ins);
             res.setInstances(instances);
             result.setReservation(res); 

http://git-wip-us.apache.org/repos/asf/camel/blob/39f04d44/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 97f2bb8..794a80d 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
@@ -65,6 +65,36 @@ public class EC2ProducerTest extends CamelTestSupport {
     }
     
     @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");
+    }
+    
+    @Test
     public void ec2CreateAndRunKoTest() throws Exception {
 
         mock.expectedMessageCount(0);

http://git-wip-us.apache.org/repos/asf/camel/blob/39f04d44/components/camel-aws/src/test/java/org/apache/camel/component/aws/ec2/integration/EC2ComponentIntegrationTest.java
----------------------------------------------------------------------
diff --git a/components/camel-aws/src/test/java/org/apache/camel/component/aws/ec2/integration/EC2ComponentIntegrationTest.java
b/components/camel-aws/src/test/java/org/apache/camel/component/aws/ec2/integration/EC2ComponentIntegrationTest.java
index 79feb55..56cf606 100644
--- a/components/camel-aws/src/test/java/org/apache/camel/component/aws/ec2/integration/EC2ComponentIntegrationTest.java
+++ b/components/camel-aws/src/test/java/org/apache/camel/component/aws/ec2/integration/EC2ComponentIntegrationTest.java
@@ -46,6 +46,23 @@ public class EC2ComponentIntegrationTest extends CamelTestSupport {
     }
     
     @Test
+    public void createAndRunInstancesWithSecurityGroupsTest() {
+        
+        template.send("direct:createAndRun", new Processor() {
+            public void process(Exchange exchange) throws Exception {
+                exchange.getIn().setHeader(EC2Constants.IMAGE_ID, "ami-fd65ba94");
+                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);
+            }
+        });
+    }
+    
+    @Test
     public void stopInstances() {
         
         template.send("direct:stop", new Processor() {


Mime
View raw message