Start line:  
End line:  

Snippet Preview

Snippet HTML Code

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

A com.yammer.metrics.core.HealthCheck which checks if one or more indices exist in Elasticsearch.

See also:
Admin Indices Indices Exists
public class EsIndexExistsHealthCheck extends HealthCheck {
    private static final String HEALTH_CHECK_NAME = "elasticsearch-index-exists";
    private final Client client;
    private final String[] indices;

    
Construct a new Elasticsearch index exists health check.

Parameters:
name the name of the health check. Useful if multiple instances of the health check should run
client an Elasticsearch org.elasticsearch.client.Client instance connected to the cluster
indices a java.util.List of indices in Elasticsearch which should be checked
Throws:
java.lang.IllegalArgumentException if indices was null or empty
    public EsIndexExistsHealthCheck(String nameClient clientList<Stringindices) {
        super(name);
        checkArgument(!indices.isEmpty(), "At least one index must be given");
        this. = checkNotNull(client);
        this. = checkNotNull(indices.toArray(new String[indices.size()]));
    }

    
Construct a new Elasticsearch index exists health check.

Parameters:
client an Elasticsearch org.elasticsearch.client.Client instance connected to the cluster
indices a java.util.List of indices in Elasticsearch which should be checked
Throws:
java.lang.IllegalArgumentException if indices was null or empty
    public EsIndexExistsHealthCheck(Client clientList<Stringindices) {
        this(clientindices);
    }

    
Construct a new Elasticsearch index exists health check.

Parameters:
name the name of the health check. Useful if multiple instances of the health check should run
client an Elasticsearch org.elasticsearch.client.Client instance connected to the cluster
indexName the index in Elasticsearch which should be checked
    public EsIndexExistsHealthCheck(String nameClient clientString indexName) {
        this(nameclient, ImmutableList.of(indexName));
    }

    
Construct a new Elasticsearch index exists health check.

Parameters:
client an Elasticsearch org.elasticsearch.client.Client instance connected to the cluster
indexName the index in Elasticsearch which should be checked
    public EsIndexExistsHealthCheck(Client clientString indexName) {
        this(client, ImmutableList.of(indexName));
    }

    
Perform a check of the number of documents in the Elasticsearch indices.

Returns:
if the Elasticsearch indices exist, 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 IndicesExistsResponse indicesExistsResponse = .admin().indices().prepareExists().get();
        if (indicesExistsResponse.isExists()) {
            return Result.healthy();
        } else {
            return Result.unhealthy("One or more indices do not exist.");
        }
    }
New to GrepCode? Check out our FAQ X