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 2023/02/06 10:11:39 UTC

[camel] branch main updated (898d9503560 -> 1e4cb72a8d9)

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 898d9503560 Ensure the resource is read only once, the stream closed and add missing calls
     new 8ff47d7631c CAMEL-18131 - camel-health - Add health checks for components that has extension for connectivity verification - AWS Translate
     new 35d97190f7f CAMEL-18131 - camel-health - Add health checks for components that has extension for connectivity verification - AWS Translate
     new fe35f3f85df CAMEL-18131 - camel-health - Add health checks for components that has extension for connectivity verification - AWS Translate
     new bfb601fd6d3 CAMEL-18131 - camel-health - Add health checks for components that has extension for connectivity verification - AWS Translate
     new 33360cae4fb CAMEL-18131 - camel-health - Add health checks for components that has extension for connectivity verification - AWS Translate
     new 4a46dfe9947 CAMEL-18131 - camel-health - Add health checks for components that has extension for connectivity verification - AWS Translate
     new 1e4cb72a8d9 CAMEL-18131 - camel-health - Add health checks for components that has extension for connectivity verification - AWS Translate

The 7 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-translate/pom.xml  | 13 +++
 .../translate/Translate2ClientHealthCheck.java}    | 24 +++---
 .../aws2/translate/Translate2Component.java        |  2 -
 .../Translate2ComponentVerifierExtension.java      | 98 ----------------------
 .../aws2/translate/Translate2Endpoint.java         | 18 ++++
 ...anslate2ClientHealthCheckProfileCredsTest.java} | 16 ++--
 ...ranslate2ClientHealthCheckStaticCredsTest.java} | 16 ++--
 7 files changed, 59 insertions(+), 128 deletions(-)
 copy components/camel-aws/{camel-aws2-eks/src/main/java/org/apache/camel/component/aws2/eks/EKS2ClientHealthCheck.java => camel-aws2-translate/src/main/java/org/apache/camel/component/aws2/translate/Translate2ClientHealthCheck.java} (70%)
 delete mode 100644 components/camel-aws/camel-aws2-translate/src/main/java/org/apache/camel/component/aws2/translate/Translate2ComponentVerifierExtension.java
 copy components/camel-aws/{camel-aws2-eventbridge/src/test/java/org/apache/camel/component/aws2/eventbridge/EventbridgeClientHealthCheckStaticCredsTest.java => camel-aws2-translate/src/test/java/org/apache/camel/component/aws2/translate/Translate2ClientHealthCheckProfileCredsTest.java} (84%)
 copy components/camel-aws/{camel-aws2-eks/src/test/java/org/apache/camel/component/aws2/eks/EKS2CliientHealthCheckStaticCredsTest.java => camel-aws2-translate/src/test/java/org/apache/camel/component/aws2/translate/Translate2ClientHealthCheckStaticCredsTest.java} (83%)


[camel] 03/07: CAMEL-18131 - camel-health - Add health checks for components that has extension for connectivity verification - AWS Translate

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 fe35f3f85dfdc5d8282b5da63b15f7b4faa20054
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Mon Feb 6 10:50:57 2023 +0100

    CAMEL-18131 - camel-health - Add health checks for components that has extension for connectivity verification - AWS Translate
    
    Signed-off-by: Andrea Cosentino <an...@gmail.com>
---
 .../translate/Translate2ClientHealthCheck.java     | 77 ++++++++++++++++++++++
 1 file changed, 77 insertions(+)

diff --git a/components/camel-aws/camel-aws2-translate/src/main/java/org/apache/camel/component/aws2/translate/Translate2ClientHealthCheck.java b/components/camel-aws/camel-aws2-translate/src/main/java/org/apache/camel/component/aws2/translate/Translate2ClientHealthCheck.java
new file mode 100644
index 00000000000..3a9293e3aee
--- /dev/null
+++ b/components/camel-aws/camel-aws2-translate/src/main/java/org/apache/camel/component/aws2/translate/Translate2ClientHealthCheck.java
@@ -0,0 +1,77 @@
+/*
+ * 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.translate;
+
+import org.apache.camel.health.HealthCheckResultBuilder;
+import org.apache.camel.impl.health.AbstractHealthCheck;
+import org.apache.camel.util.ObjectHelper;
+import software.amazon.awssdk.awscore.exception.AwsServiceException;
+import software.amazon.awssdk.regions.Region;
+import software.amazon.awssdk.services.translate.TranslateClient;
+import software.amazon.awssdk.services.translate.model.ListLanguagesRequest;
+
+import java.util.Map;
+
+public class Translate2ClientHealthCheck extends AbstractHealthCheck {
+
+    private final Translate2Endpoint translate2Endpoint;
+
+    public Translate2ClientHealthCheck(Translate2Endpoint translate2Endpoint, String clientId) {
+        super("camel", "aws2-translate-client-" + clientId);
+        this.translate2Endpoint = translate2Endpoint;
+    }
+
+    @Override
+    public boolean isLiveness() {
+        // this health check is only readiness
+        return false;
+    }
+
+    @Override
+    protected void doCall(HealthCheckResultBuilder builder, Map<String, Object> options) {
+        Translate2Configuration configuration = translate2Endpoint.getConfiguration();
+        if (ObjectHelper.isNotEmpty(configuration.getRegion())) {
+            if (!TranslateClient.serviceMetadata().regions().contains(Region.of(configuration.getRegion()))) {
+                builder.message("The service is not supported in this region");
+                builder.down();
+                return;
+            }
+        }
+        try {
+            TranslateClient translateClient = translate2Endpoint.getTranslateClient();
+
+            translateClient.listLanguages(ListLanguagesRequest.builder().maxResults(1).build());
+        } catch (AwsServiceException e) {
+            builder.message(e.getMessage());
+            builder.error(e);
+            if (ObjectHelper.isNotEmpty(e.statusCode())) {
+                builder.detail(SERVICE_STATUS_CODE, e.statusCode());
+            }
+            if (ObjectHelper.isNotEmpty(e.awsErrorDetails().errorCode())) {
+                builder.detail(SERVICE_ERROR_CODE, e.awsErrorDetails().errorCode());
+            }
+            builder.down();
+            return;
+        } catch (Exception e) {
+            builder.error(e);
+            builder.down();
+            return;
+        }
+        builder.up();
+    }
+}


[camel] 01/07: CAMEL-18131 - camel-health - Add health checks for components that has extension for connectivity verification - AWS Translate

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 8ff47d7631c0f2c013290ff3291fc4408de4def8
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Mon Feb 6 10:40:39 2023 +0100

    CAMEL-18131 - camel-health - Add health checks for components that has extension for connectivity verification - AWS Translate
    
    Signed-off-by: Andrea Cosentino <an...@gmail.com>
---
 .../aws2/translate/Translate2Component.java        |  2 -
 .../Translate2ComponentVerifierExtension.java      | 98 ----------------------
 2 files changed, 100 deletions(-)

diff --git a/components/camel-aws/camel-aws2-translate/src/main/java/org/apache/camel/component/aws2/translate/Translate2Component.java b/components/camel-aws/camel-aws2-translate/src/main/java/org/apache/camel/component/aws2/translate/Translate2Component.java
index 6d47378e40e..1eb86343d81 100644
--- a/components/camel-aws/camel-aws2-translate/src/main/java/org/apache/camel/component/aws2/translate/Translate2Component.java
+++ b/components/camel-aws/camel-aws2-translate/src/main/java/org/apache/camel/component/aws2/translate/Translate2Component.java
@@ -38,8 +38,6 @@ public class Translate2Component extends DefaultComponent {
 
     public Translate2Component(CamelContext context) {
         super(context);
-
-        registerExtension(new Translate2ComponentVerifierExtension());
     }
 
     @Override
diff --git a/components/camel-aws/camel-aws2-translate/src/main/java/org/apache/camel/component/aws2/translate/Translate2ComponentVerifierExtension.java b/components/camel-aws/camel-aws2-translate/src/main/java/org/apache/camel/component/aws2/translate/Translate2ComponentVerifierExtension.java
deleted file mode 100644
index 715cb15f765..00000000000
--- a/components/camel-aws/camel-aws2-translate/src/main/java/org/apache/camel/component/aws2/translate/Translate2ComponentVerifierExtension.java
+++ /dev/null
@@ -1,98 +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.translate;
-
-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.translate.TranslateClient;
-import software.amazon.awssdk.services.translate.TranslateClientBuilder;
-import software.amazon.awssdk.services.translate.model.TranslateTextRequest;
-
-public class Translate2ComponentVerifierExtension extends DefaultComponentVerifierExtension {
-
-    public Translate2ComponentVerifierExtension() {
-        this("aws2-translate");
-    }
-
-    public Translate2ComponentVerifierExtension(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 {
-            Translate2Configuration configuration = setProperties(new Translate2Configuration(), parameters);
-            if (!TranslateClient.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());
-            TranslateClientBuilder clientBuilder = TranslateClient.builder();
-            TranslateClient client = clientBuilder.credentialsProvider(StaticCredentialsProvider.create(cred))
-                    .region(Region.of(configuration.getRegion())).build();
-            TranslateTextRequest req
-                    = TranslateTextRequest.builder().sourceLanguageCode("it").targetLanguageCode("en").text("ciao").build();
-            client.translateText(req);
-        } catch (SdkClientException e) {
-            ResultErrorBuilder errorBuilder
-                    = ResultErrorBuilder.withCodeAndDescription(VerificationError.StandardCode.AUTHENTICATION, e.getMessage())
-                            .detail("aws_translate_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();
-    }
-}


[camel] 04/07: CAMEL-18131 - camel-health - Add health checks for components that has extension for connectivity verification - AWS Translate

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 bfb601fd6d3c75be1caca92122bfb7ff432b3aa0
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Mon Feb 6 10:54:32 2023 +0100

    CAMEL-18131 - camel-health - Add health checks for components that has extension for connectivity verification - AWS Translate
    
    Signed-off-by: Andrea Cosentino <an...@gmail.com>
---
 components/camel-aws/camel-aws2-translate/pom.xml  |  9 ++
 ...ranslate2ClientHealthCheckProfileCredsTest.java | 97 ++++++++++++++++++++++
 ...Translate2ClientHealthCheckStaticCredsTest.java | 97 ++++++++++++++++++++++
 3 files changed, 203 insertions(+)

diff --git a/components/camel-aws/camel-aws2-translate/pom.xml b/components/camel-aws/camel-aws2-translate/pom.xml
index 691eedfa186..9ab7d553f09 100644
--- a/components/camel-aws/camel-aws2-translate/pom.xml
+++ b/components/camel-aws/camel-aws2-translate/pom.xml
@@ -61,5 +61,14 @@
             <groupId>org.apache.camel</groupId>
             <artifactId>camel-health</artifactId>
         </dependency>
+
+        <!-- test infra -->
+        <dependency>
+            <groupId>org.apache.camel</groupId>
+            <artifactId>camel-test-infra-aws-v2</artifactId>
+            <version>${project.version}</version>
+            <type>test-jar</type>
+            <scope>test</scope>
+        </dependency>
     </dependencies>
 </project>
diff --git a/components/camel-aws/camel-aws2-translate/src/test/java/org/apache/camel/component/aws2/translate/Translate2ClientHealthCheckProfileCredsTest.java b/components/camel-aws/camel-aws2-translate/src/test/java/org/apache/camel/component/aws2/translate/Translate2ClientHealthCheckProfileCredsTest.java
new file mode 100644
index 00000000000..ed627e6309a
--- /dev/null
+++ b/components/camel-aws/camel-aws2-translate/src/test/java/org/apache/camel/component/aws2/translate/Translate2ClientHealthCheckProfileCredsTest.java
@@ -0,0 +1,97 @@
+/*
+ * 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.translate;
+
+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.junit5.CamelTestSupport;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+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 Translate2ClientHealthCheckProfileCredsTest extends CamelTestSupport {
+
+    private static final Logger LOG = LoggerFactory.getLogger(Translate2ClientHealthCheckProfileCredsTest.class);
+
+    CamelContext context;
+
+    @Override
+    protected CamelContext createCamelContext() throws Exception {
+        context = super.createCamelContext();
+        context.getPropertiesComponent().setLocation("ref:prop");
+
+        // 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("direct:listClusters")
+                        .to("aws2-translate://test?operation=translate&region=l&useDefaultCredentialsProvider=true");
+            }
+        };
+    }
+
+    @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 containsAwsTranslateHealthCheck = res2.stream()
+                    .filter(result -> result.getCheck().getId().startsWith("aws2-translate-client"))
+                    .findAny()
+                    .isPresent();
+            boolean hasRegionMessage = res2.stream()
+                    .anyMatch(r -> r.getMessage().stream().anyMatch(msg -> msg.contains("region")));
+            Assertions.assertTrue(down, "liveness check");
+            Assertions.assertTrue(containsAwsTranslateHealthCheck, "aws2-translate check");
+            Assertions.assertTrue(hasRegionMessage, "aws2-translate check error message");
+        });
+
+    }
+}
diff --git a/components/camel-aws/camel-aws2-translate/src/test/java/org/apache/camel/component/aws2/translate/Translate2ClientHealthCheckStaticCredsTest.java b/components/camel-aws/camel-aws2-translate/src/test/java/org/apache/camel/component/aws2/translate/Translate2ClientHealthCheckStaticCredsTest.java
new file mode 100644
index 00000000000..ac1bd4bc3c4
--- /dev/null
+++ b/components/camel-aws/camel-aws2-translate/src/test/java/org/apache/camel/component/aws2/translate/Translate2ClientHealthCheckStaticCredsTest.java
@@ -0,0 +1,97 @@
+/*
+ * 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.translate;
+
+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.junit5.CamelTestSupport;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+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 Translate2ClientHealthCheckStaticCredsTest extends CamelTestSupport {
+
+    private static final Logger LOG = LoggerFactory.getLogger(Translate2ClientHealthCheckStaticCredsTest.class);
+
+    CamelContext context;
+
+    @Override
+    protected CamelContext createCamelContext() throws Exception {
+        context = super.createCamelContext();
+        context.getPropertiesComponent().setLocation("ref:prop");
+
+        // 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("direct:listClusters")
+                        .to("aws2-translate://test?operation=translate&region=l&secretKey=l&accessKey=k");
+            }
+        };
+    }
+
+    @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 containsAwsTranslateHealthCheck = res2.stream()
+                    .filter(result -> result.getCheck().getId().startsWith("aws2-translate-client"))
+                    .findAny()
+                    .isPresent();
+            boolean hasRegionMessage = res2.stream()
+                    .anyMatch(r -> r.getMessage().stream().anyMatch(msg -> msg.contains("region")));
+            Assertions.assertTrue(down, "liveness check");
+            Assertions.assertTrue(containsAwsTranslateHealthCheck, "aws2-translate check");
+            Assertions.assertTrue(hasRegionMessage, "aws2-translate check error message");
+        });
+
+    }
+}


[camel] 07/07: CAMEL-18131 - camel-health - Add health checks for components that has extension for connectivity verification - AWS Translate

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 1e4cb72a8d9615dee63b9bcdb6297364c7a53985
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Mon Feb 6 10:59:32 2023 +0100

    CAMEL-18131 - camel-health - Add health checks for components that has extension for connectivity verification - AWS Translate
    
    Signed-off-by: Andrea Cosentino <an...@gmail.com>
---
 .../camel/component/aws2/translate/Translate2ClientHealthCheck.java | 4 ++--
 .../aws2/translate/Translate2ClientHealthCheckProfileCredsTest.java | 6 +++---
 .../aws2/translate/Translate2ClientHealthCheckStaticCredsTest.java  | 6 +++---
 3 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/components/camel-aws/camel-aws2-translate/src/main/java/org/apache/camel/component/aws2/translate/Translate2ClientHealthCheck.java b/components/camel-aws/camel-aws2-translate/src/main/java/org/apache/camel/component/aws2/translate/Translate2ClientHealthCheck.java
index 3a9293e3aee..882c6db0580 100644
--- a/components/camel-aws/camel-aws2-translate/src/main/java/org/apache/camel/component/aws2/translate/Translate2ClientHealthCheck.java
+++ b/components/camel-aws/camel-aws2-translate/src/main/java/org/apache/camel/component/aws2/translate/Translate2ClientHealthCheck.java
@@ -17,6 +17,8 @@
 
 package org.apache.camel.component.aws2.translate;
 
+import java.util.Map;
+
 import org.apache.camel.health.HealthCheckResultBuilder;
 import org.apache.camel.impl.health.AbstractHealthCheck;
 import org.apache.camel.util.ObjectHelper;
@@ -25,8 +27,6 @@ import software.amazon.awssdk.regions.Region;
 import software.amazon.awssdk.services.translate.TranslateClient;
 import software.amazon.awssdk.services.translate.model.ListLanguagesRequest;
 
-import java.util.Map;
-
 public class Translate2ClientHealthCheck extends AbstractHealthCheck {
 
     private final Translate2Endpoint translate2Endpoint;
diff --git a/components/camel-aws/camel-aws2-translate/src/test/java/org/apache/camel/component/aws2/translate/Translate2ClientHealthCheckProfileCredsTest.java b/components/camel-aws/camel-aws2-translate/src/test/java/org/apache/camel/component/aws2/translate/Translate2ClientHealthCheckProfileCredsTest.java
index 1d6cc73bd5f..95d81d7ad5e 100644
--- a/components/camel-aws/camel-aws2-translate/src/test/java/org/apache/camel/component/aws2/translate/Translate2ClientHealthCheckProfileCredsTest.java
+++ b/components/camel-aws/camel-aws2-translate/src/test/java/org/apache/camel/component/aws2/translate/Translate2ClientHealthCheckProfileCredsTest.java
@@ -17,6 +17,9 @@
 
 package org.apache.camel.component.aws2.translate;
 
+import java.util.Collection;
+import java.util.concurrent.TimeUnit;
+
 import org.apache.camel.CamelContext;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.health.HealthCheck;
@@ -29,9 +32,6 @@ import org.junit.jupiter.api.Test;
 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 Translate2ClientHealthCheckProfileCredsTest extends CamelTestSupport {
diff --git a/components/camel-aws/camel-aws2-translate/src/test/java/org/apache/camel/component/aws2/translate/Translate2ClientHealthCheckStaticCredsTest.java b/components/camel-aws/camel-aws2-translate/src/test/java/org/apache/camel/component/aws2/translate/Translate2ClientHealthCheckStaticCredsTest.java
index ec37013394e..3e034578ca7 100644
--- a/components/camel-aws/camel-aws2-translate/src/test/java/org/apache/camel/component/aws2/translate/Translate2ClientHealthCheckStaticCredsTest.java
+++ b/components/camel-aws/camel-aws2-translate/src/test/java/org/apache/camel/component/aws2/translate/Translate2ClientHealthCheckStaticCredsTest.java
@@ -17,6 +17,9 @@
 
 package org.apache.camel.component.aws2.translate;
 
+import java.util.Collection;
+import java.util.concurrent.TimeUnit;
+
 import org.apache.camel.CamelContext;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.health.HealthCheck;
@@ -29,9 +32,6 @@ import org.junit.jupiter.api.Test;
 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 Translate2ClientHealthCheckStaticCredsTest extends CamelTestSupport {


[camel] 02/07: CAMEL-18131 - camel-health - Add health checks for components that has extension for connectivity verification - AWS Translate

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 35d97190f7f42cd82bde3662d36172b5fa42b2cc
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Mon Feb 6 10:50:42 2023 +0100

    CAMEL-18131 - camel-health - Add health checks for components that has extension for connectivity verification - AWS Translate
    
    Signed-off-by: Andrea Cosentino <an...@gmail.com>
---
 components/camel-aws/camel-aws2-translate/pom.xml      |  4 ++++
 .../component/aws2/translate/Translate2Endpoint.java   | 18 ++++++++++++++++++
 2 files changed, 22 insertions(+)

diff --git a/components/camel-aws/camel-aws2-translate/pom.xml b/components/camel-aws/camel-aws2-translate/pom.xml
index 1102d25b003..691eedfa186 100644
--- a/components/camel-aws/camel-aws2-translate/pom.xml
+++ b/components/camel-aws/camel-aws2-translate/pom.xml
@@ -57,5 +57,9 @@
             <artifactId>camel-test-spring-junit5</artifactId>
             <scope>test</scope>
         </dependency>
+        <dependency>
+            <groupId>org.apache.camel</groupId>
+            <artifactId>camel-health</artifactId>
+        </dependency>
     </dependencies>
 </project>
diff --git a/components/camel-aws/camel-aws2-translate/src/main/java/org/apache/camel/component/aws2/translate/Translate2Endpoint.java b/components/camel-aws/camel-aws2-translate/src/main/java/org/apache/camel/component/aws2/translate/Translate2Endpoint.java
index 075f43e3d7e..54a474b646e 100644
--- a/components/camel-aws/camel-aws2-translate/src/main/java/org/apache/camel/component/aws2/translate/Translate2Endpoint.java
+++ b/components/camel-aws/camel-aws2-translate/src/main/java/org/apache/camel/component/aws2/translate/Translate2Endpoint.java
@@ -22,6 +22,8 @@ import org.apache.camel.Consumer;
 import org.apache.camel.Processor;
 import org.apache.camel.Producer;
 import org.apache.camel.component.aws2.translate.client.Translate2ClientFactory;
+import org.apache.camel.health.HealthCheckHelper;
+import org.apache.camel.impl.health.ComponentsHealthCheckRepository;
 import org.apache.camel.spi.UriEndpoint;
 import org.apache.camel.spi.UriParam;
 import org.apache.camel.support.ScheduledPollEndpoint;
@@ -37,6 +39,9 @@ public class Translate2Endpoint extends ScheduledPollEndpoint {
 
     private TranslateClient translateClient;
 
+    private ComponentsHealthCheckRepository healthCheckRepository;
+    private Translate2ClientHealthCheck clientHealthCheck;
+
     @UriParam
     private Translate2Configuration configuration;
 
@@ -63,10 +68,23 @@ public class Translate2Endpoint extends ScheduledPollEndpoint {
                 = configuration.getTranslateClient() != null
                         ? configuration.getTranslateClient()
                         : Translate2ClientFactory.getTranslateClient(configuration).getTranslateClient();
+
+        healthCheckRepository = HealthCheckHelper.getHealthCheckRepository(getCamelContext(),
+                ComponentsHealthCheckRepository.REPOSITORY_ID, ComponentsHealthCheckRepository.class);
+
+        if (healthCheckRepository != null) {
+            clientHealthCheck = new Translate2ClientHealthCheck(this, getId());
+            healthCheckRepository.addHealthCheck(clientHealthCheck);
+        }
     }
 
     @Override
     public void doStop() throws Exception {
+        if (healthCheckRepository != null && clientHealthCheck != null) {
+            healthCheckRepository.removeHealthCheck(clientHealthCheck);
+            clientHealthCheck = null;
+        }
+
         if (ObjectHelper.isEmpty(configuration.getTranslateClient())) {
             if (translateClient != null) {
                 translateClient.close();


[camel] 05/07: CAMEL-18131 - camel-health - Add health checks for components that has extension for connectivity verification - AWS Translate

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 33360cae4fb4474b7322b3494bb41c75024e48f4
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Mon Feb 6 10:57:24 2023 +0100

    CAMEL-18131 - camel-health - Add health checks for components that has extension for connectivity verification - AWS Translate
    
    Signed-off-by: Andrea Cosentino <an...@gmail.com>
---
 .../aws2/translate/Translate2ClientHealthCheckProfileCredsTest.java     | 2 +-
 .../aws2/translate/Translate2ClientHealthCheckStaticCredsTest.java      | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/components/camel-aws/camel-aws2-translate/src/test/java/org/apache/camel/component/aws2/translate/Translate2ClientHealthCheckProfileCredsTest.java b/components/camel-aws/camel-aws2-translate/src/test/java/org/apache/camel/component/aws2/translate/Translate2ClientHealthCheckProfileCredsTest.java
index ed627e6309a..1d6cc73bd5f 100644
--- a/components/camel-aws/camel-aws2-translate/src/test/java/org/apache/camel/component/aws2/translate/Translate2ClientHealthCheckProfileCredsTest.java
+++ b/components/camel-aws/camel-aws2-translate/src/test/java/org/apache/camel/component/aws2/translate/Translate2ClientHealthCheckProfileCredsTest.java
@@ -66,7 +66,7 @@ public class Translate2ClientHealthCheckProfileCredsTest extends CamelTestSuppor
             @Override
             public void configure() {
                 from("direct:listClusters")
-                        .to("aws2-translate://test?operation=translate&region=l&useDefaultCredentialsProvider=true");
+                        .to("aws2-translate://test?operation=translateText&region=l&useDefaultCredentialsProvider=true");
             }
         };
     }
diff --git a/components/camel-aws/camel-aws2-translate/src/test/java/org/apache/camel/component/aws2/translate/Translate2ClientHealthCheckStaticCredsTest.java b/components/camel-aws/camel-aws2-translate/src/test/java/org/apache/camel/component/aws2/translate/Translate2ClientHealthCheckStaticCredsTest.java
index ac1bd4bc3c4..ec37013394e 100644
--- a/components/camel-aws/camel-aws2-translate/src/test/java/org/apache/camel/component/aws2/translate/Translate2ClientHealthCheckStaticCredsTest.java
+++ b/components/camel-aws/camel-aws2-translate/src/test/java/org/apache/camel/component/aws2/translate/Translate2ClientHealthCheckStaticCredsTest.java
@@ -66,7 +66,7 @@ public class Translate2ClientHealthCheckStaticCredsTest extends CamelTestSupport
             @Override
             public void configure() {
                 from("direct:listClusters")
-                        .to("aws2-translate://test?operation=translate&region=l&secretKey=l&accessKey=k");
+                        .to("aws2-translate://test?operation=translateText&region=l&secretKey=l&accessKey=k");
             }
         };
     }


[camel] 06/07: CAMEL-18131 - camel-health - Add health checks for components that has extension for connectivity verification - AWS Translate

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 4a46dfe99479bc6cb83501540501fb209a74b851
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Mon Feb 6 10:57:49 2023 +0100

    CAMEL-18131 - camel-health - Add health checks for components that has extension for connectivity verification - AWS Translate
    
    Signed-off-by: Andrea Cosentino <an...@gmail.com>
---
 components/camel-aws/camel-aws2-translate/pom.xml | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/components/camel-aws/camel-aws2-translate/pom.xml b/components/camel-aws/camel-aws2-translate/pom.xml
index 9ab7d553f09..b884aa85aba 100644
--- a/components/camel-aws/camel-aws2-translate/pom.xml
+++ b/components/camel-aws/camel-aws2-translate/pom.xml
@@ -50,6 +50,10 @@
             <artifactId>apache-client</artifactId>
             <version>${aws-java-sdk2-version}</version>
         </dependency>
+        <dependency>
+            <groupId>org.apache.camel</groupId>
+            <artifactId>camel-health</artifactId>
+        </dependency>
 
         <!-- for testing -->
         <dependency>
@@ -57,10 +61,6 @@
             <artifactId>camel-test-spring-junit5</artifactId>
             <scope>test</scope>
         </dependency>
-        <dependency>
-            <groupId>org.apache.camel</groupId>
-            <artifactId>camel-health</artifactId>
-        </dependency>
 
         <!-- test infra -->
         <dependency>