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

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

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();