[ 
https://issues.apache.org/jira/browse/CAMEL-10026?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16131962#comment-16131962
 ] 

Luca Burgazzoli edited comment on CAMEL-10026 at 8/18/17 12:47 PM:
-------------------------------------------------------------------

What do you think about the following basic definition ?

{code:java}
 /**
 * The health check.
 */
interface HealthCheck extends HasId {
    /**
     * Invoke the check. The implementation is reponsible to eventually perform
     * the check according to the limitationf os the thirth party system i.e.
     * it should not be performed too often to avoid rate limiting.
     */
    HealthCheck.Response call();

    /**
     * Response to an health check invocation.
     */
    interface Response extends HasId {
        enum State {
            UP,
            DOWN
        }

        /**
         * The state of the service.
         */
        State getState();

        /**
         * A message associated to the result, used to provide more information
         * for unhealthy services.
         */
        Optional<String> getMessage();

        /**
         * An error associated to the result, used to provide the error 
associated
         * to unhealthy services.
         */
        Optional<Throwable> getError();

        /**
         * An key/value combination fo attributes.
         *
         * @return a non null attributes map
         */
        Map<String, Object> getAttributes();
    }
}


/**
 * A builder for {@link HealthCheck.Response}
 */
class ResponseBuilder implements Builder<HealthCheck.Response>{
    
    public HealthCheck.Response build() {
        ...
    }


    public static ResponseBuilder named(String id) {
        ...
    }
}

/**
 * A registry for health checks.
 */
interface HealthCheckRegistry {
    /**
     * Registers a service {@link HealthCheck}.
     */
    void register(HealthCheck check);

    /**
     * Unregisters a service {@link HealthCheck}.
     */
    void unregister(HealthCheck check);

    /**
     * Returns all the registered health checks or an empty collection if
     * no checks are regitered yet.
     */
    Collection<HealthCheck> getChecks();
}

interface CamelContext {
    /**
     * Returns an optional HealthCheckRegistry, by default no registry is 
present
     * and it must be explicit activated. Components can register/unregister 
healt 
     * checks in response to life-cycle events (i.e. start/stop).
     *
     * This registry is not used by the camel context but it is up to the impl 
to 
     * properly use it, i.e.
     *
     * - a RouteController could use the registry to decide to restart a route 
     *   with failing healt checks
     * - spring boot could integrate such checks within its healt endpoint or 
     *   make it available only as separate endpoint.
     */
    Optional<HealthCheckRegistry> getHealthCheckRegistry();

    /**
     * Sets the custom HealthCheckRegistry.
     */
    void setHealthCheckRegistry(HealthCheckRegistry registry);
}

/**
 * A service that invokes the HealthChecks available from the 
HealthCheckRegistry
 * according to a given schedule/strategy/policy.
 *
 * This service is not mandatory but maybe installed by other servies like a
 * RouteController.
 */
interface HealthCheckService implements Service {    
    /**
     * Consumer to invoke when the state of a check change.
     */
    void onStateChange(Consumer<HealthCheck> consumer);
}
{code}


was (Author: lb):
What do you think about the following basic definition ?

{code:java}
 /**
 * The health check.
 */
interface HealthCheck extends HasId {
    /**
     * Invoke the check. The implementation is reponsible to eventually perform
     * the check according to the limitationf os the thirth party system i.e.
     * it should not be performed too often to avoid rate limiting.
     */
    HealthCheck.Response call();

    /**
     * Response to an health check invocation.
     */
    interface Response extends HasId {
        enum State {
            UP,
            DOWN
        }

        /**
         * The state of the service.
         */
        State getState();

        /**
         * A message associated to the result, used to provide more information
         * for unhealthy services.
         */
        Optional<String> getMessage();

        /**
         * An error associated to the result, used to provide the error 
associated
         * to unhealthy services.
         */
        Optional<Throwable> getError();

        /**
         * An key/value combination fo attributes.
         *
         * @return a non null attributes map
         */
        Map<String, Object> getAttributes();
    }
}


/**
 * A builder for {@link HealthCheck.Response}
 */
class ResponseBuilder implements Builder<HealthCheck.Response>{
    
    public HealthCheck.Response build() {
        ...
    }


    public static ResponseBuilder named(String id) {
        ...
    }
}

/**
 * A registry for health checks.
 */
interface HealthCheckRegistry {
    /**
     * Registers a service {@link HealthCheck}.
     */
    void register(HealthCheck check);

    /**
     * Unregisters a service {@link HealthCheck}.
     */
    void unregister(HealthCheck check);

    /**
     * Returns all the registered health checks or an empty collection if
     * no checks are regitered yet.
     */
    Collection<HealthCheck> getChecks();
}

interface CamelContext {
    /**
     * Returns an optional HealthCheckRegistry, by default no registry is 
present
     * and it must be explicit activated. Components can register/unregister 
healt 
     * checks in response to life-cycle events (i.e. start/stop).
     *
     * This registry is not used by the camel context but it is up to the impl 
to 
     * properly use it, i.e.
     *
     * - a RouteController could use the registry to decide to restart a route 
     *   with failing healt checks
     * - spring boot could integrate such checks within its healt endpoint or 
     *   make it available only as separate endpoint.
     */
    Optional<HealthCheckRegistry> getHealthCheckRegistry();

    /**
     * Sets the custom HealthCheckRegistry.
     */
    void setHealthCheckRegistry(HealthCheckRegistry registry);
}

/**
 * A service that invokes the HealthChecks available from the 
HealthCheckRegistry
 * according to a given schedule/strategy/policy.
 *
 * This service is not mandatory but maybe installed by other servies like a
 * RouteController.
 */
interface HealthCheckService implements Service {    
    /**
     * The given consumer should be invoked when a service is reported up
     * according to its configuration.
     */
    void onServiceUp(BiConsumer<String, ?> consumer)

    /**
     * The given consumer should be invoked when a service is reported down
     * according to its configuration (i.e. after a given number of 
unsuccessfully 
     * checks)
     */
    void onServiceDown(BiConsumer<String, ?> consumer)
}
{code}

> HealthCheck API
> ---------------
>
>                 Key: CAMEL-10026
>                 URL: https://issues.apache.org/jira/browse/CAMEL-10026
>             Project: Camel
>          Issue Type: New Feature
>          Components: camel-core
>            Reporter: Claus Ibsen
>            Assignee: Luca Burgazzoli
>             Fix For: 2.20.0
>
>
> Add a health check API to camel-core so this API can be queried from Java / 
> JMX / spring-boot etc. so users can easily get a health check. This can be 
> used for liveness/readiness checks for their Camel apps.
> The API should allow optional support for components to implement custom 
> logic for health check. So a FTP component can connect to a FTP server and do 
> a FTP list etc. A JDBC component does a SQL query, and so on.



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Reply via email to