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 374be4eedf61837b55598798afcdc6ecf86165ad Author: Andrea Cosentino <anco...@gmail.com> AuthorDate: Tue Jul 21 12:05:27 2020 +0200 CAMEL-15310 - AWS* - Support for more than 1 client in the registry - Camel-AWS-EC2 --- .../component/aws/ec2/EC2ComponentConfigurer.java | 5 ++++ .../component/aws/ec2/EC2EndpointConfigurer.java | 5 ++++ .../apache/camel/component/aws/ec2/aws-ec2.json | 2 ++ .../src/main/docs/aws-ec2-component.adoc | 6 +++-- .../camel/component/aws/ec2/EC2Component.java | 4 +++- .../camel/component/aws/ec2/EC2Configuration.java | 15 ++++++++++++ .../aws/ec2/EC2ComponentClientRegistryTest.java | 25 +++++++++++++++++++ .../dsl/AwsEc2ComponentBuilderFactory.java | 16 +++++++++++++ .../builder/endpoint/StaticEndpointBuilders.java | 8 +++---- .../endpoint/dsl/EC2EndpointBuilderFactory.java | 28 ++++++++++++++++++++++ 10 files changed, 107 insertions(+), 7 deletions(-) diff --git a/components/camel-aws-ec2/src/generated/java/org/apache/camel/component/aws/ec2/EC2ComponentConfigurer.java b/components/camel-aws-ec2/src/generated/java/org/apache/camel/component/aws/ec2/EC2ComponentConfigurer.java index f37d4d5..cf237d2 100644 --- a/components/camel-aws-ec2/src/generated/java/org/apache/camel/component/aws/ec2/EC2ComponentConfigurer.java +++ b/components/camel-aws-ec2/src/generated/java/org/apache/camel/component/aws/ec2/EC2ComponentConfigurer.java @@ -30,6 +30,8 @@ public class EC2ComponentConfigurer extends PropertyConfigurerSupport implements case "accessKey": getOrCreateConfiguration(target).setAccessKey(property(camelContext, java.lang.String.class, value)); return true; case "amazonec2client": case "amazonEc2Client": getOrCreateConfiguration(target).setAmazonEc2Client(property(camelContext, com.amazonaws.services.ec2.AmazonEC2.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.ec2.EC2Configuration.class, value)); return true; @@ -54,6 +56,7 @@ public class EC2ComponentConfigurer extends PropertyConfigurerSupport implements Map<String, Object> answer = new CaseInsensitiveMap(); answer.put("accessKey", java.lang.String.class); answer.put("amazonEc2Client", com.amazonaws.services.ec2.AmazonEC2.class); + answer.put("autoDiscoverClient", boolean.class); answer.put("basicPropertyBinding", boolean.class); answer.put("configuration", org.apache.camel.component.aws.ec2.EC2Configuration.class); answer.put("lazyStartProducer", boolean.class); @@ -74,6 +77,8 @@ public class EC2ComponentConfigurer extends PropertyConfigurerSupport implements case "accessKey": return getOrCreateConfiguration(target).getAccessKey(); case "amazonec2client": case "amazonEc2Client": return getOrCreateConfiguration(target).getAmazonEc2Client(); + 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-ec2/src/generated/java/org/apache/camel/component/aws/ec2/EC2EndpointConfigurer.java b/components/camel-aws-ec2/src/generated/java/org/apache/camel/component/aws/ec2/EC2EndpointConfigurer.java index e32e676..e0f4ee7 100644 --- a/components/camel-aws-ec2/src/generated/java/org/apache/camel/component/aws/ec2/EC2EndpointConfigurer.java +++ b/components/camel-aws-ec2/src/generated/java/org/apache/camel/component/aws/ec2/EC2EndpointConfigurer.java @@ -23,6 +23,8 @@ public class EC2EndpointConfigurer extends PropertyConfigurerSupport implements case "accessKey": target.getConfiguration().setAccessKey(property(camelContext, java.lang.String.class, value)); return true; case "amazonec2client": case "amazonEc2Client": target.getConfiguration().setAmazonEc2Client(property(camelContext, com.amazonaws.services.ec2.AmazonEC2.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 "lazystartproducer": @@ -47,6 +49,7 @@ public class EC2EndpointConfigurer extends PropertyConfigurerSupport implements Map<String, Object> answer = new CaseInsensitiveMap(); answer.put("accessKey", java.lang.String.class); answer.put("amazonEc2Client", com.amazonaws.services.ec2.AmazonEC2.class); + answer.put("autoDiscoverClient", boolean.class); answer.put("basicPropertyBinding", boolean.class); answer.put("lazyStartProducer", boolean.class); answer.put("operation", org.apache.camel.component.aws.ec2.EC2Operations.class); @@ -67,6 +70,8 @@ public class EC2EndpointConfigurer extends PropertyConfigurerSupport implements case "accessKey": return target.getConfiguration().getAccessKey(); case "amazonec2client": case "amazonEc2Client": return target.getConfiguration().getAmazonEc2Client(); + case "autodiscoverclient": + case "autoDiscoverClient": return target.getConfiguration().isAutoDiscoverClient(); case "basicpropertybinding": case "basicPropertyBinding": return target.isBasicPropertyBinding(); case "lazystartproducer": diff --git a/components/camel-aws-ec2/src/generated/resources/org/apache/camel/component/aws/ec2/aws-ec2.json b/components/camel-aws-ec2/src/generated/resources/org/apache/camel/component/aws/ec2/aws-ec2.json index 44f858f..6f727f2 100644 --- a/components/camel-aws-ec2/src/generated/resources/org/apache/camel/component/aws/ec2/aws-ec2.json +++ b/components/camel-aws-ec2/src/generated/resources/org/apache/camel/component/aws/ec2/aws-ec2.json @@ -21,6 +21,7 @@ "lenientProperties": false }, "componentProperties": { + "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.ec2.EC2Configuration", "configurationField": "configuration", "description": "Setting the autoDiscoverClient mechanism, if true, the component will look for a client instance in the registry [...] "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.aws.ec2.EC2Configuration", "configurationField": "configuration", "description": "Amazon AWS Access Key" }, "amazonEc2Client": { "kind": "property", "displayName": "Amazon Ec2 Client", "group": "producer", "label": "producer", "required": false, "type": "object", "javaType": "com.amazonaws.services.ec2.AmazonEC2", "deprecated": false, "secret": false, "configurationClass": "org.apache.camel.component.aws.ec2.EC2Configuration", "configurationField": "configuration", "description": "To use a existing configured AmazonEC2Client as client" }, "configuration": { "kind": "property", "displayName": "Configuration", "group": "producer", "label": "", "required": false, "type": "object", "javaType": "org.apache.camel.component.aws.ec2.EC2Configuration", "deprecated": false, "secret": false, "description": "The component configuration" }, @@ -35,6 +36,7 @@ }, "properties": { "label": { "kind": "path", "displayName": "Label", "group": "producer", "label": "", "required": true, "type": "string", "javaType": "java.lang.String", "deprecated": false, "deprecationNote": "", "secret": false, "configurationClass": "org.apache.camel.component.aws.ec2.EC2Configuration", "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.aws.ec2.EC2Configuration", "configurationField": "configuration", "description": "Setting the autoDiscoverClient mechanism, if true, the component will look for a client instance in the registr [...] "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.aws.ec2.EC2Configuration", "configurationField": "configuration", "description": "Amazon AWS Access Key" }, "amazonEc2Client": { "kind": "parameter", "displayName": "Amazon Ec2 Client", "group": "producer", "label": "producer", "required": false, "type": "object", "javaType": "com.amazonaws.services.ec2.AmazonEC2", "deprecated": false, "secret": false, "configurationClass": "org.apache.camel.component.aws.ec2.EC2Configuration", "configurationField": "configuration", "description": "To use a existing configured AmazonEC2Client as client" }, "lazyStartProducer": { "kind": "parameter", "displayName": "Lazy Start Producer", "group": "producer", "label": "producer", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "secret": false, "defaultValue": false, "description": "Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the [...] diff --git a/components/camel-aws-ec2/src/main/docs/aws-ec2-component.adoc b/components/camel-aws-ec2/src/main/docs/aws-ec2-component.adoc index a0faac1..4c5b40a 100644 --- a/components/camel-aws-ec2/src/main/docs/aws-ec2-component.adoc +++ b/components/camel-aws-ec2/src/main/docs/aws-ec2-component.adoc @@ -36,13 +36,14 @@ You can append query options to the URI in the following format, // component options: START -The AWS Elastic Compute Cloud (EC2) component supports 11 options, which are listed below. +The AWS Elastic Compute Cloud (EC2) component supports 12 options, which are listed below. [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 | *amazonEc2Client* (producer) | To use a existing configured AmazonEC2Client as client | | AmazonEC2 | *configuration* (producer) | The component configuration | | EC2Configuration @@ -79,12 +80,13 @@ with the following path and query parameters: |=== -=== Query Parameters (11 parameters): +=== Query Parameters (12 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 | *amazonEc2Client* (producer) | To use a existing configured AmazonEC2Client as client | | AmazonEC2 | *lazyStartProducer* (producer) | Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel's routing error handlers. Beware that when the first message is processed then creating and [...] diff --git a/components/camel-aws-ec2/src/main/java/org/apache/camel/component/aws/ec2/EC2Component.java b/components/camel-aws-ec2/src/main/java/org/apache/camel/component/aws/ec2/EC2Component.java index b726a19..5b641f7 100644 --- a/components/camel-aws-ec2/src/main/java/org/apache/camel/component/aws/ec2/EC2Component.java +++ b/components/camel-aws-ec2/src/main/java/org/apache/camel/component/aws/ec2/EC2Component.java @@ -51,7 +51,9 @@ public class EC2Component extends DefaultComponent { EC2Configuration configuration = this.configuration != null ? this.configuration.copy() : new EC2Configuration(); EC2Endpoint endpoint = new EC2Endpoint(uri, this, configuration); setProperties(endpoint, parameters); - checkAndSetRegistryClient(configuration); + if (endpoint.getConfiguration().isAutoDiscoverClient()) { + checkAndSetRegistryClient(configuration); + } if (configuration.getAmazonEc2Client() == null && (configuration.getAccessKey() == null || configuration.getSecretKey() == null)) { throw new IllegalArgumentException("amazonEC2Client or accessKey and secretKey must be specified"); } diff --git a/components/camel-aws-ec2/src/main/java/org/apache/camel/component/aws/ec2/EC2Configuration.java b/components/camel-aws-ec2/src/main/java/org/apache/camel/component/aws/ec2/EC2Configuration.java index f75f48c..7f52904 100644 --- a/components/camel-aws-ec2/src/main/java/org/apache/camel/component/aws/ec2/EC2Configuration.java +++ b/components/camel-aws-ec2/src/main/java/org/apache/camel/component/aws/ec2/EC2Configuration.java @@ -46,6 +46,8 @@ public class EC2Configuration implements Cloneable { private Integer proxyPort; @UriParam private String region; + @UriParam(label = "common", defaultValue = "true") + private boolean autoDiscoverClient = true; public AmazonEC2 getAmazonEc2Client() { return amazonEc2Client; @@ -140,6 +142,19 @@ public class EC2Configuration 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-ec2/src/test/java/org/apache/camel/component/aws/ec2/EC2ComponentClientRegistryTest.java b/components/camel-aws-ec2/src/test/java/org/apache/camel/component/aws/ec2/EC2ComponentClientRegistryTest.java index 9413673..46520ff 100644 --- a/components/camel-aws-ec2/src/test/java/org/apache/camel/component/aws/ec2/EC2ComponentClientRegistryTest.java +++ b/components/camel-aws-ec2/src/test/java/org/apache/camel/component/aws/ec2/EC2ComponentClientRegistryTest.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.assertNotNull; +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 EC2ComponentClientRegistryTest extends CamelTestSupport { @@ -42,4 +44,27 @@ public class EC2ComponentClientRegistryTest extends CamelTestSupport { assertThrows(IllegalArgumentException.class, () -> component.createEndpoint("aws-ec2://TestDomain")); } + + @Test + public void createEndpointWithAutoDiscoverClientFalse() throws Exception { + + AmazonEC2ClientMock clientMock = new AmazonEC2ClientMock(); + context.getRegistry().bind("amazonEc2Client", clientMock); + EC2Component component = context.getComponent("aws-ec2", EC2Component.class); + EC2Endpoint endpoint = (EC2Endpoint)component.createEndpoint("aws-ec2://TestDomain?accessKey=xxx&secretKey=yyy&autoDiscoverClient=false"); + + assertNotSame(clientMock, endpoint.getConfiguration().getAmazonEc2Client()); + } + + @Test + public void createEndpointWithAutoDiscoverClientTrue() throws Exception { + + AmazonEC2ClientMock clientMock = new AmazonEC2ClientMock(); + context.getRegistry().bind("amazonEc2Client", clientMock); + EC2Component component = context.getComponent("aws-ec2", EC2Component.class); + EC2Endpoint endpoint = (EC2Endpoint)component.createEndpoint("aws-ec2://TestDomain?accessKey=xxx&secretKey=yyy"); + + assertNotNull(endpoint.getConfiguration().getAmazonEc2Client()); + assertSame(clientMock, endpoint.getConfiguration().getAmazonEc2Client()); + } } diff --git a/core/camel-componentdsl/src/generated/java/org/apache/camel/builder/component/dsl/AwsEc2ComponentBuilderFactory.java b/core/camel-componentdsl/src/generated/java/org/apache/camel/builder/component/dsl/AwsEc2ComponentBuilderFactory.java index a40a4fd..17b4db2 100644 --- a/core/camel-componentdsl/src/generated/java/org/apache/camel/builder/component/dsl/AwsEc2ComponentBuilderFactory.java +++ b/core/camel-componentdsl/src/generated/java/org/apache/camel/builder/component/dsl/AwsEc2ComponentBuilderFactory.java @@ -47,6 +47,21 @@ public interface AwsEc2ComponentBuilderFactory { */ interface AwsEc2ComponentBuilder extends ComponentBuilder<EC2Component> { /** + * 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 AwsEc2ComponentBuilder autoDiscoverClient( + boolean autoDiscoverClient) { + doSetProperty("autoDiscoverClient", autoDiscoverClient); + return this; + } + /** * Amazon AWS Access Key. * * The option is a: <code>java.lang.String</code> type. @@ -219,6 +234,7 @@ public interface AwsEc2ComponentBuilderFactory { String name, Object value) { switch (name) { + case "autoDiscoverClient": getOrCreateConfiguration((EC2Component) component).setAutoDiscoverClient((boolean) value); return true; case "accessKey": getOrCreateConfiguration((EC2Component) component).setAccessKey((java.lang.String) value); return true; case "amazonEc2Client": getOrCreateConfiguration((EC2Component) component).setAmazonEc2Client((com.amazonaws.services.ec2.AmazonEC2) value); return true; case "configuration": ((EC2Component) component).setConfiguration((org.apache.camel.component.aws.ec2.EC2Configuration) 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 40b99a7..4b13182 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 */ - static org.apache.camel.builder.endpoint.dsl.Ddb2StreamEndpointBuilderFactory.Ddb2StreamEndpointBuilder aws2Ddbstream( + public 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 */ - static org.apache.camel.builder.endpoint.dsl.Ddb2StreamEndpointBuilderFactory.Ddb2StreamEndpointBuilder aws2Ddbstream( + public 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); @@ -1750,7 +1750,7 @@ public class StaticEndpointBuilders { * * @param path label */ - public static org.apache.camel.builder.endpoint.dsl.EC2EndpointBuilderFactory.EC2EndpointBuilder awsEc2( + static org.apache.camel.builder.endpoint.dsl.EC2EndpointBuilderFactory.EC2EndpointBuilder awsEc2( String path) { return org.apache.camel.builder.endpoint.dsl.EC2EndpointBuilderFactory.endpointBuilder("aws-ec2", path); } @@ -1771,7 +1771,7 @@ public class StaticEndpointBuilders { * instead of the default name * @param path label */ - public static org.apache.camel.builder.endpoint.dsl.EC2EndpointBuilderFactory.EC2EndpointBuilder awsEc2( + static org.apache.camel.builder.endpoint.dsl.EC2EndpointBuilderFactory.EC2EndpointBuilder awsEc2( String componentName, String path) { return org.apache.camel.builder.endpoint.dsl.EC2EndpointBuilderFactory.endpointBuilder(componentName, path); diff --git a/core/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/EC2EndpointBuilderFactory.java b/core/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/EC2EndpointBuilderFactory.java index 587e229..8056683 100644 --- a/core/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/EC2EndpointBuilderFactory.java +++ b/core/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/EC2EndpointBuilderFactory.java @@ -38,6 +38,34 @@ public interface EC2EndpointBuilderFactory { return (AdvancedEC2EndpointBuilder) 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 EC2EndpointBuilder 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 EC2EndpointBuilder autoDiscoverClient(String autoDiscoverClient) { + doSetProperty("autoDiscoverClient", autoDiscoverClient); + return this; + } + /** * Amazon AWS Access Key. * * The option is a: <code>java.lang.String</code> type.