diff --git a/src/main/java/org/codelibs/fess/es/client/FessEsClient.java b/src/main/java/org/codelibs/fess/es/client/FessEsClient.java index d31de7e50..aa97777f6 100644 --- a/src/main/java/org/codelibs/fess/es/client/FessEsClient.java +++ b/src/main/java/org/codelibs/fess/es/client/FessEsClient.java @@ -186,6 +186,8 @@ public class FessEsClient implements Client { protected int maxConfigSyncStatusRetry = 10; + protected int maxEsStatusRetry = 10; + public void addIndexConfig(final String path) { indexConfigList.add(path); } @@ -589,21 +591,34 @@ public class FessEsClient implements Client { } } - private void waitForYellowStatus(final FessConfig fessConfig) { - try { - final ClusterHealthResponse response = - client.admin().cluster().prepareHealth().setWaitForYellowStatus().execute() - .actionGet(fessConfig.getIndexHealthTimeout()); - if (logger.isDebugEnabled()) { - logger.debug("Elasticsearch Cluster Status: " + response.getStatus()); + protected void waitForYellowStatus(final FessConfig fessConfig) { + Exception cause = null; + for (int i = 0; i < maxEsStatusRetry; i++) { + try { + final ClusterHealthResponse response = + client.admin().cluster().prepareHealth().setWaitForYellowStatus().execute() + .actionGet(fessConfig.getIndexHealthTimeout()); + if (logger.isDebugEnabled()) { + logger.debug("Elasticsearch Cluster Status: " + response.getStatus()); + } + return; + } catch (final Exception e) { + cause = e; + } + if (logger.isDebugEnabled()) { + logger.debug("Failed to access to Elasticsearch:" + i, cause); + } + try { + Thread.sleep(1000L); + } catch (InterruptedException e) { + // ignore } - } catch (final Exception e) { - final String message = - "Elasticsearch (" + System.getProperty(Constants.FESS_ES_TRANSPORT_ADDRESSES) - + ") is not available. Check the state of your Elasticsearch cluster (" - + fessConfig.getElasticsearchClusterName() + ")."; - throw new ContainerInitFailureException(message, e); } + final String message = + "Elasticsearch (" + System.getProperty(Constants.FESS_ES_TRANSPORT_ADDRESSES) + + ") is not available. Check the state of your Elasticsearch cluster (" + fessConfig.getElasticsearchClusterName() + + ")."; + throw new ContainerInitFailureException(message, cause); } protected void waitForConfigSyncStatus() { @@ -1455,6 +1470,10 @@ public class FessEsClient implements Client { this.maxConfigSyncStatusRetry = maxConfigSyncStatusRetry; } + public void setMaxEsStatusRetry(int maxEsStatusRetry) { + this.maxEsStatusRetry = maxEsStatusRetry; + } + @Override public Client filterWithHeader(final Map headers) { return client.filterWithHeader(headers);