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 3b696fd1df4181d6c7c3af3d9e11af769a18e9c8 Author: Andrea Cosentino <anco...@gmail.com> AuthorDate: Wed Jul 22 08:46:43 2020 +0200 CAMEL-15310 - AWS* - Support for more than 1 client in the registry - Camel-AWS-EKS --- .../component/aws/eks/EKSComponentConfigurer.java | 5 ++++ .../component/aws/eks/EKSEndpointConfigurer.java | 5 ++++ .../apache/camel/component/aws/eks/aws-eks.json | 2 ++ .../src/main/docs/aws-eks-component.adoc | 6 +++-- .../camel/component/aws/eks/EKSComponent.java | 4 +++- .../camel/component/aws/eks/EKSConfiguration.java | 15 ++++++++++++ .../aws/eks/EKSComponentClientRegistryTest.java | 24 +++++++++++++++++++ .../dsl/AwsEksComponentBuilderFactory.java | 16 +++++++++++++ .../builder/endpoint/StaticEndpointBuilders.java | 8 +++---- .../endpoint/dsl/EKSEndpointBuilderFactory.java | 28 ++++++++++++++++++++++ 10 files changed, 106 insertions(+), 7 deletions(-) diff --git a/components/camel-aws-eks/src/generated/java/org/apache/camel/component/aws/eks/EKSComponentConfigurer.java b/components/camel-aws-eks/src/generated/java/org/apache/camel/component/aws/eks/EKSComponentConfigurer.java index 9529b52..4a4e76a 100644 --- a/components/camel-aws-eks/src/generated/java/org/apache/camel/component/aws/eks/EKSComponentConfigurer.java +++ b/components/camel-aws-eks/src/generated/java/org/apache/camel/component/aws/eks/EKSComponentConfigurer.java @@ -28,6 +28,8 @@ public class EKSComponentConfigurer extends PropertyConfigurerSupport implements switch (ignoreCase ? name.toLowerCase() : name) { case "accesskey": case "accessKey": getOrCreateConfiguration(target).setAccessKey(property(camelContext, java.lang.String.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.eks.EKSConfiguration.class, value)); return true; @@ -53,6 +55,7 @@ public class EKSComponentConfigurer extends PropertyConfigurerSupport implements public Map<String, Object> getAllOptions(Object target) { Map<String, Object> answer = new CaseInsensitiveMap(); answer.put("accessKey", java.lang.String.class); + answer.put("autoDiscoverClient", boolean.class); answer.put("basicPropertyBinding", boolean.class); answer.put("configuration", org.apache.camel.component.aws.eks.EKSConfiguration.class); answer.put("eksClient", com.amazonaws.services.eks.AmazonEKS.class); @@ -72,6 +75,8 @@ public class EKSComponentConfigurer extends PropertyConfigurerSupport implements switch (ignoreCase ? name.toLowerCase() : name) { case "accesskey": case "accessKey": return getOrCreateConfiguration(target).getAccessKey(); + 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-eks/src/generated/java/org/apache/camel/component/aws/eks/EKSEndpointConfigurer.java b/components/camel-aws-eks/src/generated/java/org/apache/camel/component/aws/eks/EKSEndpointConfigurer.java index caaff33..603c378 100644 --- a/components/camel-aws-eks/src/generated/java/org/apache/camel/component/aws/eks/EKSEndpointConfigurer.java +++ b/components/camel-aws-eks/src/generated/java/org/apache/camel/component/aws/eks/EKSEndpointConfigurer.java @@ -21,6 +21,8 @@ public class EKSEndpointConfigurer extends PropertyConfigurerSupport implements switch (ignoreCase ? name.toLowerCase() : name) { case "accesskey": case "accessKey": target.getConfiguration().setAccessKey(property(camelContext, java.lang.String.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 "eksclient": @@ -46,6 +48,7 @@ public class EKSEndpointConfigurer extends PropertyConfigurerSupport implements public Map<String, Object> getAllOptions(Object target) { Map<String, Object> answer = new CaseInsensitiveMap(); answer.put("accessKey", java.lang.String.class); + answer.put("autoDiscoverClient", boolean.class); answer.put("basicPropertyBinding", boolean.class); answer.put("eksClient", com.amazonaws.services.eks.AmazonEKS.class); answer.put("lazyStartProducer", boolean.class); @@ -65,6 +68,8 @@ public class EKSEndpointConfigurer extends PropertyConfigurerSupport implements switch (ignoreCase ? name.toLowerCase() : name) { case "accesskey": case "accessKey": return target.getConfiguration().getAccessKey(); + case "autodiscoverclient": + case "autoDiscoverClient": return target.getConfiguration().isAutoDiscoverClient(); case "basicpropertybinding": case "basicPropertyBinding": return target.isBasicPropertyBinding(); case "eksclient": diff --git a/components/camel-aws-eks/src/generated/resources/org/apache/camel/component/aws/eks/aws-eks.json b/components/camel-aws-eks/src/generated/resources/org/apache/camel/component/aws/eks/aws-eks.json index 05dd4b9..fb77502 100644 --- a/components/camel-aws-eks/src/generated/resources/org/apache/camel/component/aws/eks/aws-eks.json +++ b/components/camel-aws-eks/src/generated/resources/org/apache/camel/component/aws/eks/aws-eks.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.eks.EKSConfiguration", "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.eks.EKSConfiguration", "configurationField": "configuration", "description": "Amazon AWS Access Key" }, "configuration": { "kind": "property", "displayName": "Configuration", "group": "producer", "label": "", "required": false, "type": "object", "javaType": "org.apache.camel.component.aws.eks.EKSConfiguration", "deprecated": false, "secret": false, "description": "The component configuration" }, "eksClient": { "kind": "property", "displayName": "Eks Client", "group": "producer", "label": "producer", "required": false, "type": "object", "javaType": "com.amazonaws.services.eks.AmazonEKS", "deprecated": false, "secret": false, "configurationClass": "org.apache.camel.component.aws.eks.EKSConfiguration", "configurationField": "configuration", "description": "To use a existing configured AWS EKS as client" }, @@ -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.eks.EKSConfiguration", "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.eks.EKSConfiguration", "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.eks.EKSConfiguration", "configurationField": "configuration", "description": "Amazon AWS Access Key" }, "eksClient": { "kind": "parameter", "displayName": "Eks Client", "group": "producer", "label": "producer", "required": false, "type": "object", "javaType": "com.amazonaws.services.eks.AmazonEKS", "deprecated": false, "secret": false, "configurationClass": "org.apache.camel.component.aws.eks.EKSConfiguration", "configurationField": "configuration", "description": "To use a existing configured AWS EKS 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-eks/src/main/docs/aws-eks-component.adoc b/components/camel-aws-eks/src/main/docs/aws-eks-component.adoc index 20b33a7..2a6b447 100644 --- a/components/camel-aws-eks/src/main/docs/aws-eks-component.adoc +++ b/components/camel-aws-eks/src/main/docs/aws-eks-component.adoc @@ -36,13 +36,14 @@ You can append query options to the URI in the following format, // component options: START -The AWS Elastic Kubernetes Service (EKS) component supports 11 options, which are listed below. +The AWS Elastic Kubernetes Service (EKS) 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 | *configuration* (producer) | The component configuration | | EKSConfiguration | *eksClient* (producer) | To use a existing configured AWS EKS as client | | AmazonEKS @@ -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 | *eksClient* (producer) | To use a existing configured AWS EKS as client | | AmazonEKS | *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-eks/src/main/java/org/apache/camel/component/aws/eks/EKSComponent.java b/components/camel-aws-eks/src/main/java/org/apache/camel/component/aws/eks/EKSComponent.java index e94311e..8bd24dd 100644 --- a/components/camel-aws-eks/src/main/java/org/apache/camel/component/aws/eks/EKSComponent.java +++ b/components/camel-aws-eks/src/main/java/org/apache/camel/component/aws/eks/EKSComponent.java @@ -50,7 +50,9 @@ public class EKSComponent extends DefaultComponent { EKSConfiguration configuration = this.configuration != null ? this.configuration.copy() : new EKSConfiguration(); EKSEndpoint endpoint = new EKSEndpoint(uri, this, configuration); setProperties(endpoint, parameters); - checkAndSetRegistryClient(configuration); + if (endpoint.getConfiguration().isAutoDiscoverClient()) { + checkAndSetRegistryClient(configuration); + } if (configuration.getEksClient() == null && (configuration.getAccessKey() == null || configuration.getSecretKey() == null)) { throw new IllegalArgumentException("Amazon eks client or accessKey and secretKey must be specified"); } diff --git a/components/camel-aws-eks/src/main/java/org/apache/camel/component/aws/eks/EKSConfiguration.java b/components/camel-aws-eks/src/main/java/org/apache/camel/component/aws/eks/EKSConfiguration.java index 8ed11d2..95c364a 100644 --- a/components/camel-aws-eks/src/main/java/org/apache/camel/component/aws/eks/EKSConfiguration.java +++ b/components/camel-aws-eks/src/main/java/org/apache/camel/component/aws/eks/EKSConfiguration.java @@ -47,6 +47,8 @@ public class EKSConfiguration implements Cloneable { private Integer proxyPort; @UriParam private String region; + @UriParam(label = "common", defaultValue = "true") + private boolean autoDiscoverClient = true; public AmazonEKS getEksClient() { return eksClient; @@ -137,6 +139,19 @@ public class EKSConfiguration 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-eks/src/test/java/org/apache/camel/component/aws/eks/EKSComponentClientRegistryTest.java b/components/camel-aws-eks/src/test/java/org/apache/camel/component/aws/eks/EKSComponentClientRegistryTest.java index 421c94c..8c70e8f 100644 --- a/components/camel-aws-eks/src/test/java/org/apache/camel/component/aws/eks/EKSComponentClientRegistryTest.java +++ b/components/camel-aws-eks/src/test/java/org/apache/camel/component/aws/eks/EKSComponentClientRegistryTest.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 EKSComponentClientRegistryTest extends CamelTestSupport { @@ -42,4 +44,26 @@ public class EKSComponentClientRegistryTest extends CamelTestSupport { assertThrows(IllegalArgumentException.class, () -> component.createEndpoint("aws-eks://TestDomain")); } + + @Test + public void createEndpointWithAutoDiscoverClientFalse() throws Exception { + + AmazonEKSClientMock clientMock = new AmazonEKSClientMock(); + context.getRegistry().bind("amazonEcsClient", clientMock); + EKSComponent component = context.getComponent("aws-eks", EKSComponent.class); + EKSEndpoint endpoint = (EKSEndpoint)component.createEndpoint("aws-eks://TestDomain?accessKey=xxx&secretKey=yyyy&autoDiscoverClient=false"); + + assertNotSame(clientMock, endpoint.getConfiguration().getEksClient()); + } + + @Test + public void createEndpointWithAutoDiscoverClientTrue() throws Exception { + + AmazonEKSClientMock clientMock = new AmazonEKSClientMock(); + context.getRegistry().bind("amazonEcsClient", clientMock); + EKSComponent component = context.getComponent("aws-eks", EKSComponent.class); + EKSEndpoint endpoint = (EKSEndpoint)component.createEndpoint("aws-eks://TestDomain?accessKey=xxx&secretKey=yyyy"); + + assertSame(clientMock, endpoint.getConfiguration().getEksClient()); + } } diff --git a/core/camel-componentdsl/src/generated/java/org/apache/camel/builder/component/dsl/AwsEksComponentBuilderFactory.java b/core/camel-componentdsl/src/generated/java/org/apache/camel/builder/component/dsl/AwsEksComponentBuilderFactory.java index 3c96478..5cf9f8f 100644 --- a/core/camel-componentdsl/src/generated/java/org/apache/camel/builder/component/dsl/AwsEksComponentBuilderFactory.java +++ b/core/camel-componentdsl/src/generated/java/org/apache/camel/builder/component/dsl/AwsEksComponentBuilderFactory.java @@ -47,6 +47,21 @@ public interface AwsEksComponentBuilderFactory { */ interface AwsEksComponentBuilder extends ComponentBuilder<EKSComponent> { /** + * 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 AwsEksComponentBuilder autoDiscoverClient( + boolean autoDiscoverClient) { + doSetProperty("autoDiscoverClient", autoDiscoverClient); + return this; + } + /** * Amazon AWS Access Key. * * The option is a: <code>java.lang.String</code> type. @@ -216,6 +231,7 @@ public interface AwsEksComponentBuilderFactory { String name, Object value) { switch (name) { + case "autoDiscoverClient": getOrCreateConfiguration((EKSComponent) component).setAutoDiscoverClient((boolean) value); return true; case "accessKey": getOrCreateConfiguration((EKSComponent) component).setAccessKey((java.lang.String) value); return true; case "configuration": ((EKSComponent) component).setConfiguration((org.apache.camel.component.aws.eks.EKSConfiguration) value); return true; case "eksClient": getOrCreateConfiguration((EKSComponent) component).setEksClient((com.amazonaws.services.eks.AmazonEKS) 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 69ce7bd..1800fe8 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 @@ -1832,7 +1832,7 @@ public class StaticEndpointBuilders { * * @param path label */ - public static org.apache.camel.builder.endpoint.dsl.EKSEndpointBuilderFactory.EKSEndpointBuilder awsEks( + static org.apache.camel.builder.endpoint.dsl.EKSEndpointBuilderFactory.EKSEndpointBuilder awsEks( String path) { return org.apache.camel.builder.endpoint.dsl.EKSEndpointBuilderFactory.endpointBuilder("aws-eks", path); } @@ -1853,7 +1853,7 @@ public class StaticEndpointBuilders { * instead of the default name * @param path label */ - public static org.apache.camel.builder.endpoint.dsl.EKSEndpointBuilderFactory.EKSEndpointBuilder awsEks( + static org.apache.camel.builder.endpoint.dsl.EKSEndpointBuilderFactory.EKSEndpointBuilder awsEks( String componentName, String path) { return org.apache.camel.builder.endpoint.dsl.EKSEndpointBuilderFactory.endpointBuilder(componentName, path); @@ -15475,7 +15475,7 @@ public class StaticEndpointBuilders { * * @param path serverUrls/path */ - static org.apache.camel.builder.endpoint.dsl.ZooKeeperEndpointBuilderFactory.ZooKeeperEndpointBuilder zookeeper( + public static org.apache.camel.builder.endpoint.dsl.ZooKeeperEndpointBuilderFactory.ZooKeeperEndpointBuilder zookeeper( String path) { return org.apache.camel.builder.endpoint.dsl.ZooKeeperEndpointBuilderFactory.endpointBuilder("zookeeper", path); } @@ -15499,7 +15499,7 @@ public class StaticEndpointBuilders { * instead of the default name * @param path serverUrls/path */ - static org.apache.camel.builder.endpoint.dsl.ZooKeeperEndpointBuilderFactory.ZooKeeperEndpointBuilder zookeeper( + public static org.apache.camel.builder.endpoint.dsl.ZooKeeperEndpointBuilderFactory.ZooKeeperEndpointBuilder zookeeper( String componentName, String path) { return org.apache.camel.builder.endpoint.dsl.ZooKeeperEndpointBuilderFactory.endpointBuilder(componentName, path); diff --git a/core/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/EKSEndpointBuilderFactory.java b/core/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/EKSEndpointBuilderFactory.java index 77f2198..57f950a 100644 --- a/core/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/EKSEndpointBuilderFactory.java +++ b/core/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/EKSEndpointBuilderFactory.java @@ -39,6 +39,34 @@ public interface EKSEndpointBuilderFactory { return (AdvancedEKSEndpointBuilder) 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 EKSEndpointBuilder 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 EKSEndpointBuilder autoDiscoverClient(String autoDiscoverClient) { + doSetProperty("autoDiscoverClient", autoDiscoverClient); + return this; + } + /** * Amazon AWS Access Key. * * The option is a: <code>java.lang.String</code> type.