Class 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 or to invoke only readiness or liveness checks.
    • Method Detail

      • 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,
                                                                     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,
                                                                    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)
      • 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