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 2022/09/09 13:01:55 UTC
[camel] branch main updated (3786ef8423e -> ac43ba265c9)
This is an automated email from the ASF dual-hosted git repository.
acosentino pushed a change to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
from 3786ef8423e AWS2-S3 Health Check: Consider even the case of a provided S3 Client
new a7f912c70bf CAMEL-18466 - Camel-AWS2-SQS: Move from ComponentVerifierExtension to HealtCheck
new cabdc69d100 CAMEL-18466 - Camel-AWS2-SQS: Move from ComponentVerifierExtension to HealtCheck
new ef597ca6c7a CAMEL-18466 - Camel-AWS2-SQS: Move from ComponentVerifierExtension to HealtCheck
new c33c6372cfe CAMEL-18466 - Camel-AWS2-SQS: Move from ComponentVerifierExtension to HealtCheck
new fb944daeee3 CAMEL-18466 - Camel-AWS2-SQS: Move from ComponentVerifierExtension to HealtCheck
new ac43ba265c9 CAMEL-18466 - Camel-AWS2-SQS: Move from ComponentVerifierExtension to HealtCheck
The 6 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
components/camel-aws/camel-aws2-sqs/pom.xml | 4 +
.../camel/health-check/camel-aws2-sqs-repository | 2 +
.../camel/component/aws2/sqs/Sqs2Component.java | 2 -
.../aws2/sqs/Sqs2ComponentVerifierExtension.java | 94 ------------------
.../camel/component/aws2/sqs/Sqs2Consumer.java | 12 +++
.../aws2/sqs/Sqs2ConsumerHealthCheck.java | 87 +++++++++++++++++
.../aws2/sqs/Sqs2HealthCheckRepository.java | 83 ++++++++++++++++
.../Sqs2ConsumerHealthCheckCustomClientTest.java | 107 +++++++++++++++++++++
.../Sqs2ConsumerHealthCheckProfileCredsTest.java | 107 +++++++++++++++++++++
.../Sqs2ConsumerHealthCheckStaticCredsTest.java | 107 +++++++++++++++++++++
.../sqs/SqsComponentVerifierExtensionTest.java | 90 -----------------
11 files changed, 509 insertions(+), 186 deletions(-)
create mode 100644 components/camel-aws/camel-aws2-sqs/src/generated/resources/META-INF/services/org/apache/camel/health-check/camel-aws2-sqs-repository
delete mode 100644 components/camel-aws/camel-aws2-sqs/src/main/java/org/apache/camel/component/aws2/sqs/Sqs2ComponentVerifierExtension.java
create mode 100644 components/camel-aws/camel-aws2-sqs/src/main/java/org/apache/camel/component/aws2/sqs/Sqs2ConsumerHealthCheck.java
create mode 100644 components/camel-aws/camel-aws2-sqs/src/main/java/org/apache/camel/component/aws2/sqs/Sqs2HealthCheckRepository.java
create mode 100644 components/camel-aws/camel-aws2-sqs/src/test/java/org/apache/camel/component/aws2/sqs/Sqs2ConsumerHealthCheckCustomClientTest.java
create mode 100644 components/camel-aws/camel-aws2-sqs/src/test/java/org/apache/camel/component/aws2/sqs/Sqs2ConsumerHealthCheckProfileCredsTest.java
create mode 100644 components/camel-aws/camel-aws2-sqs/src/test/java/org/apache/camel/component/aws2/sqs/Sqs2ConsumerHealthCheckStaticCredsTest.java
delete mode 100644 components/camel-aws/camel-aws2-sqs/src/test/java/org/apache/camel/component/aws2/sqs/SqsComponentVerifierExtensionTest.java
[camel] 04/06: CAMEL-18466 - Camel-AWS2-SQS: Move from ComponentVerifierExtension to HealtCheck
Posted by ac...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
acosentino pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
commit c33c6372cfe8e13c35465f71c4ad1978eabdb7e1
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Fri Sep 9 14:55:45 2022 +0200
CAMEL-18466 - Camel-AWS2-SQS: Move from ComponentVerifierExtension to HealtCheck
---
.../Sqs2ConsumerHealthCheckStaticCredsTest.java | 107 +++++++++++++++++++++
1 file changed, 107 insertions(+)
diff --git a/components/camel-aws/camel-aws2-sqs/src/test/java/org/apache/camel/component/aws2/sqs/Sqs2ConsumerHealthCheckStaticCredsTest.java b/components/camel-aws/camel-aws2-sqs/src/test/java/org/apache/camel/component/aws2/sqs/Sqs2ConsumerHealthCheckStaticCredsTest.java
new file mode 100644
index 00000000000..3f36e59b50c
--- /dev/null
+++ b/components/camel-aws/camel-aws2-sqs/src/test/java/org/apache/camel/component/aws2/sqs/Sqs2ConsumerHealthCheckStaticCredsTest.java
@@ -0,0 +1,107 @@
+/*
+ * 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.aws2.sqs;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.health.HealthCheck;
+import org.apache.camel.health.HealthCheckHelper;
+import org.apache.camel.health.HealthCheckRegistry;
+import org.apache.camel.impl.health.DefaultHealthCheckRegistry;
+import org.apache.camel.test.infra.aws.common.services.AWSService;
+import org.apache.camel.test.infra.aws2.clients.AWSSDKClientUtils;
+import org.apache.camel.test.infra.aws2.services.AWSServiceFactory;
+import org.apache.camel.test.junit5.CamelTestSupport;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.RegisterExtension;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Collection;
+import java.util.concurrent.TimeUnit;
+
+import static org.testcontainers.shaded.org.awaitility.Awaitility.await;
+
+public class Sqs2ConsumerHealthCheckStaticCredsTest extends CamelTestSupport {
+
+ @RegisterExtension
+ public static AWSService service = AWSServiceFactory.createSQSService();
+
+ private static final Logger LOG = LoggerFactory.getLogger(Sqs2ConsumerHealthCheckStaticCredsTest.class);
+
+ CamelContext context;
+
+ @Override
+ protected CamelContext createCamelContext() throws Exception {
+ context = super.createCamelContext();
+ context.getPropertiesComponent().setLocation("ref:prop");
+ Sqs2Component component = new Sqs2Component(context);
+ component.getConfiguration().setAmazonSQSClient(AWSSDKClientUtils.newSQSClient());
+ component.init();
+ context.addComponent("aws2-sqs", component);
+
+ // install health check manually (yes a bit cumbersome)
+ HealthCheckRegistry registry = new DefaultHealthCheckRegistry();
+ registry.setCamelContext(context);
+ Object hc = registry.resolveById("context");
+ registry.register(hc);
+ hc = registry.resolveById("routes");
+ registry.register(hc);
+ hc = registry.resolveById("consumers");
+ registry.register(hc);
+ context.setExtension(HealthCheckRegistry.class, registry);
+
+ return context;
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() {
+ return new RouteBuilder() {
+
+ @Override
+ public void configure() {
+ from("aws2-sqs://queue1?region=l&secretKey=l&accessKey=k&autoCreateQueue=true")
+ .startupOrder(2).log("${body}").routeId("test-health-it");
+ }
+ };
+ }
+
+ @Test
+ public void testConnectivity() {
+
+ Collection<HealthCheck.Result> res = HealthCheckHelper.invokeLiveness(context);
+ boolean up = res.stream().allMatch(r -> r.getState().equals(HealthCheck.State.UP));
+ Assertions.assertTrue(up, "liveness check");
+
+ // health-check readiness should be down
+ await().atMost(20, TimeUnit.SECONDS).untilAsserted(() -> {
+ Collection<HealthCheck.Result> res2 = HealthCheckHelper.invokeReadiness(context);
+ boolean down = res2.stream().allMatch(r -> r.getState().equals(HealthCheck.State.DOWN));
+ boolean containsAws2SqsHealthCheck = res2.stream()
+ .filter(result -> result.getCheck().getId().startsWith("aws2-sqs-consumer"))
+ .findAny()
+ .isPresent();
+ boolean hasRegionMessage = res2.stream()
+ .anyMatch(r -> r.getMessage().stream().anyMatch(msg -> msg.contains("region")));
+ Assertions.assertTrue(down, "liveness check");
+ Assertions.assertTrue(containsAws2SqsHealthCheck, "aws2-sqs check");
+ Assertions.assertTrue(hasRegionMessage, "aws2-sqs check error message");
+ });
+
+ }
+}
[camel] 02/06: CAMEL-18466 - Camel-AWS2-SQS: Move from ComponentVerifierExtension to HealtCheck
Posted by ac...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
acosentino pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
commit cabdc69d100c9174edd1d0026f9891435b43a357
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Fri Sep 9 14:46:16 2022 +0200
CAMEL-18466 - Camel-AWS2-SQS: Move from ComponentVerifierExtension to HealtCheck
---
.../sqs/SqsComponentVerifierExtensionTest.java | 90 ----------------------
1 file changed, 90 deletions(-)
diff --git a/components/camel-aws/camel-aws2-sqs/src/test/java/org/apache/camel/component/aws2/sqs/SqsComponentVerifierExtensionTest.java b/components/camel-aws/camel-aws2-sqs/src/test/java/org/apache/camel/component/aws2/sqs/SqsComponentVerifierExtensionTest.java
deleted file mode 100644
index 535b1e360ab..00000000000
--- a/components/camel-aws/camel-aws2-sqs/src/test/java/org/apache/camel/component/aws2/sqs/SqsComponentVerifierExtensionTest.java
+++ /dev/null
@@ -1,90 +0,0 @@
-/*
- * 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.aws2.sqs;
-
-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.junit5.CamelTestSupport;
-import org.junit.jupiter.api.Test;
-
-import static org.junit.jupiter.api.Assertions.assertEquals;
-
-public class SqsComponentVerifierExtensionTest extends CamelTestSupport {
-
- // *************************************************
- // Tests (parameters)
- // *************************************************
- @Override
- public boolean isUseRouteBuilder() {
- return false;
- }
-
- @Test
- public void testParameters() {
- Component component = context().getComponent("aws2-sqs");
-
- 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("queueNameOrArn", "bucket1");
-
- ComponentVerifierExtension.Result result = verifier.verify(ComponentVerifierExtension.Scope.PARAMETERS, parameters);
-
- assertEquals(ComponentVerifierExtension.Result.Status.OK, result.getStatus());
- }
-
- @Test
- public void testConnectivity() {
- Component component = context().getComponent("aws2-sqs");
- 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("queueNameOrArn", "test12");
-
- ComponentVerifierExtension.Result result = verifier.verify(ComponentVerifierExtension.Scope.CONNECTIVITY, parameters);
-
- assertEquals(ComponentVerifierExtension.Result.Status.ERROR, result.getStatus());
- }
-
- @Test
- public void testConnectivityAndRegion() {
- Component component = context().getComponent("aws2-sqs");
- 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("queueNameOrArn", "test12");
-
- ComponentVerifierExtension.Result result = verifier.verify(ComponentVerifierExtension.Scope.CONNECTIVITY, parameters);
-
- assertEquals(ComponentVerifierExtension.Result.Status.ERROR, result.getStatus());
- }
-}
[camel] 06/06: CAMEL-18466 - Camel-AWS2-SQS: Move from ComponentVerifierExtension to HealtCheck
Posted by ac...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
acosentino pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
commit ac43ba265c97a2ae28922eeac044b17a4f3fd241
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Fri Sep 9 15:01:28 2022 +0200
CAMEL-18466 - Camel-AWS2-SQS: Move from ComponentVerifierExtension to HealtCheck
---
.../Sqs2ConsumerHealthCheckCustomClientTest.java | 107 +++++++++++++++++++++
1 file changed, 107 insertions(+)
diff --git a/components/camel-aws/camel-aws2-sqs/src/test/java/org/apache/camel/component/aws2/sqs/Sqs2ConsumerHealthCheckCustomClientTest.java b/components/camel-aws/camel-aws2-sqs/src/test/java/org/apache/camel/component/aws2/sqs/Sqs2ConsumerHealthCheckCustomClientTest.java
new file mode 100644
index 00000000000..6190dcda1bb
--- /dev/null
+++ b/components/camel-aws/camel-aws2-sqs/src/test/java/org/apache/camel/component/aws2/sqs/Sqs2ConsumerHealthCheckCustomClientTest.java
@@ -0,0 +1,107 @@
+/*
+ * 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.aws2.sqs;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.health.HealthCheck;
+import org.apache.camel.health.HealthCheckHelper;
+import org.apache.camel.health.HealthCheckRegistry;
+import org.apache.camel.impl.health.DefaultHealthCheckRegistry;
+import org.apache.camel.test.infra.aws.common.services.AWSService;
+import org.apache.camel.test.infra.aws2.clients.AWSSDKClientUtils;
+import org.apache.camel.test.infra.aws2.services.AWSServiceFactory;
+import org.apache.camel.test.junit5.CamelTestSupport;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.RegisterExtension;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Collection;
+import java.util.concurrent.TimeUnit;
+
+import static org.testcontainers.shaded.org.awaitility.Awaitility.await;
+
+public class Sqs2ConsumerHealthCheckCustomClientTest extends CamelTestSupport {
+
+ @RegisterExtension
+ public static AWSService service = AWSServiceFactory.createSQSService();
+
+ private static final Logger LOG = LoggerFactory.getLogger(Sqs2ConsumerHealthCheckCustomClientTest.class);
+
+ CamelContext context;
+
+ @Override
+ protected CamelContext createCamelContext() throws Exception {
+ context = super.createCamelContext();
+ context.getPropertiesComponent().setLocation("ref:prop");
+ Sqs2Component component = new Sqs2Component(context);
+ component.getConfiguration().setAmazonSQSClient(AWSSDKClientUtils.newSQSClient());
+ component.init();
+ context.addComponent("aws2-sqs", component);
+
+ // install health check manually (yes a bit cumbersome)
+ HealthCheckRegistry registry = new DefaultHealthCheckRegistry();
+ registry.setCamelContext(context);
+ Object hc = registry.resolveById("context");
+ registry.register(hc);
+ hc = registry.resolveById("routes");
+ registry.register(hc);
+ hc = registry.resolveById("consumers");
+ registry.register(hc);
+ context.setExtension(HealthCheckRegistry.class, registry);
+
+ return context;
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() {
+ return new RouteBuilder() {
+
+ @Override
+ public void configure() {
+ from("aws2-sqs://queue1?autoCreateQueue=true")
+ .startupOrder(2).log("${body}").routeId("test-health-it");
+ }
+ };
+ }
+
+ @Test
+ public void testConnectivity() {
+
+ Collection<HealthCheck.Result> res = HealthCheckHelper.invokeLiveness(context);
+ boolean up = res.stream().allMatch(r -> r.getState().equals(HealthCheck.State.UP));
+ Assertions.assertTrue(up, "liveness check");
+
+ // health-check readiness should be down
+ await().atMost(20, TimeUnit.SECONDS).untilAsserted(() -> {
+ Collection<HealthCheck.Result> res2 = HealthCheckHelper.invokeReadiness(context);
+ boolean down = res2.stream().allMatch(r -> r.getState().equals(HealthCheck.State.DOWN));
+ boolean containsAws2SqsHealthCheck = res2.stream()
+ .filter(result -> result.getCheck().getId().startsWith("aws2-sqs-consumer"))
+ .findAny()
+ .isPresent();
+ boolean hasRegionMessage = res2.stream()
+ .anyMatch(r -> r.getMessage().stream().anyMatch(msg -> msg.contains("region")));
+ Assertions.assertTrue(down, "liveness check");
+ Assertions.assertTrue(containsAws2SqsHealthCheck, "aws2-sqs check");
+ Assertions.assertFalse(hasRegionMessage, "aws2-sqs check error message");
+ });
+
+ }
+}
[camel] 03/06: CAMEL-18466 - Camel-AWS2-SQS: Move from ComponentVerifierExtension to HealtCheck
Posted by ac...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
acosentino pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
commit ef597ca6c7a1bf98697e67df96c15ec5a2043eea
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Fri Sep 9 14:46:28 2022 +0200
CAMEL-18466 - Camel-AWS2-SQS: Move from ComponentVerifierExtension to HealtCheck
---
.../services/org/apache/camel/health-check/camel-aws2-sqs-repository | 2 ++
1 file changed, 2 insertions(+)
diff --git a/components/camel-aws/camel-aws2-sqs/src/generated/resources/META-INF/services/org/apache/camel/health-check/camel-aws2-sqs-repository b/components/camel-aws/camel-aws2-sqs/src/generated/resources/META-INF/services/org/apache/camel/health-check/camel-aws2-sqs-repository
new file mode 100644
index 00000000000..66a881d7ddc
--- /dev/null
+++ b/components/camel-aws/camel-aws2-sqs/src/generated/resources/META-INF/services/org/apache/camel/health-check/camel-aws2-sqs-repository
@@ -0,0 +1,2 @@
+# Generated by camel build tools - do NOT edit this file!
+class=org.apache.camel.component.aws2.sqs.Sqs2HealthCheckRepository
[camel] 01/06: CAMEL-18466 - Camel-AWS2-SQS: Move from ComponentVerifierExtension to HealtCheck
Posted by ac...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
acosentino pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
commit a7f912c70bf5a7defdbef2c6073e61588c32e0d3
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Fri Sep 9 14:39:01 2022 +0200
CAMEL-18466 - Camel-AWS2-SQS: Move from ComponentVerifierExtension to HealtCheck
---
components/camel-aws/camel-aws2-sqs/pom.xml | 4 +
.../camel/component/aws2/sqs/Sqs2Component.java | 2 -
.../aws2/sqs/Sqs2ComponentVerifierExtension.java | 94 ----------------------
.../camel/component/aws2/sqs/Sqs2Consumer.java | 12 +++
.../aws2/sqs/Sqs2ConsumerHealthCheck.java | 87 ++++++++++++++++++++
.../aws2/sqs/Sqs2HealthCheckRepository.java | 83 +++++++++++++++++++
6 files changed, 186 insertions(+), 96 deletions(-)
diff --git a/components/camel-aws/camel-aws2-sqs/pom.xml b/components/camel-aws/camel-aws2-sqs/pom.xml
index db2b494cc5a..674da30bde3 100644
--- a/components/camel-aws/camel-aws2-sqs/pom.xml
+++ b/components/camel-aws/camel-aws2-sqs/pom.xml
@@ -54,6 +54,10 @@
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-health</artifactId>
+ </dependency>
<!-- test infra -->
<dependency>
diff --git a/components/camel-aws/camel-aws2-sqs/src/main/java/org/apache/camel/component/aws2/sqs/Sqs2Component.java b/components/camel-aws/camel-aws2-sqs/src/main/java/org/apache/camel/component/aws2/sqs/Sqs2Component.java
index c55c45f31d1..ea497fd7f34 100644
--- a/components/camel-aws/camel-aws2-sqs/src/main/java/org/apache/camel/component/aws2/sqs/Sqs2Component.java
+++ b/components/camel-aws/camel-aws2-sqs/src/main/java/org/apache/camel/component/aws2/sqs/Sqs2Component.java
@@ -44,8 +44,6 @@ public class Sqs2Component extends DefaultComponent {
public Sqs2Component(CamelContext context) {
super(context);
-
- registerExtension(new Sqs2ComponentVerifierExtension());
}
@Override
diff --git a/components/camel-aws/camel-aws2-sqs/src/main/java/org/apache/camel/component/aws2/sqs/Sqs2ComponentVerifierExtension.java b/components/camel-aws/camel-aws2-sqs/src/main/java/org/apache/camel/component/aws2/sqs/Sqs2ComponentVerifierExtension.java
deleted file mode 100644
index 3ff8399c6bb..00000000000
--- a/components/camel-aws/camel-aws2-sqs/src/main/java/org/apache/camel/component/aws2/sqs/Sqs2ComponentVerifierExtension.java
+++ /dev/null
@@ -1,94 +0,0 @@
-/*
- * 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.aws2.sqs;
-
-import java.util.Map;
-
-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;
-import software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
-import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider;
-import software.amazon.awssdk.core.exception.SdkClientException;
-import software.amazon.awssdk.regions.Region;
-import software.amazon.awssdk.services.sqs.SqsClient;
-import software.amazon.awssdk.services.sqs.SqsClientBuilder;
-
-public class Sqs2ComponentVerifierExtension extends DefaultComponentVerifierExtension {
-
- public Sqs2ComponentVerifierExtension() {
- this("aws2-sqs");
- }
-
- public Sqs2ComponentVerifierExtension(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 {
- Sqs2Configuration configuration = setProperties(new Sqs2Configuration(), parameters);
- if (!SqsClient.serviceMetadata().regions().contains(Region.of(configuration.getRegion()))) {
- ResultErrorBuilder errorBuilder = ResultErrorBuilder.withCodeAndDescription(
- VerificationError.StandardCode.ILLEGAL_PARAMETER, "The service is not supported in this region");
- return builder.error(errorBuilder.build()).build();
- }
- AwsBasicCredentials cred = AwsBasicCredentials.create(configuration.getAccessKey(), configuration.getSecretKey());
- SqsClientBuilder clientBuilder = SqsClient.builder();
- SqsClient client = clientBuilder.credentialsProvider(StaticCredentialsProvider.create(cred))
- .region(Region.of(configuration.getRegion())).build();
- client.listQueues();
- } catch (SdkClientException e) {
- ResultErrorBuilder errorBuilder
- = ResultErrorBuilder.withCodeAndDescription(VerificationError.StandardCode.AUTHENTICATION, e.getMessage())
- .detail("aws_sqs_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/camel-aws2-sqs/src/main/java/org/apache/camel/component/aws2/sqs/Sqs2Consumer.java b/components/camel-aws/camel-aws2-sqs/src/main/java/org/apache/camel/component/aws2/sqs/Sqs2Consumer.java
index feb6c219653..768076f86ee 100644
--- a/components/camel-aws/camel-aws2-sqs/src/main/java/org/apache/camel/component/aws2/sqs/Sqs2Consumer.java
+++ b/components/camel-aws/camel-aws2-sqs/src/main/java/org/apache/camel/component/aws2/sqs/Sqs2Consumer.java
@@ -34,6 +34,7 @@ import org.apache.camel.ExchangePropertyKey;
import org.apache.camel.ExtendedExchange;
import org.apache.camel.Message;
import org.apache.camel.Processor;
+import org.apache.camel.health.HealthCheckHelper;
import org.apache.camel.spi.HeaderFilterStrategy;
import org.apache.camel.spi.ScheduledPollConsumerScheduler;
import org.apache.camel.spi.Synchronization;
@@ -69,6 +70,8 @@ public class Sqs2Consumer extends ScheduledBatchPollingConsumer {
private transient String sqsConsumerToString;
private Collection<String> attributeNames;
private Collection<String> messageAttributeNames;
+ private Sqs2HealthCheckRepository healthCheckRepository;
+ private Sqs2ConsumerHealthCheck consumerHealthCheck;
public Sqs2Consumer(Sqs2Endpoint endpoint, Processor processor) {
super(endpoint, processor);
@@ -351,6 +354,15 @@ public class Sqs2Consumer extends ScheduledBatchPollingConsumer {
}
super.doStart();
+
+ healthCheckRepository = HealthCheckHelper.getHealthCheckRepository(getEndpoint().getCamelContext(),
+ Sqs2HealthCheckRepository.REPOSITORY_ID, Sqs2HealthCheckRepository.class);
+
+ if (healthCheckRepository != null) {
+ consumerHealthCheck = new Sqs2ConsumerHealthCheck(this, getRouteId());
+ healthCheckRepository.addHealthCheck(consumerHealthCheck);
+ }
+
}
@Override
diff --git a/components/camel-aws/camel-aws2-sqs/src/main/java/org/apache/camel/component/aws2/sqs/Sqs2ConsumerHealthCheck.java b/components/camel-aws/camel-aws2-sqs/src/main/java/org/apache/camel/component/aws2/sqs/Sqs2ConsumerHealthCheck.java
new file mode 100644
index 00000000000..9aba1d38040
--- /dev/null
+++ b/components/camel-aws/camel-aws2-sqs/src/main/java/org/apache/camel/component/aws2/sqs/Sqs2ConsumerHealthCheck.java
@@ -0,0 +1,87 @@
+/*
+ * 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.aws2.sqs;
+
+import org.apache.camel.health.HealthCheckResultBuilder;
+import org.apache.camel.impl.health.AbstractHealthCheck;
+import org.apache.camel.util.ObjectHelper;
+import software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
+import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider;
+import software.amazon.awssdk.core.exception.SdkClientException;
+import software.amazon.awssdk.regions.Region;
+import software.amazon.awssdk.services.sqs.SqsClient;
+import software.amazon.awssdk.services.sqs.SqsClientBuilder;
+
+import java.util.Map;
+
+public class Sqs2ConsumerHealthCheck extends AbstractHealthCheck {
+
+ private final Sqs2Consumer sqs2Consumer;
+ private final String routeId;
+
+ public Sqs2ConsumerHealthCheck(Sqs2Consumer sqs2Consumer, String routeId) {
+ super("camel", "aws2-sqs-consumer-" + routeId);
+ this.sqs2Consumer = sqs2Consumer;
+ this.routeId = routeId;
+ }
+
+ @Override
+ public boolean isLiveness() {
+ // this health check is only readiness
+ return false;
+ }
+
+ @Override
+ protected void doCall(HealthCheckResultBuilder builder, Map<String, Object> options) {
+
+ try {
+ Sqs2Configuration configuration = sqs2Consumer.getConfiguration();
+ if (!SqsClient.serviceMetadata().regions().contains(Region.of(configuration.getRegion()))) {
+ builder.message("The service is not supported in this region");
+ builder.down();
+ return;
+ }
+ SqsClient client;
+ if (!configuration.isUseDefaultCredentialsProvider()) {
+ AwsBasicCredentials cred
+ = AwsBasicCredentials.create(configuration.getAccessKey(), configuration.getSecretKey());
+ SqsClientBuilder clientBuilder = SqsClient.builder();
+ client = clientBuilder.credentialsProvider(StaticCredentialsProvider.create(cred))
+ .region(Region.of(configuration.getRegion())).build();
+ } else if (ObjectHelper.isNotEmpty(configuration.getAmazonSQSClient())) {
+ client = configuration.getAmazonSQSClient();
+ } else {
+ SqsClientBuilder clientBuilder = SqsClient.builder();
+ client = clientBuilder.region(Region.of(configuration.getRegion())).build();
+ }
+ client.listQueues();
+ } catch (SdkClientException e) {
+ builder.message(e.getMessage());
+ builder.error(e);
+ builder.down();
+ return;
+
+ } catch (Exception e) {
+ builder.error(e);
+ builder.down();
+ return;
+ }
+
+ builder.up();
+
+ }
+}
diff --git a/components/camel-aws/camel-aws2-sqs/src/main/java/org/apache/camel/component/aws2/sqs/Sqs2HealthCheckRepository.java b/components/camel-aws/camel-aws2-sqs/src/main/java/org/apache/camel/component/aws2/sqs/Sqs2HealthCheckRepository.java
new file mode 100644
index 00000000000..ea71485af1f
--- /dev/null
+++ b/components/camel-aws/camel-aws2-sqs/src/main/java/org/apache/camel/component/aws2/sqs/Sqs2HealthCheckRepository.java
@@ -0,0 +1,83 @@
+/*
+ * 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.aws2.sqs;
+
+import org.apache.camel.*;
+import org.apache.camel.health.HealthCheck;
+import org.apache.camel.health.HealthCheckRepository;
+import org.apache.camel.support.service.ServiceSupport;
+
+import java.util.List;
+import java.util.concurrent.CopyOnWriteArrayList;
+import java.util.stream.Stream;
+
+/**
+ * Repository for camel-aws2-sqs {@link HealthCheck}s.
+ */
+@org.apache.camel.spi.annotations.HealthCheck("camel-aws2-sqs-repository")
+@DeferredContextBinding
+public class Sqs2HealthCheckRepository extends ServiceSupport
+ implements CamelContextAware, HealthCheckRepository, StaticService, NonManagedService {
+
+ public static final String REPOSITORY_ID = "camel-aws2-sqs";
+
+ private final List<HealthCheck> checks = new CopyOnWriteArrayList<>();
+ private volatile CamelContext context;
+ private boolean enabled = true;
+
+ @Override
+ public void setCamelContext(CamelContext camelContext) {
+ this.context = camelContext;
+ }
+
+ @Override
+ public String getId() {
+ return REPOSITORY_ID;
+ }
+
+ @Override
+ public CamelContext getCamelContext() {
+ return context;
+ }
+
+ @Override
+ public boolean isEnabled() {
+ return enabled;
+ }
+
+ @Override
+ public void setEnabled(boolean enabled) {
+ this.enabled = enabled;
+ }
+
+ @Override
+ public Stream<HealthCheck> stream() {
+ return this.context != null && enabled
+ ? checks.stream()
+ : Stream.empty();
+ }
+
+ public void addHealthCheck(HealthCheck healthCheck) {
+ CamelContextAware.trySetCamelContext(healthCheck, getCamelContext());
+ this.checks.add(healthCheck);
+ }
+
+ public void removeHealthCheck(HealthCheck healthCheck) {
+ this.checks.remove(healthCheck);
+ }
+
+}
[camel] 05/06: CAMEL-18466 - Camel-AWS2-SQS: Move from ComponentVerifierExtension to HealtCheck
Posted by ac...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
acosentino pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
commit fb944daeee3df5deef99b7b83f4763dae5b61cd3
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Fri Sep 9 14:57:11 2022 +0200
CAMEL-18466 - Camel-AWS2-SQS: Move from ComponentVerifierExtension to HealtCheck
---
.../Sqs2ConsumerHealthCheckProfileCredsTest.java | 107 +++++++++++++++++++++
1 file changed, 107 insertions(+)
diff --git a/components/camel-aws/camel-aws2-sqs/src/test/java/org/apache/camel/component/aws2/sqs/Sqs2ConsumerHealthCheckProfileCredsTest.java b/components/camel-aws/camel-aws2-sqs/src/test/java/org/apache/camel/component/aws2/sqs/Sqs2ConsumerHealthCheckProfileCredsTest.java
new file mode 100644
index 00000000000..c9d3de7b3f6
--- /dev/null
+++ b/components/camel-aws/camel-aws2-sqs/src/test/java/org/apache/camel/component/aws2/sqs/Sqs2ConsumerHealthCheckProfileCredsTest.java
@@ -0,0 +1,107 @@
+/*
+ * 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.aws2.sqs;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.health.HealthCheck;
+import org.apache.camel.health.HealthCheckHelper;
+import org.apache.camel.health.HealthCheckRegistry;
+import org.apache.camel.impl.health.DefaultHealthCheckRegistry;
+import org.apache.camel.test.infra.aws.common.services.AWSService;
+import org.apache.camel.test.infra.aws2.clients.AWSSDKClientUtils;
+import org.apache.camel.test.infra.aws2.services.AWSServiceFactory;
+import org.apache.camel.test.junit5.CamelTestSupport;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.RegisterExtension;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Collection;
+import java.util.concurrent.TimeUnit;
+
+import static org.testcontainers.shaded.org.awaitility.Awaitility.await;
+
+public class Sqs2ConsumerHealthCheckProfileCredsTest extends CamelTestSupport {
+
+ @RegisterExtension
+ public static AWSService service = AWSServiceFactory.createSQSService();
+
+ private static final Logger LOG = LoggerFactory.getLogger(Sqs2ConsumerHealthCheckProfileCredsTest.class);
+
+ CamelContext context;
+
+ @Override
+ protected CamelContext createCamelContext() throws Exception {
+ context = super.createCamelContext();
+ context.getPropertiesComponent().setLocation("ref:prop");
+ Sqs2Component component = new Sqs2Component(context);
+ component.getConfiguration().setAmazonSQSClient(AWSSDKClientUtils.newSQSClient());
+ component.init();
+ context.addComponent("aws2-sqs", component);
+
+ // install health check manually (yes a bit cumbersome)
+ HealthCheckRegistry registry = new DefaultHealthCheckRegistry();
+ registry.setCamelContext(context);
+ Object hc = registry.resolveById("context");
+ registry.register(hc);
+ hc = registry.resolveById("routes");
+ registry.register(hc);
+ hc = registry.resolveById("consumers");
+ registry.register(hc);
+ context.setExtension(HealthCheckRegistry.class, registry);
+
+ return context;
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() {
+ return new RouteBuilder() {
+
+ @Override
+ public void configure() {
+ from("aws2-sqs://queue1?region=l&useDefaultCredentialsProvider=true&autoCreateQueue=true")
+ .startupOrder(2).log("${body}").routeId("test-health-it");
+ }
+ };
+ }
+
+ @Test
+ public void testConnectivity() {
+
+ Collection<HealthCheck.Result> res = HealthCheckHelper.invokeLiveness(context);
+ boolean up = res.stream().allMatch(r -> r.getState().equals(HealthCheck.State.UP));
+ Assertions.assertTrue(up, "liveness check");
+
+ // health-check readiness should be down
+ await().atMost(20, TimeUnit.SECONDS).untilAsserted(() -> {
+ Collection<HealthCheck.Result> res2 = HealthCheckHelper.invokeReadiness(context);
+ boolean down = res2.stream().allMatch(r -> r.getState().equals(HealthCheck.State.DOWN));
+ boolean containsAws2SqsHealthCheck = res2.stream()
+ .filter(result -> result.getCheck().getId().startsWith("aws2-sqs-consumer"))
+ .findAny()
+ .isPresent();
+ boolean hasRegionMessage = res2.stream()
+ .anyMatch(r -> r.getMessage().stream().anyMatch(msg -> msg.contains("region")));
+ Assertions.assertTrue(down, "liveness check");
+ Assertions.assertTrue(containsAws2SqsHealthCheck, "aws2-sqs check");
+ Assertions.assertTrue(hasRegionMessage, "aws2-sqs check error message");
+ });
+
+ }
+}