camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From acosent...@apache.org
Subject [camel] 01/02: CAMEL-12012 - Camel-AWS: Add component verifiers like S3 for all the AWS components - SWF Component
Date Tue, 21 Nov 2017 10:19:55 GMT
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 447f065b2ddfbd047744d89b20b3359847b03f71
Author: Andrea Cosentino <ancosen@gmail.com>
AuthorDate: Tue Nov 21 10:44:10 2017 +0100

    CAMEL-12012 - Camel-AWS: Add component verifiers like S3 for all the AWS components -
SWF Component
---
 .../camel-aws/src/main/docs/aws-swf-component.adoc |  3 +-
 .../camel/component/aws/swf/SWFComponent.java      | 13 +++-
 .../camel/component/aws/swf/SWFConfiguration.java  | 24 +++++-
 .../aws/swf/SwfComponentVerifierExtension.java     | 88 ++++++++++++++++++++++
 .../aws/swf/SwfComponentVerifierExtensionTest.java | 71 +++++++++++++++++
 5 files changed, 192 insertions(+), 7 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 2f81671..7d75f91 100644
--- a/components/camel-aws/src/main/docs/aws-swf-component.adoc
+++ b/components/camel-aws/src/main/docs/aws-swf-component.adoc
@@ -48,7 +48,7 @@ with the following path and query parameters:
 | *type* | *Required* Activity or workflow |  | String
 |===
 
-==== Query Parameters (29 parameters):
+==== Query Parameters (30 parameters):
 
 [width="100%",cols="2,5,^1,2",options="header"]
 |===
@@ -58,6 +58,7 @@ with the following path and query parameters:
 | *dataConverter* (common) | An instance of com.amazonaws.services.simpleworkflow.flow.DataConverter
to use for serializing/deserializing the data. |  | DataConverter
 | *domainName* (common) | The workflow domain to use. |  | String
 | *eventName* (common) | The workflow or activity event name to use. |  | String
+| *region* (common) | Amazon AWS Region. |  | String
 | *secretKey* (common) | Amazon AWS Secret Key. |  | String
 | *version* (common) | The workflow or activity event version to use. |  | String
 | *bridgeErrorHandler* (consumer) | Allows for bridging the consumer to the Camel routing
Error Handler which mean any exceptions occurred while the consumer is trying to pickup incoming
messages or the likes will now be processed as a message and handled by the routing Error
Handler. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal
with exceptions that will be logged at WARN or ERROR level and ignored. | false | boolean
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 62467ab..c7a1ef7 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
@@ -18,14 +18,21 @@ package org.apache.camel.component.aws.swf;
 
 import java.util.Map;
 
+import org.apache.camel.CamelContext;
 import org.apache.camel.Endpoint;
-import org.apache.camel.impl.UriEndpointComponent;
+import org.apache.camel.impl.DefaultComponent;
 import org.apache.camel.util.IntrospectionSupport;
 
-public class SWFComponent extends UriEndpointComponent {
+public class SWFComponent extends DefaultComponent {
 
     public SWFComponent() {
-        super(SWFEndpoint.class);
+        this(null);
+    }
+
+    public SWFComponent(CamelContext context) {
+        super(context);
+
+        registerExtension(new SwfComponentVerifierExtension());
     }
 
     protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object>
parameters) throws Exception {
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 e002935..4433a5f 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
@@ -24,6 +24,7 @@ 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.spi.Metadata;
 import org.apache.camel.spi.UriParam;
 import org.apache.camel.spi.UriParams;
@@ -32,7 +33,8 @@ import org.apache.camel.spi.UriPath;
 @UriParams
 public class SWFConfiguration {
 
-    @UriPath(enums = "activity,workflow") @Metadata(required = "true")
+    @UriPath(enums = "activity,workflow")
+    @Metadata(required = "true")
     private String type;
     @UriParam
     private AmazonSimpleWorkflowClient amazonSWClient;
@@ -42,6 +44,8 @@ public class SWFConfiguration {
     private String secretKey;
     @UriParam(label = "producer,workflow", defaultValue = "START", enums = "SIGNAL,CANCEL,TERMINATE,GET_STATE,START,DESCRIBE,GET_HISTORY")
     private String operation = "START";
+    @UriParam(label = "common")
+    private String region;
     @UriParam
     private String domainName;
     @UriParam(label = "consumer,activity")
@@ -108,6 +112,17 @@ public class SWFConfiguration {
         this.secretKey = secretKey;
     }
 
+    public String getRegion() {
+        return region;
+    }
+
+    /**
+     * Amazon AWS Region.
+     */
+    public void setRegion(String region) {
+        this.region = region;
+    }
+
     public String getDomainName() {
         return domainName;
     }
@@ -190,7 +205,8 @@ public class SWFConfiguration {
     }
 
     /**
-     * To configure the AmazonSimpleWorkflowClient using the key/values from the Map.
+     * To configure the AmazonSimpleWorkflowClient using the key/values from the
+     * Map.
      */
     public void setSWClientParameters(Map<String, Object> sWClientParameters) {
         this.sWClientParameters = sWClientParameters;
@@ -213,6 +229,7 @@ public class SWFConfiguration {
 
     /**
      * To configure the StartWorkflowOptions using the key/values from the Map.
+     * 
      * @param startWorkflowOptionsParameters
      */
     public void setStartWorkflowOptionsParameters(Map<String, Object> startWorkflowOptionsParameters)
{
@@ -312,7 +329,8 @@ public class SWFConfiguration {
     }
 
     /**
-     * An instance of com.amazonaws.services.simpleworkflow.flow.DataConverter to use for
serializing/deserializing the data.
+     * An instance of com.amazonaws.services.simpleworkflow.flow.DataConverter
+     * to use for serializing/deserializing the data.
      */
     public void setDataConverter(DataConverter dataConverter) {
         this.dataConverter = dataConverter;
diff --git a/components/camel-aws/src/main/java/org/apache/camel/component/aws/swf/SwfComponentVerifierExtension.java
b/components/camel-aws/src/main/java/org/apache/camel/component/aws/swf/SwfComponentVerifierExtension.java
new file mode 100644
index 0000000..b3fe815
--- /dev/null
+++ b/components/camel-aws/src/main/java/org/apache/camel/component/aws/swf/SwfComponentVerifierExtension.java
@@ -0,0 +1,88 @@
+/**
+ * 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 java.util.Map;
+
+import com.amazonaws.SdkClientException;
+import com.amazonaws.auth.AWSCredentials;
+import com.amazonaws.auth.AWSCredentialsProvider;
+import com.amazonaws.auth.AWSStaticCredentialsProvider;
+import com.amazonaws.auth.BasicAWSCredentials;
+import com.amazonaws.services.simpleworkflow.AmazonSimpleWorkflow;
+import com.amazonaws.services.simpleworkflow.AmazonSimpleWorkflowClientBuilder;
+import com.amazonaws.services.simpleworkflow.model.ListDomainsRequest;
+
+import org.apache.camel.component.extension.verifier.DefaultComponentVerifierExtension;
+import org.apache.camel.component.extension.verifier.ResultBuilder;
+import org.apache.camel.component.extension.verifier.ResultErrorBuilder;
+import org.apache.camel.component.extension.verifier.ResultErrorHelper;
+
+public class SwfComponentVerifierExtension extends DefaultComponentVerifierExtension {
+
+    public SwfComponentVerifierExtension() {
+        this("aws-swf");
+    }
+
+    public SwfComponentVerifierExtension(String scheme) {
+        super(scheme);
+    }
+
+    // *********************************
+    // Parameters validation
+    // *********************************
+
+    @Override
+    protected Result verifyParameters(Map<String, Object> parameters) {
+
+        ResultBuilder builder = ResultBuilder.withStatusAndScope(Result.Status.OK, Scope.PARAMETERS).error(ResultErrorHelper.requiresOption("accessKey",
parameters))
+            .error(ResultErrorHelper.requiresOption("secretKey", parameters)).error(ResultErrorHelper.requiresOption("region",
parameters));
+
+        // Validate using the catalog
+
+        super.verifyParametersAgainstCatalog(builder, parameters);
+
+        return builder.build();
+    }
+
+    // *********************************
+    // Connectivity validation
+    // *********************************
+
+    @Override
+    protected Result verifyConnectivity(Map<String, Object> parameters) {
+        ResultBuilder builder = ResultBuilder.withStatusAndScope(Result.Status.OK, Scope.CONNECTIVITY);
+
+        try {
+            SWFConfiguration configuration = setProperties(new SWFConfiguration(), parameters);
+            AWSCredentials credentials = new BasicAWSCredentials(configuration.getAccessKey(),
configuration.getSecretKey());
+            AWSCredentialsProvider credentialsProvider = new AWSStaticCredentialsProvider(credentials);
+            AmazonSimpleWorkflow client = AmazonSimpleWorkflowClientBuilder.standard().withCredentials(credentialsProvider).withRegion(configuration.getRegion()).build();
+            ListDomainsRequest listDomainsRequest = new ListDomainsRequest();
+            client.listDomains(listDomainsRequest);
+        } catch (SdkClientException e) {
+            ResultErrorBuilder errorBuilder = ResultErrorBuilder.withCodeAndDescription(VerificationError.StandardCode.AUTHENTICATION,
e.getMessage())
+                .detail("aws_swf_exception_message", e.getMessage()).detail(VerificationError.ExceptionAttribute.EXCEPTION_CLASS,
e.getClass().getName())
+                .detail(VerificationError.ExceptionAttribute.EXCEPTION_INSTANCE, e);
+
+            builder.error(errorBuilder.build());
+        } catch (Exception e) {
+            builder.error(ResultErrorBuilder.withException(e).build());
+        }
+        return builder.build();
+    }
+}
diff --git a/components/camel-aws/src/test/java/org/apache/camel/component/aws/swf/SwfComponentVerifierExtensionTest.java
b/components/camel-aws/src/test/java/org/apache/camel/component/aws/swf/SwfComponentVerifierExtensionTest.java
new file mode 100644
index 0000000..7cf38c1
--- /dev/null
+++ b/components/camel-aws/src/test/java/org/apache/camel/component/aws/swf/SwfComponentVerifierExtensionTest.java
@@ -0,0 +1,71 @@
+/**
+ * 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 java.util.HashMap;
+import java.util.Map;
+
+import org.apache.camel.Component;
+import org.apache.camel.component.extension.ComponentVerifierExtension;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class SwfComponentVerifierExtensionTest extends CamelTestSupport {
+
+    // *************************************************
+    // Tests (parameters)
+    // *************************************************
+    @Override
+    public boolean isUseRouteBuilder() {
+        return false;
+    }
+
+    @Test
+    public void testParameters() throws Exception {
+        Component component = context().getComponent("aws-swf");
+
+        ComponentVerifierExtension verifier = component.getExtension(ComponentVerifierExtension.class).orElseThrow(IllegalStateException::new);
+
+        Map<String, Object> parameters = new HashMap<>();
+        parameters.put("secretKey", "l");
+        parameters.put("accessKey", "k");
+        parameters.put("region", "l");
+        parameters.put("type", "activity");
+
+        ComponentVerifierExtension.Result result = verifier.verify(ComponentVerifierExtension.Scope.PARAMETERS,
parameters);
+
+        Assert.assertEquals(ComponentVerifierExtension.Result.Status.OK, result.getStatus());
+    }
+
+    @Test
+    public void testConnectivity() throws Exception {
+        Component component = context().getComponent("aws-swf");
+        ComponentVerifierExtension verifier = component.getExtension(ComponentVerifierExtension.class).orElseThrow(IllegalStateException::new);
+
+        Map<String, Object> parameters = new HashMap<>();
+        parameters.put("secretKey", "l");
+        parameters.put("accessKey", "k");
+        parameters.put("region", "us-east-1");
+        parameters.put("type", "activity");
+
+        ComponentVerifierExtension.Result result = verifier.verify(ComponentVerifierExtension.Scope.CONNECTIVITY,
parameters);
+
+        Assert.assertEquals(ComponentVerifierExtension.Result.Status.ERROR, result.getStatus());
+    }
+
+}

-- 
To stop receiving notification emails like this one, please contact
"commits@camel.apache.org" <commits@camel.apache.org>.

Mime
View raw message