Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package com.github.joschi.dropwizard.elasticsearch.health;
 
 
 import static com.google.common.base.Preconditions.checkNotNull;

A com.yammer.metrics.core.HealthCheck which checks the cluster state of an Elasticsearch cluster.

See also:
Admin Cluster Health
public class EsClusterHealthCheck extends HealthCheck {
    private final Client client;
    private final boolean failOnYellow;

    
Construct a new Elasticsearch cluster health check.

Parameters:
name the name of the health check. Useful if multiple clusters should be checked
client an Elasticsearch org.elasticsearch.client.Client instance connected to the cluster
failOnYellow whether the health check should fail if the cluster health state is yellow
    public EsClusterHealthCheck(String nameClient clientboolean failOnYellow) {
        super(name);
        this. = checkNotNull(client);
        this. = failOnYellow;
    }

    
Construct a new Elasticsearch cluster health check.

Parameters:
client an Elasticsearch org.elasticsearch.client.Client instance connected to the cluster
failOnYellow whether the health check should fail if the cluster health state is yellow
    public EsClusterHealthCheck(Client clientboolean failOnYellow) {
        this("elasticsearch-cluster"clientfailOnYellow);
    }

    
Construct a new Elasticsearch cluster health check which will fail if the cluster health state is org.elasticsearch.action.admin.cluster.health.ClusterHealthStatus.RED.

Parameters:
client an Elasticsearch org.elasticsearch.client.Client instance connected to the cluster
    public EsClusterHealthCheck(Client client) {
        this(clientfalse);
    }

    
Perform a check of the Elasticsearch cluster health.

Returns:
if the Elasticsearch cluster is healthy, a healthy com.yammer.metrics.core.HealthCheck.Result; otherwise, an unhealthy com.yammer.metrics.core.HealthCheck.Result with a descriptive error message or exception
Throws:
java.lang.Exception if there is an unhandled error during the health check; this will result in a failed health check
    @Override
    protected Result check() throws Exception {
        final ClusterHealthStatus status = .admin().cluster().prepareHealth().get().getStatus();
        if (status == . || ( && status == .)) {
            return Result.unhealthy("Last status: %s"status.name());
        } else {
            return Result.healthy("Last status: %s"status.name());
        }
    }
New to GrepCode? Check out our FAQ X