Package org.apache.camel.health
Class HealthCheckHelper
java.lang.Object
org.apache.camel.health.HealthCheckHelper
Helper for invoking
HealthCheck
's.
The helper will look up the HealthCheckRegistry
from CamelContext
and gather all the registered
HealthCheck
s 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 Summary
Modifier and TypeMethodDescriptionstatic HealthCheck
getHealthCheck
(CamelContext context, String id) Gets theHealthCheck
by the given id (will resolve from classpath if necessary)static <T extends HealthCheck>
TgetHealthCheck
(CamelContext context, String id, Class<T> type) Gets theHealthCheck
by the given id (will resolve from classpath if necessary)static HealthCheckRegistry
getHealthCheckRegistry
(CamelContext context) Gets theHealthCheckRegistry
.static HealthCheckRepository
getHealthCheckRepository
(CamelContext context, String id) Gets theHealthCheckRepository
by the given id (will resolve from classpath if necessary)static <T extends HealthCheckRepository>
TgetHealthCheckRepository
(CamelContext context, String id, Class<T> type) Gets theHealthCheckRepository
by the given id (will resolve from classpath if necessary)static Collection<HealthCheck.Result>
invoke
(CamelContext camelContext) Invokes all the checks and returns a collection of results.static Collection<HealthCheck.Result>
invoke
(CamelContext camelContext, String exposureLevel) Invokes all the checks and returns a collection of results.static Optional<HealthCheck.Result>
Invoke a check by id.static Collection<HealthCheck.Result>
invoke
(CamelContext camelContext, Function<HealthCheck, Map<String, Object>> optionsSupplier) Invokes the checks and returns a collection of results.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.static Collection<HealthCheck.Result>
invoke
(CamelContext camelContext, Predicate<HealthCheck> filter) Invokes the checks and returns a collection of results.static Collection<HealthCheck.Result>
invokeLiveness
(CamelContext camelContext) Invokes the liveness checks and returns a collection of results.static Collection<HealthCheck.Result>
invokeLiveness
(CamelContext camelContext, String exposureLevel) Invokes the liveness checks and returns a collection of results.static Collection<HealthCheck.Result>
invokeReadiness
(CamelContext camelContext) Invokes the readiness checks and returns a collection of results.static Collection<HealthCheck.Result>
invokeReadiness
(CamelContext camelContext, String exposureLevel) Invokes the readiness checks and returns a collection of results.static boolean
isReservedKey
(String key) Is the given key a reserved key used by Camel to store metadata in health check response details.static boolean
isResultsUp
(Collection<HealthCheck.Result> results, boolean readiness) Checks the overall status of the results.
-
Method Details
-
invoke
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 contextexposureLevel
- level of exposure (full, oneline or default)
-
invokeReadiness
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 contextexposureLevel
- level of exposure (full, oneline or default)
-
invokeLiveness
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 contextexposureLevel
- 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
Gets theHealthCheckRegistry
.- Parameters:
context
- the camel context- Returns:
- the health check registry, or null if health-check is not enabled.
-
getHealthCheck
Gets theHealthCheck
by the given id (will resolve from classpath if necessary)- Parameters:
context
- the camel contextid
- 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 theHealthCheck
by the given id (will resolve from classpath if necessary)- Parameters:
context
- the camel contextid
- the id of the health checktype
- the expected type of the health check repository- Returns:
- the health check, or null if no health check exists with this id
-
getHealthCheckRepository
Gets theHealthCheckRepository
by the given id (will resolve from classpath if necessary)- Parameters:
context
- the camel contextid
- 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 theHealthCheckRepository
by the given id (will resolve from classpath if necessary)- Parameters:
context
- the camel contextid
- the id of the health check repositorytype
- 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
Checks the overall status of the results.- Parameters:
results
- the results from the invoked health checksreadiness
- readiness or liveness mode- Returns:
- true if up, or false if down
-
isReservedKey
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
-