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:21 UTC

[camel] branch camel-3.20.x updated (9f81a4e59ad -> 7b798269d9e)

This is an automated email from the ASF dual-hosted git repository.

acosentino pushed a change to branch camel-3.20.x
in repository https://gitbox.apache.org/repos/asf/camel.git


    from 9f81a4e59ad CAMEL-18980: Fix snmp  V1
     new a1f32a78b32 CAMEL-18131 - camel-health - Add health checks for components that has extension for connectivity verification - AWS Translate
     new 86accf4e235 CAMEL-18131 - camel-health - Add health checks for components that has extension for connectivity verification - AWS Translate
     new 416bf750c70 CAMEL-18131 - camel-health - Add health checks for components that has extension for connectivity verification - AWS Translate
     new d3712d36260 CAMEL-18131 - camel-health - Add health checks for components that has extension for connectivity verification - AWS Translate
     new 4fc0887a282 CAMEL-18131 - camel-health - Add health checks for components that has extension for connectivity verification - AWS Translate
     new 7d185b082d0 CAMEL-18131 - camel-health - Add health checks for components that has extension for connectivity verification - AWS Translate
     new de7747d1613 CAMEL-18131 - camel-health - Add health checks for components that has extension for connectivity verification - AWS Translate
     new 7b798269d9e CAMEL-18131 - camel-health - Add health checks for components that has extension for connectivity verification - AWS Translate

The 8 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-lambda/src/main/java/org/apache/camel/component/aws2/lambda/Lambda2ClientHealthCheck.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/EKS2CliientHealthCheckProfileCredsTest.java => camel-aws2-translate/src/test/java/org/apache/camel/component/aws2/translate/Translate2ClientHealthCheckStaticCredsTest.java} (83%)


[camel] 03/08: 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 camel-3.20.x
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 416bf750c70288bf57509128fe5ab08821b50528
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] 05/08: 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 camel-3.20.x
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 4fc0887a28200ea2b7e5531682b9ac9ae133df5e
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] 02/08: 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 camel-3.20.x
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 86accf4e235ec96935fdd1771e96f9170cddd938
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 e9f2f75a3fd..2c3c50ea39a 100644
--- a/components/camel-aws/camel-aws2-translate/pom.xml
+++ b/components/camel-aws/camel-aws2-translate/pom.xml
@@ -62,5 +62,9 @@
             <artifactId>log4j-slf4j-impl</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] 04/08: 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 camel-3.20.x
in repository https://gitbox.apache.org/repos/asf/camel.git

commit d3712d36260da8402765305ac083e2193465613c
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 2c3c50ea39a..8520feb260e 100644
--- a/components/camel-aws/camel-aws2-translate/pom.xml
+++ b/components/camel-aws/camel-aws2-translate/pom.xml
@@ -66,5 +66,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/08: 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 camel-3.20.x
in repository https://gitbox.apache.org/repos/asf/camel.git

commit de7747d1613b89d4bb52cb251a25087182b340a4
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] 08/08: 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 camel-3.20.x
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 7b798269d9eb05229d2e0537a6c325a4ab2b470b
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Mon Feb 6 11:09:30 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 ----
 1 file changed, 4 deletions(-)

diff --git a/components/camel-aws/camel-aws2-translate/pom.xml b/components/camel-aws/camel-aws2-translate/pom.xml
index 1c2839ec4cc..2cc433c287c 100644
--- a/components/camel-aws/camel-aws2-translate/pom.xml
+++ b/components/camel-aws/camel-aws2-translate/pom.xml
@@ -66,10 +66,6 @@
             <artifactId>log4j-slf4j-impl</artifactId>
             <scope>test</scope>
         </dependency>
-        <dependency>
-            <groupId>org.apache.camel</groupId>
-            <artifactId>camel-health</artifactId>
-        </dependency>
 
         <!-- test infra -->
         <dependency>


[camel] 01/08: 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 camel-3.20.x
in repository https://gitbox.apache.org/repos/asf/camel.git

commit a1f32a78b32ada7685b53ce4cd3f0967bb44fbd7
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 2730071247c..3c3f2e868f8 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
@@ -43,8 +43,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] 06/08: 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 camel-3.20.x
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 7d185b082d074573f552979216b6702989c14259
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 | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/components/camel-aws/camel-aws2-translate/pom.xml b/components/camel-aws/camel-aws2-translate/pom.xml
index 8520feb260e..1c2839ec4cc 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>