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-8843 Camel-AWS EC2: Add DescribeInstancesStatus operation to available set
Date Mon, 08 Jun 2015 15:48:47 GMT
Repository: camel
Updated Branches:
  refs/heads/master 0c2e5df10 -> 43b79533d


CAMEL-8843 Camel-AWS EC2: Add DescribeInstancesStatus operation to available set


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

Branch: refs/heads/master
Commit: 43b79533d96129919aadef2cca00db3987700e3a
Parents: 0c2e5df
Author: Andrea Cosentino <ancosen@gmail.com>
Authored: Mon Jun 8 11:18:19 2015 +0200
Committer: Andrea Cosentino <ancosen@gmail.com>
Committed: Mon Jun 8 17:48:05 2015 +0200

----------------------------------------------------------------------
 .../camel/component/aws/ec2/EC2Operations.java  |  3 +-
 .../camel/component/aws/ec2/EC2Producer.java    | 22 ++++++++++
 .../component/aws/ec2/AmazonEC2ClientMock.java  | 33 +++++++++++++++
 .../aws/ec2/EC2ComponentSpringTest.java         | 21 ++++++++++
 .../component/aws/ec2/EC2OperationsTest.java    |  4 +-
 .../component/aws/ec2/EC2ProducerTest.java      | 44 ++++++++++++++++++++
 .../aws/ec2/EC2ComponentSpringTest-context.xml  |  4 ++
 7 files changed, 129 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/43b79533/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 ef3fb2a..8a25692 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
@@ -22,5 +22,6 @@ public enum EC2Operations {
     startInstances,
     stopInstances,
     terminateInstances,
-    describeInstances
+    describeInstances,
+    describeInstancesStatus
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/43b79533/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 1a0f913..e2edacd 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
@@ -20,6 +20,8 @@ import java.util.Collection;
 
 import com.amazonaws.AmazonServiceException;
 import com.amazonaws.services.ec2.AmazonEC2Client;
+import com.amazonaws.services.ec2.model.DescribeInstanceStatusRequest;
+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;
@@ -70,6 +72,9 @@ public class EC2Producer extends DefaultProducer {
         case describeInstances:
             describeInstances(getEndpoint().getEc2Client(), exchange);
             break;
+        case describeInstancesStatus:
+            describeInstancesStatus(getEndpoint().getEc2Client(), exchange);
+            break;
         default:
             throw new IllegalArgumentException("Unsupported operation");
         }
@@ -230,4 +235,21 @@ public class EC2Producer extends DefaultProducer {
         }
         exchange.getIn().setBody(result);        
     }
+    
+    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;
+        }
+        exchange.getIn().setBody(result);        
+    }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/camel/blob/43b79533/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 ec65ad0..a5bf479 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
@@ -22,6 +22,8 @@ import java.util.Collection;
 import com.amazonaws.AmazonServiceException;
 import com.amazonaws.auth.BasicAWSCredentials;
 import com.amazonaws.services.ec2.AmazonEC2Client;
+import com.amazonaws.services.ec2.model.DescribeInstanceStatusRequest;
+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.GroupIdentifier;
@@ -29,6 +31,7 @@ import com.amazonaws.services.ec2.model.Instance;
 import com.amazonaws.services.ec2.model.InstanceState;
 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.Reservation;
 import com.amazonaws.services.ec2.model.RunInstancesRequest;
@@ -193,4 +196,34 @@ public class AmazonEC2ClientMock extends AmazonEC2Client {
         }
         return result;
     }
+    
+    @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;
+    }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/camel/blob/43b79533/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 2754c58..c9fe401 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
@@ -21,6 +21,7 @@ import java.util.Arrays;
 import java.util.Collection;
 import java.util.List;
 
+import com.amazonaws.services.ec2.model.DescribeInstanceStatusResult;
 import com.amazonaws.services.ec2.model.DescribeInstancesResult;
 import com.amazonaws.services.ec2.model.InstanceStateName;
 import com.amazonaws.services.ec2.model.InstanceType;
@@ -147,6 +148,26 @@ public class EC2ComponentSpringTest extends CamelSpringTestSupport {
         assertEquals(resultGet.getReservations().get(0).getInstances().size(), 1);
     }
     
+    @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.getIn().getBody();
+        assertEquals(resultGet.getInstanceStatuses().size(), 1);
+        assertEquals(resultGet.getInstanceStatuses().get(0).getInstanceState().getName(),
InstanceStateName.Running.toString());
+    }
+    
     @Override
     protected AbstractApplicationContext createApplicationContext() {
         return new ClassPathXmlApplicationContext(

http://git-wip-us.apache.org/repos/asf/camel/blob/43b79533/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 ce18e1f..920b84b 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(5, EC2Operations.values().length);
+        assertEquals(6, EC2Operations.values().length);
     }
     
     @Test
@@ -34,6 +34,7 @@ public class EC2OperationsTest {
         assertEquals(EC2Operations.stopInstances, EC2Operations.valueOf("stopInstances"));
         assertEquals(EC2Operations.terminateInstances, EC2Operations.valueOf("terminateInstances"));
         assertEquals(EC2Operations.describeInstances, EC2Operations.valueOf("describeInstances"));
+        assertEquals(EC2Operations.describeInstancesStatus, EC2Operations.valueOf("describeInstancesStatus"));
     }
     
     @Test
@@ -43,5 +44,6 @@ public class EC2OperationsTest {
         assertEquals(EC2Operations.stopInstances.toString(), "stopInstances");
         assertEquals(EC2Operations.terminateInstances.toString(), "terminateInstances");
         assertEquals(EC2Operations.describeInstances.toString(), "describeInstances");
+        assertEquals(EC2Operations.describeInstancesStatus.toString(), "describeInstancesStatus");
     }
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/43b79533/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 794a80d..32c724b 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
@@ -19,7 +19,9 @@ package org.apache.camel.component.aws.ec2;
 import java.util.ArrayList;
 import java.util.Collection;
 
+import com.amazonaws.services.ec2.model.DescribeInstanceStatusResult;
 import com.amazonaws.services.ec2.model.DescribeInstancesResult;
+import com.amazonaws.services.ec2.model.InstanceState;
 import com.amazonaws.services.ec2.model.InstanceStateName;
 import com.amazonaws.services.ec2.model.InstanceType;
 import com.amazonaws.services.ec2.model.RunInstancesResult;
@@ -217,6 +219,45 @@ public class EC2ProducerTest extends CamelTestSupport {
         assertEquals(resultGet.getReservations().get(0).getInstances().size(), 1);
     }
     
+    @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);
+    }
+    
+    @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());
+    }
+    
     @Override
     protected JndiRegistry createRegistry() throws Exception {
         JndiRegistry registry = super.createRegistry();
@@ -248,6 +289,9 @@ public class EC2ProducerTest extends CamelTestSupport {
                 from("direct:describe")
                     .to("aws-ec2://test?amazonEc2Client=#amazonEc2Client&operation=describeInstances")
                     .to("mock:result");
+                from("direct:describeStatus")
+                    .to("aws-ec2://test?amazonEc2Client=#amazonEc2Client&operation=describeInstancesStatus")
+                    .to("mock:result");
             }
         };
     }

http://git-wip-us.apache.org/repos/asf/camel/blob/43b79533/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 5791f88..6600925 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
@@ -41,6 +41,10 @@
             <from uri="direct:describe"/>
             <to uri="aws-ec2://Test?amazonEc2Client=#amazonEc2Client&amp;operation=describeInstances"/>
         </route>
+        <route>
+            <from uri="direct:describeStatus"/>
+            <to uri="aws-ec2://Test?amazonEc2Client=#amazonEc2Client&amp;operation=describeInstancesStatus"/>
+        </route>
     </camelContext>
 
     <bean id="amazonEc2Client" class="org.apache.camel.component.aws.ec2.AmazonEC2ClientMock"/>


Mime
View raw message