You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2023/07/28 08:22:39 UTC
[camel] 11/13: CAMEL-19645: camel-aws - producer health check
This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch hc-producer
in repository https://gitbox.apache.org/repos/asf/camel.git
commit 5628a80f361f85287f7190eac51b8752dea3fa57
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Fri Jul 28 10:13:59 2023 +0200
CAMEL-19645: camel-aws - producer health check
---
.../translate/Translate2ComponentConfigurer.java | 18 +++++++++++++
.../component/aws2/translate/aws2-translate.json | 7 +++--
.../aws2/translate/Translate2Component.java | 5 ++--
.../aws2/translate/Translate2Endpoint.java | 24 ++++-------------
.../aws2/translate/Translate2Producer.java | 31 ++++++++++++++++++++++
...eck.java => Translate2ProducerHealthCheck.java} | 6 ++---
...slate2ProducerHealthCheckProfileCredsTest.java} | 13 ++-------
...nslate2ProducerHealthCheckStaticCredsTest.java} | 13 ++-------
8 files changed, 69 insertions(+), 48 deletions(-)
diff --git a/components/camel-aws/camel-aws2-translate/src/generated/java/org/apache/camel/component/aws2/translate/Translate2ComponentConfigurer.java b/components/camel-aws/camel-aws2-translate/src/generated/java/org/apache/camel/component/aws2/translate/Translate2ComponentConfigurer.java
index 79e0476b902..f37195a8d8a 100644
--- a/components/camel-aws/camel-aws2-translate/src/generated/java/org/apache/camel/component/aws2/translate/Translate2ComponentConfigurer.java
+++ b/components/camel-aws/camel-aws2-translate/src/generated/java/org/apache/camel/component/aws2/translate/Translate2ComponentConfigurer.java
@@ -35,6 +35,12 @@ public class Translate2ComponentConfigurer extends PropertyConfigurerSupport imp
case "autowiredenabled":
case "autowiredEnabled": target.setAutowiredEnabled(property(camelContext, boolean.class, value)); return true;
case "configuration": target.setConfiguration(property(camelContext, org.apache.camel.component.aws2.translate.Translate2Configuration.class, value)); return true;
+ case "healthcheckconsumerenabled":
+ case "healthCheckConsumerEnabled": target.setHealthCheckConsumerEnabled(property(camelContext, boolean.class, value)); return true;
+ case "healthcheckenabled":
+ case "healthCheckEnabled": target.setHealthCheckEnabled(property(camelContext, boolean.class, value)); return true;
+ case "healthcheckproducerenabled":
+ case "healthCheckProducerEnabled": target.setHealthCheckProducerEnabled(property(camelContext, boolean.class, value)); return true;
case "lazystartproducer":
case "lazyStartProducer": target.setLazyStartProducer(property(camelContext, boolean.class, value)); return true;
case "operation": getOrCreateConfiguration(target).setOperation(property(camelContext, org.apache.camel.component.aws2.translate.Translate2Operations.class, value)); return true;
@@ -86,6 +92,12 @@ public class Translate2ComponentConfigurer extends PropertyConfigurerSupport imp
case "autowiredenabled":
case "autowiredEnabled": return boolean.class;
case "configuration": return org.apache.camel.component.aws2.translate.Translate2Configuration.class;
+ case "healthcheckconsumerenabled":
+ case "healthCheckConsumerEnabled": return boolean.class;
+ case "healthcheckenabled":
+ case "healthCheckEnabled": return boolean.class;
+ case "healthcheckproducerenabled":
+ case "healthCheckProducerEnabled": return boolean.class;
case "lazystartproducer":
case "lazyStartProducer": return boolean.class;
case "operation": return org.apache.camel.component.aws2.translate.Translate2Operations.class;
@@ -133,6 +145,12 @@ public class Translate2ComponentConfigurer extends PropertyConfigurerSupport imp
case "autowiredenabled":
case "autowiredEnabled": return target.isAutowiredEnabled();
case "configuration": return target.getConfiguration();
+ case "healthcheckconsumerenabled":
+ case "healthCheckConsumerEnabled": return target.isHealthCheckConsumerEnabled();
+ case "healthcheckenabled":
+ case "healthCheckEnabled": return target.isHealthCheckEnabled();
+ case "healthcheckproducerenabled":
+ case "healthCheckProducerEnabled": return target.isHealthCheckProducerEnabled();
case "lazystartproducer":
case "lazyStartProducer": return target.isLazyStartProducer();
case "operation": return getOrCreateConfiguration(target).getOperation();
diff --git a/components/camel-aws/camel-aws2-translate/src/generated/resources/org/apache/camel/component/aws2/translate/aws2-translate.json b/components/camel-aws/camel-aws2-translate/src/generated/resources/org/apache/camel/component/aws2/translate/aws2-translate.json
index 4603ae75b0f..807946ffe31 100644
--- a/components/camel-aws/camel-aws2-translate/src/generated/resources/org/apache/camel/component/aws2/translate/aws2-translate.json
+++ b/components/camel-aws/camel-aws2-translate/src/generated/resources/org/apache/camel/component/aws2/translate/aws2-translate.json
@@ -41,8 +41,11 @@
"useDefaultCredentialsProvider": { "index": 16, "kind": "property", "displayName": "Use Default Credentials Provider", "group": "producer", "label": "", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "configurationClass": "org.apache.camel.component.aws2.translate.Translate2Configuration", "configurationField": "configuration", "description": "Set whether the Translate client should expect [...]
"useProfileCredentialsProvider": { "index": 17, "kind": "property", "displayName": "Use Profile Credentials Provider", "group": "producer", "label": "", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "configurationClass": "org.apache.camel.component.aws2.translate.Translate2Configuration", "configurationField": "configuration", "description": "Set whether the Translate client should expect [...]
"autowiredEnabled": { "index": 18, "kind": "property", "displayName": "Autowired Enabled", "group": "advanced", "label": "advanced", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "description": "Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching [...]
- "accessKey": { "index": 19, "kind": "property", "displayName": "Access Key", "group": "security", "label": "security", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": true, "configurationClass": "org.apache.camel.component.aws2.translate.Translate2Configuration", "configurationField": "configuration", "description": "Amazon AWS Access Key" },
- "secretKey": { "index": 20, "kind": "property", "displayName": "Secret Key", "group": "security", "label": "security", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": true, "configurationClass": "org.apache.camel.component.aws2.translate.Translate2Configuration", "configurationField": "configuration", "description": "Amazon AWS Secret Key" }
+ "healthCheckConsumerEnabled": { "index": 19, "kind": "property", "displayName": "Health Check Consumer Enabled", "group": "health", "label": "health", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "description": "Used for enabling or disabling all consumer based health checks from this component" },
+ "healthCheckEnabled": { "index": 20, "kind": "property", "displayName": "Health Check Enabled", "group": "health", "label": "health", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "description": "Used for enabling or disabling all health checks from this component" },
+ "healthCheckProducerEnabled": { "index": 21, "kind": "property", "displayName": "Health Check Producer Enabled", "group": "health", "label": "health", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "description": "Used for enabling or disabling all producer based health checks from this component" },
+ "accessKey": { "index": 22, "kind": "property", "displayName": "Access Key", "group": "security", "label": "security", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": true, "configurationClass": "org.apache.camel.component.aws2.translate.Translate2Configuration", "configurationField": "configuration", "description": "Amazon AWS Access Key" },
+ "secretKey": { "index": 23, "kind": "property", "displayName": "Secret Key", "group": "security", "label": "security", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": true, "configurationClass": "org.apache.camel.component.aws2.translate.Translate2Configuration", "configurationField": "configuration", "description": "Amazon AWS Secret Key" }
},
"headers": {
"CamelAwsTranslateSourceLanguage": { "index": 0, "kind": "header", "displayName": "", "group": "producer", "label": "", "required": false, "javaType": "String", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "The text source language", "constantName": "org.apache.camel.component.aws2.translate.Translate2Constants#SOURCE_LANGUAGE" },
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 38ef1b5e43b..dfd0cba0f87 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
@@ -22,13 +22,14 @@ import org.apache.camel.CamelContext;
import org.apache.camel.Endpoint;
import org.apache.camel.spi.Metadata;
import org.apache.camel.spi.annotations.Component;
-import org.apache.camel.support.DefaultComponent;
+import org.apache.camel.support.HealthCheckComponent;
/**
* For working with Amazon Translate SDK v2.
*/
@Component("aws2-translate")
-public class Translate2Component extends DefaultComponent {
+public class Translate2Component extends HealthCheckComponent {
+
@Metadata
private Translate2Configuration configuration = new Translate2Configuration();
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 1c0ba85fce8..2c8e430ca84 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,8 +22,6 @@ 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;
@@ -39,9 +37,6 @@ public class Translate2Endpoint extends ScheduledPollEndpoint {
private TranslateClient translateClient;
- private ComponentsHealthCheckRepository healthCheckRepository;
- private Translate2ClientHealthCheck clientHealthCheck;
-
@UriParam
private Translate2Configuration configuration;
@@ -60,6 +55,11 @@ public class Translate2Endpoint extends ScheduledPollEndpoint {
return new Translate2Producer(this);
}
+ @Override
+ public Translate2Component getComponent() {
+ return (Translate2Component) super.getComponent();
+ }
+
@Override
public void doStart() throws Exception {
super.doStart();
@@ -68,24 +68,10 @@ 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) {
- // Do not register the health check until we resolve CAMEL-18992
- // 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();
diff --git a/components/camel-aws/camel-aws2-translate/src/main/java/org/apache/camel/component/aws2/translate/Translate2Producer.java b/components/camel-aws/camel-aws2-translate/src/main/java/org/apache/camel/component/aws2/translate/Translate2Producer.java
index ef6961ed6c0..7edeb156ed2 100644
--- a/components/camel-aws/camel-aws2-translate/src/main/java/org/apache/camel/component/aws2/translate/Translate2Producer.java
+++ b/components/camel-aws/camel-aws2-translate/src/main/java/org/apache/camel/component/aws2/translate/Translate2Producer.java
@@ -22,6 +22,9 @@ import org.apache.camel.Endpoint;
import org.apache.camel.Exchange;
import org.apache.camel.InvalidPayloadException;
import org.apache.camel.Message;
+import org.apache.camel.health.HealthCheck;
+import org.apache.camel.health.HealthCheckHelper;
+import org.apache.camel.health.WritableHealthCheckRepository;
import org.apache.camel.support.DefaultProducer;
import org.apache.camel.util.ObjectHelper;
import org.apache.camel.util.URISupport;
@@ -41,6 +44,8 @@ public class Translate2Producer extends DefaultProducer {
private static final Logger LOG = LoggerFactory.getLogger(Translate2Producer.class);
private transient String translateProducerToString;
+ private HealthCheck producerHealthCheck;
+ private WritableHealthCheckRepository healthCheckRepository;
public Translate2Producer(Endpoint endpoint) {
super(endpoint);
@@ -149,4 +154,30 @@ public class Translate2Producer extends DefaultProducer {
public static Message getMessageForResponse(final Exchange exchange) {
return exchange.getMessage();
}
+
+ @Override
+ protected void doStart() throws Exception {
+ // health-check is optional so discover and resolve
+ healthCheckRepository = HealthCheckHelper.getHealthCheckRepository(
+ getEndpoint().getCamelContext(),
+ "components",
+ WritableHealthCheckRepository.class);
+
+ if (healthCheckRepository != null) {
+ String id = getEndpoint().getId();
+ producerHealthCheck = new Translate2ProducerHealthCheck(getEndpoint(), id);
+ producerHealthCheck.setEnabled(getEndpoint().getComponent().isHealthCheckEnabled()
+ && getEndpoint().getComponent().isHealthCheckProducerEnabled());
+ healthCheckRepository.addHealthCheck(producerHealthCheck);
+ }
+ }
+
+ @Override
+ protected void doStop() throws Exception {
+ if (healthCheckRepository != null && producerHealthCheck != null) {
+ healthCheckRepository.removeHealthCheck(producerHealthCheck);
+ producerHealthCheck = null;
+ }
+ }
+
}
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/Translate2ProducerHealthCheck.java
similarity index 92%
rename from components/camel-aws/camel-aws2-translate/src/main/java/org/apache/camel/component/aws2/translate/Translate2ClientHealthCheck.java
rename to components/camel-aws/camel-aws2-translate/src/main/java/org/apache/camel/component/aws2/translate/Translate2ProducerHealthCheck.java
index e14df57ccac..52a9bc6bd7b 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/Translate2ProducerHealthCheck.java
@@ -27,12 +27,12 @@ import software.amazon.awssdk.regions.Region;
import software.amazon.awssdk.services.translate.TranslateClient;
import software.amazon.awssdk.services.translate.model.ListLanguagesRequest;
-public class Translate2ClientHealthCheck extends AbstractHealthCheck {
+public class Translate2ProducerHealthCheck extends AbstractHealthCheck {
private final Translate2Endpoint translate2Endpoint;
- public Translate2ClientHealthCheck(Translate2Endpoint translate2Endpoint, String clientId) {
- super("camel", "aws2-translate-client-" + clientId);
+ public Translate2ProducerHealthCheck(Translate2Endpoint translate2Endpoint, String clientId) {
+ super("camel", "aws2-translate-producer-" + clientId);
this.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/Translate2ProducerHealthCheckProfileCredsTest.java
similarity index 86%
rename from components/camel-aws/camel-aws2-translate/src/test/java/org/apache/camel/component/aws2/translate/Translate2ClientHealthCheckProfileCredsTest.java
rename to components/camel-aws/camel-aws2-translate/src/test/java/org/apache/camel/component/aws2/translate/Translate2ProducerHealthCheckProfileCredsTest.java
index 3d411b8ed20..4a31d642f5d 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/Translate2ProducerHealthCheckProfileCredsTest.java
@@ -28,16 +28,11 @@ 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.Disabled;
import org.junit.jupiter.api.Test;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import static org.testcontainers.shaded.org.awaitility.Awaitility.await;
-public class Translate2ClientHealthCheckProfileCredsTest extends CamelTestSupport {
-
- private static final Logger LOG = LoggerFactory.getLogger(Translate2ClientHealthCheckProfileCredsTest.class);
+public class Translate2ProducerHealthCheckProfileCredsTest extends CamelTestSupport {
CamelContext context;
@@ -73,9 +68,7 @@ public class Translate2ClientHealthCheckProfileCredsTest extends CamelTestSuppor
}
@Test
- @Disabled("Do not register the Producer Health Check until we solve CAMEL-18992")
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");
@@ -85,9 +78,7 @@ public class Translate2ClientHealthCheckProfileCredsTest extends CamelTestSuppor
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();
+ .anyMatch(result -> result.getCheck().getId().startsWith("aws2-translate-producer"));
boolean hasRegionMessage = res2.stream()
.anyMatch(r -> r.getMessage().stream().anyMatch(msg -> msg.contains("region")));
Assertions.assertTrue(down, "liveness check");
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/Translate2ProducerHealthCheckStaticCredsTest.java
similarity index 86%
rename from components/camel-aws/camel-aws2-translate/src/test/java/org/apache/camel/component/aws2/translate/Translate2ClientHealthCheckStaticCredsTest.java
rename to components/camel-aws/camel-aws2-translate/src/test/java/org/apache/camel/component/aws2/translate/Translate2ProducerHealthCheckStaticCredsTest.java
index 1598abc22db..6fda42cc593 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/Translate2ProducerHealthCheckStaticCredsTest.java
@@ -28,16 +28,11 @@ 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.Disabled;
import org.junit.jupiter.api.Test;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import static org.testcontainers.shaded.org.awaitility.Awaitility.await;
-public class Translate2ClientHealthCheckStaticCredsTest extends CamelTestSupport {
-
- private static final Logger LOG = LoggerFactory.getLogger(Translate2ClientHealthCheckStaticCredsTest.class);
+public class Translate2ProducerHealthCheckStaticCredsTest extends CamelTestSupport {
CamelContext context;
@@ -73,9 +68,7 @@ public class Translate2ClientHealthCheckStaticCredsTest extends CamelTestSupport
}
@Test
- @Disabled("Do not register the Producer Health Check until we solve CAMEL-18992")
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");
@@ -85,9 +78,7 @@ public class Translate2ClientHealthCheckStaticCredsTest extends CamelTestSupport
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();
+ .anyMatch(result -> result.getCheck().getId().startsWith("aws2-translate-producer"));
boolean hasRegionMessage = res2.stream()
.anyMatch(r -> r.getMessage().stream().anyMatch(msg -> msg.contains("region")));
Assertions.assertTrue(down, "liveness check");