You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ac...@apache.org on 2020/04/20 11:05:36 UTC

[camel] 22/24: CAMEL-14868 - Camel-AWS2-*: Where possible, give the possiblity to the end user to pass an AWS Request pojo as body, aws2-lambda fixed CS and regen

This is an automated email from the ASF dual-hosted git repository.

acosentino pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git

commit a82b2e4f7d158a5d016429f15328742ce8d7970a
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Mon Apr 20 12:59:21 2020 +0200

    CAMEL-14868 - Camel-AWS2-*: Where possible, give the possiblity to the end user to pass an AWS Request pojo as body, aws2-lambda fixed CS and regen
---
 .../component/aws2/lambda/Lambda2Producer.java     | 202 ++++++++++-----------
 1 file changed, 101 insertions(+), 101 deletions(-)

diff --git a/components/camel-aws2-lambda/src/main/java/org/apache/camel/component/aws2/lambda/Lambda2Producer.java b/components/camel-aws2-lambda/src/main/java/org/apache/camel/component/aws2/lambda/Lambda2Producer.java
index a0ba594..866b9ba 100644
--- a/components/camel-aws2-lambda/src/main/java/org/apache/camel/component/aws2/lambda/Lambda2Producer.java
+++ b/components/camel-aws2-lambda/src/main/java/org/apache/camel/component/aws2/lambda/Lambda2Producer.java
@@ -278,130 +278,130 @@ public class Lambda2Producer extends DefaultProducer {
                 Message message = getMessageForResponse(exchange);
                 message.setBody(result);
             }
-            } else {
-                CreateFunctionResponse result;
+        } else {
+            CreateFunctionResponse result;
 
-                try {
-                    CreateFunctionRequest.Builder request = CreateFunctionRequest.builder().functionName(getEndpoint().getFunction());
+            try {
+                CreateFunctionRequest.Builder request = CreateFunctionRequest.builder().functionName(getEndpoint().getFunction());
 
-                    FunctionCode.Builder functionCode = FunctionCode.builder();
-                    if (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(Lambda2Constants.S3_BUCKET))) {
-                        String s3Bucket = exchange.getIn().getHeader(Lambda2Constants.S3_BUCKET, String.class);
-                        functionCode.s3Bucket(s3Bucket);
-                    }
+                FunctionCode.Builder functionCode = FunctionCode.builder();
+                if (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(Lambda2Constants.S3_BUCKET))) {
+                    String s3Bucket = exchange.getIn().getHeader(Lambda2Constants.S3_BUCKET, String.class);
+                    functionCode.s3Bucket(s3Bucket);
+                }
 
-                    if (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(Lambda2Constants.S3_KEY))) {
-                        String s3Key = exchange.getIn().getHeader(Lambda2Constants.S3_KEY, String.class);
-                        functionCode.s3Key(s3Key);
-                    }
+                if (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(Lambda2Constants.S3_KEY))) {
+                    String s3Key = exchange.getIn().getHeader(Lambda2Constants.S3_KEY, String.class);
+                    functionCode.s3Key(s3Key);
+                }
 
-                    if (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(Lambda2Constants.S3_OBJECT_VERSION))) {
-                        String s3ObjectVersion = exchange.getIn().getHeader(Lambda2Constants.S3_OBJECT_VERSION, String.class);
-                        functionCode.s3ObjectVersion(s3ObjectVersion);
-                    }
+                if (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(Lambda2Constants.S3_OBJECT_VERSION))) {
+                    String s3ObjectVersion = exchange.getIn().getHeader(Lambda2Constants.S3_OBJECT_VERSION, String.class);
+                    functionCode.s3ObjectVersion(s3ObjectVersion);
+                }
 
-                    if (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(Lambda2Constants.ZIP_FILE))) {
-                        String zipFile = exchange.getIn().getHeader(Lambda2Constants.ZIP_FILE, String.class);
-                        File fileLocalPath = new File(zipFile);
-                        try (FileInputStream inputStream = new FileInputStream(fileLocalPath)) {
-                            functionCode.zipFile(SdkBytes.fromInputStream(inputStream));
-                        }
-                    }
-                    if (ObjectHelper.isNotEmpty(exchange.getIn().getBody())) {
-                        functionCode.zipFile(SdkBytes.fromByteBuffer(exchange.getIn().getBody(ByteBuffer.class)));
+                if (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(Lambda2Constants.ZIP_FILE))) {
+                    String zipFile = exchange.getIn().getHeader(Lambda2Constants.ZIP_FILE, String.class);
+                    File fileLocalPath = new File(zipFile);
+                    try (FileInputStream inputStream = new FileInputStream(fileLocalPath)) {
+                        functionCode.zipFile(SdkBytes.fromInputStream(inputStream));
                     }
+                }
+                if (ObjectHelper.isNotEmpty(exchange.getIn().getBody())) {
+                    functionCode.zipFile(SdkBytes.fromByteBuffer(exchange.getIn().getBody(ByteBuffer.class)));
+                }
 
-                    if (ObjectHelper.isNotEmpty(exchange.getIn().getBody()) || (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(Lambda2Constants.S3_BUCKET))
-                                                                                && ObjectHelper.isNotEmpty(exchange.getIn().getHeader(Lambda2Constants.S3_KEY)))) {
-                        request.code(functionCode.build());
-                    } else {
-                        throw new IllegalArgumentException("At least S3 bucket/S3 key or zip file must be specified");
-                    }
+                if (ObjectHelper.isNotEmpty(exchange.getIn().getBody()) || (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(Lambda2Constants.S3_BUCKET))
+                                                                            && ObjectHelper.isNotEmpty(exchange.getIn().getHeader(Lambda2Constants.S3_KEY)))) {
+                    request.code(functionCode.build());
+                } else {
+                    throw new IllegalArgumentException("At least S3 bucket/S3 key or zip file must be specified");
+                }
 
-                    if (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(Lambda2Constants.ROLE))) {
-                        request.role(exchange.getIn().getHeader(Lambda2Constants.ROLE, String.class));
-                    } else {
-                        throw new IllegalArgumentException("Role must be specified");
-                    }
+                if (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(Lambda2Constants.ROLE))) {
+                    request.role(exchange.getIn().getHeader(Lambda2Constants.ROLE, String.class));
+                } else {
+                    throw new IllegalArgumentException("Role must be specified");
+                }
 
-                    if (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(Lambda2Constants.RUNTIME))) {
-                        request.runtime(exchange.getIn().getHeader(Lambda2Constants.RUNTIME, String.class));
-                    } else {
-                        throw new IllegalArgumentException("Runtime must be specified");
-                    }
+                if (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(Lambda2Constants.RUNTIME))) {
+                    request.runtime(exchange.getIn().getHeader(Lambda2Constants.RUNTIME, String.class));
+                } else {
+                    throw new IllegalArgumentException("Runtime must be specified");
+                }
 
-                    if (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(Lambda2Constants.HANDLER))) {
-                        request.handler(exchange.getIn().getHeader(Lambda2Constants.HANDLER, String.class));
-                    } else {
-                        throw new IllegalArgumentException("Handler must be specified");
-                    }
+                if (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(Lambda2Constants.HANDLER))) {
+                    request.handler(exchange.getIn().getHeader(Lambda2Constants.HANDLER, String.class));
+                } else {
+                    throw new IllegalArgumentException("Handler must be specified");
+                }
 
-                    if (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(Lambda2Constants.DESCRIPTION))) {
-                        String description = exchange.getIn().getHeader(Lambda2Constants.DESCRIPTION, String.class);
-                        request.description(description);
-                    }
+                if (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(Lambda2Constants.DESCRIPTION))) {
+                    String description = exchange.getIn().getHeader(Lambda2Constants.DESCRIPTION, String.class);
+                    request.description(description);
+                }
 
-                    if (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(Lambda2Constants.TARGET_ARN))) {
-                        String targetArn = exchange.getIn().getHeader(Lambda2Constants.TARGET_ARN, String.class);
-                        request.deadLetterConfig(DeadLetterConfig.builder().targetArn(targetArn).build());
-                    }
+                if (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(Lambda2Constants.TARGET_ARN))) {
+                    String targetArn = exchange.getIn().getHeader(Lambda2Constants.TARGET_ARN, String.class);
+                    request.deadLetterConfig(DeadLetterConfig.builder().targetArn(targetArn).build());
+                }
 
-                    if (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(Lambda2Constants.MEMORY_SIZE))) {
-                        Integer memorySize = exchange.getIn().getHeader(Lambda2Constants.MEMORY_SIZE, Integer.class);
-                        request.memorySize(memorySize);
-                    }
+                if (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(Lambda2Constants.MEMORY_SIZE))) {
+                    Integer memorySize = exchange.getIn().getHeader(Lambda2Constants.MEMORY_SIZE, Integer.class);
+                    request.memorySize(memorySize);
+                }
 
-                    if (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(Lambda2Constants.KMS_KEY_ARN))) {
-                        String kmsKeyARN = exchange.getIn().getHeader(Lambda2Constants.KMS_KEY_ARN, String.class);
-                        request.kmsKeyArn(kmsKeyARN);
-                    }
-                    if (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(Lambda2Constants.PUBLISH))) {
-                        Boolean publish = exchange.getIn().getHeader(Lambda2Constants.PUBLISH, Boolean.class);
-                        request.publish(publish);
-                    }
+                if (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(Lambda2Constants.KMS_KEY_ARN))) {
+                    String kmsKeyARN = exchange.getIn().getHeader(Lambda2Constants.KMS_KEY_ARN, String.class);
+                    request.kmsKeyArn(kmsKeyARN);
+                }
+                if (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(Lambda2Constants.PUBLISH))) {
+                    Boolean publish = exchange.getIn().getHeader(Lambda2Constants.PUBLISH, Boolean.class);
+                    request.publish(publish);
+                }
 
-                    if (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(Lambda2Constants.TIMEOUT))) {
-                        Integer timeout = exchange.getIn().getHeader(Lambda2Constants.TIMEOUT, Integer.class);
-                        request.timeout(timeout);
-                    }
+                if (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(Lambda2Constants.TIMEOUT))) {
+                    Integer timeout = exchange.getIn().getHeader(Lambda2Constants.TIMEOUT, Integer.class);
+                    request.timeout(timeout);
+                }
 
-                    if (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(Lambda2Constants.TRACING_CONFIG))) {
-                        String tracingConfigMode = exchange.getIn().getHeader(Lambda2Constants.TRACING_CONFIG, String.class);
-                        request.tracingConfig(TracingConfig.builder().mode(tracingConfigMode).build());
-                    }
+                if (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(Lambda2Constants.TRACING_CONFIG))) {
+                    String tracingConfigMode = exchange.getIn().getHeader(Lambda2Constants.TRACING_CONFIG, String.class);
+                    request.tracingConfig(TracingConfig.builder().mode(tracingConfigMode).build());
+                }
 
-                    Map<String, String> environmentVariables = CastUtils.cast(exchange.getIn().getHeader(Lambda2Constants.ENVIRONMENT_VARIABLES, Map.class));
-                    if (environmentVariables != null) {
-                        request.environment(Environment.builder().variables(environmentVariables).build());
-                    }
+                Map<String, String> environmentVariables = CastUtils.cast(exchange.getIn().getHeader(Lambda2Constants.ENVIRONMENT_VARIABLES, Map.class));
+                if (environmentVariables != null) {
+                    request.environment(Environment.builder().variables(environmentVariables).build());
+                }
 
-                    Map<String, String> tags = CastUtils.cast(exchange.getIn().getHeader(Lambda2Constants.TAGS, Map.class));
-                    if (tags != null) {
-                        request.tags(tags);
-                    }
+                Map<String, String> tags = CastUtils.cast(exchange.getIn().getHeader(Lambda2Constants.TAGS, Map.class));
+                if (tags != null) {
+                    request.tags(tags);
+                }
 
-                    List<String> securityGroupIds = CastUtils.cast(exchange.getIn().getHeader(Lambda2Constants.SECURITY_GROUP_IDS, (Class<List<String>>)(Object)List.class));
-                    List<String> subnetIds = CastUtils.cast(exchange.getIn().getHeader(Lambda2Constants.SUBNET_IDS, (Class<List<String>>)(Object)List.class));
-                    if (securityGroupIds != null || subnetIds != null) {
-                        VpcConfig.Builder vpcConfig = VpcConfig.builder();
-                        if (securityGroupIds != null) {
-                            vpcConfig.securityGroupIds(securityGroupIds);
-                        }
-                        if (subnetIds != null) {
-                            vpcConfig.subnetIds(subnetIds);
-                        }
-                        request.vpcConfig(vpcConfig.build());
+                List<String> securityGroupIds = CastUtils.cast(exchange.getIn().getHeader(Lambda2Constants.SECURITY_GROUP_IDS, (Class<List<String>>)(Object)List.class));
+                List<String> subnetIds = CastUtils.cast(exchange.getIn().getHeader(Lambda2Constants.SUBNET_IDS, (Class<List<String>>)(Object)List.class));
+                if (securityGroupIds != null || subnetIds != null) {
+                    VpcConfig.Builder vpcConfig = VpcConfig.builder();
+                    if (securityGroupIds != null) {
+                        vpcConfig.securityGroupIds(securityGroupIds);
                     }
-                    result = lambdaClient.createFunction(request.build());
-
-                } catch (AwsServiceException ase) {
-                    LOG.trace("createFunction command returned the error code {}", ase.awsErrorDetails().errorCode());
-                    throw ase;
+                    if (subnetIds != null) {
+                        vpcConfig.subnetIds(subnetIds);
+                    }
+                    request.vpcConfig(vpcConfig.build());
                 }
+                result = lambdaClient.createFunction(request.build());
 
-                Message message = getMessageForResponse(exchange);
-                message.setBody(result);
+            } catch (AwsServiceException ase) {
+                LOG.trace("createFunction command returned the error code {}", ase.awsErrorDetails().errorCode());
+                throw ase;
             }
+
+            Message message = getMessageForResponse(exchange);
+            message.setBody(result);
+        }
     }
 
     private void updateFunction(LambdaClient lambdaClient, Exchange exchange) throws Exception {