More logging in the rolling-upgrade `waitWithAuth` (elastic/x-pack-elasticsearch#3908)

Previously this could fail without logging anything, if there was no
exception thrown. Now it records the last status code as well as the last
exception, and logs something either way.

Original commit: elastic/x-pack-elasticsearch@753333e579
This commit is contained in:
David Turner 2018-02-12 18:45:46 +01:00 committed by GitHub
parent fde2adb1b3
commit b95c971352
1 changed files with 10 additions and 3 deletions

View File

@ -21,6 +21,7 @@ Closure waitWithAuth = { NodeInfo node, AntBuilder ant ->
// wait up to two minutes
final long stopTime = System.currentTimeMillis() + (2 * 60000L);
Exception lastException = null;
int lastResponseCode = 0
while (System.currentTimeMillis() < stopTime) {
@ -36,7 +37,8 @@ Closure waitWithAuth = { NodeInfo node, AntBuilder ant ->
httpURLConnection.setConnectTimeout(1000);
httpURLConnection.setReadTimeout(30000); // read needs to wait for nodes!
httpURLConnection.connect();
if (httpURLConnection.getResponseCode() == 200) {
lastResponseCode = httpURLConnection.getResponseCode()
if (lastResponseCode == 200) {
tmpFile.withWriter StandardCharsets.UTF_8.name(), {
it.write(httpURLConnection.getInputStream().getText(StandardCharsets.UTF_8.name()))
}
@ -54,8 +56,13 @@ Closure waitWithAuth = { NodeInfo node, AntBuilder ant ->
// did not start, so wait a bit before trying again
Thread.sleep(500L);
}
if (tmpFile.exists() == false && lastException != null) {
logger.error("final attempt of calling cluster health failed", lastException)
if (tmpFile.exists() == false) {
final String message = "final attempt of calling cluster health failed [lastResponseCode=${lastResponseCode}]"
if (lastException != null) {
logger.error(message, lastException)
} else {
logger.error(message + " [no exception]")
}
}
return tmpFile.exists()
}