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 2020/06/02 11:18:14 UTC
[camel] 01/02: CAMEL-15081: camel-helath - Allow to configure
healtch checks via camel-main style.
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
commit 43eef6319d34f139dfd639ffcc97b0cd5754698e
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Tue Jun 2 11:59:34 2020 +0200
CAMEL-15081: camel-helath - Allow to configure healtch checks via camel-main style.
---
.../apache/camel/health/HealthCheckRepository.java | 21 +++
.../impl/health/HealthCheckRegistryRepository.java | 37 +++++-
.../impl/health/RoutesHealthCheckRepository.java | 35 ++++-
.../MainConfigurationPropertiesConfigurer.java | 10 --
.../camel-main-configuration-metadata.json | 2 -
.../org/apache/camel/main/BaseMainSupport.java | 141 ++++++++++++++++++++-
.../camel/main/DefaultConfigurationConfigurer.java | 21 ---
.../camel/main/DefaultConfigurationProperties.java | 63 ---------
.../camel/management/mbean/ManagedCamelHealth.java | 17 ++-
9 files changed, 242 insertions(+), 105 deletions(-)
diff --git a/core/camel-api/src/main/java/org/apache/camel/health/HealthCheckRepository.java b/core/camel-api/src/main/java/org/apache/camel/health/HealthCheckRepository.java
index 8a8f727..55dc7a0 100644
--- a/core/camel-api/src/main/java/org/apache/camel/health/HealthCheckRepository.java
+++ b/core/camel-api/src/main/java/org/apache/camel/health/HealthCheckRepository.java
@@ -16,6 +16,7 @@
*/
package org.apache.camel.health;
+import java.util.Map;
import java.util.stream.Stream;
import org.apache.camel.spi.HasId;
@@ -26,6 +27,26 @@ import org.apache.camel.spi.HasId;
public interface HealthCheckRepository extends HasId {
/**
+ * Set if the checks associated to this repository is enabled or not.
+ */
+ boolean isEnabled();
+
+ /**
+ * Set if the checks associated to this repository is enabled or not.
+ */
+ void setEnabled(boolean enabled);
+
+ /**
+ * Configurations for health checks based on their ids
+ */
+ void setConfigurations(Map<String, HealthCheckConfiguration> configurations);
+
+ /**
+ * Configurations for health checks based on their ids
+ */
+ Map<String, HealthCheckConfiguration> getConfigurations();
+
+ /**
* Returns a sequential {@code Stream} with the known {@link HealthCheck}
* as its source.
*/
diff --git a/core/camel-health/src/main/java/org/apache/camel/impl/health/HealthCheckRegistryRepository.java b/core/camel-health/src/main/java/org/apache/camel/impl/health/HealthCheckRegistryRepository.java
index 888e1c1..30ea514 100644
--- a/core/camel-health/src/main/java/org/apache/camel/impl/health/HealthCheckRegistryRepository.java
+++ b/core/camel-health/src/main/java/org/apache/camel/impl/health/HealthCheckRegistryRepository.java
@@ -16,12 +16,14 @@
*/
package org.apache.camel.impl.health;
+import java.util.Map;
import java.util.Set;
import java.util.stream.Stream;
import org.apache.camel.CamelContext;
import org.apache.camel.CamelContextAware;
import org.apache.camel.health.HealthCheck;
+import org.apache.camel.health.HealthCheckConfiguration;
import org.apache.camel.health.HealthCheckRepository;
/**
@@ -31,6 +33,8 @@ import org.apache.camel.health.HealthCheckRepository;
*/
public class HealthCheckRegistryRepository implements CamelContextAware, HealthCheckRepository {
private CamelContext context;
+ private Map<String, HealthCheckConfiguration> configurations;
+ private boolean enabled = true;
@Override
public String getId() {
@@ -47,13 +51,42 @@ public class HealthCheckRegistryRepository implements CamelContextAware, HealthC
return context;
}
+ public Map<String, HealthCheckConfiguration> getConfigurations() {
+ return configurations;
+ }
+
+ public void setConfigurations(Map<String, HealthCheckConfiguration> configurations) {
+ this.configurations = configurations;
+ }
+
+ @Override
+ public boolean isEnabled() {
+ return enabled;
+ }
+
+ @Override
+ public void setEnabled(boolean enabled) {
+ this.enabled = enabled;
+ }
+
@Override
public Stream<HealthCheck> stream() {
- if (context != null) {
+ if (context != null && enabled) {
Set<HealthCheck> set = this.context.getRegistry().findByType(HealthCheck.class);
- return set.stream();
+ return set.stream().map(this::toHealthCheck);
} else {
return Stream.empty();
}
}
+
+ private HealthCheck toHealthCheck(HealthCheck hc) {
+ if (configurations != null && configurations.containsKey(hc.getId())) {
+ HealthCheckConfiguration hcc = configurations.get(hc.getId());
+ hc.getConfiguration().setEnabled(hcc.isEnabled());
+ hc.getConfiguration().setInterval(hcc.getInterval());
+ hc.getConfiguration().setFailureThreshold(hcc.getFailureThreshold());
+ }
+ return hc;
+ }
+
}
diff --git a/core/camel-health/src/main/java/org/apache/camel/impl/health/RoutesHealthCheckRepository.java b/core/camel-health/src/main/java/org/apache/camel/impl/health/RoutesHealthCheckRepository.java
index fe7288c..3589bb7 100644
--- a/core/camel-health/src/main/java/org/apache/camel/impl/health/RoutesHealthCheckRepository.java
+++ b/core/camel-health/src/main/java/org/apache/camel/impl/health/RoutesHealthCheckRepository.java
@@ -18,6 +18,7 @@ package org.apache.camel.impl.health;
import java.util.Collection;
import java.util.HashSet;
+import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
@@ -28,6 +29,7 @@ import org.apache.camel.CamelContextAware;
import org.apache.camel.DeferredContextBinding;
import org.apache.camel.Route;
import org.apache.camel.health.HealthCheck;
+import org.apache.camel.health.HealthCheckConfiguration;
import org.apache.camel.health.HealthCheckRepository;
import org.apache.camel.spi.annotations.JdkService;
@@ -40,6 +42,8 @@ public class RoutesHealthCheckRepository implements CamelContextAware, HealthChe
private final ConcurrentMap<Route, HealthCheck> checks;
private Set<String> blacklist;
private volatile CamelContext context;
+ private Map<String, HealthCheckConfiguration> configurations;
+ private boolean enabled = true;
public RoutesHealthCheckRepository() {
this.checks = new ConcurrentHashMap<>();
@@ -60,6 +64,26 @@ public class RoutesHealthCheckRepository implements CamelContextAware, HealthChe
return context;
}
+ @Override
+ public Map<String, HealthCheckConfiguration> getConfigurations() {
+ return configurations;
+ }
+
+ @Override
+ public void setConfigurations(Map<String, HealthCheckConfiguration> configurations) {
+ this.configurations = configurations;
+ }
+
+ @Override
+ public boolean isEnabled() {
+ return enabled;
+ }
+
+ @Override
+ public void setEnabled(boolean enabled) {
+ this.enabled = enabled;
+ }
+
public void setBlacklistedRoutes(Collection<String> blacklistedRoutes) {
blacklistedRoutes.forEach(this::addBlacklistedRoute);
}
@@ -85,7 +109,7 @@ public class RoutesHealthCheckRepository implements CamelContextAware, HealthChe
// void forEachRoute(Consumer<Route> consumer);
// }
//
- return this.context != null
+ return this.context != null && enabled
? this.context.getRoutes()
.stream()
.filter(route -> route.getId() != null)
@@ -103,7 +127,14 @@ public class RoutesHealthCheckRepository implements CamelContextAware, HealthChe
}
private HealthCheck toRouteHealthCheck(Route route) {
- return checks.computeIfAbsent(route, r -> new RouteHealthCheck(route));
+ return checks.computeIfAbsent(route, r -> {
+ RouteHealthCheck rhc = new RouteHealthCheck(route);
+ if (configurations != null && configurations.containsKey(rhc.getId())) {
+ HealthCheckConfiguration hcc = configurations.get(rhc.getId());
+ rhc.setConfiguration(hcc);
+ }
+ return rhc;
+ });
}
}
diff --git a/core/camel-main/src/generated/java/org/apache/camel/main/MainConfigurationPropertiesConfigurer.java b/core/camel-main/src/generated/java/org/apache/camel/main/MainConfigurationPropertiesConfigurer.java
index b7c389d..df6f5dd 100644
--- a/core/camel-main/src/generated/java/org/apache/camel/main/MainConfigurationPropertiesConfigurer.java
+++ b/core/camel-main/src/generated/java/org/apache/camel/main/MainConfigurationPropertiesConfigurer.java
@@ -71,10 +71,6 @@ public class MainConfigurationPropertiesConfigurer extends org.apache.camel.supp
case "EndpointRuntimeStatisticsEnabled": target.setEndpointRuntimeStatisticsEnabled(property(camelContext, boolean.class, value)); return true;
case "fileconfigurations":
case "FileConfigurations": target.setFileConfigurations(property(camelContext, java.lang.String.class, value)); return true;
- case "healthcheckenabled":
- case "HealthCheckEnabled": target.setHealthCheckEnabled(property(camelContext, boolean.class, value)); return true;
- case "healthcheckroutesenabled":
- case "HealthCheckRoutesEnabled": target.setHealthCheckRoutesEnabled(property(camelContext, boolean.class, value)); return true;
case "inflightrepositorybrowseenabled":
case "InflightRepositoryBrowseEnabled": target.setInflightRepositoryBrowseEnabled(property(camelContext, boolean.class, value)); return true;
case "javaroutesexcludepattern":
@@ -218,8 +214,6 @@ public class MainConfigurationPropertiesConfigurer extends org.apache.camel.supp
answer.put("EndpointLazyStartProducer", boolean.class);
answer.put("EndpointRuntimeStatisticsEnabled", boolean.class);
answer.put("FileConfigurations", java.lang.String.class);
- answer.put("HealthCheckEnabled", boolean.class);
- answer.put("HealthCheckRoutesEnabled", boolean.class);
answer.put("InflightRepositoryBrowseEnabled", boolean.class);
answer.put("JavaRoutesExcludePattern", java.lang.String.class);
answer.put("JavaRoutesIncludePattern", java.lang.String.class);
@@ -334,10 +328,6 @@ public class MainConfigurationPropertiesConfigurer extends org.apache.camel.supp
case "EndpointRuntimeStatisticsEnabled": return target.isEndpointRuntimeStatisticsEnabled();
case "fileconfigurations":
case "FileConfigurations": return target.getFileConfigurations();
- case "healthcheckenabled":
- case "HealthCheckEnabled": return target.isHealthCheckEnabled();
- case "healthcheckroutesenabled":
- case "HealthCheckRoutesEnabled": return target.isHealthCheckRoutesEnabled();
case "inflightrepositorybrowseenabled":
case "InflightRepositoryBrowseEnabled": return target.isInflightRepositoryBrowseEnabled();
case "javaroutesexcludepattern":
diff --git a/core/camel-main/src/generated/resources/META-INF/camel-main-configuration-metadata.json b/core/camel-main/src/generated/resources/META-INF/camel-main-configuration-metadata.json
index 18e5d9b..fcb0e11 100644
--- a/core/camel-main/src/generated/resources/META-INF/camel-main-configuration-metadata.json
+++ b/core/camel-main/src/generated/resources/META-INF/camel-main-configuration-metadata.json
@@ -33,8 +33,6 @@
{ "name": "camel.main.endpointLazyStartProducer", "description": "Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel's routing error handlers. Beware that when the first mes [...]
{ "name": "camel.main.endpointRuntimeStatisticsEnabled", "description": "Sets whether endpoint runtime statistics is enabled (gathers runtime usage of each incoming and outgoing endpoints). The default value is false.", "sourceType": "org.apache.camel.main.DefaultConfigurationProperties", "type": "boolean", "javaType": "boolean" },
{ "name": "camel.main.fileConfigurations", "description": "Directory to load additional configuration files that contains configuration values that takes precedence over any other configuration. This can be used to refer to files that may have secret configuration that has been mounted on the file system for containers. You can specify a pattern to load from sub directories and a name pattern such as \/var\/app\/secret\/.properties, multiple directories can be separated by comma.", " [...]
- { "name": "camel.main.healthCheckEnabled", "description": "Whether health check is enabled. Is default enabled. If using camel-quarkus then camel-quarkus-microprofile-health has its own configuration for health-check which you should use instead.", "sourceType": "org.apache.camel.main.DefaultConfigurationProperties", "type": "boolean", "javaType": "boolean", "defaultValue": true },
- { "name": "camel.main.healthCheckRoutesEnabled", "description": "Whether routes should be included in the health check. By default only the camel context is part of the health check. Enabling routes allows to let routes that are controlled by the routes controller take part of the health check, so if there is problems starting up routes, then they can influence the health check and report its UP or DOWN. Is default disabled. If using camel-quarkus then camel-quarkus-microprofile-heal [...]
{ "name": "camel.main.inflightRepositoryBrowseEnabled", "description": "Sets whether the inflight repository should allow browsing each inflight exchange. This is by default disabled as there is a very slight performance overhead when enabled.", "sourceType": "org.apache.camel.main.DefaultConfigurationProperties", "type": "boolean", "javaType": "boolean" },
{ "name": "camel.main.javaRoutesExcludePattern", "description": "Used for exclusive filtering component scanning of RouteBuilder classes with Component annotation. The exclusive filtering takes precedence over inclusive filtering. The pattern is using Ant-path style pattern. Multiple patterns can be specified separated by comma. For example to exclude all classes starting with Bar use: **\/Bar* To exclude all routes form a specific package use: com\/mycompany\/bar\/* [...]
{ "name": "camel.main.javaRoutesIncludePattern", "description": "Used for inclusive filtering component scanning of RouteBuilder classes with Component annotation. The exclusive filtering takes precedence over inclusive filtering. The pattern is using Ant-path style pattern. Multiple patterns can be specified separated by comma. For example to include all classes starting with Foo use: **\/Foo To include all routes form a specific package use: com\/mycompany\/foo\/* To in [...]
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 5bde1e9..102af6c 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
@@ -23,6 +23,7 @@ import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
+import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
@@ -44,6 +45,10 @@ import org.apache.camel.PropertyBindingException;
import org.apache.camel.RoutesBuilder;
import org.apache.camel.RuntimeCamelException;
import org.apache.camel.builder.ThreadPoolProfileBuilder;
+import org.apache.camel.health.HealthCheck;
+import org.apache.camel.health.HealthCheckConfiguration;
+import org.apache.camel.health.HealthCheckRegistry;
+import org.apache.camel.health.HealthCheckRepository;
import org.apache.camel.model.FaultToleranceConfigurationDefinition;
import org.apache.camel.model.HystrixConfigurationDefinition;
import org.apache.camel.model.Model;
@@ -93,6 +98,7 @@ public abstract class BaseMainSupport extends BaseService {
private static final String SENSITIVE_KEYS = "passphrase|password|secretkey|accesstoken|clientsecret|authorizationtoken|sasljaasconfig";
private static final String VALID_THREAD_POOL_KEYS = "id|poolSize|maxPoolSize|keepAliveTime|timeUnit|maxQueueSize|allowCoreThreadTimeout|rejectedPolicy";
+ private static final String VALID_HEALTH_KEYS = "id|enabled|interval|failureThreshold";
protected volatile CamelContext camelContext;
protected volatile ProducerTemplate camelTemplate;
@@ -682,6 +688,7 @@ public abstract class BaseMainSupport extends BaseService {
Map<String, Object> faultToleranceProperties = new LinkedHashMap<>();
Map<String, Object> restProperties = new LinkedHashMap<>();
Map<String, Object> threadPoolProperties = new LinkedHashMap<>();
+ Map<String, Object> healthProperties = new LinkedHashMap<>();
Map<String, Object> beansProperties = new LinkedHashMap<>();
for (String key : prop.stringPropertyNames()) {
if (key.startsWith("camel.context.")) {
@@ -720,6 +727,12 @@ public abstract class BaseMainSupport extends BaseService {
String option = key.substring(16);
validateOptionAndValue(key, option, value);
threadPoolProperties.put(optionKey(option), value);
+ } else if (key.startsWith("camel.health")) {
+ // grab the value
+ String value = prop.getProperty(key);
+ String option = key.substring(12);
+ validateOptionAndValue(key, option, value);
+ healthProperties.put(optionKey(option), value);
} else if (key.startsWith("camel.beans.")) {
// grab the value
String value = prop.getProperty(key);
@@ -735,7 +748,6 @@ public abstract class BaseMainSupport extends BaseService {
bindBeansToRegistry(camelContext, beansProperties, "camel.beans.",
mainConfigurationProperties.isAutoConfigurationFailFast(), true, autoConfiguredProperties);
}
-
if (!contextProperties.isEmpty()) {
LOG.debug("Auto-configuring CamelContext from loaded properties: {}", contextProperties.size());
setPropertiesOnTarget(camelContext, camelContext, contextProperties, "camel.context.",
@@ -788,6 +800,10 @@ public abstract class BaseMainSupport extends BaseService {
LOG.debug("Auto-configuring Thread Pool from loaded properties: {}", threadPoolProperties.size());
setThreadPoolProfileProperties(camelContext, threadPoolProperties, mainConfigurationProperties.isAutoConfigurationFailFast(), autoConfiguredProperties);
}
+ if (!healthProperties.isEmpty()) {
+ LOG.debug("Auto-configuring HealthCheck from loaded properties: {}", healthProperties.size());
+ setHealthCheckProperties(camelContext, healthProperties, mainConfigurationProperties.isAutoConfigurationFailFast(), autoConfiguredProperties);
+ }
// log which options was not set
if (!beansProperties.isEmpty()) {
@@ -832,6 +848,11 @@ public abstract class BaseMainSupport extends BaseService {
LOG.warn("Property not auto-configured: camel.threadpool{}={} on bean: ThreadPoolProfileBuilder", k, v);
});
}
+ if (!healthProperties.isEmpty()) {
+ healthProperties.forEach((k, v) -> {
+ LOG.warn("Property not auto-configured: camel.health{}={}", k, v);
+ });
+ }
}
private void setThreadPoolProfileProperties(CamelContext camelContext, Map<String, Object> threadPoolProperties,
@@ -856,13 +877,14 @@ public abstract class BaseMainSupport extends BaseService {
throw new PropertyBindingException("ThreadPoolProfileBuilder", key, value);
}
- autoConfiguredProperties.put(k, value);
+ autoConfiguredProperties.put("camel.threadpool" + k, value);
});
+ // clear as we have validated all parameters
+ threadPoolProperties.clear();
// now build profiles from those options
for (String id : profiles.keySet()) {
Map<String, String> map = profiles.get(id);
- // camel-main will lower-case keys
String overrideId = map.remove("id");
String poolSize = map.remove("poolSize");
String maxPoolSize = map.remove("maxPoolSize");
@@ -911,6 +933,119 @@ public abstract class BaseMainSupport extends BaseService {
}
}
+ private void setHealthCheckProperties(CamelContext camelContext, Map<String, Object> healthCheckProperties,
+ boolean failIfNotSet, Map<String, String> autoConfiguredProperties) {
+
+ HealthCheckRegistry hcr = camelContext.getExtension(HealthCheckRegistry.class);
+ if (hcr == null) {
+ LOG.warn("Cannot find HealthCheckRegistry from classpath. Add camel-health to classpath.");
+ return;
+ }
+
+ // grab global option for enabled or disabled
+ String global = (String) healthCheckProperties.remove(".enabled");
+ if (global != null) {
+ hcr.setEnabled(CamelContextHelper.parseBoolean(camelContext, global));
+ autoConfiguredProperties.put("camel.health.enabled", global);
+ }
+
+ // common health checks to make them easy to turn on|off
+ String contextEnabled = (String) healthCheckProperties.remove(".context.enabled");
+ String routesEnabled = (String) healthCheckProperties.remove(".routes.enabled");
+
+ Map<String, Map<String, String>> checks = new LinkedHashMap<>();
+ // the id of the health-check is in the key [xx]
+ healthCheckProperties.forEach((k, v) -> {
+ String id = StringHelper.between(k, "[", "].");
+ if (id == null) {
+ throw new IllegalArgumentException("Invalid syntax for key: camel.health" + k + " should be: camel.health[id]");
+ }
+ String key = StringHelper.after(k, "].");
+ String value = v.toString();
+ if (key == null) {
+ throw new PropertyBindingException("HealthCheckConfiguration", k, value);
+ }
+ Map<String, String> map = checks.computeIfAbsent(id, o -> new HashMap<>());
+ map.put(optionKey(key), value);
+
+ if (failIfNotSet && !VALID_HEALTH_KEYS.contains(key)) {
+ throw new PropertyBindingException("HealthCheckConfiguration", key, value);
+ }
+
+ autoConfiguredProperties.put("camel.health" + k, value);
+ });
+ // clear as we have validated all parameters
+ healthCheckProperties.clear();
+
+ // context is enabled by default
+ if (hcr.isEnabled() && !checks.containsKey("context")) {
+ HealthCheck hc = (HealthCheck) hcr.resolveById("context");
+ if (hc != null) {
+ if (contextEnabled != null) {
+ hc.getConfiguration().setEnabled(CamelContextHelper.parseBoolean(camelContext, contextEnabled));
+ }
+ hcr.register(hc);
+ }
+ }
+ // routes is enabled by default
+ if (hcr.isEnabled() && !checks.containsKey("routes")) {
+ HealthCheckRepository hc = (HealthCheckRepository) hcr.resolveById("routes");
+ if (hc != null) {
+ if (routesEnabled != null) {
+ hc.setEnabled(CamelContextHelper.parseBoolean(camelContext, routesEnabled));
+ }
+ hcr.register(hc);
+ }
+ }
+
+ // grab keys that are yet another map
+// Map<String, Map<String, String>> subConfig = new LinkedHashMap<>();
+// Iterator<String> it = checks.keySet().iterator();
+// while (it.hasNext()) {
+// String key = it.next();
+// if (key.startsWith("[") && key.e)
+// }
+
+
+ // configure health checks configurations
+ for (String id : checks.keySet()) {
+ Map<String, String> map = checks.get(id);
+ String enabled = map.remove("enabled");
+ String interval = map.remove("interval");
+ String failureThreshold = map.remove("failureThreshold");
+
+ HealthCheckConfiguration hcc = new HealthCheckConfiguration();
+ if (enabled != null) {
+ hcc.setEnabled(CamelContextHelper.parseBoolean(camelContext, enabled));
+ }
+ if (interval != null) {
+ hcc.setInterval(CamelContextHelper.parseDuration(camelContext, interval).toMillis());
+ }
+ if (failureThreshold != null) {
+ hcc.setFailureThreshold(CamelContextHelper.parseInt(camelContext, failureThreshold));
+ }
+
+ // lookup health check by id
+ Object hc = hcr.getCheck(id).orElse(null);
+ if (hc == null) {
+ hc = hcr.resolveById(id);
+ if (hc == null) {
+ LOG.warn("Cannot resolve HealthCheck with id: " + id + " from classpath.");
+ continue;
+ }
+ hcr.register(hc);
+ if (hc instanceof HealthCheck) {
+ ((HealthCheck) hc).getConfiguration().setEnabled(hcc.isEnabled());
+ ((HealthCheck) hc).getConfiguration().setFailureThreshold(hcc.getFailureThreshold());
+ ((HealthCheck) hc).getConfiguration().setInterval(hcc.getInterval());
+ } else if (hc instanceof HealthCheckRepository) {
+ // ((HealthCheckRepository) hc).setEnabled(hcc.isEnabled());
+ // TODO: The other configurations
+ }
+ }
+ }
+ }
+
private void bindBeansToRegistry(CamelContext camelContext, Map<String, Object> properties,
String optionPrefix, boolean failIfNotSet, boolean ignoreCase,
Map<String, String> autoConfiguredProperties) throws Exception {
diff --git a/core/camel-main/src/main/java/org/apache/camel/main/DefaultConfigurationConfigurer.java b/core/camel-main/src/main/java/org/apache/camel/main/DefaultConfigurationConfigurer.java
index 6959bd1..e135401 100644
--- a/core/camel-main/src/main/java/org/apache/camel/main/DefaultConfigurationConfigurer.java
+++ b/core/camel-main/src/main/java/org/apache/camel/main/DefaultConfigurationConfigurer.java
@@ -211,27 +211,6 @@ public final class DefaultConfigurationConfigurer {
if (config.getRouteControllerRouteStartupLoggingLevel() != null) {
camelContext.getRouteController().setRouteStartupLoggingLevel(config.getRouteControllerRouteStartupLoggingLevel());
}
-
- // health check
- HealthCheckRegistry hc = camelContext.getExtension(HealthCheckRegistry.class);
- if (hc != null && config.isHealthCheckEnabled()) {
- // register context health-check by default
- if (!hc.getCheck("context").isPresent()) {
- Object context = hc.resolveById("context");
- if (context != null) {
- hc.register(context);
- }
- }
- // register routes if enabled
- if (config.isHealthCheckRoutesEnabled()) {
- if (!hc.getCheck("routes").isPresent()) {
- Object routes = hc.resolveById("routes");
- if (routes != null) {
- hc.register(routes);
- }
- }
- }
- }
}
/**
diff --git a/core/camel-main/src/main/java/org/apache/camel/main/DefaultConfigurationProperties.java b/core/camel-main/src/main/java/org/apache/camel/main/DefaultConfigurationProperties.java
index 7bc8c37..ec3e835 100644
--- a/core/camel-main/src/main/java/org/apache/camel/main/DefaultConfigurationProperties.java
+++ b/core/camel-main/src/main/java/org/apache/camel/main/DefaultConfigurationProperties.java
@@ -94,9 +94,6 @@ public abstract class DefaultConfigurationProperties<T> {
private long routeControllerBackOffMaxElapsedTime;
private long routeControllerBackOffMaxAttempts;
private double routeControllerBackOffMultiplier;
- // health check
- private boolean healthCheckEnabled = true;
- private boolean healthCheckRoutesEnabled;
// getter and setters
// --------------------------------------------------------------
@@ -1063,42 +1060,6 @@ public abstract class DefaultConfigurationProperties<T> {
this.routeControllerBackOffMultiplier = routeControllerBackOffMultiplier;
}
- public boolean isHealthCheckEnabled() {
- return healthCheckEnabled;
- }
-
- /**
- * Whether health check is enabled.
- * Is default enabled.
- *
- * If using camel-quarkus then camel-quarkus-microprofile-health has its own configuration for health-check
- * which you should use instead.
- */
- public void setHealthCheckEnabled(boolean healthCheckEnabled) {
- this.healthCheckEnabled = healthCheckEnabled;
- }
-
- public boolean isHealthCheckRoutesEnabled() {
- return healthCheckRoutesEnabled;
- }
-
- /**
- * Whether routes should be included in the health check.
- *
- * By default only the camel context is part of the health check.
- * Enabling routes allows to let routes that are controlled by the routes controller
- * take part of the health check, so if there is problems starting up routes, then
- * they can influence the health check and report its UP or DOWN.
- *
- * Is default disabled.
- *
- * If using camel-quarkus then camel-quarkus-microprofile-health has its own configuration for health-check
- * which you should use instead.
- */
- public void setHealthCheckRoutesEnabled(boolean healthCheckRoutesEnabled) {
- this.healthCheckRoutesEnabled = healthCheckRoutesEnabled;
- }
-
// fluent builders
// --------------------------------------------------------------
@@ -1836,28 +1797,4 @@ public abstract class DefaultConfigurationProperties<T> {
return (T) this;
}
- /**
- * Whether health check is enabled.
- * Is default enabled.
- */
- public T healthCheckEnabled(boolean healthCheckEnabled) {
- this.healthCheckEnabled = healthCheckEnabled;
- return (T) this;
- }
-
- /**
- * Whether routes should be included in the health check.
- *
- * By default only the camel context is part of the health check.
- * Enabling routes allows to let routes that are controlled by the routes controller
- * take part of the health check, so if there is problems starting up routes, then
- * they can influence the health check and report its UP or DOWN.
- *
- * Is default disabled.
- */
- public T healthCheckRoutesEnabled(boolean healthCheckRoutesEnabled) {
- this.healthCheckRoutesEnabled = healthCheckRoutesEnabled;
- return (T) this;
- }
-
}
diff --git a/core/camel-management/src/main/java/org/apache/camel/management/mbean/ManagedCamelHealth.java b/core/camel-management/src/main/java/org/apache/camel/management/mbean/ManagedCamelHealth.java
index 227e372..a4244bd 100644
--- a/core/camel-management/src/main/java/org/apache/camel/management/mbean/ManagedCamelHealth.java
+++ b/core/camel-management/src/main/java/org/apache/camel/management/mbean/ManagedCamelHealth.java
@@ -33,6 +33,7 @@ import org.apache.camel.api.management.mbean.ManagedCamelHealthMBean;
import org.apache.camel.health.HealthCheck;
import org.apache.camel.health.HealthCheckHelper;
import org.apache.camel.health.HealthCheckRegistry;
+import org.apache.camel.health.HealthCheckRepository;
import org.apache.camel.spi.ManagementStrategy;
public class ManagedCamelHealth implements ManagedCamelHealthMBean {
@@ -118,11 +119,23 @@ public class ManagedCamelHealth implements ManagedCamelHealthMBean {
@Override
public void enableById(String id) {
- healthCheckRegistry.getCheck(id).ifPresent(h -> h.getConfiguration().setEnabled(true));
+ Optional<HealthCheck> hc = healthCheckRegistry.getCheck(id);
+ if (hc.isPresent()) {
+ hc.get().getConfiguration().setEnabled(true);
+ } else {
+ Optional<HealthCheckRepository> hcr = healthCheckRegistry.getRepository(id);
+ hcr.ifPresent(repository -> repository.setEnabled(true));
+ }
}
@Override
public void disableById(String id) {
- healthCheckRegistry.getCheck(id).ifPresent(h -> h.getConfiguration().setEnabled(false));
+ Optional<HealthCheck> hc = healthCheckRegistry.getCheck(id);
+ if (hc.isPresent()) {
+ hc.get().getConfiguration().setEnabled(false);
+ } else {
+ Optional<HealthCheckRepository> hcr = healthCheckRegistry.getRepository(id);
+ hcr.ifPresent(repository -> repository.setEnabled(false));
+ }
}
}