camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From acosent...@apache.org
Subject [camel] 34/45: CAMEL-12884 - Camel-AWS Lambda: Add support for event source mapping, delete operation
Date Thu, 18 Oct 2018 16:02:58 GMT
This is an automated email from the ASF dual-hosted git repository.

acosentino pushed a commit to branch sandbox/camel-3.x
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 7c7fc0a9383c2ca7f94e9d8460272f085806bec5
Author: Andrea Cosentino <ancosen@gmail.com>
AuthorDate: Wed Oct 17 10:42:51 2018 +0200

    CAMEL-12884 - Camel-AWS Lambda: Add support for event source mapping, delete operation
---
 .../component/aws/lambda/LambdaConstants.java      |  1 +
 .../component/aws/lambda/LambdaOperations.java     |  3 +-
 .../camel/component/aws/lambda/LambdaProducer.java | 32 ++++++++++++++++++++++
 .../aws/lambda/AmazonLambdaClientMock.java         |  5 +++-
 .../aws/lambda/LambdaComponentSpringTest.java      | 15 ++++++++++
 .../component/aws/lambda/LambdaProducerTest.java   | 17 ++++++++++++
 .../lambda/LambdaComponentSpringTest-context.xml   |  5 ++++
 7 files changed, 76 insertions(+), 2 deletions(-)

diff --git a/components/camel-aws/src/main/java/org/apache/camel/component/aws/lambda/LambdaConstants.java
b/components/camel-aws/src/main/java/org/apache/camel/component/aws/lambda/LambdaConstants.java
index ce64f5d..e1a1259 100644
--- a/components/camel-aws/src/main/java/org/apache/camel/component/aws/lambda/LambdaConstants.java
+++ b/components/camel-aws/src/main/java/org/apache/camel/component/aws/lambda/LambdaConstants.java
@@ -45,4 +45,5 @@ public interface LambdaConstants {
     String SUBNET_IDS = "CamelAwsLambdaSubnetIds";
     String EVENT_SOURCE_ARN = "CamelAwsLambdaEventSourceArn";
     String EVENT_SOURCE_BATCH_SIZE = "CamelAwsLambdaEventSourceBatchSize";
+    String EVENT_SOURCE_UUID = "CamelAwsLambdaEventSourceUuid";
 }
\ No newline at end of file
diff --git a/components/camel-aws/src/main/java/org/apache/camel/component/aws/lambda/LambdaOperations.java
b/components/camel-aws/src/main/java/org/apache/camel/component/aws/lambda/LambdaOperations.java
index 23a9491..907c9bf 100644
--- a/components/camel-aws/src/main/java/org/apache/camel/component/aws/lambda/LambdaOperations.java
+++ b/components/camel-aws/src/main/java/org/apache/camel/component/aws/lambda/LambdaOperations.java
@@ -24,5 +24,6 @@ public enum LambdaOperations {
     deleteFunction,
     invokeFunction,
     updateFunction,
-    createEventSourceMapping
+    createEventSourceMapping,
+    deleteEventSourceMapping
 }
diff --git a/components/camel-aws/src/main/java/org/apache/camel/component/aws/lambda/LambdaProducer.java
b/components/camel-aws/src/main/java/org/apache/camel/component/aws/lambda/LambdaProducer.java
index 0396cc5..ac167a28 100644
--- a/components/camel-aws/src/main/java/org/apache/camel/component/aws/lambda/LambdaProducer.java
+++ b/components/camel-aws/src/main/java/org/apache/camel/component/aws/lambda/LambdaProducer.java
@@ -30,6 +30,8 @@ import com.amazonaws.services.lambda.model.CreateEventSourceMappingResult;
 import com.amazonaws.services.lambda.model.CreateFunctionRequest;
 import com.amazonaws.services.lambda.model.CreateFunctionResult;
 import com.amazonaws.services.lambda.model.DeadLetterConfig;
+import com.amazonaws.services.lambda.model.DeleteEventSourceMappingRequest;
+import com.amazonaws.services.lambda.model.DeleteEventSourceMappingResult;
 import com.amazonaws.services.lambda.model.DeleteFunctionRequest;
 import com.amazonaws.services.lambda.model.DeleteFunctionResult;
 import com.amazonaws.services.lambda.model.Environment;
@@ -90,6 +92,9 @@ public class LambdaProducer extends DefaultProducer {
         case createEventSourceMapping:
             createEventSourceMapping(getEndpoint().getAwsLambdaClient(), exchange);
             break;
+        case deleteEventSourceMapping:
+            deleteEventSourceMapping(getEndpoint().getAwsLambdaClient(), exchange);
+            break;
         default:
             throw new IllegalArgumentException("Unsupported operation");
         }
@@ -376,6 +381,33 @@ public class LambdaProducer extends DefaultProducer {
         message.setBody(result);
     }
     
+    private void deleteEventSourceMapping(AWSLambda lambdaClient, Exchange exchange) {
+        DeleteEventSourceMappingResult result;
+        try {
+            DeleteEventSourceMappingRequest request = new DeleteEventSourceMappingRequest();
+            if (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(LambdaConstants.EVENT_SOURCE_UUID)))
{
+                request.withUUID(exchange.getIn().getHeader(LambdaConstants.EVENT_SOURCE_UUID,
String.class));
+            } else {
+                throw new IllegalArgumentException("Event Source Arn must be specified");
+            }
+            if (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(LambdaConstants.SDK_CLIENT_EXECUTION_TIMEOUT)))
{
+                Integer timeout = exchange.getIn().getHeader(LambdaConstants.SDK_CLIENT_EXECUTION_TIMEOUT,
Integer.class);
+                request.withSdkClientExecutionTimeout(timeout);
+            }
+
+            if (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(LambdaConstants.SDK_REQUEST_TIMEOUT)))
{
+                Integer timeout = exchange.getIn().getHeader(LambdaConstants.SDK_REQUEST_TIMEOUT,
Integer.class);
+                request.withSdkRequestTimeout(timeout);
+            }
+            result = lambdaClient.deleteEventSourceMapping(request);
+        } catch (AmazonServiceException ase) {
+            LOG.trace("deleteEventSourceMapping command returned the error code {}", ase.getErrorCode());
+            throw ase;
+        }
+        Message message = getMessageForResponse(exchange);
+        message.setBody(result);
+    }
+    
     private LambdaOperations determineOperation(Exchange exchange) {
         LambdaOperations operation = exchange.getIn().getHeader(LambdaConstants.OPERATION,
LambdaOperations.class);
         if (operation == null) {
diff --git a/components/camel-aws/src/test/java/org/apache/camel/component/aws/lambda/AmazonLambdaClientMock.java
b/components/camel-aws/src/test/java/org/apache/camel/component/aws/lambda/AmazonLambdaClientMock.java
index 8e6ed76..8398068 100644
--- a/components/camel-aws/src/test/java/org/apache/camel/component/aws/lambda/AmazonLambdaClientMock.java
+++ b/components/camel-aws/src/test/java/org/apache/camel/component/aws/lambda/AmazonLambdaClientMock.java
@@ -157,7 +157,10 @@ public class AmazonLambdaClientMock extends AbstractAWSLambda {
 
     @Override
     public DeleteEventSourceMappingResult deleteEventSourceMapping(DeleteEventSourceMappingRequest
deleteEventSourceMappingRequest) {
-        throw new UnsupportedOperationException();
+        DeleteEventSourceMappingResult result = new DeleteEventSourceMappingResult();
+        result.setUUID("a1239494949382882383");
+        result.setState("Deleting");
+        return result;
     }
 
     @Override
diff --git a/components/camel-aws/src/test/java/org/apache/camel/component/aws/lambda/LambdaComponentSpringTest.java
b/components/camel-aws/src/test/java/org/apache/camel/component/aws/lambda/LambdaComponentSpringTest.java
index 2c9f9fa..fb3412e 100644
--- a/components/camel-aws/src/test/java/org/apache/camel/component/aws/lambda/LambdaComponentSpringTest.java
+++ b/components/camel-aws/src/test/java/org/apache/camel/component/aws/lambda/LambdaComponentSpringTest.java
@@ -20,6 +20,7 @@ import java.io.*;
 
 import com.amazonaws.services.lambda.model.CreateEventSourceMappingResult;
 import com.amazonaws.services.lambda.model.CreateFunctionResult;
+import com.amazonaws.services.lambda.model.DeleteEventSourceMappingResult;
 import com.amazonaws.services.lambda.model.DeleteFunctionResult;
 import com.amazonaws.services.lambda.model.GetFunctionResult;
 import com.amazonaws.services.lambda.model.ListFunctionsResult;
@@ -128,6 +129,20 @@ public class LambdaComponentSpringTest extends CamelSpringTestSupport
{
         CreateEventSourceMappingResult result = exchange.getOut().getBody(CreateEventSourceMappingResult.class);
         assertEquals(result.getFunctionArn(), "arn:aws:lambda:eu-central-1:643534317684:function:GetHelloWithName");
     }
+    
+    @Test
+    public void lambdaDeleteEventSourceMappingTest() throws Exception {
+        Exchange exchange = template.send("direct:deleteEventSourceMapping", ExchangePattern.InOut,
new Processor() {
+            @Override
+            public void process(Exchange exchange) throws Exception {
+                exchange.getIn().setHeader(LambdaConstants.EVENT_SOURCE_UUID, "a1239494949382882383");
+            }
+        });
+        assertMockEndpointsSatisfied();
+
+        DeleteEventSourceMappingResult result = exchange.getOut().getBody(DeleteEventSourceMappingResult.class);
+        assertTrue(result.getState().equalsIgnoreCase("Deleting"));
+    }
 
 
     @Override
diff --git a/components/camel-aws/src/test/java/org/apache/camel/component/aws/lambda/LambdaProducerTest.java
b/components/camel-aws/src/test/java/org/apache/camel/component/aws/lambda/LambdaProducerTest.java
index 32c9896..252a44d 100644
--- a/components/camel-aws/src/test/java/org/apache/camel/component/aws/lambda/LambdaProducerTest.java
+++ b/components/camel-aws/src/test/java/org/apache/camel/component/aws/lambda/LambdaProducerTest.java
@@ -21,6 +21,7 @@ import java.io.FileInputStream;
 
 import com.amazonaws.services.lambda.model.CreateEventSourceMappingResult;
 import com.amazonaws.services.lambda.model.CreateFunctionResult;
+import com.amazonaws.services.lambda.model.DeleteEventSourceMappingResult;
 import com.amazonaws.services.lambda.model.DeleteFunctionResult;
 import com.amazonaws.services.lambda.model.GetFunctionResult;
 import com.amazonaws.services.lambda.model.ListFunctionsResult;
@@ -168,6 +169,20 @@ public class LambdaProducerTest extends CamelTestSupport {
         CreateEventSourceMappingResult result = exchange.getOut().getBody(CreateEventSourceMappingResult.class);
         assertEquals(result.getFunctionArn(), "arn:aws:lambda:eu-central-1:643534317684:function:GetHelloWithName");
     }
+    
+    @Test
+    public void lambdaDeleteEventSourceMappingTest() throws Exception {
+        Exchange exchange = template.send("direct:deleteEventSourceMapping", ExchangePattern.InOut,
new Processor() {
+            @Override
+            public void process(Exchange exchange) throws Exception {
+                exchange.getIn().setHeader(LambdaConstants.EVENT_SOURCE_UUID, "a1239494949382882383");
+            }
+        });
+        assertMockEndpointsSatisfied();
+
+        DeleteEventSourceMappingResult result = exchange.getOut().getBody(DeleteEventSourceMappingResult.class);
+        assertTrue(result.getState().equalsIgnoreCase("Deleting"));
+    }
 
     @Override
     protected JndiRegistry createRegistry() throws Exception {
@@ -198,6 +213,8 @@ public class LambdaProducerTest extends CamelTestSupport {
                 from("direct:updateFunction").to("aws-lambda://GetHelloWithName?awsLambdaClient=#awsLambdaClient&operation=updateFunction").to("mock:result");
 
                 from("direct:createEventSourceMapping").to("aws-lambda://GetHelloWithName?awsLambdaClient=#awsLambdaClient&operation=createEventSourceMapping").to("mock:result");
+                
+                from("direct:deleteEventSourceMapping").to("aws-lambda://GetHelloWithName?awsLambdaClient=#awsLambdaClient&operation=deleteEventSourceMapping").to("mock:result");
             }
         };
     }
diff --git a/components/camel-aws/src/test/resources/org/apache/camel/component/aws/lambda/LambdaComponentSpringTest-context.xml
b/components/camel-aws/src/test/resources/org/apache/camel/component/aws/lambda/LambdaComponentSpringTest-context.xml
index c3211dd..1e7c83e 100644
--- a/components/camel-aws/src/test/resources/org/apache/camel/component/aws/lambda/LambdaComponentSpringTest-context.xml
+++ b/components/camel-aws/src/test/resources/org/apache/camel/component/aws/lambda/LambdaComponentSpringTest-context.xml
@@ -54,6 +54,11 @@
             <from uri="direct:createEventSourceMapping"/>
             <to uri="aws-lambda://GetHelloWithName?awsLambdaClient=#awsLambdaClient&amp;operation=createEventSourceMapping"/>
         </route>
+        
+        <route>
+            <from uri="direct:deleteEventSourceMapping"/>
+            <to uri="aws-lambda://GetHelloWithName?awsLambdaClient=#awsLambdaClient&amp;operation=deleteEventSourceMapping"/>
+        </route>
     </camelContext>
 
     <bean id="awsLambdaClient" class="org.apache.camel.component.aws.lambda.AmazonLambdaClientMock"/>


Mime
View raw message