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
The following commit(s) were added to refs/heads/master by this push: new 91f752d CAMEL-12171 - Camel-AWS DDB Stream: Add the ability to specify credentials and region at component level 91f752d is described below commit 91f752d19559697070b73cebd9db84354dc16108 Author: Andrea Cosentino <anco...@gmail.com> AuthorDate: Mon Jan 22 09:29:42 2018 +0100 CAMEL-12171 - Camel-AWS DDB Stream: Add the ability to specify credentials and region at component level --- .../src/main/docs/aws-ddbstream-component.adoc | 14 +- .../aws/ddbstream/DdbStreamComponent.java | 71 +++++++++- .../aws/ddbstream/DdbStreamConfiguration.java | 17 ++- .../DdbStreamComponentConfigurationTest.java | 28 ++++ .../DdbStreamComponentConfiguration.java | 149 +++++++++++++++++++++ 5 files changed, 272 insertions(+), 7 deletions(-) diff --git a/components/camel-aws/src/main/docs/aws-ddbstream-component.adoc b/components/camel-aws/src/main/docs/aws-ddbstream-component.adoc index dc2a2af..f1c3593 100644 --- a/components/camel-aws/src/main/docs/aws-ddbstream-component.adoc +++ b/components/camel-aws/src/main/docs/aws-ddbstream-component.adoc @@ -26,7 +26,19 @@ The stream needs to be created prior to it being used. + // component options: START -The AWS DynamoDB Streams component has no options. +The AWS DynamoDB Streams component supports 5 options which are listed below. + + + +[width="100%",cols="2,5,^1,2",options="header"] +|=== +| Name | Description | Default | Type +| *configuration* (advanced) | The AWS DDB stream default configuration | | DdbStreamConfiguration +| *accessKey* (consumer) | Amazon AWS Access Key | | String +| *secretKey* (consumer) | Amazon AWS Secret Key | | String +| *region* (consumer) | Amazon AWS Region | | String +| *resolveProperty Placeholders* (advanced) | Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders. | true | boolean +|=== // component options: END diff --git a/components/camel-aws/src/main/java/org/apache/camel/component/aws/ddbstream/DdbStreamComponent.java b/components/camel-aws/src/main/java/org/apache/camel/component/aws/ddbstream/DdbStreamComponent.java index c948e41..ca16663 100644 --- a/components/camel-aws/src/main/java/org/apache/camel/component/aws/ddbstream/DdbStreamComponent.java +++ b/components/camel-aws/src/main/java/org/apache/camel/component/aws/ddbstream/DdbStreamComponent.java @@ -21,11 +21,19 @@ import org.apache.camel.CamelContext; import org.apache.camel.Endpoint; import org.apache.camel.component.aws.ddb.DdbComponentVerifierExtension; import org.apache.camel.impl.DefaultComponent; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import org.apache.camel.spi.Metadata; +import org.apache.camel.util.ObjectHelper; public class DdbStreamComponent extends DefaultComponent { - private static final Logger LOG = LoggerFactory.getLogger(DdbStreamComponent.class); + + @Metadata + private String accessKey; + @Metadata + private String secretKey; + @Metadata + private String region; + @Metadata(label = "advanced") + private DdbStreamConfiguration configuration; public DdbStreamComponent() { this(null); @@ -34,12 +42,13 @@ public class DdbStreamComponent extends DefaultComponent { public DdbStreamComponent(CamelContext context) { super(context); + this.configuration = new DdbStreamConfiguration(); registerExtension(new DdbComponentVerifierExtension()); } @Override protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception { - DdbStreamConfiguration configuration = new DdbStreamConfiguration(); + DdbStreamConfiguration configuration = this.configuration.copy(); configuration.setTableName(remaining); setProperties(configuration, parameters); @@ -48,7 +57,61 @@ public class DdbStreamComponent extends DefaultComponent { } configuration.setTableName(remaining); + if (ObjectHelper.isEmpty(configuration.getAccessKey())) { + setAccessKey(accessKey); + } + if (ObjectHelper.isEmpty(configuration.getSecretKey())) { + setSecretKey(secretKey); + } + if (ObjectHelper.isEmpty(configuration.getRegion())) { + setRegion(region); + } + DdbStreamEndpoint endpoint = new DdbStreamEndpoint(uri, configuration, this); return endpoint; } + + public DdbStreamConfiguration getConfiguration() { + return configuration; + } + + /** + * The AWS DDB stream default configuration + */ + public void setConfiguration(DdbStreamConfiguration configuration) { + this.configuration = configuration; + } + + public String getAccessKey() { + return configuration.getAccessKey(); + } + + /** + * Amazon AWS Access Key + */ + public void setAccessKey(String accessKey) { + configuration.setAccessKey(accessKey); + } + + public String getSecretKey() { + return configuration.getSecretKey(); + } + + /** + * Amazon AWS Secret Key + */ + public void setSecretKey(String secretKey) { + configuration.setSecretKey(secretKey); + } + + public String getRegion() { + return configuration.getRegion(); + } + + /** + * Amazon AWS Region + */ + public void setRegion(String region) { + configuration.setRegion(region); + } } diff --git a/components/camel-aws/src/main/java/org/apache/camel/component/aws/ddbstream/DdbStreamConfiguration.java b/components/camel-aws/src/main/java/org/apache/camel/component/aws/ddbstream/DdbStreamConfiguration.java index 96a45e2..47cc49b 100644 --- a/components/camel-aws/src/main/java/org/apache/camel/component/aws/ddbstream/DdbStreamConfiguration.java +++ b/components/camel-aws/src/main/java/org/apache/camel/component/aws/ddbstream/DdbStreamConfiguration.java @@ -19,13 +19,14 @@ package org.apache.camel.component.aws.ddbstream; import com.amazonaws.services.dynamodbv2.AmazonDynamoDBStreams; import com.amazonaws.services.dynamodbv2.model.ShardIteratorType; +import org.apache.camel.RuntimeCamelException; import org.apache.camel.spi.Metadata; import org.apache.camel.spi.UriParam; import org.apache.camel.spi.UriParams; import org.apache.camel.spi.UriPath; @UriParams -public class DdbStreamConfiguration { +public class DdbStreamConfiguration implements Cloneable { @UriPath(label = "consumer", description = "Name of the dynamodb table") @Metadata(required = "true") @@ -139,5 +140,17 @@ public class DdbStreamConfiguration { public void setProxyPort(Integer proxyPort) { this.proxyPort = proxyPort; - } + } + + // ************************************************* + // + // ************************************************* + + public DdbStreamConfiguration copy() { + try { + return (DdbStreamConfiguration)super.clone(); + } catch (CloneNotSupportedException e) { + throw new RuntimeCamelException(e); + } + } } diff --git a/components/camel-aws/src/test/java/org/apache/camel/component/aws/ddbstream/DdbStreamComponentConfigurationTest.java b/components/camel-aws/src/test/java/org/apache/camel/component/aws/ddbstream/DdbStreamComponentConfigurationTest.java index 3ea6d22..1874c2a 100644 --- a/components/camel-aws/src/test/java/org/apache/camel/component/aws/ddbstream/DdbStreamComponentConfigurationTest.java +++ b/components/camel-aws/src/test/java/org/apache/camel/component/aws/ddbstream/DdbStreamComponentConfigurationTest.java @@ -16,6 +16,8 @@ */ package org.apache.camel.component.aws.ddbstream; +import com.amazonaws.regions.Regions; + import org.apache.camel.test.junit4.CamelTestSupport; import org.junit.Test; @@ -31,4 +33,30 @@ public class DdbStreamComponentConfigurationTest extends CamelTestSupport { assertEquals("yyyyy", endpoint.getConfiguration().getSecretKey()); } + @Test + public void createEndpointWithComponentElements() throws Exception { + DdbStreamComponent component = new DdbStreamComponent(context); + component.setAccessKey("XXX"); + component.setSecretKey("YYY"); + DdbStreamEndpoint endpoint = (DdbStreamEndpoint)component.createEndpoint("aws-ddb://myTable"); + + assertEquals("myTable", endpoint.getConfiguration().getTableName()); + assertEquals("XXX", endpoint.getConfiguration().getAccessKey()); + assertEquals("YYY", endpoint.getConfiguration().getSecretKey()); + } + + @Test + public void createEndpointWithComponentAndEndpointElements() throws Exception { + DdbStreamComponent component = new DdbStreamComponent(context); + component.setAccessKey("XXX"); + component.setSecretKey("YYY"); + component.setRegion(Regions.US_WEST_1.toString()); + DdbStreamEndpoint endpoint = (DdbStreamEndpoint)component.createEndpoint("aws-ddb://myTable?accessKey=xxxxxx&secretKey=yyyyy®ion=US_EAST_1"); + + assertEquals("myTable", endpoint.getConfiguration().getTableName()); + assertEquals("xxxxxx", endpoint.getConfiguration().getAccessKey()); + assertEquals("yyyyy", endpoint.getConfiguration().getSecretKey()); + assertEquals("US_EAST_1", endpoint.getConfiguration().getRegion()); + } + } \ No newline at end of file diff --git a/platforms/spring-boot/components-starter/camel-aws-starter/src/main/java/org/apache/camel/component/aws/ddbstream/springboot/DdbStreamComponentConfiguration.java b/platforms/spring-boot/components-starter/camel-aws-starter/src/main/java/org/apache/camel/component/aws/ddbstream/springboot/DdbStreamComponentConfiguration.java index b87ec6e..808b586 100644 --- a/platforms/spring-boot/components-starter/camel-aws-starter/src/main/java/org/apache/camel/component/aws/ddbstream/springboot/DdbStreamComponentConfiguration.java +++ b/platforms/spring-boot/components-starter/camel-aws-starter/src/main/java/org/apache/camel/component/aws/ddbstream/springboot/DdbStreamComponentConfiguration.java @@ -17,6 +17,10 @@ package org.apache.camel.component.aws.ddbstream.springboot; import javax.annotation.Generated; +import com.amazonaws.services.dynamodbv2.AmazonDynamoDBStreams; +import com.amazonaws.services.dynamodbv2.model.ShardIteratorType; +import org.apache.camel.component.aws.ddbstream.DdbStreamComponent; +import org.apache.camel.component.aws.ddbstream.SequenceNumberProvider; import org.apache.camel.spring.boot.ComponentConfigurationPropertiesCommon; import org.springframework.boot.context.properties.ConfigurationProperties; @@ -32,12 +36,61 @@ public class DdbStreamComponentConfiguration ComponentConfigurationPropertiesCommon { /** + * The AWS DDB stream default configuration + */ + private DdbStreamConfigurationNestedConfiguration configuration; + /** + * Amazon AWS Access Key + */ + private String accessKey; + /** + * Amazon AWS Secret Key + */ + private String secretKey; + /** + * Amazon AWS Region + */ + private String region; + /** * Whether the component should resolve property placeholders on itself when * starting. Only properties which are of String type can use property * placeholders. */ private Boolean resolvePropertyPlaceholders = true; + public DdbStreamConfigurationNestedConfiguration getConfiguration() { + return configuration; + } + + public void setConfiguration( + DdbStreamConfigurationNestedConfiguration configuration) { + this.configuration = configuration; + } + + public String getAccessKey() { + return accessKey; + } + + public void setAccessKey(String accessKey) { + this.accessKey = accessKey; + } + + public String getSecretKey() { + return secretKey; + } + + public void setSecretKey(String secretKey) { + this.secretKey = secretKey; + } + + public String getRegion() { + return region; + } + + public void setRegion(String region) { + this.region = region; + } + public Boolean getResolvePropertyPlaceholders() { return resolvePropertyPlaceholders; } @@ -46,4 +99,100 @@ public class DdbStreamComponentConfiguration Boolean resolvePropertyPlaceholders) { this.resolvePropertyPlaceholders = resolvePropertyPlaceholders; } + + public static class DdbStreamConfigurationNestedConfiguration { + public static final Class CAMEL_NESTED_CLASS = org.apache.camel.component.aws.ddbstream.DdbStreamConfiguration.class; + private AmazonDynamoDBStreams amazonDynamoDbStreamsClient; + private String accessKey; + private String secretKey; + private String region; + private Integer maxResultsPerRequest; + private String tableName; + private ShardIteratorType iteratorType = ShardIteratorType.LATEST; + private SequenceNumberProvider sequenceNumberProvider; + private String proxyHost; + private Integer proxyPort; + + public AmazonDynamoDBStreams getAmazonDynamoDbStreamsClient() { + return amazonDynamoDbStreamsClient; + } + + public void setAmazonDynamoDbStreamsClient( + AmazonDynamoDBStreams amazonDynamoDbStreamsClient) { + this.amazonDynamoDbStreamsClient = amazonDynamoDbStreamsClient; + } + + public String getAccessKey() { + return accessKey; + } + + public void setAccessKey(String accessKey) { + this.accessKey = accessKey; + } + + public String getSecretKey() { + return secretKey; + } + + public void setSecretKey(String secretKey) { + this.secretKey = secretKey; + } + + public String getRegion() { + return region; + } + + public void setRegion(String region) { + this.region = region; + } + + public Integer getMaxResultsPerRequest() { + return maxResultsPerRequest; + } + + public void setMaxResultsPerRequest(Integer maxResultsPerRequest) { + this.maxResultsPerRequest = maxResultsPerRequest; + } + + public String getTableName() { + return tableName; + } + + public void setTableName(String tableName) { + this.tableName = tableName; + } + + public ShardIteratorType getIteratorType() { + return iteratorType; + } + + public void setIteratorType(ShardIteratorType iteratorType) { + this.iteratorType = iteratorType; + } + + public SequenceNumberProvider getSequenceNumberProvider() { + return sequenceNumberProvider; + } + + public void setSequenceNumberProvider( + SequenceNumberProvider sequenceNumberProvider) { + this.sequenceNumberProvider = sequenceNumberProvider; + } + + public String getProxyHost() { + return proxyHost; + } + + public void setProxyHost(String proxyHost) { + this.proxyHost = proxyHost; + } + + public Integer getProxyPort() { + return proxyPort; + } + + public void setProxyPort(Integer proxyPort) { + this.proxyPort = proxyPort; + } + } } \ No newline at end of file -- To stop receiving notification emails like this one, please contact acosent...@apache.org.