Parcourir la source

fix #752 wait for configsync setup

Shinsuke Sugaya il y a 8 ans
Parent
commit
16d0caec35
2 fichiers modifiés avec 30 ajouts et 4 suppressions
  1. 3 3
      plugin.xml
  2. 27 1
      src/main/java/org/codelibs/fess/es/client/FessEsClient.java

+ 3 - 3
plugin.xml

@@ -40,12 +40,12 @@
 		</antcall>
 		<!-- configsync -->
 		<antcall target="install.plugin">
-			<param name="repo.url" value="${maven.release.repo.url}" />
+			<param name="repo.url" value="${maven.snapshot.repo.url}" />
 			<param name="plugin.groupId" value="org/codelibs" />
 			<param name="plugin.name.prefix" value="elasticsearch-" />
 			<param name="plugin.name" value="configsync" />
-			<param name="plugin.version" value="2.4.1" />
-			<param name="plugin.zip.version" value="2.4.1" />
+			<param name="plugin.version" value="2.4.2-SNAPSHOT" />
+			<param name="plugin.zip.version" value="2.4.2-20161024.143331-4" />
 		</antcall>
 		<!-- dataformat -->
 		<antcall target="install.plugin">

+ 27 - 1
src/main/java/org/codelibs/fess/es/client/FessEsClient.java

@@ -19,6 +19,7 @@ import static org.codelibs.core.stream.StreamUtil.stream;
 import static org.codelibs.elasticsearch.runner.ElasticsearchClusterRunner.newConfigs;
 
 import java.io.File;
+import java.io.IOException;
 import java.net.InetAddress;
 import java.net.UnknownHostException;
 import java.nio.charset.StandardCharsets;
@@ -170,6 +171,7 @@ import org.elasticsearch.search.aggregations.bucket.terms.Terms.Order;
 import org.elasticsearch.search.aggregations.bucket.terms.TermsBuilder;
 import org.elasticsearch.threadpool.ThreadPool;
 import org.lastaflute.core.message.UserMessages;
+import org.lastaflute.di.exception.IORuntimeException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -328,6 +330,7 @@ public class FessEsClient implements Client {
                     // ignore
             }
             if (!exists) {
+                waitForConfigSyncStatus();
                 configListMap.getOrDefault(configIndex, Collections.emptyList()).forEach(
                         path -> {
                             String source = null;
@@ -340,7 +343,12 @@ public class FessEsClient implements Client {
                                     if (response.getHttpStatusCode() == 200) {
                                         logger.info("Register " + path + " to " + configIndex);
                                     } else {
-                                        logger.warn("Invalid request for " + path);
+                                        if (response.getContentException() != null) {
+                                            logger.warn("Invalid request for " + path + ".", response.getContentException());
+                                        } else {
+                                            logger.warn("Invalid request for " + path + ". The response is "
+                                                    + response.getContentAsString());
+                                        }
                                     }
                                 }
                             } catch (final Exception e) {
@@ -520,6 +528,24 @@ public class FessEsClient implements Client {
         }
     }
 
+    private void waitForConfigSyncStatus() {
+        try (CurlResponse response =
+                Curl.get(org.codelibs.fess.util.ResourceUtil.getElasticsearchHttpUrl() + "/_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());
+                } else {
+                    throw new FessSystemException("Configsync is not available.", response.getContentException());
+                }
+            }
+        } catch (final IOException e) {
+            throw new FessSystemException("Configsync is not available.", e);
+        }
+    }
+
     @Override
     @PreDestroy
     public void close() {