YARN-5567. Fix script exit code checking in NodeHealthScriptRunner#reportHealthStatus. (Yufei Gu via rchiang)

(cherry picked from commit 05ede003868871addc30162e9707c3dc14ed6b7a)
(cherry picked from commit 3b19bcb8f0f70606a8080bc46fa64cd34f6280d7)
This commit is contained in:
Ray Chiang 2016-08-29 15:55:33 -07:00
parent 765139e4da
commit 9ad3a7a43b
2 changed files with 9 additions and 1 deletions

View File

@ -106,6 +106,7 @@ public void run() {
shexec.execute(); shexec.execute();
} catch (ExitCodeException e) { } catch (ExitCodeException e) {
// ignore the exit code of the script // ignore the exit code of the script
exceptionStackTrace = StringUtils.stringifyException(e);
status = HealthCheckerExitStatus.FAILED_WITH_EXIT_CODE; status = HealthCheckerExitStatus.FAILED_WITH_EXIT_CODE;
// On Windows, we will not hit the Stream closed IOException // On Windows, we will not hit the Stream closed IOException
// thrown by stdout buffered reader for timeout event. // thrown by stdout buffered reader for timeout event.
@ -162,7 +163,7 @@ void reportHealthStatus(HealthCheckerExitStatus status) {
setHealthStatus(false, exceptionStackTrace); setHealthStatus(false, exceptionStackTrace);
break; break;
case FAILED_WITH_EXIT_CODE: case FAILED_WITH_EXIT_CODE:
setHealthStatus(true, "", now); setHealthStatus(false, exceptionStackTrace);
break; break;
case FAILED: case FAILED:
setHealthStatus(false, shexec.getOutput()); setHealthStatus(false, shexec.getOutput());

View File

@ -91,6 +91,7 @@ public void testNodeHealthScriptShouldRun() throws IOException {
public void testNodeHealthScript() throws Exception { public void testNodeHealthScript() throws Exception {
String errorScript = "echo ERROR\n echo \"Tracker not healthy\""; String errorScript = "echo ERROR\n echo \"Tracker not healthy\"";
String normalScript = "echo \"I am all fine\""; String normalScript = "echo \"I am all fine\"";
String failWithExitCodeScript = "echo \"Not healthy\"; exit -1";
String timeOutScript = String timeOutScript =
Shell.WINDOWS ? "@echo off\nping -n 4 127.0.0.1 >nul\necho \"I am fine\"" Shell.WINDOWS ? "@echo off\nping -n 4 127.0.0.1 >nul\necho \"I am fine\""
: "sleep 4\necho \"I am fine\""; : "sleep 4\necho \"I am fine\"";
@ -124,6 +125,12 @@ public void testNodeHealthScript() throws Exception {
nodeHealthScriptRunner.isHealthy()); nodeHealthScriptRunner.isHealthy());
Assert.assertEquals("", nodeHealthScriptRunner.getHealthReport()); Assert.assertEquals("", nodeHealthScriptRunner.getHealthReport());
// Script which fails with exit code.
writeNodeHealthScriptFile(failWithExitCodeScript, true);
timerTask.run();
Assert.assertFalse("Node health status reported healthy",
nodeHealthScriptRunner.isHealthy());
// Timeout script. // Timeout script.
writeNodeHealthScriptFile(timeOutScript, true); writeNodeHealthScriptFile(timeOutScript, true);
timerTask.run(); timerTask.run();