camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From acosent...@apache.org
Subject [2/2] camel git commit: CAMEL-8850 Camel-AWS EC2: Add rebootInstances operation
Date Tue, 09 Jun 2015 15:13:54 GMT
CAMEL-8850 Camel-AWS EC2: Add rebootInstances operation


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

Branch: refs/heads/master
Commit: dc6f78aacf68738ab77565e296083cdea9b07b57
Parents: 054815f
Author: Andrea Cosentino <ancosen@gmail.com>
Authored: Tue Jun 9 14:24:19 2015 +0200
Committer: Andrea Cosentino <ancosen@gmail.com>
Committed: Tue Jun 9 17:11:42 2015 +0200

----------------------------------------------------------------------
 .../camel/component/aws/ec2/EC2Operations.java  |  3 ++-
 .../camel/component/aws/ec2/EC2Producer.java    | 22 ++++++++++++++++++++
 .../component/aws/ec2/AmazonEC2ClientMock.java  |  6 ++++++
 .../aws/ec2/EC2ComponentSpringTest.java         | 15 +++++++++++++
 .../component/aws/ec2/EC2OperationsTest.java    |  4 +++-
 .../component/aws/ec2/EC2ProducerTest.java      | 20 ++++++++++++++++++
 .../aws/ec2/EC2ComponentSpringTest-context.xml  |  4 ++++
 7 files changed, 72 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/dc6f78aa/components/camel-aws/src/main/java/org/apache/camel/component/aws/ec2/EC2Operations.java
----------------------------------------------------------------------
diff --git a/components/camel-aws/src/main/java/org/apache/camel/component/aws/ec2/EC2Operations.java
b/components/camel-aws/src/main/java/org/apache/camel/component/aws/ec2/EC2Operations.java
index 8a25692..e602f7a 100644
--- a/components/camel-aws/src/main/java/org/apache/camel/component/aws/ec2/EC2Operations.java
+++ b/components/camel-aws/src/main/java/org/apache/camel/component/aws/ec2/EC2Operations.java
@@ -23,5 +23,6 @@ public enum EC2Operations {
     stopInstances,
     terminateInstances,
     describeInstances,
-    describeInstancesStatus
+    describeInstancesStatus,
+    rebootInstances
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/dc6f78aa/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 e2edacd..0169d53 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
@@ -25,6 +25,7 @@ import com.amazonaws.services.ec2.model.DescribeInstanceStatusResult;
 import com.amazonaws.services.ec2.model.DescribeInstancesRequest;
 import com.amazonaws.services.ec2.model.DescribeInstancesResult;
 import com.amazonaws.services.ec2.model.InstanceType;
+import com.amazonaws.services.ec2.model.RebootInstancesRequest;
 import com.amazonaws.services.ec2.model.RunInstancesRequest;
 import com.amazonaws.services.ec2.model.RunInstancesResult;
 import com.amazonaws.services.ec2.model.StartInstancesRequest;
@@ -33,6 +34,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.RebootInstanceRequest;
 import com.amazonaws.services.opsworks.model.StartInstanceRequest;
 
 import org.apache.camel.Endpoint;
@@ -75,6 +77,9 @@ public class EC2Producer extends DefaultProducer {
         case describeInstancesStatus:
             describeInstancesStatus(getEndpoint().getEc2Client(), exchange);
             break;
+        case rebootInstances:
+            rebootInstances(getEndpoint().getEc2Client(), exchange);
+            break;            
         default:
             throw new IllegalArgumentException("Unsupported operation");
         }
@@ -252,4 +257,21 @@ public class EC2Producer extends DefaultProducer {
         }
         exchange.getIn().setBody(result);        
     }
+    
+    private void rebootInstances(AmazonEC2Client ec2Client, Exchange exchange) {
+        Collection instanceIds;
+        RebootInstancesRequest request = new RebootInstancesRequest();
+        if (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(EC2Constants.INSTANCES_IDS)))
{
+            instanceIds = exchange.getIn().getHeader(EC2Constants.INSTANCES_IDS, Collection.class);
+            request.withInstanceIds(instanceIds);
+        } else {
+            throw new IllegalArgumentException("Instances Ids must be specified");
+        }
+        try {
+            ec2Client.rebootInstances(request);
+        } catch (AmazonServiceException ase) {
+            LOG.trace("Describe Instances Status command returned the error code {}", ase.getErrorCode());
+            throw ase;
+        }
+    }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/camel/blob/dc6f78aa/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 a5bf479..60c87f9 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
@@ -33,6 +33,7 @@ import com.amazonaws.services.ec2.model.InstanceStateChange;
 import com.amazonaws.services.ec2.model.InstanceStateName;
 import com.amazonaws.services.ec2.model.InstanceStatus;
 import com.amazonaws.services.ec2.model.InstanceType;
+import com.amazonaws.services.ec2.model.RebootInstancesRequest;
 import com.amazonaws.services.ec2.model.Reservation;
 import com.amazonaws.services.ec2.model.RunInstancesRequest;
 import com.amazonaws.services.ec2.model.RunInstancesResult;
@@ -226,4 +227,9 @@ public class AmazonEC2ClientMock extends AmazonEC2Client {
         result.setInstanceStatuses(instanceStatuses);
         return result;
     }
+
+    @Override
+    public void rebootInstances(RebootInstancesRequest rebootInstancesRequest) {
+        return;
+    }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/camel/blob/dc6f78aa/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 c9fe401..7ac631b 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
@@ -168,6 +168,21 @@ public class EC2ComponentSpringTest extends CamelSpringTestSupport {
         assertEquals(resultGet.getInstanceStatuses().get(0).getInstanceState().getName(),
InstanceStateName.Running.toString());
     }
     
+    @Test
+    public void ec2RebootInstancesTest() throws Exception {
+
+        Exchange exchange = template.request("direct:reboot", 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);   
+            }
+        });
+        
+    }
+    
     @Override
     protected AbstractApplicationContext createApplicationContext() {
         return new ClassPathXmlApplicationContext(

http://git-wip-us.apache.org/repos/asf/camel/blob/dc6f78aa/components/camel-aws/src/test/java/org/apache/camel/component/aws/ec2/EC2OperationsTest.java
----------------------------------------------------------------------
diff --git a/components/camel-aws/src/test/java/org/apache/camel/component/aws/ec2/EC2OperationsTest.java
b/components/camel-aws/src/test/java/org/apache/camel/component/aws/ec2/EC2OperationsTest.java
index 920b84b..7bb7de5 100644
--- a/components/camel-aws/src/test/java/org/apache/camel/component/aws/ec2/EC2OperationsTest.java
+++ b/components/camel-aws/src/test/java/org/apache/camel/component/aws/ec2/EC2OperationsTest.java
@@ -24,7 +24,7 @@ public class EC2OperationsTest {
 
     @Test
     public void supportedOperationCount() {
-        assertEquals(6, EC2Operations.values().length);
+        assertEquals(7, EC2Operations.values().length);
     }
     
     @Test
@@ -35,6 +35,7 @@ public class EC2OperationsTest {
         assertEquals(EC2Operations.terminateInstances, EC2Operations.valueOf("terminateInstances"));
         assertEquals(EC2Operations.describeInstances, EC2Operations.valueOf("describeInstances"));
         assertEquals(EC2Operations.describeInstancesStatus, EC2Operations.valueOf("describeInstancesStatus"));
+        assertEquals(EC2Operations.rebootInstances, EC2Operations.valueOf("rebootInstances"));
     }
     
     @Test
@@ -45,5 +46,6 @@ public class EC2OperationsTest {
         assertEquals(EC2Operations.terminateInstances.toString(), "terminateInstances");
         assertEquals(EC2Operations.describeInstances.toString(), "describeInstances");
         assertEquals(EC2Operations.describeInstancesStatus.toString(), "describeInstancesStatus");
+        assertEquals(EC2Operations.rebootInstances.toString(), "rebootInstances");
     }
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/dc6f78aa/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 32c724b..8157071 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
@@ -258,6 +258,23 @@ public class EC2ProducerTest extends CamelTestSupport {
         assertEquals(resultGet.getInstanceStatuses().get(0).getInstanceState().getName(),
InstanceStateName.Running.toString());
     }
     
+    @Test
+    public void ec2RebootInstancesTest() throws Exception {
+
+        mock.expectedMessageCount(1);
+        Exchange exchange = template.request("direct:reboot", 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();
+    }
+    
     @Override
     protected JndiRegistry createRegistry() throws Exception {
         JndiRegistry registry = super.createRegistry();
@@ -292,6 +309,9 @@ public class EC2ProducerTest extends CamelTestSupport {
                 from("direct:describeStatus")
                     .to("aws-ec2://test?amazonEc2Client=#amazonEc2Client&operation=describeInstancesStatus")
                     .to("mock:result");
+                from("direct:reboot")
+                    .to("aws-ec2://test?amazonEc2Client=#amazonEc2Client&operation=rebootInstances")
+                    .to("mock:result");
             }
         };
     }

http://git-wip-us.apache.org/repos/asf/camel/blob/dc6f78aa/components/camel-aws/src/test/resources/org/apache/camel/component/aws/ec2/EC2ComponentSpringTest-context.xml
----------------------------------------------------------------------
diff --git a/components/camel-aws/src/test/resources/org/apache/camel/component/aws/ec2/EC2ComponentSpringTest-context.xml
b/components/camel-aws/src/test/resources/org/apache/camel/component/aws/ec2/EC2ComponentSpringTest-context.xml
index 6600925..1282e3d 100644
--- a/components/camel-aws/src/test/resources/org/apache/camel/component/aws/ec2/EC2ComponentSpringTest-context.xml
+++ b/components/camel-aws/src/test/resources/org/apache/camel/component/aws/ec2/EC2ComponentSpringTest-context.xml
@@ -45,6 +45,10 @@
             <from uri="direct:describeStatus"/>
             <to uri="aws-ec2://Test?amazonEc2Client=#amazonEc2Client&amp;operation=describeInstancesStatus"/>
         </route>
+        <route>
+            <from uri="direct:reboot"/>
+            <to uri="aws-ec2://Test?amazonEc2Client=#amazonEc2Client&amp;operation=rebootInstances"/>
+        </route>
     </camelContext>
 
     <bean id="amazonEc2Client" class="org.apache.camel.component.aws.ec2.AmazonEC2ClientMock"/>


Mime
View raw message