All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.redhat.lightblue.rest.health.ControllerHealthCheck Maven / Gradle / Ivy

There is a newer version: 2.32.0
Show newest version
package com.redhat.lightblue.rest.health;

import com.codahale.metrics.health.HealthCheck;
import com.codahale.metrics.health.annotation.Async;
import com.redhat.lightblue.crud.CRUDController;
import com.redhat.lightblue.crud.CRUDHealth;

import java.util.Map;
import java.util.concurrent.TimeUnit;

/**
 * Metrics Health check class for CRUD Controller health
 */
@Async(period = 10, unit = TimeUnit.SECONDS)
public class ControllerHealthCheck extends HealthCheck {
    private final CRUDController controller;

    public ControllerHealthCheck(CRUDController controller) {
        this.controller = controller;
    }

    @Override
    protected Result check() throws Exception {
        CRUDHealth health = controller.checkHealth();

        ResultBuilder resultBuilder;

        if (health.isHealthy()) {
            resultBuilder = Result.builder().healthy();
        } else {
            resultBuilder = Result.builder().unhealthy();
        }

        for (Map.Entry entry : health.details().entrySet()) {
            resultBuilder.withDetail(entry.getKey(), entry.getValue());
        }

        return resultBuilder.build();
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy