You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ja...@apache.org on 2021/03/29 14:34:27 UTC
[camel] branch master updated: CAMEL-16391: Deprecate and remove
redundant health checks in camel-microprofile-health
This is an automated email from the ASF dual-hosted git repository.
jamesnetherton pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/master by this push:
new 4cb6284 CAMEL-16391: Deprecate and remove redundant health checks in camel-microprofile-health
4cb6284 is described below
commit 4cb6284ea317454cc819db2b4ace09e6c65485fd
Author: James Netherton <ja...@gmail.com>
AuthorDate: Mon Mar 29 11:12:05 2021 +0100
CAMEL-16391: Deprecate and remove redundant health checks in camel-microprofile-health
---
.../camel/catalog/docs/microprofile-health.adoc | 8 ++-
.../src/main/docs/microprofile-health.adoc | 8 ++-
.../AbstractCamelMicroProfileHealthCheck.java | 7 +--
.../AbstractCamelMicroProfileLivenessCheck.java | 3 +
.../AbstractCamelMicroProfileReadinessCheck.java | 3 +
.../health/CamelMicroProfileContextCheck.java | 73 ----------------------
.../health/CamelMicroProfileHealthCheckTest.java | 21 ++++---
.../modules/others/pages/microprofile-health.adoc | 8 ++-
8 files changed, 37 insertions(+), 94 deletions(-)
diff --git a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/microprofile-health.adoc b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/microprofile-health.adoc
index 5c0d050..fa1ad93 100644
--- a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/microprofile-health.adoc
+++ b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/microprofile-health.adoc
@@ -29,13 +29,13 @@ for this component:
== Usage
By default, Camel health checks are registered as both MicroProfile Health liveness and readiness checks. To have finer control over whether a Camel health check should
-be considered either a readiness or liveness check, you can extend the `AbstractCamelMicroProfileLivenessCheck` and `AbstractCamelMicroProfileReadinessCheck` classes.
+be considered either a readiness or liveness check, you can extend `AbstractHealthCheck` and override the `isLiveness()` and `isReadiness()` methods.
For example, to have a check registered exclusively as a liveness check:
[source,java]
----
-public class MyHealthCheck extends AbstractCamelMicroProfileLivenessCheck {
+public class MyHealthCheck extends AbstractHealthCheck {
public MyHealthCheck() {
super("my-liveness-check-id");
@@ -52,6 +52,10 @@ public class MyHealthCheck extends AbstractCamelMicroProfileLivenessCheck {
builder.down();
}
}
+
+ public boolean isReadiness() {
+ return false;
+ }
}
----
diff --git a/components/camel-microprofile/camel-microprofile-health/src/main/docs/microprofile-health.adoc b/components/camel-microprofile/camel-microprofile-health/src/main/docs/microprofile-health.adoc
index 5c0d050..fa1ad93 100644
--- a/components/camel-microprofile/camel-microprofile-health/src/main/docs/microprofile-health.adoc
+++ b/components/camel-microprofile/camel-microprofile-health/src/main/docs/microprofile-health.adoc
@@ -29,13 +29,13 @@ for this component:
== Usage
By default, Camel health checks are registered as both MicroProfile Health liveness and readiness checks. To have finer control over whether a Camel health check should
-be considered either a readiness or liveness check, you can extend the `AbstractCamelMicroProfileLivenessCheck` and `AbstractCamelMicroProfileReadinessCheck` classes.
+be considered either a readiness or liveness check, you can extend `AbstractHealthCheck` and override the `isLiveness()` and `isReadiness()` methods.
For example, to have a check registered exclusively as a liveness check:
[source,java]
----
-public class MyHealthCheck extends AbstractCamelMicroProfileLivenessCheck {
+public class MyHealthCheck extends AbstractHealthCheck {
public MyHealthCheck() {
super("my-liveness-check-id");
@@ -52,6 +52,10 @@ public class MyHealthCheck extends AbstractCamelMicroProfileLivenessCheck {
builder.down();
}
}
+
+ public boolean isReadiness() {
+ return false;
+ }
}
----
diff --git a/components/camel-microprofile/camel-microprofile-health/src/main/java/org/apache/camel/microprofile/health/AbstractCamelMicroProfileHealthCheck.java b/components/camel-microprofile/camel-microprofile-health/src/main/java/org/apache/camel/microprofile/health/AbstractCamelMicroProfileHealthCheck.java
index 221eeb2..541664f 100644
--- a/components/camel-microprofile/camel-microprofile-health/src/main/java/org/apache/camel/microprofile/health/AbstractCamelMicroProfileHealthCheck.java
+++ b/components/camel-microprofile/camel-microprofile-health/src/main/java/org/apache/camel/microprofile/health/AbstractCamelMicroProfileHealthCheck.java
@@ -50,11 +50,8 @@ public abstract class AbstractCamelMicroProfileHealthCheck implements HealthChec
if (camelContext != null) {
Collection<Result> results = HealthCheckHelper.invoke(camelContext,
- (HealthCheckFilter) check ->
- // skip context as we have our own context check
- check.getId().equals("context")
- // or if not accepted
- || check instanceof AbstractHealthCheck && !acceptHealthCheck((AbstractHealthCheck) check));
+ (HealthCheckFilter) check -> check instanceof AbstractHealthCheck
+ && !acceptHealthCheck((AbstractHealthCheck) check));
for (Result result : results) {
Map<String, Object> details = result.getDetails();
diff --git a/components/camel-microprofile/camel-microprofile-health/src/main/java/org/apache/camel/microprofile/health/AbstractCamelMicroProfileLivenessCheck.java b/components/camel-microprofile/camel-microprofile-health/src/main/java/org/apache/camel/microprofile/health/AbstractCamelMicroProfileLivenessCheck.java
index d868985..37c6388 100644
--- a/components/camel-microprofile/camel-microprofile-health/src/main/java/org/apache/camel/microprofile/health/AbstractCamelMicroProfileLivenessCheck.java
+++ b/components/camel-microprofile/camel-microprofile-health/src/main/java/org/apache/camel/microprofile/health/AbstractCamelMicroProfileLivenessCheck.java
@@ -22,7 +22,10 @@ import org.apache.camel.impl.health.AbstractHealthCheck;
/**
* Ensures the implemented health check will be considered as a MicroProfile Health liveness check
+ *
+ * @deprecated extend {@link AbstractHealthCheck} then override and return false from isReadiness
*/
+@Deprecated
public abstract class AbstractCamelMicroProfileLivenessCheck extends AbstractHealthCheck {
public AbstractCamelMicroProfileLivenessCheck(String id) {
diff --git a/components/camel-microprofile/camel-microprofile-health/src/main/java/org/apache/camel/microprofile/health/AbstractCamelMicroProfileReadinessCheck.java b/components/camel-microprofile/camel-microprofile-health/src/main/java/org/apache/camel/microprofile/health/AbstractCamelMicroProfileReadinessCheck.java
index b6687ce..7971e10 100644
--- a/components/camel-microprofile/camel-microprofile-health/src/main/java/org/apache/camel/microprofile/health/AbstractCamelMicroProfileReadinessCheck.java
+++ b/components/camel-microprofile/camel-microprofile-health/src/main/java/org/apache/camel/microprofile/health/AbstractCamelMicroProfileReadinessCheck.java
@@ -20,7 +20,10 @@ import org.apache.camel.impl.health.AbstractHealthCheck;
/**
* Ensures the implemented health check will be considered as a MicroProfile Health readiness check
+ *
+ * @deprecated extend {@link AbstractHealthCheck} then override and return false from isLiveness
*/
+@Deprecated
public abstract class AbstractCamelMicroProfileReadinessCheck extends AbstractHealthCheck {
public AbstractCamelMicroProfileReadinessCheck(String id) {
diff --git a/components/camel-microprofile/camel-microprofile-health/src/main/java/org/apache/camel/microprofile/health/CamelMicroProfileContextCheck.java b/components/camel-microprofile/camel-microprofile-health/src/main/java/org/apache/camel/microprofile/health/CamelMicroProfileContextCheck.java
deleted file mode 100644
index 4c1820b..0000000
--- a/components/camel-microprofile/camel-microprofile-health/src/main/java/org/apache/camel/microprofile/health/CamelMicroProfileContextCheck.java
+++ /dev/null
@@ -1,73 +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.microprofile.health;
-
-import java.util.Map;
-
-import javax.inject.Inject;
-
-import org.apache.camel.CamelContext;
-import org.apache.camel.CamelContextAware;
-import org.apache.camel.health.HealthCheck.Result;
-import org.apache.camel.health.HealthCheck.State;
-import org.apache.camel.impl.health.ContextHealthCheck;
-import org.eclipse.microprofile.health.HealthCheck;
-import org.eclipse.microprofile.health.HealthCheckResponse;
-import org.eclipse.microprofile.health.HealthCheckResponseBuilder;
-import org.eclipse.microprofile.health.Readiness;
-
-/**
- * A simple health check implementation for checking the status of a CamelContext
- */
-@Readiness
-public class CamelMicroProfileContextCheck implements HealthCheck, CamelContextAware {
-
- @Inject
- CamelContext camelContext;
-
- @Override
- public HealthCheckResponse call() {
- final HealthCheckResponseBuilder builder = HealthCheckResponse.builder();
- builder.name("camel-context-check");
- builder.down();
-
- if (camelContext != null) {
- ContextHealthCheck chc = new ContextHealthCheck();
- chc.setCamelContext(camelContext);
- Result result = chc.call();
- Map<String, Object> details = result.getDetails();
- builder.withData("name", details.get("context.name").toString());
- builder.withData("contextStatus", details.get("context.status").toString());
-
- if (result.getState().equals(State.UP)) {
- builder.up();
- }
- }
-
- return builder.build();
- }
-
- @Override
- public void setCamelContext(CamelContext camelContext) {
- this.camelContext = camelContext;
- }
-
- @Override
- public CamelContext getCamelContext() {
- return this.camelContext;
- }
-}
diff --git a/components/camel-microprofile/camel-microprofile-health/src/test/java/org/apache/camel/microprofile/health/CamelMicroProfileHealthCheckTest.java b/components/camel-microprofile/camel-microprofile-health/src/test/java/org/apache/camel/microprofile/health/CamelMicroProfileHealthCheckTest.java
index 9d27f12..cbbc2a7 100644
--- a/components/camel-microprofile/camel-microprofile-health/src/test/java/org/apache/camel/microprofile/health/CamelMicroProfileHealthCheckTest.java
+++ b/components/camel-microprofile/camel-microprofile-health/src/test/java/org/apache/camel/microprofile/health/CamelMicroProfileHealthCheckTest.java
@@ -20,9 +20,9 @@ import javax.json.JsonArray;
import javax.json.JsonObject;
import io.smallrye.health.SmallRyeHealth;
-import org.apache.camel.ServiceStatus;
import org.apache.camel.health.HealthCheckRegistry;
import org.apache.camel.impl.engine.ExplicitCamelContextNameStrategy;
+import org.apache.camel.impl.health.ContextHealthCheck;
import org.eclipse.microprofile.health.HealthCheckResponse.State;
import org.junit.jupiter.api.Test;
@@ -34,7 +34,9 @@ public class CamelMicroProfileHealthCheckTest extends CamelMicroProfileHealthTes
@Test
public void testCamelContextHealthCheckUpStatus() {
context.setNameStrategy(new ExplicitCamelContextNameStrategy("health-context"));
- CamelMicroProfileContextCheck check = new CamelMicroProfileContextCheck();
+ context.getExtension(HealthCheckRegistry.class).register(new ContextHealthCheck());
+
+ CamelMicroProfileReadinessCheck check = new CamelMicroProfileReadinessCheck();
check.setCamelContext(context);
reporter.addHealthCheck(check);
@@ -47,16 +49,17 @@ public class CamelMicroProfileHealthCheckTest extends CamelMicroProfileHealthTes
JsonArray checks = healthObject.getJsonArray("checks");
assertEquals(1, checks.size());
- assertHealthCheckOutput("camel-context-check", State.UP, checks.getJsonObject(0), checksJson -> {
- assertEquals(ServiceStatus.Started.toString(), checksJson.getString("contextStatus"));
- assertEquals("health-context", checksJson.getString("name"));
+ assertHealthCheckOutput("camel-readiness-checks", State.UP, checks.getJsonObject(0), checksJson -> {
+ assertEquals(State.UP.name(), checksJson.getString("context"));
});
}
@Test
public void testCamelContextHealthCheckDownStatus() {
context.setNameStrategy(new ExplicitCamelContextNameStrategy("health-context"));
- CamelMicroProfileContextCheck check = new CamelMicroProfileContextCheck();
+ context.getExtension(HealthCheckRegistry.class).register(new ContextHealthCheck());
+
+ CamelMicroProfileReadinessCheck check = new CamelMicroProfileReadinessCheck();
check.setCamelContext(context);
reporter.addHealthCheck(check);
@@ -65,15 +68,13 @@ public class CamelMicroProfileHealthCheckTest extends CamelMicroProfileHealthTes
SmallRyeHealth health = reporter.getHealth();
JsonObject healthObject = getHealthJson(health);
-
assertEquals(State.DOWN.name(), healthObject.getString("status"));
JsonArray checks = healthObject.getJsonArray("checks");
assertEquals(1, checks.size());
- assertHealthCheckOutput("camel-context-check", State.DOWN, checks.getJsonObject(0), checksJson -> {
- assertEquals(ServiceStatus.Stopped.toString(), checksJson.getString("contextStatus"));
- assertEquals("health-context", checksJson.getString("name"));
+ assertHealthCheckOutput("camel-readiness-checks", State.DOWN, checks.getJsonObject(0), checksJson -> {
+ assertEquals(State.DOWN.name(), checksJson.getString("context"));
});
}
diff --git a/docs/components/modules/others/pages/microprofile-health.adoc b/docs/components/modules/others/pages/microprofile-health.adoc
index c0580d9..b28a658 100644
--- a/docs/components/modules/others/pages/microprofile-health.adoc
+++ b/docs/components/modules/others/pages/microprofile-health.adoc
@@ -31,13 +31,13 @@ for this component:
== Usage
By default, Camel health checks are registered as both MicroProfile Health liveness and readiness checks. To have finer control over whether a Camel health check should
-be considered either a readiness or liveness check, you can extend the `AbstractCamelMicroProfileLivenessCheck` and `AbstractCamelMicroProfileReadinessCheck` classes.
+be considered either a readiness or liveness check, you can extend `AbstractHealthCheck` and override the `isLiveness()` and `isReadiness()` methods.
For example, to have a check registered exclusively as a liveness check:
[source,java]
----
-public class MyHealthCheck extends AbstractCamelMicroProfileLivenessCheck {
+public class MyHealthCheck extends AbstractHealthCheck {
public MyHealthCheck() {
super("my-liveness-check-id");
@@ -54,6 +54,10 @@ public class MyHealthCheck extends AbstractCamelMicroProfileLivenessCheck {
builder.down();
}
}
+
+ public boolean isReadiness() {
+ return false;
+ }
}
----