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 9a788f4274b084d6fa6fcb1ebba76965790ea57d Author: Andrea Cosentino <anco...@gmail.com> AuthorDate: Tue Jul 21 08:30:04 2020 +0200 CAMEL-15310 - AWS* - Support for more than 1 client in the registry - Camel-AWS-DDB --- .../component/aws/ddb/DdbComponentConfigurer.java | 5 ++++ .../component/aws/ddb/DdbEndpointConfigurer.java | 5 ++++ .../apache/camel/component/aws/ddb/aws-ddb.json | 2 ++ .../src/main/docs/aws-ddb-component.adoc | 6 +++-- .../camel/component/aws/ddb/DdbComponent.java | 4 +++- .../camel/component/aws/ddb/DdbConfiguration.java | 15 ++++++++++++ .../aws/ddb/DdbComponentRegistryClientTest.java | 24 +++++++++++++++++++ .../dsl/AwsDdbComponentBuilderFactory.java | 16 +++++++++++++ .../builder/endpoint/StaticEndpointBuilders.java | 8 +++---- .../endpoint/dsl/DdbEndpointBuilderFactory.java | 28 ++++++++++++++++++++++ 10 files changed, 106 insertions(+), 7 deletions(-) diff --git a/components/camel-aws-ddb/src/generated/java/org/apache/camel/component/aws/ddb/DdbComponentConfigurer.java b/components/camel-aws-ddb/src/generated/java/org/apache/camel/component/aws/ddb/DdbComponentConfigurer.java index 6fd18e2..1f3b29f 100644 --- a/components/camel-aws-ddb/src/generated/java/org/apache/camel/component/aws/ddb/DdbComponentConfigurer.java +++ b/components/camel-aws-ddb/src/generated/java/org/apache/camel/component/aws/ddb/DdbComponentConfigurer.java @@ -30,6 +30,8 @@ public class DdbComponentConfigurer extends PropertyConfigurerSupport implements case "accessKey": getOrCreateConfiguration(target).setAccessKey(property(camelContext, java.lang.String.class, value)); return true; case "amazonddbclient": case "amazonDDBClient": getOrCreateConfiguration(target).setAmazonDDBClient(property(camelContext, com.amazonaws.services.dynamodbv2.AmazonDynamoDB.class, value)); return true; + case "autodiscoverclient": + case "autoDiscoverClient": getOrCreateConfiguration(target).setAutoDiscoverClient(property(camelContext, boolean.class, value)); return true; case "basicpropertybinding": case "basicPropertyBinding": target.setBasicPropertyBinding(property(camelContext, boolean.class, value)); return true; case "configuration": target.setConfiguration(property(camelContext, org.apache.camel.component.aws.ddb.DdbConfiguration.class, value)); return true; @@ -64,6 +66,7 @@ public class DdbComponentConfigurer extends PropertyConfigurerSupport implements Map<String, Object> answer = new CaseInsensitiveMap(); answer.put("accessKey", java.lang.String.class); answer.put("amazonDDBClient", com.amazonaws.services.dynamodbv2.AmazonDynamoDB.class); + answer.put("autoDiscoverClient", boolean.class); answer.put("basicPropertyBinding", boolean.class); answer.put("configuration", org.apache.camel.component.aws.ddb.DdbConfiguration.class); answer.put("consistentRead", boolean.class); @@ -89,6 +92,8 @@ public class DdbComponentConfigurer extends PropertyConfigurerSupport implements case "accessKey": return getOrCreateConfiguration(target).getAccessKey(); case "amazonddbclient": case "amazonDDBClient": return getOrCreateConfiguration(target).getAmazonDDBClient(); + case "autodiscoverclient": + case "autoDiscoverClient": return getOrCreateConfiguration(target).isAutoDiscoverClient(); case "basicpropertybinding": case "basicPropertyBinding": return target.isBasicPropertyBinding(); case "configuration": return target.getConfiguration(); diff --git a/components/camel-aws-ddb/src/generated/java/org/apache/camel/component/aws/ddb/DdbEndpointConfigurer.java b/components/camel-aws-ddb/src/generated/java/org/apache/camel/component/aws/ddb/DdbEndpointConfigurer.java index 5fb12ff..86e0fda 100644 --- a/components/camel-aws-ddb/src/generated/java/org/apache/camel/component/aws/ddb/DdbEndpointConfigurer.java +++ b/components/camel-aws-ddb/src/generated/java/org/apache/camel/component/aws/ddb/DdbEndpointConfigurer.java @@ -23,6 +23,8 @@ public class DdbEndpointConfigurer extends PropertyConfigurerSupport implements case "accessKey": target.getConfiguration().setAccessKey(property(camelContext, java.lang.String.class, value)); return true; case "amazonddbclient": case "amazonDDBClient": target.getConfiguration().setAmazonDDBClient(property(camelContext, com.amazonaws.services.dynamodbv2.AmazonDynamoDB.class, value)); return true; + case "autodiscoverclient": + case "autoDiscoverClient": target.getConfiguration().setAutoDiscoverClient(property(camelContext, boolean.class, value)); return true; case "basicpropertybinding": case "basicPropertyBinding": target.setBasicPropertyBinding(property(camelContext, boolean.class, value)); return true; case "consistentread": @@ -57,6 +59,7 @@ public class DdbEndpointConfigurer extends PropertyConfigurerSupport implements Map<String, Object> answer = new CaseInsensitiveMap(); answer.put("accessKey", java.lang.String.class); answer.put("amazonDDBClient", com.amazonaws.services.dynamodbv2.AmazonDynamoDB.class); + answer.put("autoDiscoverClient", boolean.class); answer.put("basicPropertyBinding", boolean.class); answer.put("consistentRead", boolean.class); answer.put("keyAttributeName", java.lang.String.class); @@ -82,6 +85,8 @@ public class DdbEndpointConfigurer extends PropertyConfigurerSupport implements case "accessKey": return target.getConfiguration().getAccessKey(); case "amazonddbclient": case "amazonDDBClient": return target.getConfiguration().getAmazonDDBClient(); + case "autodiscoverclient": + case "autoDiscoverClient": return target.getConfiguration().isAutoDiscoverClient(); case "basicpropertybinding": case "basicPropertyBinding": return target.isBasicPropertyBinding(); case "consistentread": diff --git a/components/camel-aws-ddb/src/generated/resources/org/apache/camel/component/aws/ddb/aws-ddb.json b/components/camel-aws-ddb/src/generated/resources/org/apache/camel/component/aws/ddb/aws-ddb.json index a420fd0..71a6ac8 100644 --- a/components/camel-aws-ddb/src/generated/resources/org/apache/camel/component/aws/ddb/aws-ddb.json +++ b/components/camel-aws-ddb/src/generated/resources/org/apache/camel/component/aws/ddb/aws-ddb.json @@ -22,6 +22,7 @@ }, "componentProperties": { "amazonDDBClient": { "kind": "property", "displayName": "Amazon DDBClient", "group": "producer", "label": "", "required": false, "type": "object", "javaType": "com.amazonaws.services.dynamodbv2.AmazonDynamoDB", "deprecated": false, "secret": false, "configurationClass": "org.apache.camel.component.aws.ddb.DdbConfiguration", "configurationField": "configuration", "description": "To use the AmazonDynamoDB as the client" }, + "autoDiscoverClient": { "kind": "property", "displayName": "Auto Discover Client", "group": "common", "label": "common", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "secret": false, "defaultValue": "true", "configurationClass": "org.apache.camel.component.aws.ddb.DdbConfiguration", "configurationField": "configuration", "description": "Setting the autoDiscoverClient mechanism, if true, the component will look for a client instance in the registry [...] "configuration": { "kind": "property", "displayName": "Configuration", "group": "producer", "label": "", "required": false, "type": "object", "javaType": "org.apache.camel.component.aws.ddb.DdbConfiguration", "deprecated": false, "secret": false, "description": "The component configuration" }, "consistentRead": { "kind": "property", "displayName": "Consistent Read", "group": "producer", "label": "", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "secret": false, "defaultValue": false, "configurationClass": "org.apache.camel.component.aws.ddb.DdbConfiguration", "configurationField": "configuration", "description": "Determines whether or not strong consistency should be enforced when data is read." }, "keyAttributeName": { "kind": "property", "displayName": "Key Attribute Name", "group": "producer", "label": "", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "secret": false, "configurationClass": "org.apache.camel.component.aws.ddb.DdbConfiguration", "configurationField": "configuration", "description": "Attribute name when creating table" }, @@ -41,6 +42,7 @@ "properties": { "tableName": { "kind": "path", "displayName": "Table Name", "group": "producer", "label": "", "required": true, "type": "string", "javaType": "java.lang.String", "deprecated": false, "deprecationNote": "", "secret": false, "configurationClass": "org.apache.camel.component.aws.ddb.DdbConfiguration", "configurationField": "configuration", "description": "The name of the table currently worked with." }, "amazonDDBClient": { "kind": "parameter", "displayName": "Amazon DDBClient", "group": "producer", "label": "", "required": false, "type": "object", "javaType": "com.amazonaws.services.dynamodbv2.AmazonDynamoDB", "deprecated": false, "secret": false, "configurationClass": "org.apache.camel.component.aws.ddb.DdbConfiguration", "configurationField": "configuration", "description": "To use the AmazonDynamoDB as the client" }, + "autoDiscoverClient": { "kind": "parameter", "displayName": "Auto Discover Client", "group": "common", "label": "common", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "secret": false, "defaultValue": "true", "configurationClass": "org.apache.camel.component.aws.ddb.DdbConfiguration", "configurationField": "configuration", "description": "Setting the autoDiscoverClient mechanism, if true, the component will look for a client instance in the registr [...] "consistentRead": { "kind": "parameter", "displayName": "Consistent Read", "group": "producer", "label": "", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "secret": false, "defaultValue": false, "configurationClass": "org.apache.camel.component.aws.ddb.DdbConfiguration", "configurationField": "configuration", "description": "Determines whether or not strong consistency should be enforced when data is read." }, "keyAttributeName": { "kind": "parameter", "displayName": "Key Attribute Name", "group": "producer", "label": "", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "secret": false, "configurationClass": "org.apache.camel.component.aws.ddb.DdbConfiguration", "configurationField": "configuration", "description": "Attribute name when creating table" }, "keyAttributeType": { "kind": "parameter", "displayName": "Key Attribute Type", "group": "producer", "label": "", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "secret": false, "configurationClass": "org.apache.camel.component.aws.ddb.DdbConfiguration", "configurationField": "configuration", "description": "Attribute type when creating table" }, diff --git a/components/camel-aws-ddb/src/main/docs/aws-ddb-component.adoc b/components/camel-aws-ddb/src/main/docs/aws-ddb-component.adoc index f56ee2e..db8ca19 100644 --- a/components/camel-aws-ddb/src/main/docs/aws-ddb-component.adoc +++ b/components/camel-aws-ddb/src/main/docs/aws-ddb-component.adoc @@ -36,7 +36,7 @@ You can append query options to the URI in the following format, // component options: START -The AWS DynamoDB component supports 16 options, which are listed below. +The AWS DynamoDB component supports 17 options, which are listed below. @@ -44,6 +44,7 @@ The AWS DynamoDB component supports 16 options, which are listed below. |=== | Name | Description | Default | Type | *amazonDDBClient* (producer) | To use the AmazonDynamoDB as the client | | AmazonDynamoDB +| *autoDiscoverClient* (common) | Setting the autoDiscoverClient mechanism, if true, the component will look for a client instance in the registry automatically otherwise it will skip that checking. | true | boolean | *configuration* (producer) | The component configuration | | DdbConfiguration | *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 @@ -84,13 +85,14 @@ with the following path and query parameters: |=== -=== Query Parameters (16 parameters): +=== Query Parameters (17 parameters): [width="100%",cols="2,5,^1,2",options="header"] |=== | Name | Description | Default | Type | *amazonDDBClient* (producer) | To use the AmazonDynamoDB as the client | | AmazonDynamoDB +| *autoDiscoverClient* (common) | Setting the autoDiscoverClient mechanism, if true, the component will look for a client instance in the registry automatically otherwise it will skip that checking. | true | boolean | *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 diff --git a/components/camel-aws-ddb/src/main/java/org/apache/camel/component/aws/ddb/DdbComponent.java b/components/camel-aws-ddb/src/main/java/org/apache/camel/component/aws/ddb/DdbComponent.java index ba2dd66..263e804 100644 --- a/components/camel-aws-ddb/src/main/java/org/apache/camel/component/aws/ddb/DdbComponent.java +++ b/components/camel-aws-ddb/src/main/java/org/apache/camel/component/aws/ddb/DdbComponent.java @@ -52,7 +52,9 @@ public class DdbComponent extends DefaultComponent { configuration.setTableName(remaining); DdbEndpoint endpoint = new DdbEndpoint(uri, this, configuration); setProperties(endpoint, parameters); - checkAndSetRegistryClient(configuration); + if (endpoint.getConfiguration().isAutoDiscoverClient()) { + checkAndSetRegistryClient(configuration); + } if (configuration.getAmazonDDBClient() == null && (configuration.getAccessKey() == null || configuration.getSecretKey() == null)) { throw new IllegalArgumentException("amazonDDBClient or accessKey and secretKey must be specified"); } diff --git a/components/camel-aws-ddb/src/main/java/org/apache/camel/component/aws/ddb/DdbConfiguration.java b/components/camel-aws-ddb/src/main/java/org/apache/camel/component/aws/ddb/DdbConfiguration.java index 4a8c3d4..6d65684 100644 --- a/components/camel-aws-ddb/src/main/java/org/apache/camel/component/aws/ddb/DdbConfiguration.java +++ b/components/camel-aws-ddb/src/main/java/org/apache/camel/component/aws/ddb/DdbConfiguration.java @@ -55,6 +55,8 @@ public class DdbConfiguration implements Cloneable { private Integer proxyPort; @UriParam private String region; + @UriParam(label = "common", defaultValue = "true") + private boolean autoDiscoverClient = true; public String getAccessKey() { return accessKey; @@ -211,6 +213,19 @@ public class DdbConfiguration implements Cloneable { this.region = region; } + public boolean isAutoDiscoverClient() { + return autoDiscoverClient; + } + + /** + * Setting the autoDiscoverClient mechanism, if true, the component will + * look for a client instance in the registry automatically otherwise it + * will skip that checking. + */ + public void setAutoDiscoverClient(boolean autoDiscoverClient) { + this.autoDiscoverClient = autoDiscoverClient; + } + // ************************************************* // // ************************************************* diff --git a/components/camel-aws-ddb/src/test/java/org/apache/camel/component/aws/ddb/DdbComponentRegistryClientTest.java b/components/camel-aws-ddb/src/test/java/org/apache/camel/component/aws/ddb/DdbComponentRegistryClientTest.java index 597399b..3c987bb 100644 --- a/components/camel-aws-ddb/src/test/java/org/apache/camel/component/aws/ddb/DdbComponentRegistryClientTest.java +++ b/components/camel-aws-ddb/src/test/java/org/apache/camel/component/aws/ddb/DdbComponentRegistryClientTest.java @@ -20,6 +20,8 @@ import org.apache.camel.test.junit5.CamelTestSupport; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotSame; +import static org.junit.jupiter.api.Assertions.assertSame; import static org.junit.jupiter.api.Assertions.assertThrows; public class DdbComponentRegistryClientTest extends CamelTestSupport { @@ -40,4 +42,26 @@ public class DdbComponentRegistryClientTest extends CamelTestSupport { assertThrows(IllegalArgumentException.class, () -> component.createEndpoint("aws-ddb://myTable")); } + + @Test + public void createEndpointWithAutoDiscoverClientFalse() throws Exception { + AmazonDDBClientMock ddbClient = new AmazonDDBClientMock(); + context.getRegistry().bind("ddbClient", ddbClient); + DdbComponent component = context.getComponent("aws-ddb", DdbComponent.class); + DdbEndpoint endpoint = (DdbEndpoint)component.createEndpoint("aws-ddb://myTable?autoDiscoverClient=false&accessKey=xxx&secretKey=xxx"); + + assertEquals("myTable", endpoint.getConfiguration().getTableName()); + assertNotSame(ddbClient, endpoint.getConfiguration().getAmazonDDBClient()); + } + + @Test + public void createEndpointWithAutoDiscoverClientTrue() throws Exception { + AmazonDDBClientMock ddbClient = new AmazonDDBClientMock(); + context.getRegistry().bind("ddbClient", ddbClient); + DdbComponent component = context.getComponent("aws-ddb", DdbComponent.class); + DdbEndpoint endpoint = (DdbEndpoint)component.createEndpoint("aws-ddb://myTable"); + + assertEquals("myTable", endpoint.getConfiguration().getTableName()); + assertSame(ddbClient, endpoint.getConfiguration().getAmazonDDBClient()); + } } \ No newline at end of file diff --git a/core/camel-componentdsl/src/generated/java/org/apache/camel/builder/component/dsl/AwsDdbComponentBuilderFactory.java b/core/camel-componentdsl/src/generated/java/org/apache/camel/builder/component/dsl/AwsDdbComponentBuilderFactory.java index 14f9dd6..131a0b7 100644 --- a/core/camel-componentdsl/src/generated/java/org/apache/camel/builder/component/dsl/AwsDdbComponentBuilderFactory.java +++ b/core/camel-componentdsl/src/generated/java/org/apache/camel/builder/component/dsl/AwsDdbComponentBuilderFactory.java @@ -60,6 +60,21 @@ public interface AwsDdbComponentBuilderFactory { return this; } /** + * Setting the autoDiscoverClient mechanism, if true, the component will + * look for a client instance in the registry automatically otherwise it + * will skip that checking. + * + * The option is a: <code>boolean</code> type. + * + * Default: true + * Group: common + */ + default AwsDdbComponentBuilder autoDiscoverClient( + boolean autoDiscoverClient) { + doSetProperty("autoDiscoverClient", autoDiscoverClient); + return this; + } + /** * The component configuration. * * The option is a: @@ -280,6 +295,7 @@ public interface AwsDdbComponentBuilderFactory { Object value) { switch (name) { case "amazonDDBClient": getOrCreateConfiguration((DdbComponent) component).setAmazonDDBClient((com.amazonaws.services.dynamodbv2.AmazonDynamoDB) value); return true; + case "autoDiscoverClient": getOrCreateConfiguration((DdbComponent) component).setAutoDiscoverClient((boolean) value); return true; case "configuration": ((DdbComponent) component).setConfiguration((org.apache.camel.component.aws.ddb.DdbConfiguration) value); return true; case "consistentRead": getOrCreateConfiguration((DdbComponent) component).setConsistentRead((boolean) value); return true; case "keyAttributeName": getOrCreateConfiguration((DdbComponent) component).setKeyAttributeName((java.lang.String) value); return true; diff --git a/core/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/StaticEndpointBuilders.java b/core/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/StaticEndpointBuilders.java index 1c60f30..e6fdb6b 100644 --- a/core/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/StaticEndpointBuilders.java +++ b/core/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/StaticEndpointBuilders.java @@ -877,7 +877,7 @@ public class StaticEndpointBuilders { * * @param path namespace */ - static org.apache.camel.builder.endpoint.dsl.Cw2EndpointBuilderFactory.Cw2EndpointBuilder aws2Cw( + public static org.apache.camel.builder.endpoint.dsl.Cw2EndpointBuilderFactory.Cw2EndpointBuilder aws2Cw( String path) { return org.apache.camel.builder.endpoint.dsl.Cw2EndpointBuilderFactory.endpointBuilder("aws2-cw", path); } @@ -898,7 +898,7 @@ public class StaticEndpointBuilders { * instead of the default name * @param path namespace */ - static org.apache.camel.builder.endpoint.dsl.Cw2EndpointBuilderFactory.Cw2EndpointBuilder aws2Cw( + public static org.apache.camel.builder.endpoint.dsl.Cw2EndpointBuilderFactory.Cw2EndpointBuilder aws2Cw( String componentName, String path) { return org.apache.camel.builder.endpoint.dsl.Cw2EndpointBuilderFactory.endpointBuilder(componentName, path); @@ -1668,7 +1668,7 @@ public class StaticEndpointBuilders { * * @param path tableName */ - public static org.apache.camel.builder.endpoint.dsl.DdbEndpointBuilderFactory.DdbEndpointBuilder awsDdb( + static org.apache.camel.builder.endpoint.dsl.DdbEndpointBuilderFactory.DdbEndpointBuilder awsDdb( String path) { return org.apache.camel.builder.endpoint.dsl.DdbEndpointBuilderFactory.endpointBuilder("aws-ddb", path); } @@ -1689,7 +1689,7 @@ public class StaticEndpointBuilders { * instead of the default name * @param path tableName */ - public static org.apache.camel.builder.endpoint.dsl.DdbEndpointBuilderFactory.DdbEndpointBuilder awsDdb( + static org.apache.camel.builder.endpoint.dsl.DdbEndpointBuilderFactory.DdbEndpointBuilder awsDdb( String componentName, String path) { return org.apache.camel.builder.endpoint.dsl.DdbEndpointBuilderFactory.endpointBuilder(componentName, path); diff --git a/core/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/DdbEndpointBuilderFactory.java b/core/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/DdbEndpointBuilderFactory.java index 4c80f18..8984710 100644 --- a/core/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/DdbEndpointBuilderFactory.java +++ b/core/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/DdbEndpointBuilderFactory.java @@ -62,6 +62,34 @@ public interface DdbEndpointBuilderFactory { return this; } /** + * Setting the autoDiscoverClient mechanism, if true, the component will + * look for a client instance in the registry automatically otherwise it + * will skip that checking. + * + * The option is a: <code>boolean</code> type. + * + * Default: true + * Group: common + */ + default DdbEndpointBuilder autoDiscoverClient(boolean autoDiscoverClient) { + doSetProperty("autoDiscoverClient", autoDiscoverClient); + return this; + } + /** + * Setting the autoDiscoverClient mechanism, if true, the component will + * look for a client instance in the registry automatically otherwise it + * will skip that checking. + * + * The option will be converted to a <code>boolean</code> type. + * + * Default: true + * Group: common + */ + default DdbEndpointBuilder autoDiscoverClient(String autoDiscoverClient) { + doSetProperty("autoDiscoverClient", autoDiscoverClient); + return this; + } + /** * Determines whether or not strong consistency should be enforced when * data is read. *