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 062c79a88982f26ae98387abd4c4e8a8ec3895c9 Author: Claus Ibsen <claus.ib...@gmail.com> AuthorDate: Sun May 24 10:21:19 2020 +0200 CAMEL-15084: Move health implementation in camel-base into camel-health --- apache-camel/pom.xml | 4 ++ apache-camel/src/main/descriptors/common-bin.xml | 1 + .../apache/camel/health/HealthCheckRegistry.java | 6 +++ .../camel/impl/engine/AbstractCamelContext.java | 7 +-- .../camel/impl/engine/SimpleCamelContext.java | 4 +- core/camel-core/pom.xml | 4 ++ core/camel-health/pom.xml | 56 ++++++++++++++++++++++ .../org/apache/camel/health-check-registry | 2 + .../camel/impl/health/AbstractHealthCheck.java | 0 .../camel/impl/health/ContextHealthCheck.java | 0 .../impl/health/DefaultHealthCheckRegistry.java | 20 +++++--- .../impl/health/DefaultHealthCheckService.java | 0 .../impl/health/PerformanceCounterEvaluator.java | 1 + .../camel/impl/health/RegistryRepository.java | 0 .../apache/camel/impl/health/RouteHealthCheck.java | 0 .../health/RoutePerformanceCounterEvaluators.java | 0 .../impl/health/RoutesHealthCheckRepository.java | 0 .../java/org/apache/camel/impl/health/package.html | 0 core/pom.xml | 1 + .../ROOT/pages/camel-3x-upgrade-guide-3_4.adoc | 6 ++- parent/pom.xml | 5 ++ 21 files changed, 105 insertions(+), 12 deletions(-) diff --git a/apache-camel/pom.xml b/apache-camel/pom.xml index 39cab65..6373d06 100644 --- a/apache-camel/pom.xml +++ b/apache-camel/pom.xml @@ -98,6 +98,10 @@ </dependency> <dependency> <groupId>org.apache.camel</groupId> + <artifactId>camel-health</artifactId> + </dependency> + <dependency> + <groupId>org.apache.camel</groupId> <artifactId>camel-headersmap</artifactId> </dependency> <dependency> diff --git a/apache-camel/src/main/descriptors/common-bin.xml b/apache-camel/src/main/descriptors/common-bin.xml index b952547..d925cac 100644 --- a/apache-camel/src/main/descriptors/common-bin.xml +++ b/apache-camel/src/main/descriptors/common-bin.xml @@ -40,6 +40,7 @@ <include>org.apache.camel:camel-core-catalog</include> <include>org.apache.camel:camel-cloud</include> <include>org.apache.camel:camel-cluster</include> + <include>org.apache.camel:camel-health</include> <include>org.apache.camel:camel-xml-jaxp</include> <include>org.apache.camel:camel-main</include> <include>org.apache.camel:camel-tooling-model</include> 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 2edef6e..6187114 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 @@ -31,6 +31,12 @@ import org.apache.camel.util.ObjectHelper; * registry, @see <a href="https://issues.apache.org/jira/browse/CAMEL-10792"/>. */ public interface HealthCheckRegistry extends HealthCheckRepository, CamelContextAware { + + /** + * Service factory key. + */ + String FACTORY = "health-check-registry"; + /** * Registers a service {@link HealthCheck}. */ diff --git a/core/camel-base/src/main/java/org/apache/camel/impl/engine/AbstractCamelContext.java b/core/camel-base/src/main/java/org/apache/camel/impl/engine/AbstractCamelContext.java index 86d7f32..324423b 100644 --- a/core/camel-base/src/main/java/org/apache/camel/impl/engine/AbstractCamelContext.java +++ b/core/camel-base/src/main/java/org/apache/camel/impl/engine/AbstractCamelContext.java @@ -341,7 +341,7 @@ public abstract class AbstractCamelContext extends BaseService this.lifecycleStrategies.add(new LifecycleStrategySupport() { @Override public void onContextInitialized(CamelContext context) throws VetoCamelContextStartException { - for (OnCamelContextInitialized handler: context.getRegistry().findByType(OnCamelContextInitialized.class)) { + for (OnCamelContextInitialized handler : context.getRegistry().findByType(OnCamelContextInitialized.class)) { // RoutesBuilder should register them-self to the camel context // to avoid invoking them multiple times if routes are discovered // from the registry (i.e. camel-main) @@ -353,7 +353,7 @@ public abstract class AbstractCamelContext extends BaseService @Override public void onContextStart(CamelContext context) throws VetoCamelContextStartException { - for (OnCamelContextStart handler: context.getRegistry().findByType(OnCamelContextStart.class)) { + for (OnCamelContextStart handler : context.getRegistry().findByType(OnCamelContextStart.class)) { // RoutesBuilder should register them-self to the camel context // to avoid invoking them multiple times if routes are discovered // from the registry (i.e. camel-main) @@ -365,7 +365,7 @@ public abstract class AbstractCamelContext extends BaseService @Override public void onContextStop(CamelContext context) { - for (OnCamelContextStop handler: context.getRegistry().findByType(OnCamelContextStop.class)) { + for (OnCamelContextStop handler : context.getRegistry().findByType(OnCamelContextStop.class)) { // RoutesBuilder should register them-self to the camel context // to avoid invoking them multiple times if routes are discovered // from the registry (i.e. camel-main) @@ -377,6 +377,7 @@ public abstract class AbstractCamelContext extends BaseService }); setDefaultExtension(HealthCheckRegistry.class, this::createHealthCheckRegistry); + // TODO: is route controller needed as extension? setDefaultExtension(RouteController.class, this::createRouteController); if (build) { diff --git a/core/camel-base/src/main/java/org/apache/camel/impl/engine/SimpleCamelContext.java b/core/camel-base/src/main/java/org/apache/camel/impl/engine/SimpleCamelContext.java index 4c713e6..0b5a471 100644 --- a/core/camel-base/src/main/java/org/apache/camel/impl/engine/SimpleCamelContext.java +++ b/core/camel-base/src/main/java/org/apache/camel/impl/engine/SimpleCamelContext.java @@ -29,7 +29,6 @@ import org.apache.camel.TypeConverter; import org.apache.camel.catalog.RuntimeCamelCatalog; import org.apache.camel.health.HealthCheckRegistry; import org.apache.camel.impl.converter.DefaultTypeConverter; -import org.apache.camel.impl.health.DefaultHealthCheckRegistry; import org.apache.camel.impl.transformer.TransformerKey; import org.apache.camel.impl.validator.ValidatorKey; import org.apache.camel.processor.MulticastProcessor; @@ -112,7 +111,8 @@ public class SimpleCamelContext extends AbstractCamelContext { @Override protected HealthCheckRegistry createHealthCheckRegistry() { - return new DefaultHealthCheckRegistry(this); + return new BaseServiceResolver<>(HealthCheckRegistry.FACTORY, HealthCheckRegistry.class) + .resolve(getCamelContextReference()).orElse(null); } @Override diff --git a/core/camel-core/pom.xml b/core/camel-core/pom.xml index 964c6de..038f509 100644 --- a/core/camel-core/pom.xml +++ b/core/camel-core/pom.xml @@ -87,6 +87,10 @@ </dependency> <dependency> <groupId>org.apache.camel</groupId> + <artifactId>camel-health</artifactId> + </dependency> + <dependency> + <groupId>org.apache.camel</groupId> <artifactId>camel-language</artifactId> </dependency> <dependency> diff --git a/core/camel-health/pom.xml b/core/camel-health/pom.xml new file mode 100644 index 0000000..1f4bd8d --- /dev/null +++ b/core/camel-health/pom.xml @@ -0,0 +1,56 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + + 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. + +--> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + + <parent> + <groupId>org.apache.camel</groupId> + <artifactId>core</artifactId> + <version>3.4.0-SNAPSHOT</version> + <relativePath>..</relativePath> + </parent> + + <artifactId>camel-health</artifactId> + <packaging>jar</packaging> + + <name>Camel :: Health</name> + <description>Camel Health Support</description> + + <properties> + <firstVersion>3.4.0</firstVersion> + <label>core</label> + <camel-prepare-component>false</camel-prepare-component> + </properties> + + <dependencies> + + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-core-engine</artifactId> + </dependency> + + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-api</artifactId> + </dependency> + + </dependencies> + +</project> diff --git a/core/camel-health/src/generated/resources/META-INF/services/org/apache/camel/health-check-registry b/core/camel-health/src/generated/resources/META-INF/services/org/apache/camel/health-check-registry new file mode 100644 index 0000000..6990728 --- /dev/null +++ b/core/camel-health/src/generated/resources/META-INF/services/org/apache/camel/health-check-registry @@ -0,0 +1,2 @@ +# Generated by camel build tools - do NOT edit this file! +class=org.apache.camel.impl.health.DefaultHealthCheckRegistry diff --git a/core/camel-base/src/main/java/org/apache/camel/impl/health/AbstractHealthCheck.java b/core/camel-health/src/main/java/org/apache/camel/impl/health/AbstractHealthCheck.java similarity index 100% rename from core/camel-base/src/main/java/org/apache/camel/impl/health/AbstractHealthCheck.java rename to core/camel-health/src/main/java/org/apache/camel/impl/health/AbstractHealthCheck.java diff --git a/core/camel-base/src/main/java/org/apache/camel/impl/health/ContextHealthCheck.java b/core/camel-health/src/main/java/org/apache/camel/impl/health/ContextHealthCheck.java similarity index 100% rename from core/camel-base/src/main/java/org/apache/camel/impl/health/ContextHealthCheck.java rename to core/camel-health/src/main/java/org/apache/camel/impl/health/ContextHealthCheck.java diff --git a/core/camel-base/src/main/java/org/apache/camel/impl/health/DefaultHealthCheckRegistry.java b/core/camel-health/src/main/java/org/apache/camel/impl/health/DefaultHealthCheckRegistry.java similarity index 83% rename from core/camel-base/src/main/java/org/apache/camel/impl/health/DefaultHealthCheckRegistry.java rename to core/camel-health/src/main/java/org/apache/camel/impl/health/DefaultHealthCheckRegistry.java index fd65b14..53cde1e 100644 --- a/core/camel-base/src/main/java/org/apache/camel/impl/health/DefaultHealthCheckRegistry.java +++ b/core/camel-health/src/main/java/org/apache/camel/impl/health/DefaultHealthCheckRegistry.java @@ -24,14 +24,21 @@ import java.util.stream.Stream; import org.apache.camel.CamelContext; import org.apache.camel.CamelContextAware; +import org.apache.camel.StaticService; import org.apache.camel.health.HealthCheck; import org.apache.camel.health.HealthCheckRegistry; import org.apache.camel.health.HealthCheckRepository; +import org.apache.camel.spi.annotations.JdkService; +import org.apache.camel.support.service.ServiceSupport; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public class DefaultHealthCheckRegistry implements HealthCheckRegistry { - private static final Logger LOGGER = LoggerFactory.getLogger(DefaultHealthCheckRegistry.class); +/** + * Default {@link HealthCheckRegistry}. + */ +@JdkService(HealthCheckRegistry.FACTORY) +public class DefaultHealthCheckRegistry extends ServiceSupport implements HealthCheckRegistry, StaticService { + private static final Logger LOG = LoggerFactory.getLogger(DefaultHealthCheckRegistry.class); private final Set<HealthCheck> checks; private final Set<HealthCheckRepository> repositories; @@ -57,6 +64,7 @@ public class DefaultHealthCheckRegistry implements HealthCheckRegistry { public final void setCamelContext(CamelContext camelContext) { this.camelContext = camelContext; + // TODO: Move this to doInit for (HealthCheck check: checks) { if (check instanceof CamelContextAware) { ((CamelContextAware) check).setCamelContext(camelContext); @@ -83,7 +91,7 @@ public class DefaultHealthCheckRegistry implements HealthCheckRegistry { ((CamelContextAware) check).setCamelContext(camelContext); } - LOGGER.debug("HealthCheck with id {} successfully registered", check.getId()); + LOG.debug("HealthCheck with id {} successfully registered", check.getId()); } return result; @@ -93,7 +101,7 @@ public class DefaultHealthCheckRegistry implements HealthCheckRegistry { public boolean unregister(HealthCheck check) { boolean result = checks.remove(check); if (result) { - LOGGER.debug("HealthCheck with id {} successfully un-registered", check.getId()); + LOG.debug("HealthCheck with id {} successfully un-registered", check.getId()); } return result; @@ -117,7 +125,7 @@ public class DefaultHealthCheckRegistry implements HealthCheckRegistry { if (repository instanceof CamelContextAware) { ((CamelContextAware) repository).setCamelContext(getCamelContext()); - LOGGER.debug("HealthCheckRepository {} successfully registered", repository); + LOG.debug("HealthCheckRepository {} successfully registered", repository); } } @@ -128,7 +136,7 @@ public class DefaultHealthCheckRegistry implements HealthCheckRegistry { public boolean removeRepository(HealthCheckRepository repository) { boolean result = repositories.remove(repository); if (result) { - LOGGER.debug("HealthCheckRepository with {} successfully un-registered", repository); + LOG.debug("HealthCheckRepository with {} successfully un-registered", repository); } return result; diff --git a/core/camel-base/src/main/java/org/apache/camel/impl/health/DefaultHealthCheckService.java b/core/camel-health/src/main/java/org/apache/camel/impl/health/DefaultHealthCheckService.java similarity index 100% rename from core/camel-base/src/main/java/org/apache/camel/impl/health/DefaultHealthCheckService.java rename to core/camel-health/src/main/java/org/apache/camel/impl/health/DefaultHealthCheckService.java diff --git a/core/camel-base/src/main/java/org/apache/camel/impl/health/PerformanceCounterEvaluator.java b/core/camel-health/src/main/java/org/apache/camel/impl/health/PerformanceCounterEvaluator.java similarity index 99% rename from core/camel-base/src/main/java/org/apache/camel/impl/health/PerformanceCounterEvaluator.java rename to core/camel-health/src/main/java/org/apache/camel/impl/health/PerformanceCounterEvaluator.java index eb1dece..92c290f 100644 --- a/core/camel-base/src/main/java/org/apache/camel/impl/health/PerformanceCounterEvaluator.java +++ b/core/camel-health/src/main/java/org/apache/camel/impl/health/PerformanceCounterEvaluator.java @@ -23,6 +23,7 @@ import org.apache.camel.health.HealthCheckResultBuilder; @FunctionalInterface public interface PerformanceCounterEvaluator<T extends ManagedPerformanceCounterMBean> { + /** * Check the given performance counter. */ diff --git a/core/camel-base/src/main/java/org/apache/camel/impl/health/RegistryRepository.java b/core/camel-health/src/main/java/org/apache/camel/impl/health/RegistryRepository.java similarity index 100% rename from core/camel-base/src/main/java/org/apache/camel/impl/health/RegistryRepository.java rename to core/camel-health/src/main/java/org/apache/camel/impl/health/RegistryRepository.java diff --git a/core/camel-base/src/main/java/org/apache/camel/impl/health/RouteHealthCheck.java b/core/camel-health/src/main/java/org/apache/camel/impl/health/RouteHealthCheck.java similarity index 100% rename from core/camel-base/src/main/java/org/apache/camel/impl/health/RouteHealthCheck.java rename to core/camel-health/src/main/java/org/apache/camel/impl/health/RouteHealthCheck.java diff --git a/core/camel-base/src/main/java/org/apache/camel/impl/health/RoutePerformanceCounterEvaluators.java b/core/camel-health/src/main/java/org/apache/camel/impl/health/RoutePerformanceCounterEvaluators.java similarity index 100% rename from core/camel-base/src/main/java/org/apache/camel/impl/health/RoutePerformanceCounterEvaluators.java rename to core/camel-health/src/main/java/org/apache/camel/impl/health/RoutePerformanceCounterEvaluators.java diff --git a/core/camel-base/src/main/java/org/apache/camel/impl/health/RoutesHealthCheckRepository.java b/core/camel-health/src/main/java/org/apache/camel/impl/health/RoutesHealthCheckRepository.java similarity index 100% rename from core/camel-base/src/main/java/org/apache/camel/impl/health/RoutesHealthCheckRepository.java rename to core/camel-health/src/main/java/org/apache/camel/impl/health/RoutesHealthCheckRepository.java diff --git a/core/camel-base/src/main/java/org/apache/camel/impl/health/package.html b/core/camel-health/src/main/java/org/apache/camel/impl/health/package.html similarity index 100% rename from core/camel-base/src/main/java/org/apache/camel/impl/health/package.html rename to core/camel-health/src/main/java/org/apache/camel/impl/health/package.html diff --git a/core/pom.xml b/core/pom.xml index 4f9490f..66be686 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -51,6 +51,7 @@ <module>camel-core</module> <module>camel-core-xml</module> <module>camel-cloud</module> + <module>camel-health</module> <module>camel-main</module> <module>camel-allcomponents</module> <module>camel-endpointdsl</module> diff --git a/docs/user-manual/modules/ROOT/pages/camel-3x-upgrade-guide-3_4.adoc b/docs/user-manual/modules/ROOT/pages/camel-3x-upgrade-guide-3_4.adoc index c234d31..736d7d4 100644 --- a/docs/user-manual/modules/ROOT/pages/camel-3x-upgrade-guide-3_4.adoc +++ b/docs/user-manual/modules/ROOT/pages/camel-3x-upgrade-guide-3_4.adoc @@ -5,7 +5,7 @@ from Camel 3.x to 3.y. For example if you are upgrading Camel 3.0 to 3.2, then y from both 3.0 to 3.1 and 3.1 to 3.2. == Upgrading Camel 3.3 to 3.4 -======= + === camel-test and JMX The `camel-test` module no longer has dependency on `camel-management` out of the box. @@ -22,6 +22,10 @@ For example to use JMX during testing you the following dependency as test scope </dependency> ---- +=== Health Check + +The default health check implementation has been moved out of `camel-base` into `camel-health` as a separate module. + === Template components The template components which allows access to the current `Exchange` and `CamelContext` API diff --git a/parent/pom.xml b/parent/pom.xml index 17301fb..1743ddf 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -714,6 +714,11 @@ </dependency> <dependency> <groupId>org.apache.camel</groupId> + <artifactId>camel-health</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>org.apache.camel</groupId> <artifactId>camel-main</artifactId> <version>${project.version}</version> </dependency>