fix #1591 add maxConfigSyncStatusRetry

This commit is contained in:
Shinsuke Sugaya 2018-04-05 18:28:43 +09:00
parent 701bf4116a
commit 5917a29b73

View file

@ -184,6 +184,8 @@ public class FessEsClient implements Client {
protected String scrollForDelete = "1m";
protected int maxConfigSyncStatusRetry = 10;
public void addIndexConfig(final String path) {
indexConfigList.add(path);
}
@ -604,20 +606,35 @@ public class FessEsClient implements Client {
}
}
private void waitForConfigSyncStatus() {
try (CurlResponse response = ComponentUtil.getCurlHelper().get("/_configsync/wait").param("status", "green").execute()) {
if (response.getHttpStatusCode() == 200) {
logger.info("ConfigSync is ready.");
} else {
if (response.getContentException() != null) {
throw new FessSystemException("Configsync is not available.", response.getContentException());
protected void waitForConfigSyncStatus() {
FessSystemException cause = null;
for (int i = 0; i < maxConfigSyncStatusRetry; i++) {
try (CurlResponse response = ComponentUtil.getCurlHelper().get("/_configsync/wait").param("status", "green").execute()) {
final int httpStatusCode = response.getHttpStatusCode();
if (httpStatusCode == 200) {
logger.info("ConfigSync is ready.");
return;
} else {
throw new FessSystemException("Configsync is not available.", response.getContentException());
final String message = "Configsync is not available. HTTP Status is " + httpStatusCode;
if (response.getContentException() != null) {
throw new FessSystemException(message, response.getContentException());
} else {
throw new FessSystemException(message);
}
}
} catch (final Exception e) {
cause = new FessSystemException("Configsync is not available.", e);
}
if (logger.isDebugEnabled()) {
logger.debug("Failed to access to configsync:" + i, cause);
}
try {
Thread.sleep(1000L);
} catch (InterruptedException e) {
// ignore
}
} catch (final IOException e) {
throw new FessSystemException("Configsync is not available.", e);
}
throw cause;
}
@Override
@ -1434,6 +1451,10 @@ public class FessEsClient implements Client {
this.scrollForSearch = scrollForSearch;
}
public void setMaxConfigSyncStatusRetry(int maxConfigSyncStatusRetry) {
this.maxConfigSyncStatusRetry = maxConfigSyncStatusRetry;
}
@Override
public Client filterWithHeader(final Map<String, String> headers) {
return client.filterWithHeader(headers);