Search in sources :

Example 1 with HealthCheck

use of org.apache.camel.health.HealthCheck in project camel-quarkus by apache.

the class MicroProfileHealthProcessor method camelHealthDiscovery.

@BuildStep(onlyIf = HealthEnabled.class)
List<CamelBeanBuildItem> camelHealthDiscovery(CombinedIndexBuildItem combinedIndex) {
    IndexView index = combinedIndex.getIndex();
    List<CamelBeanBuildItem> buildItems = new ArrayList<>();
    Collection<ClassInfo> healthChecks = index.getAllKnownImplementors(CAMEL_HEALTH_CHECK_DOTNAME);
    Collection<ClassInfo> healthCheckRepositories = index.getAllKnownImplementors(CAMEL_HEALTH_CHECK_REPOSITORY_DOTNAME);
    Config config = ConfigProvider.getConfig();
    Predicate<ClassInfo> healthCheckFilter = classInfo -> {
        String className = classInfo.name().toString();
        if (className.equals(HealthCheckRegistryRepository.class.getName())) {
            // HealthCheckRegistryRepository is created internally by Camel
            return false;
        }
        if (className.equals(ContextHealthCheck.class.getName())) {
            return config.getOptionalValue("camel.health.contextEnabled", boolean.class).orElse(true);
        }
        if (className.equals(RoutesHealthCheckRepository.class.getName())) {
            return config.getOptionalValue("camel.health.routesEnabled", boolean.class).orElse(true);
        }
        if (className.equals(ConsumersHealthCheckRepository.class.getName())) {
            return config.getOptionalValue("camel.health.consumersEnabled", boolean.class).orElse(true);
        }
        return true;
    };
    // Create CamelBeanBuildItem to bind instances of HealthCheck to the camel registry
    healthChecks.stream().filter(CamelSupport::isConcrete).filter(CamelSupport::isPublic).filter(ClassInfo::hasNoArgsConstructor).filter(healthCheckFilter).map(this::createHealthCamelBeanBuildItem).forEach(buildItems::add);
    // Create CamelBeanBuildItem to bind instances of HealthCheckRepository to the camel registry
    healthCheckRepositories.stream().filter(CamelSupport::isConcrete).filter(CamelSupport::isPublic).filter(ClassInfo::hasNoArgsConstructor).filter(healthCheckFilter).map(this::createHealthCamelBeanBuildItem).forEach(buildItems::add);
    return buildItems;
}
Also used : Record(io.quarkus.deployment.annotations.Record) CamelSupport(org.apache.camel.quarkus.core.deployment.util.CamelSupport) HealthCheckRepository(org.apache.camel.health.HealthCheckRepository) DotName(org.jboss.jandex.DotName) CamelServicePatternBuildItem(org.apache.camel.quarkus.core.deployment.spi.CamelServicePatternBuildItem) ClassInfo(org.jboss.jandex.ClassInfo) CombinedIndexBuildItem(io.quarkus.deployment.builditem.CombinedIndexBuildItem) HealthCheckRegistry(org.apache.camel.health.HealthCheckRegistry) ArrayList(java.util.ArrayList) BooleanSupplier(java.util.function.BooleanSupplier) BuildStep(io.quarkus.deployment.annotations.BuildStep) FeatureBuildItem(io.quarkus.deployment.builditem.FeatureBuildItem) CamelServiceDestination(org.apache.camel.quarkus.core.deployment.spi.CamelServiceDestination) CamelMicroProfileHealthConfig(org.apache.camel.quarkus.component.microprofile.health.runtime.CamelMicroProfileHealthConfig) HealthCheckRegistryRepository(org.apache.camel.impl.health.HealthCheckRegistryRepository) HealthCheck(org.apache.camel.health.HealthCheck) IndexView(org.jboss.jandex.IndexView) CamelMicroProfileHealthRecorder(org.apache.camel.quarkus.component.microprofile.health.runtime.CamelMicroProfileHealthRecorder) ConsumersHealthCheckRepository(org.apache.camel.impl.health.ConsumersHealthCheckRepository) CamelContextCustomizerBuildItem(org.apache.camel.quarkus.core.deployment.spi.CamelContextCustomizerBuildItem) CamelBeanBuildItem(org.apache.camel.quarkus.core.deployment.spi.CamelBeanBuildItem) Predicate(java.util.function.Predicate) Collection(java.util.Collection) ExecutionTime(io.quarkus.deployment.annotations.ExecutionTime) ContextHealthCheck(org.apache.camel.impl.health.ContextHealthCheck) Config(org.eclipse.microprofile.config.Config) HealthBuildTimeConfig(io.quarkus.smallrye.health.deployment.HealthBuildTimeConfig) List(java.util.List) RoutesHealthCheckRepository(org.apache.camel.impl.health.RoutesHealthCheckRepository) ConfigProvider(org.eclipse.microprofile.config.ConfigProvider) ObjectHelper(org.apache.camel.util.ObjectHelper) CamelBeanBuildItem(org.apache.camel.quarkus.core.deployment.spi.CamelBeanBuildItem) IndexView(org.jboss.jandex.IndexView) CamelMicroProfileHealthConfig(org.apache.camel.quarkus.component.microprofile.health.runtime.CamelMicroProfileHealthConfig) Config(org.eclipse.microprofile.config.Config) HealthBuildTimeConfig(io.quarkus.smallrye.health.deployment.HealthBuildTimeConfig) ArrayList(java.util.ArrayList) CamelSupport(org.apache.camel.quarkus.core.deployment.util.CamelSupport) ClassInfo(org.jboss.jandex.ClassInfo) BuildStep(io.quarkus.deployment.annotations.BuildStep)

Example 2 with HealthCheck

use of org.apache.camel.health.HealthCheck in project camel-quarkus by apache.

the class MicroProfileHealthResource method modifyHealthCheckStatus.

@Path("/{healthCheckId}/return/status")
@POST
public void modifyHealthCheckStatus(@PathParam("healthCheckId") String healthCheckId, @QueryParam("returnStatusUp") boolean isReturnStatusUp) {
    HealthCheck healthCheck = camelContext.getExtension(HealthCheckRegistry.class).getCheck(healthCheckId).get();
    FailureThresholdHealthCheck failureThresholdHealthCheck = (FailureThresholdHealthCheck) healthCheck;
    failureThresholdHealthCheck.setReturnStatusUp(isReturnStatusUp);
}
Also used : HealthCheck(org.apache.camel.health.HealthCheck) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST)

Aggregations

HealthCheck (org.apache.camel.health.HealthCheck)2 BuildStep (io.quarkus.deployment.annotations.BuildStep)1 ExecutionTime (io.quarkus.deployment.annotations.ExecutionTime)1 Record (io.quarkus.deployment.annotations.Record)1 CombinedIndexBuildItem (io.quarkus.deployment.builditem.CombinedIndexBuildItem)1 FeatureBuildItem (io.quarkus.deployment.builditem.FeatureBuildItem)1 HealthBuildTimeConfig (io.quarkus.smallrye.health.deployment.HealthBuildTimeConfig)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 List (java.util.List)1 BooleanSupplier (java.util.function.BooleanSupplier)1 Predicate (java.util.function.Predicate)1 POST (javax.ws.rs.POST)1 Path (javax.ws.rs.Path)1 HealthCheckRegistry (org.apache.camel.health.HealthCheckRegistry)1 HealthCheckRepository (org.apache.camel.health.HealthCheckRepository)1 ConsumersHealthCheckRepository (org.apache.camel.impl.health.ConsumersHealthCheckRepository)1 ContextHealthCheck (org.apache.camel.impl.health.ContextHealthCheck)1 HealthCheckRegistryRepository (org.apache.camel.impl.health.HealthCheckRegistryRepository)1 RoutesHealthCheckRepository (org.apache.camel.impl.health.RoutesHealthCheckRepository)1