camel-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Luca Burgazzoli (JIRA)" <j...@apache.org>
Subject [jira] [Comment Edited] (CAMEL-10026) HealthCheck API
Date Fri, 18 Aug 2017 10:01:00 GMT

    [ 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 10:00 AM:
-------------------------------------------------------------------

What do you think about the following basic definition ?

{code:java}

/**
 * The health check.
 */
interface HealthCheck extends HasId, Callable<HealthCheck.Response> {

    /**
     * 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, tipically used to provide more
         * information for unhealty services.
         */
        default Optional<String> getMessage() {
            return Optional.empty();
        }

        /**
         * An error associated to the result, tipically used for unhealty services.
         */
        default Optional<Throwable> getError() {
            return Optional.empty();
        }

        /**
         * An optional key/value combination fo attrinutes. Tt can be used to
         * store the component name, the endpoint id, etc.
         */
        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 the IDs of all registered health checks.
     */
    Collection<String> getCheckIDs();

    /**
     * Runs the health check with the given ID.
     */
    HealthCheck.Response runCheck(String id);
    
    /**
     * Runs the registered health checks.
     */
    Collection<HealthCheck.Response> runChecks();
}

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.
     */
    default Optional<HealthCheckRegistry> getHealthCheckRegistry() {
        return Optional.empty();
    }

    boolean isHealthCheckEnabled();

    void setHealthCheckEnabled();
}
{code}


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

{code:java}

/**
 * The health check.
 */
interface HealthCheck extends HasId, Callable<HealthCheck.Response> {

    /**
     * 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, tipically used to provide more
         * information for unhealty services.
         */
        default Optional<String> getMessage() {
            return Optional.empty();
        }

        /**
         * An error associated to the result, tipically used for unhealty services.
         */
        default Optional<Throwable> getError() {
            return Optional.empty();
        }

        /**
         * An optional key/value combination fo attrinutes. Tt can be used to
         * store the component name, the endpoint id, etc.
         */
        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 the IDs of all registered health checks.
     */
    Collection<String> getCheckIDs();

    /**
     * Runs the health check with the given ID.
     */
    HealthCheck.Response runCheck(String id);
    
    /**
     * Runs the registered health checks.
     */
    Collection<HealthCheck.Response> runChecks();
}

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.
     * 
     * As this new method in maked as default it should not introduce API breaks
     * so it should be safe to introduce it in 2.20.x.
     */
    default Optional<HealthCheckRegistry> getHealthCheckRegistry() {
        return Optional.empty();
    }

    boolean isHealthCheckEnabled();

    void setHealthCheckEnabled();
}
{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)

Mime
View raw message