fix #1592 add maxEsStatusRetry

This commit is contained in:
Shinsuke Sugaya 2018-04-05 21:28:05 +09:00
parent 5917a29b73
commit c08bbdcb06

View file

@ -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<String, String> headers) {
return client.filterWithHeader(headers);