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 d8da7a4917a5d1a5861e7c8034b4c5036718d0ac Author: Andrea Cosentino <anco...@gmail.com> AuthorDate: Tue Jul 28 10:50:27 2020 +0200 CAMEL-15310 - AWS* - Support for more than 1 client in the registry - Camel-AWS2-Athena --- .../aws2/athena/Athena2ComponentConfigurer.java | 5 ++++ .../aws2/athena/Athena2EndpointConfigurer.java | 5 ++++ .../camel/component/aws2/athena/aws2-athena.json | 2 ++ .../src/main/docs/aws2-athena-component.adoc | 6 +++-- .../component/aws2/athena/Athena2Component.java | 4 ++- .../aws2/athena/Athena2Configuration.java | 16 ++++++++++++ .../athena/AthenaComponentClientRegistryTest.java | 22 ++++++++++++++++ .../dsl/Aws2AthenaComponentBuilderFactory.java | 16 ++++++++++++ .../dsl/Athena2EndpointBuilderFactory.java | 30 ++++++++++++++++++++++ 9 files changed, 103 insertions(+), 3 deletions(-) diff --git a/components/camel-aws2-athena/src/generated/java/org/apache/camel/component/aws2/athena/Athena2ComponentConfigurer.java b/components/camel-aws2-athena/src/generated/java/org/apache/camel/component/aws2/athena/Athena2ComponentConfigurer.java index 1a6f70c..1f2c9ff 100644 --- a/components/camel-aws2-athena/src/generated/java/org/apache/camel/component/aws2/athena/Athena2ComponentConfigurer.java +++ b/components/camel-aws2-athena/src/generated/java/org/apache/camel/component/aws2/athena/Athena2ComponentConfigurer.java @@ -30,6 +30,8 @@ public class Athena2ComponentConfigurer extends PropertyConfigurerSupport implem case "accessKey": getOrCreateConfiguration(target).setAccessKey(property(camelContext, java.lang.String.class, value)); return true; case "amazonathenaclient": case "amazonAthenaClient": getOrCreateConfiguration(target).setAmazonAthenaClient(property(camelContext, software.amazon.awssdk.services.athena.AthenaClient.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 "clientrequesttoken": @@ -87,6 +89,7 @@ public class Athena2ComponentConfigurer extends PropertyConfigurerSupport implem Map<String, Object> answer = new CaseInsensitiveMap(); answer.put("accessKey", java.lang.String.class); answer.put("amazonAthenaClient", software.amazon.awssdk.services.athena.AthenaClient.class); + answer.put("autoDiscoverClient", boolean.class); answer.put("basicPropertyBinding", boolean.class); answer.put("clientRequestToken", java.lang.String.class); answer.put("configuration", org.apache.camel.component.aws2.athena.Athena2Configuration.class); @@ -125,6 +128,8 @@ public class Athena2ComponentConfigurer extends PropertyConfigurerSupport implem case "accessKey": return getOrCreateConfiguration(target).getAccessKey(); case "amazonathenaclient": case "amazonAthenaClient": return getOrCreateConfiguration(target).getAmazonAthenaClient(); + case "autodiscoverclient": + case "autoDiscoverClient": return getOrCreateConfiguration(target).isAutoDiscoverClient(); case "basicpropertybinding": case "basicPropertyBinding": return target.isBasicPropertyBinding(); case "clientrequesttoken": diff --git a/components/camel-aws2-athena/src/generated/java/org/apache/camel/component/aws2/athena/Athena2EndpointConfigurer.java b/components/camel-aws2-athena/src/generated/java/org/apache/camel/component/aws2/athena/Athena2EndpointConfigurer.java index 9641082..e3b871b 100644 --- a/components/camel-aws2-athena/src/generated/java/org/apache/camel/component/aws2/athena/Athena2EndpointConfigurer.java +++ b/components/camel-aws2-athena/src/generated/java/org/apache/camel/component/aws2/athena/Athena2EndpointConfigurer.java @@ -23,6 +23,8 @@ public class Athena2EndpointConfigurer extends PropertyConfigurerSupport impleme case "accessKey": target.getConfiguration().setAccessKey(property(camelContext, java.lang.String.class, value)); return true; case "amazonathenaclient": case "amazonAthenaClient": target.getConfiguration().setAmazonAthenaClient(property(camelContext, software.amazon.awssdk.services.athena.AthenaClient.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 "clientrequesttoken": @@ -80,6 +82,7 @@ public class Athena2EndpointConfigurer extends PropertyConfigurerSupport impleme Map<String, Object> answer = new CaseInsensitiveMap(); answer.put("accessKey", java.lang.String.class); answer.put("amazonAthenaClient", software.amazon.awssdk.services.athena.AthenaClient.class); + answer.put("autoDiscoverClient", boolean.class); answer.put("basicPropertyBinding", boolean.class); answer.put("clientRequestToken", java.lang.String.class); answer.put("database", java.lang.String.class); @@ -118,6 +121,8 @@ public class Athena2EndpointConfigurer extends PropertyConfigurerSupport impleme case "accessKey": return target.getConfiguration().getAccessKey(); case "amazonathenaclient": case "amazonAthenaClient": return target.getConfiguration().getAmazonAthenaClient(); + case "autodiscoverclient": + case "autoDiscoverClient": return target.getConfiguration().isAutoDiscoverClient(); case "basicpropertybinding": case "basicPropertyBinding": return target.isBasicPropertyBinding(); case "clientrequesttoken": diff --git a/components/camel-aws2-athena/src/generated/resources/org/apache/camel/component/aws2/athena/aws2-athena.json b/components/camel-aws2-athena/src/generated/resources/org/apache/camel/component/aws2/athena/aws2-athena.json index 9cf0701..beaef3c 100644 --- a/components/camel-aws2-athena/src/generated/resources/org/apache/camel/component/aws2/athena/aws2-athena.json +++ b/components/camel-aws2-athena/src/generated/resources/org/apache/camel/component/aws2/athena/aws2-athena.json @@ -23,6 +23,7 @@ "componentProperties": { "accessKey": { "kind": "property", "displayName": "Access Key", "group": "producer", "label": "producer", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "secret": true, "configurationClass": "org.apache.camel.component.aws2.athena.Athena2Configuration", "configurationField": "configuration", "description": "Amazon AWS Access Key." }, "amazonAthenaClient": { "kind": "property", "displayName": "Amazon Athena Client", "group": "producer", "label": "", "required": false, "type": "object", "javaType": "software.amazon.awssdk.services.athena.AthenaClient", "deprecated": false, "secret": false, "configurationClass": "org.apache.camel.component.aws2.athena.Athena2Configuration", "configurationField": "configuration", "description": "The AmazonAthena instance to use 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.athena.Athena2Configuration", "configurationField": "configuration", "description": "Setting the autoDiscoverClient mechanism, if true, the component will look for a client instance in the [...] "configuration": { "kind": "property", "displayName": "Configuration", "group": "producer", "label": "", "required": false, "type": "object", "javaType": "org.apache.camel.component.aws2.athena.Athena2Configuration", "deprecated": false, "secret": false, "description": "The component configuration." }, "database": { "kind": "property", "displayName": "Database", "group": "producer", "label": "producer", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "secret": false, "configurationClass": "org.apache.camel.component.aws2.athena.Athena2Configuration", "configurationField": "configuration", "description": "The Athena database to use." }, "delay": { "kind": "property", "displayName": "Delay", "group": "producer", "label": "producer", "required": false, "type": "integer", "javaType": "long", "deprecated": false, "secret": false, "defaultValue": "2000", "configurationClass": "org.apache.camel.component.aws2.athena.Athena2Configuration", "configurationField": "configuration", "description": "Milliseconds before the next poll for query execution status. See the section 'Waiting for Query Completion and Retrying Failed Que [...] @@ -53,6 +54,7 @@ }, "properties": { "label": { "kind": "path", "displayName": "Label", "group": "producer", "label": "producer", "required": true, "type": "string", "javaType": "java.lang.String", "deprecated": false, "deprecationNote": "", "secret": false, "configurationClass": "org.apache.camel.component.aws2.athena.Athena2Configuration", "configurationField": "configuration", "description": "Logical name" }, + "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.athena.Athena2Configuration", "configurationField": "configuration", "description": "Setting the autoDiscoverClient mechanism, if true, the component will look for a client instance in the [...] "accessKey": { "kind": "parameter", "displayName": "Access Key", "group": "producer", "label": "producer", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "secret": true, "configurationClass": "org.apache.camel.component.aws2.athena.Athena2Configuration", "configurationField": "configuration", "description": "Amazon AWS Access Key." }, "amazonAthenaClient": { "kind": "parameter", "displayName": "Amazon Athena Client", "group": "producer", "label": "", "required": false, "type": "object", "javaType": "software.amazon.awssdk.services.athena.AthenaClient", "deprecated": false, "secret": false, "configurationClass": "org.apache.camel.component.aws2.athena.Athena2Configuration", "configurationField": "configuration", "description": "The AmazonAthena instance to use as the client." }, "database": { "kind": "parameter", "displayName": "Database", "group": "producer", "label": "producer", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "secret": false, "configurationClass": "org.apache.camel.component.aws2.athena.Athena2Configuration", "configurationField": "configuration", "description": "The Athena database to use." }, diff --git a/components/camel-aws2-athena/src/main/docs/aws2-athena-component.adoc b/components/camel-aws2-athena/src/main/docs/aws2-athena-component.adoc index 0fe7946..f978a7d 100644 --- a/components/camel-aws2-athena/src/main/docs/aws2-athena-component.adoc +++ b/components/camel-aws2-athena/src/main/docs/aws2-athena-component.adoc @@ -59,7 +59,7 @@ from("direct:start") // component options: START -The AWS 2 Athena component supports 29 options, which are listed below. +The AWS 2 Athena component supports 30 options, which are listed below. @@ -68,6 +68,7 @@ The AWS 2 Athena component supports 29 options, which are listed below. | Name | Description | Default | Type | *accessKey* (producer) | Amazon AWS Access Key. | | String | *amazonAthenaClient* (producer) | The AmazonAthena instance to use as the client. | | AthenaClient +| *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. | | Athena2Configuration | *database* (producer) | The Athena database to use. | | String | *delay* (producer) | Milliseconds before the next poll for query execution status. See the section 'Waiting for Query Completion and Retrying Failed Queries' to learn more. | 2000 | long @@ -127,12 +128,13 @@ with the following path and query parameters: |=== -=== Query Parameters (29 parameters): +=== Query Parameters (30 parameters): [width="100%",cols="2,5,^1,2",options="header"] |=== | Name | Description | Default | Type +| *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 | *accessKey* (producer) | Amazon AWS Access Key. | | String | *amazonAthenaClient* (producer) | The AmazonAthena instance to use as the client. | | AthenaClient | *database* (producer) | The Athena database to use. | | String diff --git a/components/camel-aws2-athena/src/main/java/org/apache/camel/component/aws2/athena/Athena2Component.java b/components/camel-aws2-athena/src/main/java/org/apache/camel/component/aws2/athena/Athena2Component.java index 8343332..c5a0259 100644 --- a/components/camel-aws2-athena/src/main/java/org/apache/camel/component/aws2/athena/Athena2Component.java +++ b/components/camel-aws2-athena/src/main/java/org/apache/camel/component/aws2/athena/Athena2Component.java @@ -54,7 +54,9 @@ public class Athena2Component extends DefaultComponent { Athena2Configuration configuration = this.configuration != null ? this.configuration.copy() : new Athena2Configuration(); Athena2Endpoint endpoint = new Athena2Endpoint(uri, this, configuration); setProperties(endpoint, parameters); - checkAndSetRegistryClient(configuration, endpoint); + if (endpoint.getConfiguration().isAutoDiscoverClient()) { + checkAndSetRegistryClient(configuration, endpoint); + } if (configuration.getAmazonAthenaClient() == null && (configuration.getAccessKey() == null || configuration.getSecretKey() == null)) { throw new IllegalArgumentException("accessKey/secretKey or amazonAthenaClient must be specified"); diff --git a/components/camel-aws2-athena/src/main/java/org/apache/camel/component/aws2/athena/Athena2Configuration.java b/components/camel-aws2-athena/src/main/java/org/apache/camel/component/aws2/athena/Athena2Configuration.java index c18b62e..21e07ea 100644 --- a/components/camel-aws2-athena/src/main/java/org/apache/camel/component/aws2/athena/Athena2Configuration.java +++ b/components/camel-aws2-athena/src/main/java/org/apache/camel/component/aws2/athena/Athena2Configuration.java @@ -135,6 +135,9 @@ public class Athena2Configuration implements Cloneable { private Integer proxyPort; @UriParam private String region; + @UriParam(label = "common", defaultValue = "true", description = "Setting the autoDiscoverClient mechanism, if true, the component will " + + " look for a client instance in the registry automatically otherwise it will skip that checking") + private boolean autoDiscoverClient = true; public String getAccessKey() { return accessKey; @@ -443,6 +446,19 @@ public class Athena2Configuration implements Cloneable { public void setIncludeTrace(boolean includeTrace) { this.includeTrace = includeTrace; } + + 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-athena/src/test/java/org/apache/camel/component/aws2/athena/AthenaComponentClientRegistryTest.java b/components/camel-aws2-athena/src/test/java/org/apache/camel/component/aws2/athena/AthenaComponentClientRegistryTest.java index 84f8a7a..9484223 100644 --- a/components/camel-aws2-athena/src/test/java/org/apache/camel/component/aws2/athena/AthenaComponentClientRegistryTest.java +++ b/components/camel-aws2-athena/src/test/java/org/apache/camel/component/aws2/athena/AthenaComponentClientRegistryTest.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 AthenaComponentClientRegistryTest extends CamelTestSupport { @@ -39,4 +41,24 @@ public class AthenaComponentClientRegistryTest extends CamelTestSupport { Athena2Component component = context.getComponent("aws2-athena", Athena2Component.class); assertThrows(IllegalArgumentException.class, () -> component.createEndpoint("aws2-athena://label")); } + + @Test + public void createEndpointWithAutoDiscoverClientFalse() throws Exception { + AmazonAthenaClientMock clientMock = new AmazonAthenaClientMock(); + context.getRegistry().bind("amazonAthenaClient", clientMock); + Athena2Component component = context.getComponent("aws2-athena", Athena2Component.class); + Athena2Endpoint endpoint = (Athena2Endpoint) component.createEndpoint("aws2-athena://label?accessKey=xxx&secretKey=yyy&autoDiscoverClient=false"); + + assertNotSame(clientMock, endpoint.getConfiguration().getAmazonAthenaClient()); + } + + @Test + public void createEndpointWithAutoDiscoverClientTrue() throws Exception { + AmazonAthenaClientMock clientMock = new AmazonAthenaClientMock(); + context.getRegistry().bind("amazonAthenaClient", clientMock); + Athena2Component component = context.getComponent("aws2-athena", Athena2Component.class); + Athena2Endpoint endpoint = (Athena2Endpoint) component.createEndpoint("aws2-athena://label?accessKey=xxx&secretKey=yyy"); + + assertSame(clientMock, endpoint.getConfiguration().getAmazonAthenaClient()); + } } diff --git a/core/camel-componentdsl/src/generated/java/org/apache/camel/builder/component/dsl/Aws2AthenaComponentBuilderFactory.java b/core/camel-componentdsl/src/generated/java/org/apache/camel/builder/component/dsl/Aws2AthenaComponentBuilderFactory.java index bf06240..780e285 100644 --- a/core/camel-componentdsl/src/generated/java/org/apache/camel/builder/component/dsl/Aws2AthenaComponentBuilderFactory.java +++ b/core/camel-componentdsl/src/generated/java/org/apache/camel/builder/component/dsl/Aws2AthenaComponentBuilderFactory.java @@ -74,6 +74,21 @@ public interface Aws2AthenaComponentBuilderFactory { 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 Aws2AthenaComponentBuilder autoDiscoverClient( + boolean autoDiscoverClient) { + doSetProperty("autoDiscoverClient", autoDiscoverClient); + return this; + } + /** * The component configuration. * * The option is a: @@ -473,6 +488,7 @@ public interface Aws2AthenaComponentBuilderFactory { switch (name) { case "accessKey": getOrCreateConfiguration((Athena2Component) component).setAccessKey((java.lang.String) value); return true; case "amazonAthenaClient": getOrCreateConfiguration((Athena2Component) component).setAmazonAthenaClient((software.amazon.awssdk.services.athena.AthenaClient) value); return true; + case "autoDiscoverClient": getOrCreateConfiguration((Athena2Component) component).setAutoDiscoverClient((boolean) value); return true; case "configuration": ((Athena2Component) component).setConfiguration((org.apache.camel.component.aws2.athena.Athena2Configuration) value); return true; case "database": getOrCreateConfiguration((Athena2Component) component).setDatabase((java.lang.String) value); return true; case "delay": getOrCreateConfiguration((Athena2Component) component).setDelay((long) value); return true; diff --git a/core/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/Athena2EndpointBuilderFactory.java b/core/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/Athena2EndpointBuilderFactory.java index e7b2198..ef50b91 100644 --- a/core/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/Athena2EndpointBuilderFactory.java +++ b/core/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/Athena2EndpointBuilderFactory.java @@ -38,6 +38,36 @@ public interface Athena2EndpointBuilderFactory { return (AdvancedAthena2EndpointBuilder) 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 Athena2EndpointBuilder 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 Athena2EndpointBuilder autoDiscoverClient( + String autoDiscoverClient) { + doSetProperty("autoDiscoverClient", autoDiscoverClient); + return this; + } + /** * Amazon AWS Access Key. * * The option is a: <code>java.lang.String</code> type.