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 951b1840284ca7fd9f4971ddeb85f5081919fd82 Author: Andrea Cosentino <anco...@gmail.com> AuthorDate: Tue Jul 21 08:13:48 2020 +0200 CAMEL-15310 - AWS* - Support for more than 1 client in the registry - Camel-AWS-CW --- .../component/aws/cw/CwComponentConfigurer.java | 5 ++++ .../component/aws/cw/CwEndpointConfigurer.java | 5 ++++ .../org/apache/camel/component/aws/cw/aws-cw.json | 2 ++ .../src/main/docs/aws-cw-component.adoc | 6 +++-- .../apache/camel/component/aws/cw/CwComponent.java | 6 +++-- .../camel/component/aws/cw/CwConfiguration.java | 15 ++++++++++++ .../aws/cw/CwComponentRegistryClientTest.java | 24 +++++++++++++++++++ .../dsl/AwsCwComponentBuilderFactory.java | 16 +++++++++++++ .../builder/endpoint/StaticEndpointBuilders.java | 8 +++---- .../endpoint/dsl/CwEndpointBuilderFactory.java | 28 ++++++++++++++++++++++ 10 files changed, 107 insertions(+), 8 deletions(-) diff --git a/components/camel-aws-cw/src/generated/java/org/apache/camel/component/aws/cw/CwComponentConfigurer.java b/components/camel-aws-cw/src/generated/java/org/apache/camel/component/aws/cw/CwComponentConfigurer.java index c3cb310..ec3f2ce 100644 --- a/components/camel-aws-cw/src/generated/java/org/apache/camel/component/aws/cw/CwComponentConfigurer.java +++ b/components/camel-aws-cw/src/generated/java/org/apache/camel/component/aws/cw/CwComponentConfigurer.java @@ -30,6 +30,8 @@ public class CwComponentConfigurer extends PropertyConfigurerSupport implements case "accessKey": getOrCreateConfiguration(target).setAccessKey(property(camelContext, java.lang.String.class, value)); return true; case "amazoncwclient": case "amazonCwClient": getOrCreateConfiguration(target).setAmazonCwClient(property(camelContext, com.amazonaws.services.cloudwatch.AmazonCloudWatch.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.cw.CwConfiguration.class, value)); return true; @@ -57,6 +59,7 @@ public class CwComponentConfigurer extends PropertyConfigurerSupport implements Map<String, Object> answer = new CaseInsensitiveMap(); answer.put("accessKey", java.lang.String.class); answer.put("amazonCwClient", com.amazonaws.services.cloudwatch.AmazonCloudWatch.class); + answer.put("autoDiscoverClient", boolean.class); answer.put("basicPropertyBinding", boolean.class); answer.put("configuration", org.apache.camel.component.aws.cw.CwConfiguration.class); answer.put("lazyStartProducer", boolean.class); @@ -80,6 +83,8 @@ public class CwComponentConfigurer extends PropertyConfigurerSupport implements case "accessKey": return getOrCreateConfiguration(target).getAccessKey(); case "amazoncwclient": case "amazonCwClient": return getOrCreateConfiguration(target).getAmazonCwClient(); + 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-cw/src/generated/java/org/apache/camel/component/aws/cw/CwEndpointConfigurer.java b/components/camel-aws-cw/src/generated/java/org/apache/camel/component/aws/cw/CwEndpointConfigurer.java index b05d25d..8b86897 100644 --- a/components/camel-aws-cw/src/generated/java/org/apache/camel/component/aws/cw/CwEndpointConfigurer.java +++ b/components/camel-aws-cw/src/generated/java/org/apache/camel/component/aws/cw/CwEndpointConfigurer.java @@ -23,6 +23,8 @@ public class CwEndpointConfigurer extends PropertyConfigurerSupport implements G case "accessKey": target.getConfiguration().setAccessKey(property(camelContext, java.lang.String.class, value)); return true; case "amazoncwclient": case "amazonCwClient": target.getConfiguration().setAmazonCwClient(property(camelContext, com.amazonaws.services.cloudwatch.AmazonCloudWatch.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": @@ -50,6 +52,7 @@ public class CwEndpointConfigurer extends PropertyConfigurerSupport implements G Map<String, Object> answer = new CaseInsensitiveMap(); answer.put("accessKey", java.lang.String.class); answer.put("amazonCwClient", com.amazonaws.services.cloudwatch.AmazonCloudWatch.class); + answer.put("autoDiscoverClient", boolean.class); answer.put("basicPropertyBinding", boolean.class); answer.put("lazyStartProducer", boolean.class); answer.put("name", java.lang.String.class); @@ -73,6 +76,8 @@ public class CwEndpointConfigurer extends PropertyConfigurerSupport implements G case "accessKey": return target.getConfiguration().getAccessKey(); case "amazoncwclient": case "amazonCwClient": return target.getConfiguration().getAmazonCwClient(); + case "autodiscoverclient": + case "autoDiscoverClient": return target.getConfiguration().isAutoDiscoverClient(); case "basicpropertybinding": case "basicPropertyBinding": return target.isBasicPropertyBinding(); case "lazystartproducer": diff --git a/components/camel-aws-cw/src/generated/resources/org/apache/camel/component/aws/cw/aws-cw.json b/components/camel-aws-cw/src/generated/resources/org/apache/camel/component/aws/cw/aws-cw.json index ca4ebe0..4a7b445 100644 --- a/components/camel-aws-cw/src/generated/resources/org/apache/camel/component/aws/cw/aws-cw.json +++ b/components/camel-aws-cw/src/generated/resources/org/apache/camel/component/aws/cw/aws-cw.json @@ -22,6 +22,7 @@ }, "componentProperties": { "amazonCwClient": { "kind": "property", "displayName": "Amazon Cw Client", "group": "producer", "label": "", "required": false, "type": "object", "javaType": "com.amazonaws.services.cloudwatch.AmazonCloudWatch", "deprecated": false, "secret": false, "configurationClass": "org.apache.camel.component.aws.cw.CwConfiguration", "configurationField": "configuration", "description": "To use the AmazonCloudWatch 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.cw.CwConfiguration", "configurationField": "configuration", "description": "Setting the autoDiscoverClient mechanism, if true, the component will look for a client instance in the registry a [...] "configuration": { "kind": "property", "displayName": "Configuration", "group": "producer", "label": "", "required": false, "type": "object", "javaType": "org.apache.camel.component.aws.cw.CwConfiguration", "deprecated": false, "secret": false, "description": "The component configuration" }, "lazyStartProducer": { "kind": "property", "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 r [...] "name": { "kind": "property", "displayName": "Name", "group": "producer", "label": "", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "secret": false, "configurationClass": "org.apache.camel.component.aws.cw.CwConfiguration", "configurationField": "configuration", "description": "The metric name" }, @@ -39,6 +40,7 @@ "properties": { "namespace": { "kind": "path", "displayName": "Namespace", "group": "producer", "label": "", "required": true, "type": "string", "javaType": "java.lang.String", "deprecated": false, "deprecationNote": "", "secret": false, "configurationClass": "org.apache.camel.component.aws.cw.CwConfiguration", "configurationField": "configuration", "description": "The metric namespace" }, "amazonCwClient": { "kind": "parameter", "displayName": "Amazon Cw Client", "group": "producer", "label": "", "required": false, "type": "object", "javaType": "com.amazonaws.services.cloudwatch.AmazonCloudWatch", "deprecated": false, "secret": false, "configurationClass": "org.apache.camel.component.aws.cw.CwConfiguration", "configurationField": "configuration", "description": "To use the AmazonCloudWatch 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.cw.CwConfiguration", "configurationField": "configuration", "description": "Setting the autoDiscoverClient mechanism, if true, the component will look for a client instance in the registry [...] "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 [...] "name": { "kind": "parameter", "displayName": "Name", "group": "producer", "label": "", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "secret": false, "configurationClass": "org.apache.camel.component.aws.cw.CwConfiguration", "configurationField": "configuration", "description": "The metric name" }, "proxyHost": { "kind": "parameter", "displayName": "Proxy Host", "group": "producer", "label": "", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "secret": false, "configurationClass": "org.apache.camel.component.aws.cw.CwConfiguration", "configurationField": "configuration", "description": "To define a proxy host when instantiating the CW client" }, diff --git a/components/camel-aws-cw/src/main/docs/aws-cw-component.adoc b/components/camel-aws-cw/src/main/docs/aws-cw-component.adoc index 0da1476..ae218f4 100644 --- a/components/camel-aws-cw/src/main/docs/aws-cw-component.adoc +++ b/components/camel-aws-cw/src/main/docs/aws-cw-component.adoc @@ -39,7 +39,7 @@ The metrics will be created if they don't already exists. + // component options: START -The AWS CloudWatch component supports 14 options, which are listed below. +The AWS CloudWatch component supports 15 options, which are listed below. @@ -47,6 +47,7 @@ The AWS CloudWatch component supports 14 options, which are listed below. |=== | Name | Description | Default | Type | *amazonCwClient* (producer) | To use the AmazonCloudWatch as the client | | AmazonCloudWatch +| *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 | | CwConfiguration | *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 [...] | *name* (producer) | The metric name | | String @@ -85,13 +86,14 @@ with the following path and query parameters: |=== -=== Query Parameters (14 parameters): +=== Query Parameters (15 parameters): [width="100%",cols="2,5,^1,2",options="header"] |=== | Name | Description | Default | Type | *amazonCwClient* (producer) | To use the AmazonCloudWatch as the client | | AmazonCloudWatch +| *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 | *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 [...] | *name* (producer) | The metric name | | String | *proxyHost* (producer) | To define a proxy host when instantiating the CW client | | String diff --git a/components/camel-aws-cw/src/main/java/org/apache/camel/component/aws/cw/CwComponent.java b/components/camel-aws-cw/src/main/java/org/apache/camel/component/aws/cw/CwComponent.java index f90308b..ac61ebd 100644 --- a/components/camel-aws-cw/src/main/java/org/apache/camel/component/aws/cw/CwComponent.java +++ b/components/camel-aws-cw/src/main/java/org/apache/camel/component/aws/cw/CwComponent.java @@ -52,8 +52,10 @@ public class CwComponent extends DefaultComponent { CwEndpoint endpoint = new CwEndpoint(uri, this, configuration); setProperties(endpoint, parameters); - - checkAndSetRegistryClient(configuration); + + if (endpoint.getConfiguration().isAutoDiscoverClient()) { + checkAndSetRegistryClient(configuration); + } if (configuration.getAmazonCwClient() == null && (configuration.getAccessKey() == null || configuration.getSecretKey() == null)) { throw new IllegalArgumentException("AmazonCwClient or accessKey and secretKey must be specified"); } diff --git a/components/camel-aws-cw/src/main/java/org/apache/camel/component/aws/cw/CwConfiguration.java b/components/camel-aws-cw/src/main/java/org/apache/camel/component/aws/cw/CwConfiguration.java index 76a57b0..4fb815a 100644 --- a/components/camel-aws-cw/src/main/java/org/apache/camel/component/aws/cw/CwConfiguration.java +++ b/components/camel-aws-cw/src/main/java/org/apache/camel/component/aws/cw/CwConfiguration.java @@ -53,6 +53,8 @@ public class CwConfiguration implements Cloneable { private Integer proxyPort; @UriParam private String region; + @UriParam(label = "common", defaultValue = "true") + private boolean autoDiscoverClient = true; public String getAccessKey() { return accessKey; @@ -186,6 +188,19 @@ public class CwConfiguration implements Cloneable { public void setRegion(String region) { 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-cw/src/test/java/org/apache/camel/component/aws/cw/CwComponentRegistryClientTest.java b/components/camel-aws-cw/src/test/java/org/apache/camel/component/aws/cw/CwComponentRegistryClientTest.java index af7c117..4696d1f 100644 --- a/components/camel-aws-cw/src/test/java/org/apache/camel/component/aws/cw/CwComponentRegistryClientTest.java +++ b/components/camel-aws-cw/src/test/java/org/apache/camel/component/aws/cw/CwComponentRegistryClientTest.java @@ -24,6 +24,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; import static org.mockito.Mockito.mock; @@ -52,4 +54,26 @@ public class CwComponentRegistryClientTest extends CamelTestSupport { assertThrows(IllegalArgumentException.class, () -> component.createEndpoint("aws-cw://camel.apache.org/test")); } + + @Test + public void createEndpointWithAutoDiscoverClientFalse() throws Exception { + AmazonCloudWatchClient cloudWatchClient = mock(AmazonCloudWatchClient.class); + context.getRegistry().bind("amazonCwClient", cloudWatchClient); + CwComponent component = context.getComponent("aws-cw", CwComponent.class); + CwEndpoint endpoint = (CwEndpoint) component.createEndpoint("aws-cw://camel.apache.org/test?accessKey=xxx&secretKey=yyy&autoDiscoverClient=false"); + + assertEquals("camel.apache.org/test", endpoint.getConfiguration().getNamespace()); + assertNotSame(cloudWatchClient, endpoint.getConfiguration().getAmazonCwClient()); + } + + @Test + public void createEndpointWithAutoDiscoverClientTrue() throws Exception { + AmazonCloudWatchClient cloudWatchClient = mock(AmazonCloudWatchClient.class); + context.getRegistry().bind("amazonCwClient", cloudWatchClient); + CwComponent component = context.getComponent("aws-cw", CwComponent.class); + CwEndpoint endpoint = (CwEndpoint) component.createEndpoint("aws-cw://camel.apache.org/test?accessKey=xxx&secretKey=yyy"); + + assertEquals("camel.apache.org/test", endpoint.getConfiguration().getNamespace()); + assertSame(cloudWatchClient, endpoint.getConfiguration().getAmazonCwClient()); + } } diff --git a/core/camel-componentdsl/src/generated/java/org/apache/camel/builder/component/dsl/AwsCwComponentBuilderFactory.java b/core/camel-componentdsl/src/generated/java/org/apache/camel/builder/component/dsl/AwsCwComponentBuilderFactory.java index 6ce9731..38216cc 100644 --- a/core/camel-componentdsl/src/generated/java/org/apache/camel/builder/component/dsl/AwsCwComponentBuilderFactory.java +++ b/core/camel-componentdsl/src/generated/java/org/apache/camel/builder/component/dsl/AwsCwComponentBuilderFactory.java @@ -60,6 +60,21 @@ public interface AwsCwComponentBuilderFactory { 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 AwsCwComponentBuilder autoDiscoverClient( + boolean autoDiscoverClient) { + doSetProperty("autoDiscoverClient", autoDiscoverClient); + return this; + } + /** * The component configuration. * * The option is a: @@ -247,6 +262,7 @@ public interface AwsCwComponentBuilderFactory { Object value) { switch (name) { case "amazonCwClient": getOrCreateConfiguration((CwComponent) component).setAmazonCwClient((com.amazonaws.services.cloudwatch.AmazonCloudWatch) value); return true; + case "autoDiscoverClient": getOrCreateConfiguration((CwComponent) component).setAutoDiscoverClient((boolean) value); return true; case "configuration": ((CwComponent) component).setConfiguration((org.apache.camel.component.aws.cw.CwConfiguration) value); return true; case "lazyStartProducer": ((CwComponent) component).setLazyStartProducer((boolean) value); return true; case "name": getOrCreateConfiguration((CwComponent) component).setName((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 5031310..884a1a6 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 @@ -1417,7 +1417,7 @@ public class StaticEndpointBuilders { * * @param path //bucketNameOrArn */ - static org.apache.camel.builder.endpoint.dsl.AWS2S3EndpointBuilderFactory.AWS2S3EndpointBuilder aws2S3( + public static org.apache.camel.builder.endpoint.dsl.AWS2S3EndpointBuilderFactory.AWS2S3EndpointBuilder aws2S3( String path) { return org.apache.camel.builder.endpoint.dsl.AWS2S3EndpointBuilderFactory.endpointBuilder("aws2-s3", path); } @@ -1439,7 +1439,7 @@ public class StaticEndpointBuilders { * instead of the default name * @param path //bucketNameOrArn */ - static org.apache.camel.builder.endpoint.dsl.AWS2S3EndpointBuilderFactory.AWS2S3EndpointBuilder aws2S3( + public static org.apache.camel.builder.endpoint.dsl.AWS2S3EndpointBuilderFactory.AWS2S3EndpointBuilder aws2S3( String componentName, String path) { return org.apache.camel.builder.endpoint.dsl.AWS2S3EndpointBuilderFactory.endpointBuilder(componentName, path); @@ -1627,7 +1627,7 @@ public class StaticEndpointBuilders { * * @param path namespace */ - public static org.apache.camel.builder.endpoint.dsl.CwEndpointBuilderFactory.CwEndpointBuilder awsCw( + static org.apache.camel.builder.endpoint.dsl.CwEndpointBuilderFactory.CwEndpointBuilder awsCw( String path) { return org.apache.camel.builder.endpoint.dsl.CwEndpointBuilderFactory.endpointBuilder("aws-cw", path); } @@ -1648,7 +1648,7 @@ public class StaticEndpointBuilders { * instead of the default name * @param path namespace */ - public static org.apache.camel.builder.endpoint.dsl.CwEndpointBuilderFactory.CwEndpointBuilder awsCw( + static org.apache.camel.builder.endpoint.dsl.CwEndpointBuilderFactory.CwEndpointBuilder awsCw( String componentName, String path) { return org.apache.camel.builder.endpoint.dsl.CwEndpointBuilderFactory.endpointBuilder(componentName, path); diff --git a/core/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/CwEndpointBuilderFactory.java b/core/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/CwEndpointBuilderFactory.java index 02d531a..528233d 100644 --- a/core/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/CwEndpointBuilderFactory.java +++ b/core/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/CwEndpointBuilderFactory.java @@ -63,6 +63,34 @@ public interface CwEndpointBuilderFactory { 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 CwEndpointBuilder 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 CwEndpointBuilder autoDiscoverClient(String autoDiscoverClient) { + doSetProperty("autoDiscoverClient", autoDiscoverClient); + return this; + } + /** * 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