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 7dbe94e3c0761e83998d95375b70680aedb0ffa0 Author: Andrea Cosentino <anco...@gmail.com> AuthorDate: Tue Jul 21 11:39:46 2020 +0200 CAMEL-15310 - AWS* - Support for more than 1 client in the registry - Camel-AWS2-DDB --- .../aws2/ddb/Ddb2ComponentConfigurer.java | 5 ++++ .../component/aws2/ddb/Ddb2EndpointConfigurer.java | 5 ++++ .../apache/camel/component/aws2/ddb/aws2-ddb.json | 2 ++ .../src/main/docs/aws2-ddb-component.adoc | 6 +++-- .../camel/component/aws2/ddb/Ddb2Component.java | 4 ++- .../component/aws2/ddb/Ddb2Configuration.java | 15 +++++++++++ .../aws2/ddb/DdbComponentRegistryClientTest.java | 24 ++++++++++++++++++ .../dsl/Aws2DdbComponentBuilderFactory.java | 16 ++++++++++++ .../builder/endpoint/StaticEndpointBuilders.java | 8 +++--- .../endpoint/dsl/Ddb2EndpointBuilderFactory.java | 29 ++++++++++++++++++++++ 10 files changed, 107 insertions(+), 7 deletions(-) diff --git a/components/camel-aws2-ddb/src/generated/java/org/apache/camel/component/aws2/ddb/Ddb2ComponentConfigurer.java b/components/camel-aws2-ddb/src/generated/java/org/apache/camel/component/aws2/ddb/Ddb2ComponentConfigurer.java index 99e8a9c..eeb5100 100644 --- a/components/camel-aws2-ddb/src/generated/java/org/apache/camel/component/aws2/ddb/Ddb2ComponentConfigurer.java +++ b/components/camel-aws2-ddb/src/generated/java/org/apache/camel/component/aws2/ddb/Ddb2ComponentConfigurer.java @@ -30,6 +30,8 @@ public class Ddb2ComponentConfigurer extends PropertyConfigurerSupport implement case "accessKey": getOrCreateConfiguration(target).setAccessKey(property(camelContext, java.lang.String.class, value)); return true; case "amazonddbclient": case "amazonDDBClient": getOrCreateConfiguration(target).setAmazonDDBClient(property(camelContext, software.amazon.awssdk.services.dynamodb.DynamoDbClient.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.aws2.ddb.Ddb2Configuration.class, value)); return true; @@ -66,6 +68,7 @@ public class Ddb2ComponentConfigurer extends PropertyConfigurerSupport implement Map<String, Object> answer = new CaseInsensitiveMap(); answer.put("accessKey", java.lang.String.class); answer.put("amazonDDBClient", software.amazon.awssdk.services.dynamodb.DynamoDbClient.class); + answer.put("autoDiscoverClient", boolean.class); answer.put("basicPropertyBinding", boolean.class); answer.put("configuration", org.apache.camel.component.aws2.ddb.Ddb2Configuration.class); answer.put("consistentRead", boolean.class); @@ -92,6 +95,8 @@ public class Ddb2ComponentConfigurer extends PropertyConfigurerSupport implement 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-aws2-ddb/src/generated/java/org/apache/camel/component/aws2/ddb/Ddb2EndpointConfigurer.java b/components/camel-aws2-ddb/src/generated/java/org/apache/camel/component/aws2/ddb/Ddb2EndpointConfigurer.java index 47595e8..78f23fe 100644 --- a/components/camel-aws2-ddb/src/generated/java/org/apache/camel/component/aws2/ddb/Ddb2EndpointConfigurer.java +++ b/components/camel-aws2-ddb/src/generated/java/org/apache/camel/component/aws2/ddb/Ddb2EndpointConfigurer.java @@ -23,6 +23,8 @@ public class Ddb2EndpointConfigurer 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, software.amazon.awssdk.services.dynamodb.DynamoDbClient.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": @@ -59,6 +61,7 @@ public class Ddb2EndpointConfigurer extends PropertyConfigurerSupport implements Map<String, Object> answer = new CaseInsensitiveMap(); answer.put("accessKey", java.lang.String.class); answer.put("amazonDDBClient", software.amazon.awssdk.services.dynamodb.DynamoDbClient.class); + answer.put("autoDiscoverClient", boolean.class); answer.put("basicPropertyBinding", boolean.class); answer.put("consistentRead", boolean.class); answer.put("keyAttributeName", java.lang.String.class); @@ -85,6 +88,8 @@ public class Ddb2EndpointConfigurer 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-aws2-ddb/src/generated/resources/org/apache/camel/component/aws2/ddb/aws2-ddb.json b/components/camel-aws2-ddb/src/generated/resources/org/apache/camel/component/aws2/ddb/aws2-ddb.json index dba4232..43fa65f 100644 --- a/components/camel-aws2-ddb/src/generated/resources/org/apache/camel/component/aws2/ddb/aws2-ddb.json +++ b/components/camel-aws2-ddb/src/generated/resources/org/apache/camel/component/aws2/ddb/aws2-ddb.json @@ -22,6 +22,7 @@ }, "componentProperties": { "amazonDDBClient": { "kind": "property", "displayName": "Amazon DDBClient", "group": "producer", "label": "", "required": false, "type": "object", "javaType": "software.amazon.awssdk.services.dynamodb.DynamoDbClient", "deprecated": false, "secret": false, "configurationClass": "org.apache.camel.component.aws2.ddb.Ddb2Configuration", "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.aws2.ddb.Ddb2Configuration", "configurationField": "configuration", "description": "Setting the autoDiscoverClient mechanism, if true, the component will look for a client instance in the regist [...] "configuration": { "kind": "property", "displayName": "Configuration", "group": "producer", "label": "", "required": false, "type": "object", "javaType": "org.apache.camel.component.aws2.ddb.Ddb2Configuration", "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.aws2.ddb.Ddb2Configuration", "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.aws2.ddb.Ddb2Configuration", "configurationField": "configuration", "description": "Attribute name when creating table" }, @@ -42,6 +43,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.aws2.ddb.Ddb2Configuration", "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": "software.amazon.awssdk.services.dynamodb.DynamoDbClient", "deprecated": false, "secret": false, "configurationClass": "org.apache.camel.component.aws2.ddb.Ddb2Configuration", "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.aws2.ddb.Ddb2Configuration", "configurationField": "configuration", "description": "Setting the autoDiscoverClient mechanism, if true, the component will look for a client instance in the regis [...] "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.aws2.ddb.Ddb2Configuration", "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.aws2.ddb.Ddb2Configuration", "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.aws2.ddb.Ddb2Configuration", "configurationField": "configuration", "description": "Attribute type when creating table" }, diff --git a/components/camel-aws2-ddb/src/main/docs/aws2-ddb-component.adoc b/components/camel-aws2-ddb/src/main/docs/aws2-ddb-component.adoc index b827e73..c238f22 100644 --- a/components/camel-aws2-ddb/src/main/docs/aws2-ddb-component.adoc +++ b/components/camel-aws2-ddb/src/main/docs/aws2-ddb-component.adoc @@ -41,7 +41,7 @@ You can append query options to the URI in the following format, // component options: START -The AWS 2 DynamoDB component supports 17 options, which are listed below. +The AWS 2 DynamoDB component supports 18 options, which are listed below. @@ -49,6 +49,7 @@ The AWS 2 DynamoDB component supports 17 options, which are listed below. |=== | Name | Description | Default | Type | *amazonDDBClient* (producer) | To use the AmazonDynamoDB as the client | | DynamoDbClient +| *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 | | Ddb2Configuration | *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 @@ -90,13 +91,14 @@ with the following path and query parameters: |=== -=== Query Parameters (17 parameters): +=== Query Parameters (18 parameters): [width="100%",cols="2,5,^1,2",options="header"] |=== | Name | Description | Default | Type | *amazonDDBClient* (producer) | To use the AmazonDynamoDB as the client | | DynamoDbClient +| *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-aws2-ddb/src/main/java/org/apache/camel/component/aws2/ddb/Ddb2Component.java b/components/camel-aws2-ddb/src/main/java/org/apache/camel/component/aws2/ddb/Ddb2Component.java index a84b652..37ad859 100644 --- a/components/camel-aws2-ddb/src/main/java/org/apache/camel/component/aws2/ddb/Ddb2Component.java +++ b/components/camel-aws2-ddb/src/main/java/org/apache/camel/component/aws2/ddb/Ddb2Component.java @@ -57,7 +57,9 @@ public class Ddb2Component extends DefaultComponent { configuration.setTableName(remaining); Ddb2Endpoint endpoint = new Ddb2Endpoint(uri, this, configuration); setProperties(endpoint, parameters); - checkAndSetRegistryClient(configuration, endpoint); + if (endpoint.getConfiguration().isAutoDiscoverClient()) { + checkAndSetRegistryClient(configuration, endpoint); + } 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-aws2-ddb/src/main/java/org/apache/camel/component/aws2/ddb/Ddb2Configuration.java b/components/camel-aws2-ddb/src/main/java/org/apache/camel/component/aws2/ddb/Ddb2Configuration.java index 31f46f6..9d6e466 100644 --- a/components/camel-aws2-ddb/src/main/java/org/apache/camel/component/aws2/ddb/Ddb2Configuration.java +++ b/components/camel-aws2-ddb/src/main/java/org/apache/camel/component/aws2/ddb/Ddb2Configuration.java @@ -58,6 +58,8 @@ public class Ddb2Configuration implements Cloneable { private String region; @UriParam(defaultValue = "false") private boolean trustAllCertificates; + @UriParam(label = "common", defaultValue = "true") + private boolean autoDiscoverClient = true; public String getAccessKey() { return accessKey; @@ -229,6 +231,19 @@ public class Ddb2Configuration implements Cloneable { public void setTrustAllCertificates(boolean trustAllCertificates) { this.trustAllCertificates = trustAllCertificates; } + + 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-aws2-ddb/src/test/java/org/apache/camel/component/aws2/ddb/DdbComponentRegistryClientTest.java b/components/camel-aws2-ddb/src/test/java/org/apache/camel/component/aws2/ddb/DdbComponentRegistryClientTest.java index 9210038..d79bfef 100644 --- a/components/camel-aws2-ddb/src/test/java/org/apache/camel/component/aws2/ddb/DdbComponentRegistryClientTest.java +++ b/components/camel-aws2-ddb/src/test/java/org/apache/camel/component/aws2/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 { @@ -41,4 +43,26 @@ public class DdbComponentRegistryClientTest extends CamelTestSupport { component.createEndpoint("aws2-ddb://myTable"); }); } + + @Test + public void createEndpointWithAutoDiscoverFalse() throws Exception { + AmazonDDBClientMock ddbClient = new AmazonDDBClientMock(); + context.getRegistry().bind("ddbClient", ddbClient); + Ddb2Component component = context.getComponent("aws2-ddb", Ddb2Component.class); + Ddb2Endpoint endpoint = (Ddb2Endpoint)component.createEndpoint("aws2-ddb://myTable?accessKey=xxx&secretKey=yyy&autoDiscoverClient=false"); + + assertEquals("myTable", endpoint.getConfiguration().getTableName()); + assertNotSame(ddbClient, endpoint.getConfiguration().getAmazonDDBClient()); + } + + @Test + public void createEndpointWithAutoDiscoverTrue() throws Exception { + AmazonDDBClientMock ddbClient = new AmazonDDBClientMock(); + context.getRegistry().bind("ddbClient", ddbClient); + Ddb2Component component = context.getComponent("aws2-ddb", Ddb2Component.class); + Ddb2Endpoint endpoint = (Ddb2Endpoint)component.createEndpoint("aws2-ddb://myTable?accessKey=xxx&secretKey=yyy"); + + assertEquals("myTable", endpoint.getConfiguration().getTableName()); + assertSame(ddbClient, endpoint.getConfiguration().getAmazonDDBClient()); + } } diff --git a/core/camel-componentdsl/src/generated/java/org/apache/camel/builder/component/dsl/Aws2DdbComponentBuilderFactory.java b/core/camel-componentdsl/src/generated/java/org/apache/camel/builder/component/dsl/Aws2DdbComponentBuilderFactory.java index 8d6d088..77e44ab 100644 --- a/core/camel-componentdsl/src/generated/java/org/apache/camel/builder/component/dsl/Aws2DdbComponentBuilderFactory.java +++ b/core/camel-componentdsl/src/generated/java/org/apache/camel/builder/component/dsl/Aws2DdbComponentBuilderFactory.java @@ -62,6 +62,21 @@ public interface Aws2DdbComponentBuilderFactory { 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 Aws2DdbComponentBuilder autoDiscoverClient( + boolean autoDiscoverClient) { + doSetProperty("autoDiscoverClient", autoDiscoverClient); + return this; + } + /** * The component configuration. * * The option is a: @@ -297,6 +312,7 @@ public interface Aws2DdbComponentBuilderFactory { Object value) { switch (name) { case "amazonDDBClient": getOrCreateConfiguration((Ddb2Component) component).setAmazonDDBClient((software.amazon.awssdk.services.dynamodb.DynamoDbClient) value); return true; + case "autoDiscoverClient": getOrCreateConfiguration((Ddb2Component) component).setAutoDiscoverClient((boolean) value); return true; case "configuration": ((Ddb2Component) component).setConfiguration((org.apache.camel.component.aws2.ddb.Ddb2Configuration) value); return true; case "consistentRead": getOrCreateConfiguration((Ddb2Component) component).setConsistentRead((boolean) value); return true; case "keyAttributeName": getOrCreateConfiguration((Ddb2Component) 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 df61b9e..40b99a7 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 @@ -962,7 +962,7 @@ public class StaticEndpointBuilders { * * @param path tableName */ - public static org.apache.camel.builder.endpoint.dsl.Ddb2StreamEndpointBuilderFactory.Ddb2StreamEndpointBuilder aws2Ddbstream( + static org.apache.camel.builder.endpoint.dsl.Ddb2StreamEndpointBuilderFactory.Ddb2StreamEndpointBuilder aws2Ddbstream( String path) { return org.apache.camel.builder.endpoint.dsl.Ddb2StreamEndpointBuilderFactory.endpointBuilder("aws2-ddbstream", path); } @@ -984,7 +984,7 @@ public class StaticEndpointBuilders { * instead of the default name * @param path tableName */ - public static org.apache.camel.builder.endpoint.dsl.Ddb2StreamEndpointBuilderFactory.Ddb2StreamEndpointBuilder aws2Ddbstream( + static org.apache.camel.builder.endpoint.dsl.Ddb2StreamEndpointBuilderFactory.Ddb2StreamEndpointBuilder aws2Ddbstream( String componentName, String path) { return org.apache.camel.builder.endpoint.dsl.Ddb2StreamEndpointBuilderFactory.endpointBuilder(componentName, path); @@ -2450,7 +2450,7 @@ public class StaticEndpointBuilders { * @param path containerOrBlobUri */ @Deprecated - static org.apache.camel.builder.endpoint.dsl.BlobServiceEndpointBuilderFactory.BlobServiceEndpointBuilder azureBlob( + public static org.apache.camel.builder.endpoint.dsl.BlobServiceEndpointBuilderFactory.BlobServiceEndpointBuilder azureBlob( String path) { return org.apache.camel.builder.endpoint.dsl.BlobServiceEndpointBuilderFactory.endpointBuilder("azure-blob", path); } @@ -2472,7 +2472,7 @@ public class StaticEndpointBuilders { * @param path containerOrBlobUri */ @Deprecated - static org.apache.camel.builder.endpoint.dsl.BlobServiceEndpointBuilderFactory.BlobServiceEndpointBuilder azureBlob( + public static org.apache.camel.builder.endpoint.dsl.BlobServiceEndpointBuilderFactory.BlobServiceEndpointBuilder azureBlob( String componentName, String path) { return org.apache.camel.builder.endpoint.dsl.BlobServiceEndpointBuilderFactory.endpointBuilder(componentName, path); diff --git a/core/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/Ddb2EndpointBuilderFactory.java b/core/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/Ddb2EndpointBuilderFactory.java index bd19b42..4221252 100644 --- a/core/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/Ddb2EndpointBuilderFactory.java +++ b/core/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/Ddb2EndpointBuilderFactory.java @@ -64,6 +64,35 @@ public interface Ddb2EndpointBuilderFactory { 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 Ddb2EndpointBuilder 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 Ddb2EndpointBuilder autoDiscoverClient(String autoDiscoverClient) { + doSetProperty("autoDiscoverClient", autoDiscoverClient); + return this; + } + /** * Determines whether or not strong consistency should be enforced when * data is read. *