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:32 UTC
[camel] 04/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 ea264fd327a5c8e6bc43df962332d43ff42bd8fa
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Fri Jul 28 09:54:28 2023 +0200
CAMEL-19645: camel-aws - producer health check
---
.../aws2/eks/EKS2ComponentConfigurer.java | 18 +++++++++++++
.../apache/camel/component/aws2/eks/aws2-eks.json | 7 +++--
.../camel/component/aws2/eks/EKS2Component.java | 5 ++--
.../camel/component/aws2/eks/EKS2Endpoint.java | 23 ++++------------
.../camel/component/aws2/eks/EKS2Producer.java | 31 ++++++++++++++++++++++
...althCheck.java => EKS2ProducerHealthCheck.java} | 6 ++---
...> EKS2ProducerHealthCheckProfileCredsTest.java} | 13 ++-------
...=> EKS2ProducerHealthCheckStaticCredsTest.java} | 12 ++-------
8 files changed, 69 insertions(+), 46 deletions(-)
diff --git a/components/camel-aws/camel-aws2-eks/src/generated/java/org/apache/camel/component/aws2/eks/EKS2ComponentConfigurer.java b/components/camel-aws/camel-aws2-eks/src/generated/java/org/apache/camel/component/aws2/eks/EKS2ComponentConfigurer.java
index f70f9afd3f9..a388cd6adea 100644
--- a/components/camel-aws/camel-aws2-eks/src/generated/java/org/apache/camel/component/aws2/eks/EKS2ComponentConfigurer.java
+++ b/components/camel-aws/camel-aws2-eks/src/generated/java/org/apache/camel/component/aws2/eks/EKS2ComponentConfigurer.java
@@ -35,6 +35,12 @@ public class EKS2ComponentConfigurer extends PropertyConfigurerSupport implement
case "configuration": target.setConfiguration(property(camelContext, org.apache.camel.component.aws2.eks.EKS2Configuration.class, value)); return true;
case "eksclient":
case "eksClient": getOrCreateConfiguration(target).setEksClient(property(camelContext, software.amazon.awssdk.services.eks.EksClient.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.eks.EKS2Operations.class, value)); return true;
@@ -80,6 +86,12 @@ public class EKS2ComponentConfigurer extends PropertyConfigurerSupport implement
case "configuration": return org.apache.camel.component.aws2.eks.EKS2Configuration.class;
case "eksclient":
case "eksClient": return software.amazon.awssdk.services.eks.EksClient.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.eks.EKS2Operations.class;
@@ -121,6 +133,12 @@ public class EKS2ComponentConfigurer extends PropertyConfigurerSupport implement
case "configuration": return target.getConfiguration();
case "eksclient":
case "eksClient": return getOrCreateConfiguration(target).getEksClient();
+ 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-eks/src/generated/resources/org/apache/camel/component/aws2/eks/aws2-eks.json b/components/camel-aws/camel-aws2-eks/src/generated/resources/org/apache/camel/component/aws2/eks/aws2-eks.json
index fea921f0b44..ec6cacc4173 100644
--- a/components/camel-aws/camel-aws2-eks/src/generated/resources/org/apache/camel/component/aws2/eks/aws2-eks.json
+++ b/components/camel-aws/camel-aws2-eks/src/generated/resources/org/apache/camel/component/aws2/eks/aws2-eks.json
@@ -38,8 +38,11 @@
"useDefaultCredentialsProvider": { "index": 13, "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.eks.EKS2Configuration", "configurationField": "configuration", "description": "Set whether the EKS client should expect to load credential [...]
"useProfileCredentialsProvider": { "index": 14, "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.eks.EKS2Configuration", "configurationField": "configuration", "description": "Set whether the EKS client should expect to load credential [...]
"autowiredEnabled": { "index": 15, "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": 16, "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.eks.EKS2Configuration", "configurationField": "configuration", "description": "Amazon AWS Access Key" },
- "secretKey": { "index": 17, "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.eks.EKS2Configuration", "configurationField": "configuration", "description": "Amazon AWS Secret Key" }
+ "healthCheckConsumerEnabled": { "index": 16, "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": 17, "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": 18, "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": 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.eks.EKS2Configuration", "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.eks.EKS2Configuration", "configurationField": "configuration", "description": "Amazon AWS Secret Key" }
},
"headers": {
"CamelAwsEKSOperation": { "index": 0, "kind": "header", "displayName": "", "group": "producer", "label": "", "required": false, "javaType": "String", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "The operation we want to perform", "constantName": "org.apache.camel.component.aws2.eks.EKS2Constants#OPERATION" },
diff --git a/components/camel-aws/camel-aws2-eks/src/main/java/org/apache/camel/component/aws2/eks/EKS2Component.java b/components/camel-aws/camel-aws2-eks/src/main/java/org/apache/camel/component/aws2/eks/EKS2Component.java
index d67bd10d79f..3473c54866a 100644
--- a/components/camel-aws/camel-aws2-eks/src/main/java/org/apache/camel/component/aws2/eks/EKS2Component.java
+++ b/components/camel-aws/camel-aws2-eks/src/main/java/org/apache/camel/component/aws2/eks/EKS2Component.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 EKS SDK v2.
*/
@Component("aws2-eks")
-public class EKS2Component extends DefaultComponent {
+public class EKS2Component extends HealthCheckComponent {
+
@Metadata
private EKS2Configuration configuration = new EKS2Configuration();
diff --git a/components/camel-aws/camel-aws2-eks/src/main/java/org/apache/camel/component/aws2/eks/EKS2Endpoint.java b/components/camel-aws/camel-aws2-eks/src/main/java/org/apache/camel/component/aws2/eks/EKS2Endpoint.java
index 6d20b1815ca..f825c02c739 100644
--- a/components/camel-aws/camel-aws2-eks/src/main/java/org/apache/camel/component/aws2/eks/EKS2Endpoint.java
+++ b/components/camel-aws/camel-aws2-eks/src/main/java/org/apache/camel/component/aws2/eks/EKS2Endpoint.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.eks.client.EKS2ClientFactory;
-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,8 +37,6 @@ import software.amazon.awssdk.services.eks.EksClient;
public class EKS2Endpoint extends ScheduledPollEndpoint {
private EksClient eksClient;
- private ComponentsHealthCheckRepository healthCheckRepository;
- private EKS2ClientHealthCheck clientHealthCheck;
@UriParam
private EKS2Configuration configuration;
@@ -60,30 +56,21 @@ public class EKS2Endpoint extends ScheduledPollEndpoint {
return new EKS2Producer(this);
}
+ @Override
+ public EKS2Component getComponent() {
+ return (EKS2Component) super.getComponent();
+ }
+
@Override
public void doStart() throws Exception {
super.doStart();
eksClient = configuration.getEksClient() != null
? configuration.getEksClient() : EKS2ClientFactory.getEksClient(configuration).getEksClient();
-
- 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 EKS2ClientHealthCheck(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.getEksClient())) {
if (eksClient != null) {
eksClient.close();
diff --git a/components/camel-aws/camel-aws2-eks/src/main/java/org/apache/camel/component/aws2/eks/EKS2Producer.java b/components/camel-aws/camel-aws2-eks/src/main/java/org/apache/camel/component/aws2/eks/EKS2Producer.java
index a6f1755d96f..892095f480a 100644
--- a/components/camel-aws/camel-aws2-eks/src/main/java/org/apache/camel/component/aws2/eks/EKS2Producer.java
+++ b/components/camel-aws/camel-aws2-eks/src/main/java/org/apache/camel/component/aws2/eks/EKS2Producer.java
@@ -20,6 +20,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;
@@ -44,6 +47,8 @@ public class EKS2Producer extends DefaultProducer {
private static final Logger LOG = LoggerFactory.getLogger(EKS2Producer.class);
private transient String eksProducerToString;
+ private HealthCheck producerHealthCheck;
+ private WritableHealthCheckRepository healthCheckRepository;
public EKS2Producer(Endpoint endpoint) {
super(endpoint);
@@ -237,4 +242,30 @@ public class EKS2Producer 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 EKS2ProducerHealthCheck(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-eks/src/main/java/org/apache/camel/component/aws2/eks/EKS2ClientHealthCheck.java b/components/camel-aws/camel-aws2-eks/src/main/java/org/apache/camel/component/aws2/eks/EKS2ProducerHealthCheck.java
similarity index 92%
rename from components/camel-aws/camel-aws2-eks/src/main/java/org/apache/camel/component/aws2/eks/EKS2ClientHealthCheck.java
rename to components/camel-aws/camel-aws2-eks/src/main/java/org/apache/camel/component/aws2/eks/EKS2ProducerHealthCheck.java
index 3f094582d18..cb37ec160de 100644
--- a/components/camel-aws/camel-aws2-eks/src/main/java/org/apache/camel/component/aws2/eks/EKS2ClientHealthCheck.java
+++ b/components/camel-aws/camel-aws2-eks/src/main/java/org/apache/camel/component/aws2/eks/EKS2ProducerHealthCheck.java
@@ -27,12 +27,12 @@ import software.amazon.awssdk.regions.Region;
import software.amazon.awssdk.services.eks.EksClient;
import software.amazon.awssdk.services.eks.model.ListClustersRequest;
-public class EKS2ClientHealthCheck extends AbstractHealthCheck {
+public class EKS2ProducerHealthCheck extends AbstractHealthCheck {
private final EKS2Endpoint eks2Endpoint;
- public EKS2ClientHealthCheck(EKS2Endpoint eks2Endpoint, String clientId) {
- super("camel", "aws2-eks-client-" + clientId);
+ public EKS2ProducerHealthCheck(EKS2Endpoint eks2Endpoint, String clientId) {
+ super("camel", "aws2-eks-producer-" + clientId);
this.eks2Endpoint = eks2Endpoint;
}
diff --git a/components/camel-aws/camel-aws2-eks/src/test/java/org/apache/camel/component/aws2/eks/EKS2CliientHealthCheckProfileCredsTest.java b/components/camel-aws/camel-aws2-eks/src/test/java/org/apache/camel/component/aws2/eks/EKS2ProducerHealthCheckProfileCredsTest.java
similarity index 87%
rename from components/camel-aws/camel-aws2-eks/src/test/java/org/apache/camel/component/aws2/eks/EKS2CliientHealthCheckProfileCredsTest.java
rename to components/camel-aws/camel-aws2-eks/src/test/java/org/apache/camel/component/aws2/eks/EKS2ProducerHealthCheckProfileCredsTest.java
index 7d5397631cc..b137373673c 100644
--- a/components/camel-aws/camel-aws2-eks/src/test/java/org/apache/camel/component/aws2/eks/EKS2CliientHealthCheckProfileCredsTest.java
+++ b/components/camel-aws/camel-aws2-eks/src/test/java/org/apache/camel/component/aws2/eks/EKS2ProducerHealthCheckProfileCredsTest.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 EKS2CliientHealthCheckProfileCredsTest extends CamelTestSupport {
-
- private static final Logger LOG = LoggerFactory.getLogger(EKS2CliientHealthCheckProfileCredsTest.class);
+public class EKS2ProducerHealthCheckProfileCredsTest extends CamelTestSupport {
CamelContext context;
@@ -73,9 +68,7 @@ public class EKS2CliientHealthCheckProfileCredsTest 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 EKS2CliientHealthCheckProfileCredsTest 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-eks-client"))
- .findAny()
- .isPresent();
+ .anyMatch(result -> result.getCheck().getId().startsWith("aws2-eks-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-eks/src/test/java/org/apache/camel/component/aws2/eks/EKS2CliientHealthCheckStaticCredsTest.java b/components/camel-aws/camel-aws2-eks/src/test/java/org/apache/camel/component/aws2/eks/EKS2ProducerHealthCheckStaticCredsTest.java
similarity index 87%
rename from components/camel-aws/camel-aws2-eks/src/test/java/org/apache/camel/component/aws2/eks/EKS2CliientHealthCheckStaticCredsTest.java
rename to components/camel-aws/camel-aws2-eks/src/test/java/org/apache/camel/component/aws2/eks/EKS2ProducerHealthCheckStaticCredsTest.java
index deeceeb2200..a1592744be9 100644
--- a/components/camel-aws/camel-aws2-eks/src/test/java/org/apache/camel/component/aws2/eks/EKS2CliientHealthCheckStaticCredsTest.java
+++ b/components/camel-aws/camel-aws2-eks/src/test/java/org/apache/camel/component/aws2/eks/EKS2ProducerHealthCheckStaticCredsTest.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 EKS2CliientHealthCheckStaticCredsTest extends CamelTestSupport {
-
- private static final Logger LOG = LoggerFactory.getLogger(EKS2CliientHealthCheckStaticCredsTest.class);
+public class EKS2ProducerHealthCheckStaticCredsTest extends CamelTestSupport {
CamelContext context;
@@ -73,7 +68,6 @@ public class EKS2CliientHealthCheckStaticCredsTest 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);
@@ -85,9 +79,7 @@ public class EKS2CliientHealthCheckStaticCredsTest 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-eks-client"))
- .findAny()
- .isPresent();
+ .anyMatch(result -> result.getCheck().getId().startsWith("aws2-eks-producer"));
boolean hasRegionMessage = res2.stream()
.anyMatch(r -> r.getMessage().stream().anyMatch(msg -> msg.contains("region")));
Assertions.assertTrue(down, "liveness check");