You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ac...@apache.org on 2018/01/17 10:48:59 UTC
[camel] branch master updated: CAMEL-12151 - Camel-AWS CW: Add the
ability to specify credentials and region at component level
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
The following commit(s) were added to refs/heads/master by this push:
new c9666fe CAMEL-12151 - Camel-AWS CW: Add the ability to specify credentials and region at component level
c9666fe is described below
commit c9666fe25bf082ea41364d2d97bddb9b35b6cd44
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Wed Jan 17 11:47:52 2018 +0100
CAMEL-12151 - Camel-AWS CW: Add the ability to specify credentials and region at component level
---
.../camel-aws/src/main/docs/aws-cw-component.adoc | 14 +-
.../apache/camel/component/aws/cw/CwComponent.java | 72 +++++++-
.../camel/component/aws/cw/CwConfiguration.java | 12 ++
.../aws/cw/CwComponentConfigurationTest.java | 28 +++
.../cw/springboot/CwComponentConfiguration.java | 190 +++++++++++++++++++++
5 files changed, 312 insertions(+), 4 deletions(-)
diff --git a/components/camel-aws/src/main/docs/aws-cw-component.adoc b/components/camel-aws/src/main/docs/aws-cw-component.adoc
index 84b8c74..079f9db 100644
--- a/components/camel-aws/src/main/docs/aws-cw-component.adoc
+++ b/components/camel-aws/src/main/docs/aws-cw-component.adoc
@@ -28,7 +28,19 @@ The metrics will be created if they don't already exists. +
// component options: START
-The AWS CloudWatch component has no options.
+The AWS CloudWatch component supports 5 options which are listed below.
+
+
+
+[width="100%",cols="2,5,^1,2",options="header"]
+|===
+| Name | Description | Default | Type
+| *configuration* (advanced) | The AWS CW default configuration | | CwConfiguration
+| *accessKey* (producer) | Amazon AWS Access Key | | String
+| *secretKey* (producer) | Amazon AWS Secret Key | | String
+| *region* (producer) | The region in which CW client needs to work | | String
+| *resolveProperty Placeholders* (advanced) | Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders. | true | boolean
+|===
// component options: END
diff --git a/components/camel-aws/src/main/java/org/apache/camel/component/aws/cw/CwComponent.java b/components/camel-aws/src/main/java/org/apache/camel/component/aws/cw/CwComponent.java
index 5a3822e..6995b37 100644
--- a/components/camel-aws/src/main/java/org/apache/camel/component/aws/cw/CwComponent.java
+++ b/components/camel-aws/src/main/java/org/apache/camel/component/aws/cw/CwComponent.java
@@ -20,10 +20,22 @@ import java.util.Map;
import org.apache.camel.CamelContext;
import org.apache.camel.Endpoint;
+import org.apache.camel.component.aws.s3.S3Configuration;
import org.apache.camel.impl.DefaultComponent;
+import org.apache.camel.spi.Metadata;
+import org.apache.camel.util.ObjectHelper;
public class CwComponent extends DefaultComponent {
+ @Metadata
+ private String accessKey;
+ @Metadata
+ private String secretKey;
+ @Metadata
+ private String region;
+ @Metadata(label = "advanced")
+ private CwConfiguration configuration;
+
public CwComponent() {
this(null);
}
@@ -31,11 +43,12 @@ public class CwComponent extends DefaultComponent {
public CwComponent(CamelContext context) {
super(context);
+ this.configuration = new CwConfiguration();
registerExtension(new CwComponentVerifierExtension());
}
protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception {
- CwConfiguration configuration = new CwConfiguration();
+ CwConfiguration configuration = this.configuration.copy();
setProperties(configuration, parameters);
if (remaining == null || remaining.trim().length() == 0) {
@@ -43,11 +56,64 @@ public class CwComponent extends DefaultComponent {
}
configuration.setNamespace(remaining);
- if (configuration.getAmazonCwClient() == null) {
- throw new IllegalArgumentException("AmazonCwClient must be specified");
+ if (ObjectHelper.isEmpty(configuration.getAccessKey())) {
+ setAccessKey(accessKey);
+ }
+ if (ObjectHelper.isEmpty(configuration.getSecretKey())) {
+ setSecretKey(secretKey);
+ }
+ if (ObjectHelper.isEmpty(configuration.getRegion())) {
+ setRegion(region);
+ }
+ if (configuration.getAmazonCwClient() == null && (configuration.getAccessKey() == null || configuration.getSecretKey() == null)) {
+ throw new IllegalArgumentException("AmazonCwClient or accessKey and secretKey must be specified");
}
CwEndpoint endpoint = new CwEndpoint(uri, this, configuration);
return endpoint;
}
+
+ public CwConfiguration getConfiguration() {
+ return configuration;
+ }
+
+ /**
+ * The AWS CW default configuration
+ */
+ public void setConfiguration(CwConfiguration configuration) {
+ this.configuration = configuration;
+ }
+
+ public String getAccessKey() {
+ return configuration.getAccessKey();
+ }
+
+ /**
+ * Amazon AWS Access Key
+ */
+ public void setAccessKey(String accessKey) {
+ configuration.setAccessKey(accessKey);
+ }
+
+ public String getSecretKey() {
+ return configuration.getSecretKey();
+ }
+
+ /**
+ * Amazon AWS Secret Key
+ */
+ public void setSecretKey(String secretKey) {
+ configuration.setSecretKey(secretKey);
+ }
+
+ /**
+ * The region in which CW client needs to work
+ */
+ public String getRegion() {
+ return configuration.getRegion();
+ }
+
+ public void setRegion(String region) {
+ configuration.setRegion(region);
+ }
}
\ No newline at end of file
diff --git a/components/camel-aws/src/main/java/org/apache/camel/component/aws/cw/CwConfiguration.java b/components/camel-aws/src/main/java/org/apache/camel/component/aws/cw/CwConfiguration.java
index ba1104f..a1b0618 100644
--- a/components/camel-aws/src/main/java/org/apache/camel/component/aws/cw/CwConfiguration.java
+++ b/components/camel-aws/src/main/java/org/apache/camel/component/aws/cw/CwConfiguration.java
@@ -20,6 +20,7 @@ import java.util.Date;
import com.amazonaws.services.cloudwatch.AmazonCloudWatch;
+import org.apache.camel.RuntimeCamelException;
import org.apache.camel.spi.Metadata;
import org.apache.camel.spi.UriParam;
import org.apache.camel.spi.UriParams;
@@ -187,4 +188,15 @@ public class CwConfiguration implements Cloneable {
this.region = region;
}
+ // *************************************************
+ //
+ // *************************************************
+
+ public CwConfiguration copy() {
+ try {
+ return (CwConfiguration)super.clone();
+ } catch (CloneNotSupportedException e) {
+ throw new RuntimeCamelException(e);
+ }
+ }
}
\ No newline at end of file
diff --git a/components/camel-aws/src/test/java/org/apache/camel/component/aws/cw/CwComponentConfigurationTest.java b/components/camel-aws/src/test/java/org/apache/camel/component/aws/cw/CwComponentConfigurationTest.java
index d5db7e8..e95fab0 100644
--- a/components/camel-aws/src/test/java/org/apache/camel/component/aws/cw/CwComponentConfigurationTest.java
+++ b/components/camel-aws/src/test/java/org/apache/camel/component/aws/cw/CwComponentConfigurationTest.java
@@ -19,7 +19,9 @@ package org.apache.camel.component.aws.cw;
import java.util.Date;
+import com.amazonaws.regions.Regions;
import com.amazonaws.services.cloudwatch.AmazonCloudWatchClient;
+
import org.apache.camel.impl.JndiRegistry;
import org.apache.camel.test.junit4.CamelTestSupport;
import org.junit.Test;
@@ -59,6 +61,32 @@ public class CwComponentConfigurationTest extends CamelTestSupport {
CwComponent component = new CwComponent(context);
component.createEndpoint("aws-cw://camel.apache.org/test?amazonCwClient=#amazonCwClient&accessKey=xxx");
}
+
+ @Test
+ public void createEndpointWithComponentElements() throws Exception {
+ CwComponent component = new CwComponent(context);
+ component.setAccessKey("XXX");
+ component.setSecretKey("YYY");
+ CwEndpoint endpoint = (CwEndpoint)component.createEndpoint("aws-cw://camel.apache.org/test");
+
+ assertEquals("camel.apache.org/test", endpoint.getConfiguration().getNamespace());
+ assertEquals("XXX", endpoint.getConfiguration().getAccessKey());
+ assertEquals("YYY", endpoint.getConfiguration().getSecretKey());
+ }
+
+ @Test
+ public void createEndpointWithComponentAndEndpointElements() throws Exception {
+ CwComponent component = new CwComponent(context);
+ component.setAccessKey("XXX");
+ component.setSecretKey("YYY");
+ component.setRegion(Regions.US_WEST_1.toString());
+ CwEndpoint endpoint = (CwEndpoint)component.createEndpoint("aws-cw://camel.apache.org/test?accessKey=xxxxxx&secretKey=yyyyy®ion=US_EAST_1");
+
+ assertEquals("camel.apache.org/test", endpoint.getConfiguration().getNamespace());
+ assertEquals("xxxxxx", endpoint.getConfiguration().getAccessKey());
+ assertEquals("yyyyy", endpoint.getConfiguration().getSecretKey());
+ assertEquals("US_EAST_1", endpoint.getConfiguration().getRegion());
+ }
@Override
protected JndiRegistry createRegistry() throws Exception {
diff --git a/platforms/spring-boot/components-starter/camel-aws-starter/src/main/java/org/apache/camel/component/aws/cw/springboot/CwComponentConfiguration.java b/platforms/spring-boot/components-starter/camel-aws-starter/src/main/java/org/apache/camel/component/aws/cw/springboot/CwComponentConfiguration.java
index 950d9b9..f4b7887 100644
--- a/platforms/spring-boot/components-starter/camel-aws-starter/src/main/java/org/apache/camel/component/aws/cw/springboot/CwComponentConfiguration.java
+++ b/platforms/spring-boot/components-starter/camel-aws-starter/src/main/java/org/apache/camel/component/aws/cw/springboot/CwComponentConfiguration.java
@@ -16,7 +16,9 @@
*/
package org.apache.camel.component.aws.cw.springboot;
+import java.util.Date;
import javax.annotation.Generated;
+import com.amazonaws.services.cloudwatch.AmazonCloudWatch;
import org.apache.camel.spring.boot.ComponentConfigurationPropertiesCommon;
import org.springframework.boot.context.properties.ConfigurationProperties;
@@ -32,12 +34,61 @@ public class CwComponentConfiguration
ComponentConfigurationPropertiesCommon {
/**
+ * The AWS CW default configuration
+ */
+ private CwConfigurationNestedConfiguration configuration;
+ /**
+ * Amazon AWS Access Key
+ */
+ private String accessKey;
+ /**
+ * Amazon AWS Secret Key
+ */
+ private String secretKey;
+ /**
+ * The region in which CW client needs to work
+ */
+ private String region;
+ /**
* Whether the component should resolve property placeholders on itself when
* starting. Only properties which are of String type can use property
* placeholders.
*/
private Boolean resolvePropertyPlaceholders = true;
+ public CwConfigurationNestedConfiguration getConfiguration() {
+ return configuration;
+ }
+
+ public void setConfiguration(
+ CwConfigurationNestedConfiguration configuration) {
+ this.configuration = configuration;
+ }
+
+ public String getAccessKey() {
+ return accessKey;
+ }
+
+ public void setAccessKey(String accessKey) {
+ this.accessKey = accessKey;
+ }
+
+ public String getSecretKey() {
+ return secretKey;
+ }
+
+ public void setSecretKey(String secretKey) {
+ this.secretKey = secretKey;
+ }
+
+ public String getRegion() {
+ return region;
+ }
+
+ public void setRegion(String region) {
+ this.region = region;
+ }
+
public Boolean getResolvePropertyPlaceholders() {
return resolvePropertyPlaceholders;
}
@@ -46,4 +97,143 @@ public class CwComponentConfiguration
Boolean resolvePropertyPlaceholders) {
this.resolvePropertyPlaceholders = resolvePropertyPlaceholders;
}
+
+ public static class CwConfigurationNestedConfiguration {
+ public static final Class CAMEL_NESTED_CLASS = org.apache.camel.component.aws.cw.CwConfiguration.class;
+ /**
+ * The endpoint with which the AWS-CW client wants to work with.
+ */
+ private String amazonCwEndpoint;
+ /**
+ * Amazon AWS Access Key
+ */
+ private String accessKey;
+ /**
+ * Amazon AWS Secret Key
+ */
+ private String secretKey;
+ /**
+ * The metric name
+ */
+ private String name;
+ /**
+ * The metric value
+ */
+ private Double value;
+ /**
+ * The metric unit
+ */
+ private String unit;
+ /**
+ * The metric namespace
+ */
+ private String namespace;
+ /**
+ * The metric timestamp
+ */
+ private Date timestamp;
+ /**
+ * To use the AmazonCloudWatch as the client
+ */
+ private AmazonCloudWatch amazonCwClient;
+ private String proxyHost;
+ private Integer proxyPort;
+ private String region;
+
+ public String getAmazonCwEndpoint() {
+ return amazonCwEndpoint;
+ }
+
+ public void setAmazonCwEndpoint(String amazonCwEndpoint) {
+ this.amazonCwEndpoint = amazonCwEndpoint;
+ }
+
+ public String getAccessKey() {
+ return accessKey;
+ }
+
+ public void setAccessKey(String accessKey) {
+ this.accessKey = accessKey;
+ }
+
+ public String getSecretKey() {
+ return secretKey;
+ }
+
+ public void setSecretKey(String secretKey) {
+ this.secretKey = secretKey;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public Double getValue() {
+ return value;
+ }
+
+ public void setValue(Double value) {
+ this.value = value;
+ }
+
+ public String getUnit() {
+ return unit;
+ }
+
+ public void setUnit(String unit) {
+ this.unit = unit;
+ }
+
+ public String getNamespace() {
+ return namespace;
+ }
+
+ public void setNamespace(String namespace) {
+ this.namespace = namespace;
+ }
+
+ public Date getTimestamp() {
+ return timestamp;
+ }
+
+ public void setTimestamp(Date timestamp) {
+ this.timestamp = timestamp;
+ }
+
+ public AmazonCloudWatch getAmazonCwClient() {
+ return amazonCwClient;
+ }
+
+ public void setAmazonCwClient(AmazonCloudWatch amazonCwClient) {
+ this.amazonCwClient = amazonCwClient;
+ }
+
+ public String getProxyHost() {
+ return proxyHost;
+ }
+
+ public void setProxyHost(String proxyHost) {
+ this.proxyHost = proxyHost;
+ }
+
+ public Integer getProxyPort() {
+ return proxyPort;
+ }
+
+ public void setProxyPort(Integer proxyPort) {
+ this.proxyPort = proxyPort;
+ }
+
+ public String getRegion() {
+ return region;
+ }
+
+ public void setRegion(String region) {
+ this.region = region;
+ }
+ }
}
\ No newline at end of file
--
To stop receiving notification emails like this one, please contact
['"commits@camel.apache.org" <co...@camel.apache.org>'].