Search in sources :

Example 1 with Health

use of com.b2international.snowowl.core.RepositoryInfo.Health in project snow-owl by b2ihealthcare.

the class TerminologyRepository method waitForHealth.

public void waitForHealth(RepositoryInfo.Health desiredHealth, long seconds) {
    final RetryPolicy<Health> retryPolicy = new RetryPolicy<Health>().handleResult(Health.RED).withMaxAttempts(-1).withMaxDuration(Duration.of(seconds, ChronoUnit.SECONDS)).withBackoff(1, Math.max(2, seconds / 3), ChronoUnit.SECONDS);
    final Health finalHealth = Failsafe.with(retryPolicy).get(() -> status().health());
    if (finalHealth != desiredHealth) {
        throw new RequestTimeoutException("Repository health status couldn't reach '%s' in '%s' seconds.", desiredHealth, seconds);
    }
}
Also used : RequestTimeoutException(com.b2international.commons.exceptions.RequestTimeoutException) Health(com.b2international.snowowl.core.RepositoryInfo.Health) RetryPolicy(net.jodah.failsafe.RetryPolicy)

Example 2 with Health

use of com.b2international.snowowl.core.RepositoryInfo.Health in project snow-owl by b2ihealthcare.

the class TerminologyRepository method status.

@Override
public RepositoryInfo status() {
    // by default assume it is in GREEN status with no diagnosis
    Health health = Health.GREEN;
    String diagnosis = "";
    final String[] indices = service(Index.class).admin().indices();
    final EsClusterStatus status = service(IndexClient.class).client().status(indices);
    if (!status.isAvailable()) {
        // check if cluster is available or not, and report RED state if not along with index diagnosis
        health = Health.RED;
        diagnosis = status.getDiagnosis();
    } else if (!status.isHealthy(indices)) {
        // check if index is healthy and report RED if not along with diagnosis
        health = Health.RED;
        diagnosis = String.format("Repository indices '%s' are not healthy.", Arrays.toString(indices));
    }
    return RepositoryInfo.of(id(), health, diagnosis, status.getIndices());
}
Also used : Health(com.b2international.snowowl.core.RepositoryInfo.Health) EsClusterStatus(com.b2international.index.es.client.EsClusterStatus)

Aggregations

Health (com.b2international.snowowl.core.RepositoryInfo.Health)2 RequestTimeoutException (com.b2international.commons.exceptions.RequestTimeoutException)1 EsClusterStatus (com.b2international.index.es.client.EsClusterStatus)1 RetryPolicy (net.jodah.failsafe.RetryPolicy)1