Search in sources :

Example 1 with SofaBootApplicationAfterHealthCheckCallback

use of com.alipay.sofa.healthcheck.startup.SofaBootApplicationAfterHealthCheckCallback in project sofa-boot by alipay.

the class AfterHealthCheckCallbackProcessor method doApplicationAfterHealthCheckCallback.

/**
 * process application afterHealthCheckCallback
 * @return
 */
private boolean doApplicationAfterHealthCheckCallback() {
    boolean result = true;
    logger.info("Begin ApplicationAfterHealthCheckCallback startup health check");
    List<SofaBootApplicationAfterHealthCheckCallback> afterHealthCheckCallbacks = HealthCheckManager.getApplicationAfterHealthCheckCallbacks();
    for (SofaBootApplicationAfterHealthCheckCallback afterHealthCheckCallback : afterHealthCheckCallbacks) {
        try {
            Health health = afterHealthCheckCallback.onHealthy(HealthCheckManager.getApplicationContext());
            Status status = health.getStatus();
            if (!status.equals(Status.UP)) {
                result = false;
                logger.error("sofaboot application afterHealthCheck callback(" + afterHealthCheckCallback.getClass() + ") failed, the details is: " + JSON.toJSONString(health.getDetails()));
            } else {
                logger.info("sofaboot application afterHealthCheck callback(" + afterHealthCheckCallback.getClass() + ") ]success.");
            }
            StartUpHealthCheckStatus.putAfterHealthCheckCallbackDetail(getKey(afterHealthCheckCallback.getClass().getName()), health);
        } catch (Throwable t) {
            result = false;
            logger.error("Invoking  ApplicationAfterHealthCheckCallback " + afterHealthCheckCallback.getClass().getName() + " got an exception.", t);
        }
    }
    if (result) {
        logger.info("ApplicationAfterHealthCheckCallback startup health check result: success.");
    } else {
        logger.error("ApplicationAfterHealthCheckCallback startup health check result: failed.");
    }
    return result;
}
Also used : Status(org.springframework.boot.actuate.health.Status) StartUpHealthCheckStatus(com.alipay.sofa.healthcheck.startup.StartUpHealthCheckStatus) SofaBootApplicationAfterHealthCheckCallback(com.alipay.sofa.healthcheck.startup.SofaBootApplicationAfterHealthCheckCallback) Health(org.springframework.boot.actuate.health.Health)

Aggregations

SofaBootApplicationAfterHealthCheckCallback (com.alipay.sofa.healthcheck.startup.SofaBootApplicationAfterHealthCheckCallback)1 StartUpHealthCheckStatus (com.alipay.sofa.healthcheck.startup.StartUpHealthCheckStatus)1 Health (org.springframework.boot.actuate.health.Health)1 Status (org.springframework.boot.actuate.health.Status)1