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:37 UTC
[camel] 09/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 ae2d5c82324955205cf258ca8a8e54f034e6de5d
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Fri Jul 28 10:08:57 2023 +0200
CAMEL-19645: camel-aws - producer health check
---
.../aws2/ses/Ses2ComponentConfigurer.java | 18 +++++++++++++
.../apache/camel/component/aws2/ses/aws2-ses.json | 7 +++--
.../camel/component/aws2/ses/Ses2Component.java | 5 ++--
.../camel/component/aws2/ses/Ses2Endpoint.java | 25 ++++-------------
.../camel/component/aws2/ses/Ses2Producer.java | 31 ++++++++++++++++++++++
...althCheck.java => Ses2ProducerHealthCheck.java} | 7 +++--
...> Ses2ProducerHealthCheckProfileCredsTest.java} | 13 ++-------
...=> Ses2ProducerHealthCheckStaticCredsTest.java} | 13 ++-------
8 files changed, 69 insertions(+), 50 deletions(-)
diff --git a/components/camel-aws/camel-aws2-ses/src/generated/java/org/apache/camel/component/aws2/ses/Ses2ComponentConfigurer.java b/components/camel-aws/camel-aws2-ses/src/generated/java/org/apache/camel/component/aws2/ses/Ses2ComponentConfigurer.java
index 8932a4cc8fd..ea747b17fe1 100644
--- a/components/camel-aws/camel-aws2-ses/src/generated/java/org/apache/camel/component/aws2/ses/Ses2ComponentConfigurer.java
+++ b/components/camel-aws/camel-aws2-ses/src/generated/java/org/apache/camel/component/aws2/ses/Ses2ComponentConfigurer.java
@@ -39,6 +39,12 @@ public class Ses2ComponentConfigurer extends PropertyConfigurerSupport implement
case "configuration": target.setConfiguration(property(camelContext, org.apache.camel.component.aws2.ses.Ses2Configuration.class, value)); return true;
case "configurationset":
case "configurationSet": getOrCreateConfiguration(target).setConfigurationSet(property(camelContext, java.lang.String.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 "overrideendpoint":
@@ -91,6 +97,12 @@ public class Ses2ComponentConfigurer extends PropertyConfigurerSupport implement
case "configuration": return org.apache.camel.component.aws2.ses.Ses2Configuration.class;
case "configurationset":
case "configurationSet": return java.lang.String.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 "overrideendpoint":
@@ -139,6 +151,12 @@ public class Ses2ComponentConfigurer extends PropertyConfigurerSupport implement
case "configuration": return target.getConfiguration();
case "configurationset":
case "configurationSet": return getOrCreateConfiguration(target).getConfigurationSet();
+ 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 "overrideendpoint":
diff --git a/components/camel-aws/camel-aws2-ses/src/generated/resources/org/apache/camel/component/aws2/ses/aws2-ses.json b/components/camel-aws/camel-aws2-ses/src/generated/resources/org/apache/camel/component/aws2/ses/aws2-ses.json
index 5cdca1ffe7f..cbc64a45e2c 100644
--- a/components/camel-aws/camel-aws2-ses/src/generated/resources/org/apache/camel/component/aws2/ses/aws2-ses.json
+++ b/components/camel-aws/camel-aws2-ses/src/generated/resources/org/apache/camel/component/aws2/ses/aws2-ses.json
@@ -43,8 +43,11 @@
"useDefaultCredentialsProvider": { "index": 18, "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.ses.Ses2Configuration", "configurationField": "configuration", "description": "Set whether the Ses client should expect to load credential [...]
"useProfileCredentialsProvider": { "index": 19, "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.ses.Ses2Configuration", "configurationField": "configuration", "description": "Set whether the SES client should expect to load credential [...]
"autowiredEnabled": { "index": 20, "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": 21, "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.ses.Ses2Configuration", "configurationField": "configuration", "description": "Amazon AWS Access Key" },
- "secretKey": { "index": 22, "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.ses.Ses2Configuration", "configurationField": "configuration", "description": "Amazon AWS Secret Key" }
+ "healthCheckConsumerEnabled": { "index": 21, "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": 22, "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": 23, "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": 24, "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.ses.Ses2Configuration", "configurationField": "configuration", "description": "Amazon AWS Access Key" },
+ "secretKey": { "index": 25, "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.ses.Ses2Configuration", "configurationField": "configuration", "description": "Amazon AWS Secret Key" }
},
"headers": {
"CamelAwsSesFrom": { "index": 0, "kind": "header", "displayName": "", "group": "producer", "label": "", "required": false, "javaType": "String", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "The sender's email address.", "constantName": "org.apache.camel.component.aws2.ses.Ses2Constants#FROM" },
diff --git a/components/camel-aws/camel-aws2-ses/src/main/java/org/apache/camel/component/aws2/ses/Ses2Component.java b/components/camel-aws/camel-aws2-ses/src/main/java/org/apache/camel/component/aws2/ses/Ses2Component.java
index a00d06544b2..1b0cd4211d9 100644
--- a/components/camel-aws/camel-aws2-ses/src/main/java/org/apache/camel/component/aws2/ses/Ses2Component.java
+++ b/components/camel-aws/camel-aws2-ses/src/main/java/org/apache/camel/component/aws2/ses/Ses2Component.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 SES SDK v2.
*/
@Component("aws2-ses")
-public class Ses2Component extends DefaultComponent {
+public class Ses2Component extends HealthCheckComponent {
+
@Metadata
private Ses2Configuration configuration = new Ses2Configuration();
diff --git a/components/camel-aws/camel-aws2-ses/src/main/java/org/apache/camel/component/aws2/ses/Ses2Endpoint.java b/components/camel-aws/camel-aws2-ses/src/main/java/org/apache/camel/component/aws2/ses/Ses2Endpoint.java
index ce97a04bebf..e98049ca874 100644
--- a/components/camel-aws/camel-aws2-ses/src/main/java/org/apache/camel/component/aws2/ses/Ses2Endpoint.java
+++ b/components/camel-aws/camel-aws2-ses/src/main/java/org/apache/camel/component/aws2/ses/Ses2Endpoint.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.ses.client.Ses2ClientFactory;
-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.DefaultEndpoint;
@@ -37,9 +35,6 @@ import software.amazon.awssdk.services.ses.SesClient;
producerOnly = true, category = { Category.CLOUD, Category.MAIL }, headersClass = Ses2Constants.class)
public class Ses2Endpoint extends DefaultEndpoint {
- private ComponentsHealthCheckRepository healthCheckRepository;
- private Ses2HealthCheck clientHealthCheck;
-
private SesClient sesClient;
@UriParam
@@ -50,21 +45,17 @@ public class Ses2Endpoint extends DefaultEndpoint {
this.configuration = configuration;
}
+ @Override
+ public Ses2Component getComponent() {
+ return (Ses2Component) super.getComponent();
+ }
+
@Override
public void doStart() throws Exception {
super.doStart();
sesClient = configuration.getAmazonSESClient() != null
? configuration.getAmazonSESClient()
: Ses2ClientFactory.getSesClient(configuration).getSesClient();
-
- 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 Ses2HealthCheck(this, getId());
- // healthCheckRepository.addHealthCheck(clientHealthCheck);
- }
}
@Override
@@ -74,12 +65,6 @@ public class Ses2Endpoint extends DefaultEndpoint {
sesClient.close();
}
}
-
- if (healthCheckRepository != null && clientHealthCheck != null) {
- healthCheckRepository.removeHealthCheck(clientHealthCheck);
- clientHealthCheck = null;
- }
-
super.doStop();
}
diff --git a/components/camel-aws/camel-aws2-ses/src/main/java/org/apache/camel/component/aws2/ses/Ses2Producer.java b/components/camel-aws/camel-aws2-ses/src/main/java/org/apache/camel/component/aws2/ses/Ses2Producer.java
index fb24f157524..e68b83ec895 100644
--- a/components/camel-aws/camel-aws2-ses/src/main/java/org/apache/camel/component/aws2/ses/Ses2Producer.java
+++ b/components/camel-aws/camel-aws2-ses/src/main/java/org/apache/camel/component/aws2/ses/Ses2Producer.java
@@ -27,6 +27,9 @@ import java.util.stream.Stream;
import org.apache.camel.Endpoint;
import org.apache.camel.Exchange;
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;
@@ -50,6 +53,8 @@ public class Ses2Producer extends DefaultProducer {
private static final Logger LOG = LoggerFactory.getLogger(Ses2Producer.class);
private transient String sesProducerToString;
+ private HealthCheck producerHealthCheck;
+ private WritableHealthCheckRepository healthCheckRepository;
public Ses2Producer(Endpoint endpoint) {
super(endpoint);
@@ -240,4 +245,30 @@ public class Ses2Producer 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 Ses2ProducerHealthCheck(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-ses/src/main/java/org/apache/camel/component/aws2/ses/Ses2HealthCheck.java b/components/camel-aws/camel-aws2-ses/src/main/java/org/apache/camel/component/aws2/ses/Ses2ProducerHealthCheck.java
similarity index 91%
rename from components/camel-aws/camel-aws2-ses/src/main/java/org/apache/camel/component/aws2/ses/Ses2HealthCheck.java
rename to components/camel-aws/camel-aws2-ses/src/main/java/org/apache/camel/component/aws2/ses/Ses2ProducerHealthCheck.java
index b04ccd928ac..f9c632f02fa 100644
--- a/components/camel-aws/camel-aws2-ses/src/main/java/org/apache/camel/component/aws2/ses/Ses2HealthCheck.java
+++ b/components/camel-aws/camel-aws2-ses/src/main/java/org/apache/camel/component/aws2/ses/Ses2ProducerHealthCheck.java
@@ -24,18 +24,17 @@ import software.amazon.awssdk.awscore.exception.AwsServiceException;
import software.amazon.awssdk.regions.Region;
import software.amazon.awssdk.services.ses.SesClient;
-public class Ses2HealthCheck extends AbstractHealthCheck {
+public class Ses2ProducerHealthCheck extends AbstractHealthCheck {
private final Ses2Endpoint ses2Endpoint;
- public Ses2HealthCheck(Ses2Endpoint ses2Endpoint, String clientId) {
- super("camel", "aws2-ses-client-" + clientId);
+ public Ses2ProducerHealthCheck(Ses2Endpoint ses2Endpoint, String clientId) {
+ super("camel", "aws2-ses-producer-" + clientId);
this.ses2Endpoint = ses2Endpoint;
}
@Override
protected void doCall(HealthCheckResultBuilder builder, Map<String, Object> options) {
-
Ses2Configuration configuration = ses2Endpoint.getConfiguration();
try {
if (!SesClient.serviceMetadata().regions().contains(Region.of(configuration.getRegion()))) {
diff --git a/components/camel-aws/camel-aws2-ses/src/test/java/org/apache/camel/component/aws2/ses/Ses2HealthCheckProfileCredsTest.java b/components/camel-aws/camel-aws2-ses/src/test/java/org/apache/camel/component/aws2/ses/Ses2ProducerHealthCheckProfileCredsTest.java
similarity index 87%
rename from components/camel-aws/camel-aws2-ses/src/test/java/org/apache/camel/component/aws2/ses/Ses2HealthCheckProfileCredsTest.java
rename to components/camel-aws/camel-aws2-ses/src/test/java/org/apache/camel/component/aws2/ses/Ses2ProducerHealthCheckProfileCredsTest.java
index 35ae715957f..c8dcd536052 100644
--- a/components/camel-aws/camel-aws2-ses/src/test/java/org/apache/camel/component/aws2/ses/Ses2HealthCheckProfileCredsTest.java
+++ b/components/camel-aws/camel-aws2-ses/src/test/java/org/apache/camel/component/aws2/ses/Ses2ProducerHealthCheckProfileCredsTest.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 Ses2HealthCheckProfileCredsTest extends CamelTestSupport {
-
- private static final Logger LOG = LoggerFactory.getLogger(Ses2HealthCheckProfileCredsTest.class);
+public class Ses2ProducerHealthCheckProfileCredsTest extends CamelTestSupport {
CamelContext context;
@@ -73,9 +68,7 @@ public class Ses2HealthCheckProfileCredsTest 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 Ses2HealthCheckProfileCredsTest extends CamelTestSupport {
Collection<HealthCheck.Result> res2 = HealthCheckHelper.invokeReadiness(context);
boolean down = res2.stream().allMatch(r -> r.getState().equals(HealthCheck.State.DOWN));
boolean containsAws2AthenaHealthCheck = res2.stream()
- .filter(result -> result.getCheck().getId().startsWith("aws2-ses-client"))
- .findAny()
- .isPresent();
+ .anyMatch(result -> result.getCheck().getId().startsWith("aws2-ses-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-ses/src/test/java/org/apache/camel/component/aws2/ses/Ses2HealthCheckStaticCredsTest.java b/components/camel-aws/camel-aws2-ses/src/test/java/org/apache/camel/component/aws2/ses/Ses2ProducerHealthCheckStaticCredsTest.java
similarity index 87%
rename from components/camel-aws/camel-aws2-ses/src/test/java/org/apache/camel/component/aws2/ses/Ses2HealthCheckStaticCredsTest.java
rename to components/camel-aws/camel-aws2-ses/src/test/java/org/apache/camel/component/aws2/ses/Ses2ProducerHealthCheckStaticCredsTest.java
index f38913f7af4..25dee40304b 100644
--- a/components/camel-aws/camel-aws2-ses/src/test/java/org/apache/camel/component/aws2/ses/Ses2HealthCheckStaticCredsTest.java
+++ b/components/camel-aws/camel-aws2-ses/src/test/java/org/apache/camel/component/aws2/ses/Ses2ProducerHealthCheckStaticCredsTest.java
@@ -27,16 +27,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 Ses2HealthCheckStaticCredsTest extends CamelTestSupport {
-
- private static final Logger LOG = LoggerFactory.getLogger(Ses2HealthCheckStaticCredsTest.class);
+public class Ses2ProducerHealthCheckStaticCredsTest extends CamelTestSupport {
CamelContext context;
@@ -72,9 +67,7 @@ public class Ses2HealthCheckStaticCredsTest 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");
@@ -84,9 +77,7 @@ public class Ses2HealthCheckStaticCredsTest extends CamelTestSupport {
Collection<HealthCheck.Result> res2 = HealthCheckHelper.invokeReadiness(context);
boolean down = res2.stream().allMatch(r -> r.getState().equals(HealthCheck.State.DOWN));
boolean containsAws2AthenaHealthCheck = res2.stream()
- .filter(result -> result.getCheck().getId().startsWith("aws2-ses-client"))
- .findAny()
- .isPresent();
+ .anyMatch(result -> result.getCheck().getId().startsWith("aws2-ses-producer"));
boolean hasRegionMessage = res2.stream()
.anyMatch(r -> r.getMessage().stream().anyMatch(msg -> msg.contains("region")));
Assertions.assertTrue(down, "liveness check");