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 2642cb8f16d4830ed17022d3fbecc8422bff39f2 Author: Claus Ibsen <claus.ib...@gmail.com> AuthorDate: Sun Jun 7 21:30:10 2020 +0200 camel-health - configuration properties class. WIP --- .../HealthConfigurationPropertiesConfigurer.java | 65 +++++++++++ .../camel-main-configuration-metadata.json | 5 + .../camel/configurer/HealthConfigurationProperties | 2 + .../org/apache/camel/main/BaseMainSupport.java | 17 +-- .../camel/main/HealthConfigurationProperties.java | 119 +++++++++++++++++++++ .../camel/main/MainConfigurationProperties.java | 8 ++ 6 files changed, 209 insertions(+), 7 deletions(-) diff --git a/core/camel-main/src/generated/java/org/apache/camel/main/HealthConfigurationPropertiesConfigurer.java b/core/camel-main/src/generated/java/org/apache/camel/main/HealthConfigurationPropertiesConfigurer.java new file mode 100644 index 0000000..6aa5c20 --- /dev/null +++ b/core/camel-main/src/generated/java/org/apache/camel/main/HealthConfigurationPropertiesConfigurer.java @@ -0,0 +1,65 @@ +/* Generated by camel build tools - do NOT edit this file! */ +package org.apache.camel.main; + +import java.util.Map; + +import org.apache.camel.CamelContext; +import org.apache.camel.spi.GeneratedPropertyConfigurer; +import org.apache.camel.spi.PropertyConfigurerGetter; +import org.apache.camel.util.CaseInsensitiveMap; +import org.apache.camel.main.HealthConfigurationProperties; + +/** + * Generated by camel build tools - do NOT edit this file! + */ +@SuppressWarnings("unchecked") +public class HealthConfigurationPropertiesConfigurer extends org.apache.camel.support.component.PropertyConfigurerSupport implements GeneratedPropertyConfigurer, PropertyConfigurerGetter { + + @Override + public boolean configure(CamelContext camelContext, Object obj, String name, Object value, boolean ignoreCase) { + org.apache.camel.main.HealthConfigurationProperties target = (org.apache.camel.main.HealthConfigurationProperties) obj; + switch (ignoreCase ? name.toLowerCase() : name) { + case "config": + case "Config": target.setConfig(property(camelContext, java.util.Map.class, value)); return true; + case "contextenabled": + case "ContextEnabled": target.setContextEnabled(property(camelContext, java.lang.Boolean.class, value)); return true; + case "enabled": + case "Enabled": target.setEnabled(property(camelContext, java.lang.Boolean.class, value)); return true; + case "registryenabled": + case "RegistryEnabled": target.setRegistryEnabled(property(camelContext, java.lang.Boolean.class, value)); return true; + case "routesenabled": + case "RoutesEnabled": target.setRoutesEnabled(property(camelContext, java.lang.Boolean.class, value)); return true; + default: return false; + } + } + + @Override + public Map<String, Object> getAllOptions(Object target) { + Map<String, Object> answer = new CaseInsensitiveMap(); + answer.put("Config", java.util.Map.class); + answer.put("ContextEnabled", java.lang.Boolean.class); + answer.put("Enabled", java.lang.Boolean.class); + answer.put("RegistryEnabled", java.lang.Boolean.class); + answer.put("RoutesEnabled", java.lang.Boolean.class); + return answer; + } + + @Override + public Object getOptionValue(Object obj, String name, boolean ignoreCase) { + org.apache.camel.main.HealthConfigurationProperties target = (org.apache.camel.main.HealthConfigurationProperties) obj; + switch (ignoreCase ? name.toLowerCase() : name) { + case "config": + case "Config": return target.getConfig(); + case "contextenabled": + case "ContextEnabled": return target.getContextEnabled(); + case "enabled": + case "Enabled": return target.getEnabled(); + case "registryenabled": + case "RegistryEnabled": return target.getRegistryEnabled(); + case "routesenabled": + case "RoutesEnabled": return target.getRoutesEnabled(); + default: return null; + } + } +} + 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 d062260..77f7c2c 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 @@ -21,13 +21,16 @@ { "name": "camel.main.beanIntrospectionExtendedStatistics", "description": "Sets whether bean introspection uses extended statistics. The default is false.", "sourceType": "org.apache.camel.main.DefaultConfigurationProperties", "type": "boolean", "javaType": "boolean" }, { "name": "camel.main.beanIntrospectionLoggingLevel", "description": "Sets the logging level used by bean introspection, logging activity of its usage. The default is TRACE.", "sourceType": "org.apache.camel.main.DefaultConfigurationProperties", "type": "object", "javaType": "org.apache.camel.LoggingLevel", "enum": [ "ERROR", "WARN", "INFO", "DEBUG", "TRACE", "OFF" ] }, { "name": "camel.main.caseInsensitiveHeaders", "description": "Whether to use case sensitive or insensitive headers. Important: When using case sensitive (this is set to false). Then the map is case sensitive which means headers such as content-type and Content-Type are two different keys which can be a problem for some protocols such as HTTP based, which rely on case insensitive headers. However case sensitive implementations can yield faster performance. Therefore use case sensitiv [...] + { "name": "camel.main.config", "description": null, "sourceType": "org.apache.camel.main.HealthConfigurationProperties", "type": "object", "javaType": "java.util.Map", "defaultValue": "new HashMap<>()" }, { "name": "camel.main.configurationClasses", "description": "Sets classes names that will be used to configure the camel context as example by providing custom beans through org.apache.camel.BindToRegistry annotation.", "sourceType": "org.apache.camel.main.MainConfigurationProperties", "type": "string", "javaType": "java.lang.String" }, { "name": "camel.main.configurations", "description": "Sets the configuration objects used to configure the camel context.", "sourceType": "org.apache.camel.main.MainConfigurationProperties", "type": "object", "javaType": "java.util.List", "defaultValue": "new ArrayList<>()" }, { "name": "camel.main.consumerTemplateCacheSize", "description": "Consumer template endpoints cache size.", "sourceType": "org.apache.camel.main.DefaultConfigurationProperties", "type": "integer", "javaType": "int", "defaultValue": 1000 }, + { "name": "camel.main.contextEnabled", "description": null, "sourceType": "org.apache.camel.main.HealthConfigurationProperties", "type": "boolean", "javaType": "java.lang.Boolean" }, { "name": "camel.main.durationHitExitCode", "description": "Sets the exit code for the application if duration was hit", "sourceType": "org.apache.camel.main.MainConfigurationProperties", "type": "integer", "javaType": "int" }, { "name": "camel.main.durationMaxIdleSeconds", "description": "To specify for how long time in seconds Camel can be idle before automatic terminating the JVM. You can use this to run Camel for a short while.", "sourceType": "org.apache.camel.main.DefaultConfigurationProperties", "type": "integer", "javaType": "int" }, { "name": "camel.main.durationMaxMessages", "description": "To specify how many messages to process by Camel before automatic terminating the JVM. You can use this to run Camel for a short while.", "sourceType": "org.apache.camel.main.DefaultConfigurationProperties", "type": "integer", "javaType": "int" }, { "name": "camel.main.durationMaxSeconds", "description": "To specify for how long time in seconds to keep running the JVM before automatic terminating the JVM. You can use this to run Camel for a short while.", "sourceType": "org.apache.camel.main.DefaultConfigurationProperties", "type": "integer", "javaType": "int" }, + { "name": "camel.main.enabled", "description": null, "sourceType": "org.apache.camel.main.HealthConfigurationProperties", "type": "boolean", "javaType": "java.lang.Boolean" }, { "name": "camel.main.endpointBasicPropertyBinding", "description": "Whether the endpoint should use basic property binding (Camel 2.x) or the newer property binding with additional capabilities. The default value is false.", "sourceType": "org.apache.camel.main.DefaultConfigurationProperties", "type": "boolean", "javaType": "boolean" }, { "name": "camel.main.endpointBridgeErrorHandler", "description": "Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions occurred while the consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN\/ERROR level and ignored. The default va [...] { "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 [...] @@ -49,6 +52,7 @@ { "name": "camel.main.name", "description": "Sets the name of the CamelContext.", "sourceType": "org.apache.camel.main.DefaultConfigurationProperties", "type": "string", "javaType": "java.lang.String" }, { "name": "camel.main.packageScanRouteBuilders", "description": "Sets package names for scanning for org.apache.camel.builder.RouteBuilder classes as candidates to be included. If you are using Spring Boot then its instead recommended to use Spring Boots component scanning and annotate your route builder classes with Component. In other words only use this for Camel Main in standalone mode.", "sourceType": "org.apache.camel.main.MainConfigurationProperties", "type": "string", "javaTy [...] { "name": "camel.main.producerTemplateCacheSize", "description": "Producer template endpoints cache size.", "sourceType": "org.apache.camel.main.DefaultConfigurationProperties", "type": "integer", "javaType": "int", "defaultValue": 1000 }, + { "name": "camel.main.registryEnabled", "description": null, "sourceType": "org.apache.camel.main.HealthConfigurationProperties", "type": "boolean", "javaType": "java.lang.Boolean" }, { "name": "camel.main.routeControllerBackOffDelay", "description": "Backoff delay in millis when restarting a route that failed to startup.", "sourceType": "org.apache.camel.main.DefaultConfigurationProperties", "type": "integer", "javaType": "long" }, { "name": "camel.main.routeControllerBackOffMaxAttempts", "description": "Backoff maximum number of attempts to restart a route that failed to startup. When this threshold has been exceeded then the controller will give up attempting to restart the route, and the route will remain as stopped.", "sourceType": "org.apache.camel.main.DefaultConfigurationProperties", "type": "integer", "javaType": "long" }, { "name": "camel.main.routeControllerBackOffMaxDelay", "description": "Backoff maximum delay in millis when restarting a route that failed to startup.", "sourceType": "org.apache.camel.main.DefaultConfigurationProperties", "type": "integer", "javaType": "long" }, @@ -66,6 +70,7 @@ { "name": "camel.main.routesBuilderClasses", "description": "Sets classes names that implement RoutesBuilder .", "sourceType": "org.apache.camel.main.MainConfigurationProperties", "type": "string", "javaType": "java.lang.String" }, { "name": "camel.main.routesBuilders", "description": "Sets the RoutesBuilder instances.", "sourceType": "org.apache.camel.main.MainConfigurationProperties", "type": "object", "javaType": "java.util.List", "defaultValue": "new ArrayList<>()" }, { "name": "camel.main.routesCollectorEnabled", "description": "Whether the routes collector is enabled or not. When enabled Camel will auto-discover routes (RouteBuilder instances from the registry and also load additional XML routes from the file system. The routes collector is default enabled.", "sourceType": "org.apache.camel.main.DefaultConfigurationProperties", "type": "boolean", "javaType": "boolean", "defaultValue": true }, + { "name": "camel.main.routesEnabled", "description": null, "sourceType": "org.apache.camel.main.HealthConfigurationProperties", "type": "boolean", "javaType": "java.lang.Boolean" }, { "name": "camel.main.shutdownLogInflightExchangesOnTimeout", "description": "Sets whether to log information about the inflight Exchanges which are still running during a shutdown which didn't complete without the given timeout. This requires to enable the option inflightRepositoryBrowseEnabled.", "sourceType": "org.apache.camel.main.DefaultConfigurationProperties", "type": "boolean", "javaType": "boolean", "defaultValue": true }, { "name": "camel.main.shutdownNowOnTimeout", "description": "Sets whether to force shutdown of all consumers when a timeout occurred and thus not all consumers was shutdown within that period. You should have good reasons to set this option to false as it means that the routes keep running and is halted abruptly when CamelContext has been shutdown.", "sourceType": "org.apache.camel.main.DefaultConfigurationProperties", "type": "boolean", "javaType": "boolean", "defaultValue": true }, { "name": "camel.main.shutdownRoutesInReverseOrder", "description": "Sets whether routes should be shutdown in reverse or the same order as they where started.", "sourceType": "org.apache.camel.main.DefaultConfigurationProperties", "type": "boolean", "javaType": "boolean", "defaultValue": true }, diff --git a/core/camel-main/src/generated/resources/META-INF/services/org/apache/camel/configurer/HealthConfigurationProperties b/core/camel-main/src/generated/resources/META-INF/services/org/apache/camel/configurer/HealthConfigurationProperties new file mode 100644 index 0000000..b4730ed --- /dev/null +++ b/core/camel-main/src/generated/resources/META-INF/services/org/apache/camel/configurer/HealthConfigurationProperties @@ -0,0 +1,2 @@ +# Generated by camel build tools - do NOT edit this file! +class=org.apache.camel.main.HealthConfigurationPropertiesConfigurer 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 3285f89..7a290f1 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 @@ -98,7 +98,6 @@ 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; @@ -727,10 +726,10 @@ 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")) { + } else if (key.startsWith("camel.health.")) { // grab the value String value = prop.getProperty(key); - String option = key.substring(12); + String option = key.substring(13); validateOptionAndValue(key, option, value); healthProperties.put(optionKey(option), value); } else if (key.startsWith("camel.beans.")) { @@ -802,7 +801,10 @@ public abstract class BaseMainSupport extends BaseService { } if (!healthProperties.isEmpty()) { LOG.debug("Auto-configuring HealthCheck from loaded properties: {}", healthProperties.size()); - setHealthCheckProperties(camelContext, healthProperties, mainConfigurationProperties.isAutoConfigurationFailFast(), autoConfiguredProperties); + HealthConfigurationProperties health = mainConfigurationProperties.health(); + setPropertiesOnTarget(camelContext, health, healthProperties, "camel.health.", + mainConfigurationProperties.isAutoConfigurationFailFast(), true, autoConfiguredProperties); + // TODO: setup health check via HealthConfigurationProperties } // log which options was not set @@ -933,6 +935,7 @@ public abstract class BaseMainSupport extends BaseService { } } + @Deprecated private void setHealthCheckProperties(CamelContext camelContext, Map<String, Object> healthCheckProperties, boolean failIfNotSet, Map<String, String> autoConfiguredProperties) { @@ -978,9 +981,9 @@ public abstract class BaseMainSupport extends BaseService { 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); - } +// if (failIfNotSet && !VALID_HEALTH_KEYS.contains(key)) { +// throw new PropertyBindingException("HealthCheckConfiguration", key, value); +// } autoConfiguredProperties.put("camel.health" + k, value); }); diff --git a/core/camel-main/src/main/java/org/apache/camel/main/HealthConfigurationProperties.java b/core/camel-main/src/main/java/org/apache/camel/main/HealthConfigurationProperties.java new file mode 100644 index 0000000..0d59b30 --- /dev/null +++ b/core/camel-main/src/main/java/org/apache/camel/main/HealthConfigurationProperties.java @@ -0,0 +1,119 @@ +/* + * 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.main; + +import java.util.HashMap; +import java.util.Map; + +import org.apache.camel.spi.Configurer; + +/** + * Global configuration for Health Check + */ +@Configurer +public class HealthConfigurationProperties { + + private final MainConfigurationProperties parent; + + private Boolean enabled; + private Boolean contextEnabled; + private Boolean routesEnabled; + private Boolean registryEnabled; + private Map<String, HealthConfiguration> config = new HashMap<>(); + + public HealthConfigurationProperties(MainConfigurationProperties parent) { + this.parent = parent; + } + + public MainConfigurationProperties end() { + return parent; + } + + public Boolean getEnabled() { + return enabled; + } + + public void setEnabled(Boolean enabled) { + this.enabled = enabled; + } + + public Boolean getContextEnabled() { + return contextEnabled; + } + + public void setContextEnabled(Boolean contextEnabled) { + this.contextEnabled = contextEnabled; + } + + public Boolean getRoutesEnabled() { + return routesEnabled; + } + + public void setRoutesEnabled(Boolean routesEnabled) { + this.routesEnabled = routesEnabled; + } + + public Boolean getRegistryEnabled() { + return registryEnabled; + } + + public void setRegistryEnabled(Boolean registryEnabled) { + this.registryEnabled = registryEnabled; + } + + public Map<String, HealthConfiguration> getConfig() { + return config; + } + + public void setConfig(Map<String, HealthConfiguration> config) { + this.config = config; + } + + // TODO: Fluent builder + + @Configurer + public static class HealthConfiguration { + + private Boolean enabled; + private Long interval; + private Integer failureThreshold; + + public Boolean getEnabled() { + return enabled; + } + + public void setEnabled(Boolean enabled) { + this.enabled = enabled; + } + + public Long getInterval() { + return interval; + } + + public void setInterval(Long interval) { + this.interval = interval; + } + + public Integer getFailureThreshold() { + return failureThreshold; + } + + public void setFailureThreshold(Integer failureThreshold) { + this.failureThreshold = failureThreshold; + } + } +} diff --git a/core/camel-main/src/main/java/org/apache/camel/main/MainConfigurationProperties.java b/core/camel-main/src/main/java/org/apache/camel/main/MainConfigurationProperties.java index d5529ce..854be68 100644 --- a/core/camel-main/src/main/java/org/apache/camel/main/MainConfigurationProperties.java +++ b/core/camel-main/src/main/java/org/apache/camel/main/MainConfigurationProperties.java @@ -46,6 +46,7 @@ public class MainConfigurationProperties extends DefaultConfigurationProperties< private List<Object> configurations = new ArrayList<>(); // extended configuration + private final HealthConfigurationProperties healthConfigurationProperties = new HealthConfigurationProperties(this); private final HystrixConfigurationProperties hystrixConfigurationProperties = new HystrixConfigurationProperties(this); private final Resilience4jConfigurationProperties resilience4jConfigurationProperties = new Resilience4jConfigurationProperties(this); private final FaultToleranceConfigurationProperties faultToleranceConfigurationProperties = new FaultToleranceConfigurationProperties(this); @@ -55,6 +56,13 @@ public class MainConfigurationProperties extends DefaultConfigurationProperties< // -------------------------------------------------------------- /** + * To configure Health Check + */ + public HealthConfigurationProperties health() { + return healthConfigurationProperties; + } + + /** * To configure Circuit Breaker EIP with Hystrix */ public HystrixConfigurationProperties hystrix() {