fix #752 wait for configsync setup

This commit is contained in:
Shinsuke Sugaya 2016-10-24 23:39:19 +09:00
parent 8157eea100
commit 16d0caec35
2 changed files with 30 additions and 4 deletions

View file

@ -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">

View file

@ -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() {