This is an automated email from the ASF dual-hosted git repository.
davsclaus 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 24b089a CAMEL-15081: camel-helath - Allow to configure healtch checks
via camel-main style.
24b089a is described below
commit 24b089a4508cad134cb490a404cea326589eff47
Author: Claus Ibsen <[email protected]>
AuthorDate: Tue Jun 2 17:28:51 2020 +0200
CAMEL-15081: camel-helath - Allow to configure healtch checks via
camel-main style.
---
.../apache/camel/health/HealthCheckRegistry.java | 2 +-
.../impl/health/DefaultHealthCheckRegistry.java | 3 ++-
.../org/apache/camel/main/BaseMainSupport.java | 24 +++++++++++++++++++---
3 files changed, 24 insertions(+), 5 deletions(-)
diff --git
a/core/camel-api/src/main/java/org/apache/camel/health/HealthCheckRegistry.java
b/core/camel-api/src/main/java/org/apache/camel/health/HealthCheckRegistry.java
index b34fd7e..c5d8e1a 100644
---
a/core/camel-api/src/main/java/org/apache/camel/health/HealthCheckRegistry.java
+++
b/core/camel-api/src/main/java/org/apache/camel/health/HealthCheckRegistry.java
@@ -83,7 +83,7 @@ public interface HealthCheckRegistry extends
CamelContextAware, StaticService, I
*/
default Optional<HealthCheck> getCheck(String id) {
return stream()
- .filter(check -> ObjectHelper.equal(check.getId(), id))
+ .filter(r -> ObjectHelper.equal(r.getId(), id) ||
ObjectHelper.equal(r.getId().replace("-health-check", ""), id))
.findFirst();
}
diff --git
a/core/camel-health/src/main/java/org/apache/camel/impl/health/DefaultHealthCheckRegistry.java
b/core/camel-health/src/main/java/org/apache/camel/impl/health/DefaultHealthCheckRegistry.java
index 1c2b811..0cd7e6a 100644
---
a/core/camel-health/src/main/java/org/apache/camel/impl/health/DefaultHealthCheckRegistry.java
+++
b/core/camel-health/src/main/java/org/apache/camel/impl/health/DefaultHealthCheckRegistry.java
@@ -235,7 +235,8 @@ public class DefaultHealthCheckRegistry extends
ServiceSupport implements Health
*/
public Optional<HealthCheckRepository> getRepository(String id) {
return repositories.stream()
- .filter(r -> ObjectHelper.equal(r.getId(), id))
+ // try also shorthand naming
+ .filter(r -> ObjectHelper.equal(r.getId(), id) ||
ObjectHelper.equal(r.getId().replace("-health-check-repository", ""), id))
.findFirst();
}
diff --git
a/core/camel-main/src/main/java/org/apache/camel/main/BaseMainSupport.java
b/core/camel-main/src/main/java/org/apache/camel/main/BaseMainSupport.java
index ff37d43..3285f89 100644
--- a/core/camel-main/src/main/java/org/apache/camel/main/BaseMainSupport.java
+++ b/core/camel-main/src/main/java/org/apache/camel/main/BaseMainSupport.java
@@ -951,7 +951,17 @@ public abstract class BaseMainSupport extends BaseService {
// common health checks to make them easy to turn on|off
String contextEnabled = (String)
healthCheckProperties.remove(".context.enabled");
+ if (contextEnabled != null) {
+ autoConfiguredProperties.put("camel.health.context.enabled",
contextEnabled);
+ }
String routesEnabled = (String)
healthCheckProperties.remove(".routes.enabled");
+ if (routesEnabled != null) {
+ autoConfiguredProperties.put("camel.health.routes.enabled",
routesEnabled);
+ }
+ String registryEnabled = (String)
healthCheckProperties.remove(".registry.enabled");
+ if (registryEnabled != null) {
+ autoConfiguredProperties.put("camel.health.registry.enabled",
registryEnabled);
+ }
Map<String, Map<String, String>> checks = new LinkedHashMap<>();
// the id of the health-check is in the key [xx]
@@ -978,7 +988,7 @@ public abstract class BaseMainSupport extends BaseService {
healthCheckProperties.clear();
// context is enabled by default
- if (hcr.isEnabled() && !checks.containsKey("context")) {
+ if (hcr.isEnabled() && (!checks.containsKey("context") ||
contextEnabled != null)) {
HealthCheck hc = (HealthCheck) hcr.resolveById("context");
if (hc != null) {
if (contextEnabled != null) {
@@ -988,8 +998,8 @@ public abstract class BaseMainSupport extends BaseService {
}
}
// routes is enabled by default
- if (hcr.isEnabled() && !checks.containsKey("routes")) {
- HealthCheckRepository hc = (HealthCheckRepository)
hcr.resolveById("routes");
+ if (hcr.isEnabled() && (!checks.containsKey("routes") || routesEnabled
!= null)) {
+ HealthCheckRepository hc =
hcr.getRepository("routes").orElse((HealthCheckRepository)
hcr.resolveById("routes"));
if (hc != null) {
if (routesEnabled != null) {
hc.setEnabled(CamelContextHelper.parseBoolean(camelContext, routesEnabled));
@@ -997,6 +1007,14 @@ public abstract class BaseMainSupport extends BaseService
{
hcr.register(hc);
}
}
+ // registry is enabled by default
+ if (hcr.isEnabled() && (!checks.containsKey("registry") ||
registryEnabled != null)) {
+ hcr.getRepository("registry").ifPresent(h -> {
+ if (registryEnabled != null) {
+ h.setEnabled(CamelContextHelper.parseBoolean(camelContext,
registryEnabled));
+ }
+ });
+ }
// extract all keys that are for sub configuration (such as fine
grained on routes)
Map<String, Map<String, String>> subConfig = new LinkedHashMap<>();