Class HealthCheckHelper

java.lang.Object
org.apache.camel.health.HealthCheckHelper

public final class HealthCheckHelper extends Object
Helper for invoking HealthCheck's. The helper will look up the HealthCheckRegistry from CamelContext and gather all the registered HealthChecks and invoke them and gather their results. The helper allows filtering out unwanted health checks using Predicate<HealthCheck> or to invoke only readiness or liveness checks.
  • Method Details

    • invoke

      public static Collection<HealthCheck.Result> invoke(CamelContext camelContext)
      Invokes all the checks and returns a collection of results.
    • invoke

      public static Collection<HealthCheck.Result> invoke(CamelContext camelContext, String exposureLevel)
      Invokes all the checks and returns a collection of results.
      Parameters:
      camelContext - the camel context
      exposureLevel - level of exposure (full, oneline or default)
    • invokeReadiness

      public static Collection<HealthCheck.Result> invokeReadiness(CamelContext camelContext)
      Invokes the readiness checks and returns a collection of results.
    • invokeReadiness

      public static Collection<HealthCheck.Result> invokeReadiness(CamelContext camelContext, String exposureLevel)
      Invokes the readiness checks and returns a collection of results.
      Parameters:
      camelContext - the camel context
      exposureLevel - level of exposure (full, oneline or default)
    • invokeLiveness

      public static Collection<HealthCheck.Result> invokeLiveness(CamelContext camelContext)
      Invokes the liveness checks and returns a collection of results.
    • invokeLiveness

      public static Collection<HealthCheck.Result> invokeLiveness(CamelContext camelContext, String exposureLevel)
      Invokes the liveness checks and returns a collection of results.
      Parameters:
      camelContext - the camel context
      exposureLevel - level of exposure (full, oneline or default)
    • invoke

      public static Collection<HealthCheck.Result> invoke(CamelContext camelContext, Function<HealthCheck,Map<String,Object>> optionsSupplier)
      Invokes the checks and returns a collection of results.
    • invoke

      public static Collection<HealthCheck.Result> invoke(CamelContext camelContext, Predicate<HealthCheck> filter)
      Invokes the checks and returns a collection of results.
    • invoke

      public static Collection<HealthCheck.Result> invoke(CamelContext camelContext, Function<HealthCheck,Map<String,Object>> optionsSupplier, Predicate<HealthCheck> filter, String exposureLevel)
      Invokes the checks and returns a collection of results.
      Parameters:
      camelContext - the camel context.
      optionsSupplier - a supplier for options.
      filter - filter to exclude some checks.
      exposureLevel - full or oneline (null to use default)
    • invoke

      public static Optional<HealthCheck.Result> invoke(CamelContext camelContext, String id, Map<String,Object> options)
      Invoke a check by id.
      Parameters:
      camelContext - the camel context.
      id - the check id.
      options - the check options.
      Returns:
      an optional HealthCheck.Result.
    • getHealthCheckRegistry

      public static HealthCheckRegistry getHealthCheckRegistry(CamelContext context)
      Parameters:
      context - the camel context
      Returns:
      the health check registry, or null if health-check is not enabled.
    • getHealthCheck

      public static HealthCheck getHealthCheck(CamelContext context, String id)
      Gets the HealthCheck by the given id (will resolve from classpath if necessary)
      Parameters:
      context - the camel context
      id - the id of the health check
      Returns:
      the health check, or null if no health check exists with this id
    • getHealthCheck

      public static <T extends HealthCheck> T getHealthCheck(CamelContext context, String id, Class<T> type)
      Gets the HealthCheck by the given id (will resolve from classpath if necessary)
      Parameters:
      context - the camel context
      id - the id of the health check
      type - the expected type of the health check repository
      Returns:
      the health check, or null if no health check exists with this id
    • getHealthCheckRepository

      public static HealthCheckRepository getHealthCheckRepository(CamelContext context, String id)
      Gets the HealthCheckRepository by the given id (will resolve from classpath if necessary)
      Parameters:
      context - the camel context
      id - the id of the health check repository
      Returns:
      the health check repository, or null if no health check repository exists with this id
    • getHealthCheckRepository

      public static <T extends HealthCheckRepository> T getHealthCheckRepository(CamelContext context, String id, Class<T> type)
      Gets the HealthCheckRepository by the given id (will resolve from classpath if necessary)
      Parameters:
      context - the camel context
      id - the id of the health check repository
      type - the expected type of the health check repository
      Returns:
      the health check repository, or null if no health check repository exists with this id
    • isResultsUp

      public static boolean isResultsUp(Collection<HealthCheck.Result> results, boolean readiness)
      Checks the overall status of the results.
      Parameters:
      results - the results from the invoked health checks
      readiness - readiness or liveness mode
      Returns:
      true if up, or false if down
    • isReservedKey

      public static boolean isReservedKey(String key)
      Is the given key a reserved key used by Camel to store metadata in health check response details.
      Parameters:
      key - the key
      Returns:
      true if reserved, false otherwise