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/15 10:48:15 UTC
[camel] 01/03: CAMEL-12145 - Camel-AWS SWF: 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
commit e9802d3b77194a659330d2b1c0c543e709fc8339
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Mon Jan 15 11:45:02 2018 +0100
CAMEL-12145 - Camel-AWS SWF: Add the ability to specify credentials and region at component level
---
.../camel-aws/src/main/docs/aws-swf-component.adoc | 14 +-
.../camel/component/aws/swf/SWFComponent.java | 68 +++-
.../camel/component/aws/swf/SWFConfiguration.java | 15 +-
.../aws/swf/SWFComponentConfigurationTest.java | 51 +++
.../swf/springboot/SWFComponentConfiguration.java | 398 +++++++++++++++++++++
5 files changed, 543 insertions(+), 3 deletions(-)
diff --git a/components/camel-aws/src/main/docs/aws-swf-component.adoc b/components/camel-aws/src/main/docs/aws-swf-component.adoc
index 7d75f91..d4677e1 100644
--- a/components/camel-aws/src/main/docs/aws-swf-component.adoc
+++ b/components/camel-aws/src/main/docs/aws-swf-component.adoc
@@ -25,7 +25,19 @@ You can append query options to the URI in the following format,
// component options: START
-The AWS Simple Workflow component has no options.
+The AWS Simple Workflow 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 SWF default configuration | | SWFConfiguration
+| *accessKey* (common) | Amazon AWS Access Key. | | String
+| *secretKey* (common) | Amazon AWS Secret Key. | | String
+| *region* (common) | Amazon AWS Region. | | 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/swf/SWFComponent.java b/components/camel-aws/src/main/java/org/apache/camel/component/aws/swf/SWFComponent.java
index c7a1ef7..2fb6798 100644
--- a/components/camel-aws/src/main/java/org/apache/camel/component/aws/swf/SWFComponent.java
+++ b/components/camel-aws/src/main/java/org/apache/camel/component/aws/swf/SWFComponent.java
@@ -21,10 +21,21 @@ import java.util.Map;
import org.apache.camel.CamelContext;
import org.apache.camel.Endpoint;
import org.apache.camel.impl.DefaultComponent;
+import org.apache.camel.spi.Metadata;
import org.apache.camel.util.IntrospectionSupport;
+import org.apache.camel.util.ObjectHelper;
public class SWFComponent extends DefaultComponent {
+ @Metadata
+ private String accessKey;
+ @Metadata
+ private String secretKey;
+ @Metadata
+ private String region;
+ @Metadata(label = "advanced")
+ private SWFConfiguration configuration;
+
public SWFComponent() {
this(null);
}
@@ -32,6 +43,7 @@ public class SWFComponent extends DefaultComponent {
public SWFComponent(CamelContext context) {
super(context);
+ this.configuration = new SWFConfiguration();
registerExtension(new SwfComponentVerifierExtension());
}
@@ -40,13 +52,67 @@ public class SWFComponent extends DefaultComponent {
Map<String, Object> sWClientParameters = IntrospectionSupport.extractProperties(parameters, "sWClient.");
Map<String, Object> startWorkflowOptionsParameters = IntrospectionSupport.extractProperties(parameters, "startWorkflowOptions.");
- SWFConfiguration configuration = new SWFConfiguration();
+ SWFConfiguration configuration = this.configuration.copy();
configuration.setType(remaining);
setProperties(configuration, parameters);
configuration.setClientConfigurationParameters(clientConfigurationParameters);
configuration.setSWClientParameters(sWClientParameters);
configuration.setStartWorkflowOptionsParameters(startWorkflowOptionsParameters);
+
+ if (ObjectHelper.isEmpty(configuration.getAccessKey())) {
+ setAccessKey(accessKey);
+ }
+ if (ObjectHelper.isEmpty(configuration.getSecretKey())) {
+ setSecretKey(secretKey);
+ }
+ if (ObjectHelper.isEmpty(configuration.getRegion())) {
+ setRegion(region);
+ }
return new SWFEndpoint(uri, this, configuration);
}
+
+ public SWFConfiguration getConfiguration() {
+ return configuration;
+ }
+
+ /**
+ * The AWS SWF default configuration
+ */
+ public void setConfiguration(SWFConfiguration 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);
+ }
+
+ public String getRegion() {
+ return configuration.getRegion();
+ }
+
+ /**
+ * Amazon AWS Region.
+ */
+ public void setRegion(String region) {
+ configuration.setRegion(region);
+ }
}
diff --git a/components/camel-aws/src/main/java/org/apache/camel/component/aws/swf/SWFConfiguration.java b/components/camel-aws/src/main/java/org/apache/camel/component/aws/swf/SWFConfiguration.java
index 4433a5f..6d86c29 100644
--- a/components/camel-aws/src/main/java/org/apache/camel/component/aws/swf/SWFConfiguration.java
+++ b/components/camel-aws/src/main/java/org/apache/camel/component/aws/swf/SWFConfiguration.java
@@ -25,13 +25,14 @@ import com.amazonaws.services.simpleworkflow.flow.WorkflowTypeRegistrationOption
import com.amazonaws.services.simpleworkflow.flow.worker.ActivityTypeExecutionOptions;
import com.amazonaws.services.simpleworkflow.flow.worker.ActivityTypeRegistrationOptions;
+import org.apache.camel.RuntimeCamelException;
import org.apache.camel.spi.Metadata;
import org.apache.camel.spi.UriParam;
import org.apache.camel.spi.UriParams;
import org.apache.camel.spi.UriPath;
@UriParams
-public class SWFConfiguration {
+public class SWFConfiguration implements Cloneable {
@UriPath(enums = "activity,workflow")
@Metadata(required = "true")
@@ -390,4 +391,16 @@ public class SWFConfiguration {
public void setTaskStartToCloseTimeout(String taskStartToCloseTimeout) {
this.taskStartToCloseTimeout = taskStartToCloseTimeout;
}
+
+ // *************************************************
+ //
+ // *************************************************
+
+ public SWFConfiguration copy() {
+ try {
+ return (SWFConfiguration)super.clone();
+ } catch (CloneNotSupportedException e) {
+ throw new RuntimeCamelException(e);
+ }
+ }
}
diff --git a/components/camel-aws/src/test/java/org/apache/camel/component/aws/swf/SWFComponentConfigurationTest.java b/components/camel-aws/src/test/java/org/apache/camel/component/aws/swf/SWFComponentConfigurationTest.java
new file mode 100644
index 0000000..9ee8da6
--- /dev/null
+++ b/components/camel-aws/src/test/java/org/apache/camel/component/aws/swf/SWFComponentConfigurationTest.java
@@ -0,0 +1,51 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.aws.swf;
+
+import com.amazonaws.regions.Regions;
+
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Test;
+
+public class SWFComponentConfigurationTest extends CamelTestSupport {
+
+ @Test
+ public void createEndpointWithComponentElements() throws Exception {
+ SWFComponent component = new SWFComponent(context);
+ component.setAccessKey("XXX");
+ component.setSecretKey("YYY");
+ SWFEndpoint endpoint = (SWFEndpoint)component.createEndpoint("aws-swf://workflow");
+
+ assertEquals("workflow", endpoint.getConfiguration().getType());
+ assertEquals("XXX", endpoint.getConfiguration().getAccessKey());
+ assertEquals("YYY", endpoint.getConfiguration().getSecretKey());
+ }
+
+ @Test
+ public void createEndpointWithComponentAndEndpointElements() throws Exception {
+ SWFComponent component = new SWFComponent(context);
+ component.setAccessKey("XXX");
+ component.setSecretKey("YYY");
+ component.setRegion(Regions.US_WEST_1.toString());
+ SWFEndpoint endpoint = (SWFEndpoint)component.createEndpoint("aws-swf://workflow?accessKey=xxxxxx&secretKey=yyyyy®ion=US_EAST_1");
+
+ assertEquals("workflow", endpoint.getConfiguration().getType());
+ assertEquals("xxxxxx", endpoint.getConfiguration().getAccessKey());
+ assertEquals("yyyyy", endpoint.getConfiguration().getSecretKey());
+ assertEquals("US_EAST_1", endpoint.getConfiguration().getRegion());
+ }
+}
diff --git a/platforms/spring-boot/components-starter/camel-aws-starter/src/main/java/org/apache/camel/component/aws/swf/springboot/SWFComponentConfiguration.java b/platforms/spring-boot/components-starter/camel-aws-starter/src/main/java/org/apache/camel/component/aws/swf/springboot/SWFComponentConfiguration.java
index 10623c9..c78b7d2 100644
--- a/platforms/spring-boot/components-starter/camel-aws-starter/src/main/java/org/apache/camel/component/aws/swf/springboot/SWFComponentConfiguration.java
+++ b/platforms/spring-boot/components-starter/camel-aws-starter/src/main/java/org/apache/camel/component/aws/swf/springboot/SWFComponentConfiguration.java
@@ -16,9 +16,17 @@
*/
package org.apache.camel.component.aws.swf.springboot;
+import java.util.Map;
import javax.annotation.Generated;
+import com.amazonaws.services.simpleworkflow.AmazonSimpleWorkflowClient;
+import com.amazonaws.services.simpleworkflow.flow.ActivitySchedulingOptions;
+import com.amazonaws.services.simpleworkflow.flow.DataConverter;
+import com.amazonaws.services.simpleworkflow.flow.WorkflowTypeRegistrationOptions;
+import com.amazonaws.services.simpleworkflow.flow.worker.ActivityTypeExecutionOptions;
+import com.amazonaws.services.simpleworkflow.flow.worker.ActivityTypeRegistrationOptions;
import org.apache.camel.spring.boot.ComponentConfigurationPropertiesCommon;
import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.boot.context.properties.NestedConfigurationProperty;
/**
* The aws-swf component is used for managing workflows from Amazon Simple
@@ -33,12 +41,61 @@ public class SWFComponentConfiguration
ComponentConfigurationPropertiesCommon {
/**
+ * The AWS SWF default configuration
+ */
+ private SWFConfigurationNestedConfiguration configuration;
+ /**
+ * Amazon AWS Access Key.
+ */
+ private String accessKey;
+ /**
+ * Amazon AWS Secret Key.
+ */
+ private String secretKey;
+ /**
+ * Amazon AWS Region.
+ */
+ 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 SWFConfigurationNestedConfiguration getConfiguration() {
+ return configuration;
+ }
+
+ public void setConfiguration(
+ SWFConfigurationNestedConfiguration 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;
}
@@ -47,4 +104,345 @@ public class SWFComponentConfiguration
Boolean resolvePropertyPlaceholders) {
this.resolvePropertyPlaceholders = resolvePropertyPlaceholders;
}
+
+ public static class SWFConfigurationNestedConfiguration {
+ public static final Class CAMEL_NESTED_CLASS = org.apache.camel.component.aws.swf.SWFConfiguration.class;
+ /**
+ * Amazon AWS Access Key.
+ */
+ private String accessKey;
+ /**
+ * Amazon AWS Secret Key.
+ */
+ private String secretKey;
+ /**
+ * Amazon AWS Region.
+ */
+ private String region;
+ /**
+ * The workflow domain to use.
+ */
+ private String domainName;
+ /**
+ * The list name to consume activities from.
+ */
+ private String activityList;
+ /**
+ * The list name to consume workflows from.
+ */
+ private String workflowList;
+ /**
+ * The workflow or activity event name to use.
+ */
+ private String eventName;
+ /**
+ * The workflow or activity event version to use.
+ */
+ private String version;
+ /**
+ * Activity or workflow
+ */
+ private String type;
+ /**
+ * To configure the ClientConfiguration using the key/values from the
+ * Map.
+ */
+ private Map clientConfigurationParameters;
+ /**
+ * To configure the AmazonSimpleWorkflowClient using the key/values from
+ * the Map.
+ */
+ private Map sWClientParameters;
+ /**
+ * To use the given AmazonSimpleWorkflowClient as client
+ */
+ @NestedConfigurationProperty
+ private AmazonSimpleWorkflowClient amazonSWClient;
+ /**
+ * To configure the StartWorkflowOptions using the key/values from the
+ * Map.
+ *
+ * @param startWorkflowOptionsParameters
+ */
+ private Map startWorkflowOptionsParameters;
+ /**
+ * Workflow operation
+ */
+ private String operation = "START";
+ /**
+ * The name of the signal to send to the workflow.
+ */
+ private String signalName;
+ /**
+ * The policy to use on child workflows when terminating a workflow.
+ */
+ private String childPolicy;
+ /**
+ * The reason for terminating a workflow.
+ */
+ private String terminationReason;
+ /**
+ * The type of the result when a workflow state is queried.
+ */
+ private String stateResultType;
+ /**
+ * Details for terminating a workflow.
+ */
+ private String terminationDetails;
+ /**
+ * Activity execution options
+ */
+ @NestedConfigurationProperty
+ private ActivityTypeExecutionOptions activityTypeExecutionOptions;
+ /**
+ * Activity registration options
+ */
+ @NestedConfigurationProperty
+ private ActivityTypeRegistrationOptions activityTypeRegistrationOptions;
+ /**
+ * An instance of
+ * com.amazonaws.services.simpleworkflow.flow.DataConverter to use for
+ * serializing/deserializing the data.
+ */
+ private DataConverter dataConverter;
+ /**
+ * Workflow registration options
+ */
+ @NestedConfigurationProperty
+ private WorkflowTypeRegistrationOptions workflowTypeRegistrationOptions;
+ /**
+ * Activity scheduling options
+ */
+ @NestedConfigurationProperty
+ private ActivitySchedulingOptions activitySchedulingOptions;
+ /**
+ * Maximum number of threads in work pool for activity.
+ */
+ private Integer activityThreadPoolSize = 100;
+ private String executionStartToCloseTimeout = "3600";
+ private String taskStartToCloseTimeout = "600";
+
+ 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 String getDomainName() {
+ return domainName;
+ }
+
+ public void setDomainName(String domainName) {
+ this.domainName = domainName;
+ }
+
+ public String getActivityList() {
+ return activityList;
+ }
+
+ public void setActivityList(String activityList) {
+ this.activityList = activityList;
+ }
+
+ public String getWorkflowList() {
+ return workflowList;
+ }
+
+ public void setWorkflowList(String workflowList) {
+ this.workflowList = workflowList;
+ }
+
+ public String getEventName() {
+ return eventName;
+ }
+
+ public void setEventName(String eventName) {
+ this.eventName = eventName;
+ }
+
+ public String getVersion() {
+ return version;
+ }
+
+ public void setVersion(String version) {
+ this.version = version;
+ }
+
+ public String getType() {
+ return type;
+ }
+
+ public void setType(String type) {
+ this.type = type;
+ }
+
+ public Map getClientConfigurationParameters() {
+ return clientConfigurationParameters;
+ }
+
+ public void setClientConfigurationParameters(
+ Map clientConfigurationParameters) {
+ this.clientConfigurationParameters = clientConfigurationParameters;
+ }
+
+ public Map getSWClientParameters() {
+ return sWClientParameters;
+ }
+
+ public void setSWClientParameters(Map sWClientParameters) {
+ this.sWClientParameters = sWClientParameters;
+ }
+
+ public AmazonSimpleWorkflowClient getAmazonSWClient() {
+ return amazonSWClient;
+ }
+
+ public void setAmazonSWClient(AmazonSimpleWorkflowClient amazonSWClient) {
+ this.amazonSWClient = amazonSWClient;
+ }
+
+ public Map getStartWorkflowOptionsParameters() {
+ return startWorkflowOptionsParameters;
+ }
+
+ public void setStartWorkflowOptionsParameters(
+ Map startWorkflowOptionsParameters) {
+ this.startWorkflowOptionsParameters = startWorkflowOptionsParameters;
+ }
+
+ public String getOperation() {
+ return operation;
+ }
+
+ public void setOperation(String operation) {
+ this.operation = operation;
+ }
+
+ public String getSignalName() {
+ return signalName;
+ }
+
+ public void setSignalName(String signalName) {
+ this.signalName = signalName;
+ }
+
+ public String getChildPolicy() {
+ return childPolicy;
+ }
+
+ public void setChildPolicy(String childPolicy) {
+ this.childPolicy = childPolicy;
+ }
+
+ public String getTerminationReason() {
+ return terminationReason;
+ }
+
+ public void setTerminationReason(String terminationReason) {
+ this.terminationReason = terminationReason;
+ }
+
+ public String getStateResultType() {
+ return stateResultType;
+ }
+
+ public void setStateResultType(String stateResultType) {
+ this.stateResultType = stateResultType;
+ }
+
+ public String getTerminationDetails() {
+ return terminationDetails;
+ }
+
+ public void setTerminationDetails(String terminationDetails) {
+ this.terminationDetails = terminationDetails;
+ }
+
+ public ActivityTypeExecutionOptions getActivityTypeExecutionOptions() {
+ return activityTypeExecutionOptions;
+ }
+
+ public void setActivityTypeExecutionOptions(
+ ActivityTypeExecutionOptions activityTypeExecutionOptions) {
+ this.activityTypeExecutionOptions = activityTypeExecutionOptions;
+ }
+
+ public ActivityTypeRegistrationOptions getActivityTypeRegistrationOptions() {
+ return activityTypeRegistrationOptions;
+ }
+
+ public void setActivityTypeRegistrationOptions(
+ ActivityTypeRegistrationOptions activityTypeRegistrationOptions) {
+ this.activityTypeRegistrationOptions = activityTypeRegistrationOptions;
+ }
+
+ public DataConverter getDataConverter() {
+ return dataConverter;
+ }
+
+ public void setDataConverter(DataConverter dataConverter) {
+ this.dataConverter = dataConverter;
+ }
+
+ public WorkflowTypeRegistrationOptions getWorkflowTypeRegistrationOptions() {
+ return workflowTypeRegistrationOptions;
+ }
+
+ public void setWorkflowTypeRegistrationOptions(
+ WorkflowTypeRegistrationOptions workflowTypeRegistrationOptions) {
+ this.workflowTypeRegistrationOptions = workflowTypeRegistrationOptions;
+ }
+
+ public ActivitySchedulingOptions getActivitySchedulingOptions() {
+ return activitySchedulingOptions;
+ }
+
+ public void setActivitySchedulingOptions(
+ ActivitySchedulingOptions activitySchedulingOptions) {
+ this.activitySchedulingOptions = activitySchedulingOptions;
+ }
+
+ public Integer getActivityThreadPoolSize() {
+ return activityThreadPoolSize;
+ }
+
+ public void setActivityThreadPoolSize(Integer activityThreadPoolSize) {
+ this.activityThreadPoolSize = activityThreadPoolSize;
+ }
+
+ public String getExecutionStartToCloseTimeout() {
+ return executionStartToCloseTimeout;
+ }
+
+ public void setExecutionStartToCloseTimeout(
+ String executionStartToCloseTimeout) {
+ this.executionStartToCloseTimeout = executionStartToCloseTimeout;
+ }
+
+ public String getTaskStartToCloseTimeout() {
+ return taskStartToCloseTimeout;
+ }
+
+ public void setTaskStartToCloseTimeout(String taskStartToCloseTimeout) {
+ this.taskStartToCloseTimeout = taskStartToCloseTimeout;
+ }
+ }
}
\ No newline at end of file
--
To stop receiving notification emails like this one, please contact
"commits@camel.apache.org" <co...@camel.apache.org>.