فهرست منبع

fix #1591 add maxConfigSyncStatusRetry

Shinsuke Sugaya 7 سال پیش
والد
کامیت
5917a29b73
1فایلهای تغییر یافته به همراه31 افزوده شده و 10 حذف شده
  1. 31 10
      src/main/java/org/codelibs/fess/es/client/FessEsClient.java

+ 31 - 10
src/main/java/org/codelibs/fess/es/client/FessEsClient.java

@@ -184,6 +184,8 @@ public class FessEsClient implements Client {
 
 
     protected String scrollForDelete = "1m";
     protected String scrollForDelete = "1m";
 
 
+    protected int maxConfigSyncStatusRetry = 10;
+
     public void addIndexConfig(final String path) {
     public void addIndexConfig(final String path) {
         indexConfigList.add(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 {
                 } 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
     @Override
@@ -1434,6 +1451,10 @@ public class FessEsClient implements Client {
         this.scrollForSearch = scrollForSearch;
         this.scrollForSearch = scrollForSearch;
     }
     }
 
 
+    public void setMaxConfigSyncStatusRetry(int maxConfigSyncStatusRetry) {
+        this.maxConfigSyncStatusRetry = maxConfigSyncStatusRetry;
+    }
+
     @Override
     @Override
     public Client filterWithHeader(final Map<String, String> headers) {
     public Client filterWithHeader(final Map<String, String> headers) {
         return client.filterWithHeader(headers);
         return client.filterWithHeader(headers);