Java Code Examples for org.elasticsearch.cluster.health.ClusterHealthStatus#name()

The following examples show how to use org.elasticsearch.cluster.health.ClusterHealthStatus#name() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ElasticSearchComponent.java    From metron with Apache License 2.0 6 votes vote down vote up
public static void waitForCluster(Client client, ClusterHealthStatus statusThreshold,
    String timeout) throws UnableToStartException {
  try {
    ClusterHealthResponse healthResponse = (ClusterHealthResponse) client
        .execute(ClusterHealthAction.INSTANCE,
            new ClusterHealthRequest().waitForStatus(statusThreshold).timeout(timeout))
        .actionGet();
    if (healthResponse != null && healthResponse.isTimedOut()) {
      throw new UnableToStartException("cluster state is " + healthResponse.getStatus().name()
          + " and not " + statusThreshold.name()
          + ", from here on, everything will fail!");
    }
  } catch (ElasticsearchTimeoutException e) {
    throw new UnableToStartException(
        "timeout, cluster does not respond to health request, cowardly refusing to continue with operations");
  }
}
 
Example 2
Source File: IMAPImporter.java    From elasticsearch-imap with Apache License 2.0 6 votes vote down vote up
public static void waitForYellowCluster(Client client) throws IOException {

        ClusterHealthStatus status = ClusterHealthStatus.YELLOW;
        
        try {
            logger.debug("waiting for cluster state {}", status.name());
            final ClusterHealthResponse healthResponse = client.admin().cluster().prepareHealth().setWaitForStatus(status)
                    .setTimeout(TimeValue.timeValueSeconds(30)).execute().actionGet();
            if (healthResponse.isTimedOut()) {
                logger.error("Timeout while waiting for cluster state: {}, current cluster state is: {}", status.name(), healthResponse.getStatus().name());
                throw new IOException("cluster state is " + healthResponse.getStatus().name() + " and not " + status.name()
                       + ", cowardly refusing to continue with operations");
            } else {
                logger.debug("... cluster state ok");
            }
        } catch (final Exception e) {
            logger.error("Exception while waiting for cluster state: {} due to ", e, status.name(), e.toString());
            throw new IOException("timeout, cluster does not respond to health request, cowardly refusing to continue with operations", e);
        }
    }
 
Example 3
Source File: BaseClient.java    From elasticsearch-helper with Apache License 2.0 6 votes vote down vote up
public void waitForCluster(String statusString, TimeValue timeout) throws IOException {
    if (client() == null) {
        return;
    }
    try {
        ClusterHealthStatus status = ClusterHealthStatus.fromString(statusString);
        ClusterHealthResponse healthResponse =
                client().execute(ClusterHealthAction.INSTANCE, new ClusterHealthRequest().waitForStatus(status).timeout(timeout)).actionGet();
        if (healthResponse != null && healthResponse.isTimedOut()) {
            throw new IOException("cluster state is " + healthResponse.getStatus().name()
                    + " and not " + status.name()
                    + ", from here on, everything will fail!");
        }
    } catch (ElasticsearchTimeoutException e) {
        throw new IOException("timeout, cluster does not respond to health request, cowardly refusing to continue with operations");
    }
}
 
Example 4
Source File: AbstractUnitTest.java    From elasticsearch-shield-kerberos-realm with Apache License 2.0 5 votes vote down vote up
protected void waitForCluster(final ClusterHealthStatus status, final TimeValue timeout) throws IOException {
    try {
        log.debug("waiting for cluster state {}", status.name());
        final ClusterHealthResponse healthResponse = client.admin().cluster().prepareHealth().setWaitForStatus(status)
                .setWaitForNodes(">2").setTimeout(timeout).execute().actionGet();
        if (healthResponse.isTimedOut()) {
            throw new IOException("cluster state is " + healthResponse.getStatus().name() + " and not " + status.name()
                    + ", cowardly refusing to continue with operations");
        } else {
            log.debug("... cluster state ok");
        }
    } catch (final ElasticsearchTimeoutException e) {
        throw new IOException("timeout, cluster does not respond to health request, cowardly refusing to continue with operations");
    }
}
 
Example 5
Source File: ElasticsearchStateManager.java    From elasticsearch-imap with Apache License 2.0 5 votes vote down vote up
private void waitForCluster(final ClusterHealthStatus status, final TimeValue timeout) throws IOException {
    try {
        logger.debug("waiting for cluster state {}", status.name());
        final ClusterHealthResponse healthResponse = client.admin().cluster().prepareHealth().setWaitForStatus(status)
                .setTimeout(timeout).execute().actionGet();
        if (healthResponse.isTimedOut()) {
            throw new IOException("cluster state is " + healthResponse.getStatus().name() + " and not " + status.name()
                    + ", cowardly refusing to continue with operations");
        } else {
            logger.debug("... cluster state ok");
        }
    } catch (final ElasticsearchTimeoutException e) {
        throw new IOException("timeout, cluster does not respond to health request, cowardly refusing to continue with operations");
    }
}
 
Example 6
Source File: AbstractIMAPRiverUnitTest.java    From elasticsearch-imap with Apache License 2.0 5 votes vote down vote up
protected void waitForCluster(final ClusterHealthStatus status, final TimeValue timeout, final Client client) throws IOException {
    try {
        logger.debug("waiting for cluster state {}", status.name());
        final ClusterHealthResponse healthResponse = client.admin().cluster().prepareHealth().setWaitForStatus(status)
                .setTimeout(timeout).execute().actionGet();
        if (healthResponse.isTimedOut()) {
            throw new IOException("cluster state is " + healthResponse.getStatus().name() + " and not " + status.name()
                    + ", cowardly refusing to continue with operations");
        } else {
            logger.debug("... cluster state ok");
        }
    } catch (final ElasticsearchTimeoutException e) {
        throw new IOException("timeout, cluster does not respond to health request, cowardly refusing to continue with operations");
    }
}