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 2017/09/01 11:45:19 UTC

[3/9] camel git commit: CAMEL-11736 - Camel-AWS: Use regional client instead of define region for single operation - AWS DDB

CAMEL-11736 - Camel-AWS: Use regional client instead of define region for single operation - AWS DDB


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

Branch: refs/heads/master
Commit: 4bc17ccf7fca929f57cc301d4c49fe57e8644344
Parents: 4dc5457
Author: Andrea Cosentino <an...@gmail.com>
Authored: Fri Sep 1 11:48:49 2017 +0200
Committer: Andrea Cosentino <an...@gmail.com>
Committed: Fri Sep 1 11:52:04 2017 +0200

----------------------------------------------------------------------
 .../src/main/docs/aws-ddb-component.adoc         |  9 +++++----
 .../component/aws/ddb/DdbConfiguration.java      | 19 ++++++++++++++++---
 .../camel/component/aws/ddb/DdbEndpoint.java     | 15 +++++++++++----
 3 files changed, 32 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/4bc17ccf/components/camel-aws/src/main/docs/aws-ddb-component.adoc
----------------------------------------------------------------------
diff --git a/components/camel-aws/src/main/docs/aws-ddb-component.adoc b/components/camel-aws/src/main/docs/aws-ddb-component.adoc
index a8a6b8b..24b14d9 100644
--- a/components/camel-aws/src/main/docs/aws-ddb-component.adoc
+++ b/components/camel-aws/src/main/docs/aws-ddb-component.adoc
@@ -46,21 +46,22 @@ with the following path and query parameters:
 | **tableName** | *Required* The name of the table currently worked with. |  | String
 |=======================================================================
 
-#### Query Parameters (13 parameters):
+#### Query Parameters (14 parameters):
 
 [width="100%",cols="2,5,^1,2",options="header"]
 |=======================================================================
 | Name | Description | Default | Type
 | **accessKey** (producer) | Amazon AWS Access Key |  | String
 | **amazonDDBClient** (producer) | To use the AmazonDynamoDB as the client |  | AmazonDynamoDB
-| **amazonDdbEndpoint** (producer) | The region with which the AWS-DDB client wants to work with. |  | String
+| **amazonDdbEndpoint** (producer) | The endpoint with which the AWS-DDB client wants to work with. |  | String
 | **consistentRead** (producer) | Determines whether or not strong consistency should be enforced when data is read. | false | boolean
 | **keyAttributeName** (producer) | Attribute name when creating table |  | String
 | **keyAttributeType** (producer) | Attribute type when creating table |  | String
 | **operation** (producer) | What operation to perform | PutItem | DdbOperations
-| **proxyHost** (producer) | To define a proxy host when instantiating the SQS client |  | String
-| **proxyPort** (producer) | To define a proxy port when instantiating the SQS client |  | Integer
+| **proxyHost** (producer) | To define a proxy host when instantiating the DDB client |  | String
+| **proxyPort** (producer) | To define a proxy port when instantiating the DDB client |  | Integer
 | **readCapacity** (producer) | The provisioned throughput to reserve for reading resources from your table |  | Long
+| **region** (producer) | The region in which DDB client needs to work |  | String
 | **secretKey** (producer) | Amazon AWS Secret Key |  | String
 | **writeCapacity** (producer) | The provisioned throughput to reserved for writing resources to your table |  | Long
 | **synchronous** (advanced) | Sets whether synchronous processing should be strictly used or Camel is allowed to use asynchronous processing (if supported). | false | boolean

http://git-wip-us.apache.org/repos/asf/camel/blob/4bc17ccf/components/camel-aws/src/main/java/org/apache/camel/component/aws/ddb/DdbConfiguration.java
----------------------------------------------------------------------
diff --git a/components/camel-aws/src/main/java/org/apache/camel/component/aws/ddb/DdbConfiguration.java b/components/camel-aws/src/main/java/org/apache/camel/component/aws/ddb/DdbConfiguration.java
index e8060c8..f95fc7a 100644
--- a/components/camel-aws/src/main/java/org/apache/camel/component/aws/ddb/DdbConfiguration.java
+++ b/components/camel-aws/src/main/java/org/apache/camel/component/aws/ddb/DdbConfiguration.java
@@ -52,9 +52,11 @@ public class DdbConfiguration {
     private String proxyHost;
     @UriParam
     private Integer proxyPort;
+    @UriParam
+    private String region;
 
     /**
-     * The region with which the AWS-DDB client wants to work with.
+     * The endpoint with which the AWS-DDB client wants to work with.
      */
     public void setAmazonDdbEndpoint(String amazonDdbEndpoint) {
         this.amazonDdbEndpoint = amazonDdbEndpoint;
@@ -175,7 +177,7 @@ public class DdbConfiguration {
     }
     
     /**
-     * To define a proxy host when instantiating the SQS client
+     * To define a proxy host when instantiating the DDB client
      */
     public String getProxyHost() {
         return proxyHost;
@@ -186,7 +188,7 @@ public class DdbConfiguration {
     }
 
     /**
-     * To define a proxy port when instantiating the SQS client
+     * To define a proxy port when instantiating the DDB client
      */
     public Integer getProxyPort() {
         return proxyPort;
@@ -195,4 +197,15 @@ public class DdbConfiguration {
     public void setProxyPort(Integer proxyPort) {
         this.proxyPort = proxyPort;
     }
+
+    /**
+     * The region in which DDB client needs to work
+     */
+    public String getRegion() {
+        return region;
+    }
+
+    public void setRegion(String region) {
+        this.region = region;
+    }
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/4bc17ccf/components/camel-aws/src/main/java/org/apache/camel/component/aws/ddb/DdbEndpoint.java
----------------------------------------------------------------------
diff --git a/components/camel-aws/src/main/java/org/apache/camel/component/aws/ddb/DdbEndpoint.java b/components/camel-aws/src/main/java/org/apache/camel/component/aws/ddb/DdbEndpoint.java
index 7c201dd..306aa06 100644
--- a/components/camel-aws/src/main/java/org/apache/camel/component/aws/ddb/DdbEndpoint.java
+++ b/components/camel-aws/src/main/java/org/apache/camel/component/aws/ddb/DdbEndpoint.java
@@ -22,6 +22,7 @@ import com.amazonaws.auth.AWSCredentials;
 import com.amazonaws.auth.AWSCredentialsProvider;
 import com.amazonaws.auth.AWSStaticCredentialsProvider;
 import com.amazonaws.auth.BasicAWSCredentials;
+import com.amazonaws.client.builder.AwsClientBuilder.EndpointConfiguration;
 import com.amazonaws.services.dynamodbv2.AmazonDynamoDB;
 import com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient;
 import com.amazonaws.services.dynamodbv2.AmazonDynamoDBClientBuilder;
@@ -139,6 +140,7 @@ public class DdbEndpoint extends ScheduledPollEndpoint {
     AmazonDynamoDB createDdbClient() {
         AmazonDynamoDB client = null;
         ClientConfiguration clientConfiguration = null;
+        AmazonDynamoDBClientBuilder clientBuilder = null;
         boolean isClientConfigFound = false;
         if (ObjectHelper.isNotEmpty(configuration.getProxyHost()) && ObjectHelper.isNotEmpty(configuration.getProxyPort())) {
             clientConfiguration = new ClientConfiguration();
@@ -150,17 +152,22 @@ public class DdbEndpoint extends ScheduledPollEndpoint {
             AWSCredentials credentials = new BasicAWSCredentials(configuration.getAccessKey(), configuration.getSecretKey());
             AWSCredentialsProvider credentialsProvider = new AWSStaticCredentialsProvider(credentials);
             if (isClientConfigFound) {
-                client = AmazonDynamoDBClientBuilder.standard().withClientConfiguration(clientConfiguration).withCredentials(credentialsProvider).build();
+                clientBuilder = AmazonDynamoDBClientBuilder.standard().withClientConfiguration(clientConfiguration).withCredentials(credentialsProvider);
             } else {
-                client = AmazonDynamoDBClientBuilder.standard().withCredentials(credentialsProvider).build();
+                clientBuilder = AmazonDynamoDBClientBuilder.standard().withCredentials(credentialsProvider);
             }
         } else {
             if (isClientConfigFound) {
-                client = AmazonDynamoDBClientBuilder.standard().build();
+                clientBuilder = AmazonDynamoDBClientBuilder.standard();
             } else {
-                client = AmazonDynamoDBClientBuilder.standard().withClientConfiguration(clientConfiguration).build();
+                clientBuilder = AmazonDynamoDBClientBuilder.standard().withClientConfiguration(clientConfiguration);
             }
         }
+        if (ObjectHelper.isNotEmpty(configuration.getAmazonDdbEndpoint()) && ObjectHelper.isNotEmpty(configuration.getRegion())) {
+            EndpointConfiguration endpointConfiguration = new EndpointConfiguration(configuration.getAmazonDdbEndpoint(), configuration.getRegion());
+            clientBuilder = clientBuilder.withEndpointConfiguration(endpointConfiguration);
+        }
+        client = clientBuilder.build();
         return client;
     }