YARN-7914. Fix exit code handling for short lived Docker containers. Contributed by Shane Kumpf
Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/5a1db60a Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/5a1db60a Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/5a1db60a Branch: refs/heads/HDFS-7240 Commit: 5a1db60ab1e8b28cd73367c69970513de88cf4dd Parents: 87e2570 Author: Jason Lowe <jl...@apache.org> Authored: Mon Feb 12 15:50:10 2018 -0600 Committer: Jason Lowe <jl...@apache.org> Committed: Mon Feb 12 15:50:10 2018 -0600 ---------------------------------------------------------------------- .../impl/container-executor.c | 92 ++++++++++---------- 1 file changed, 46 insertions(+), 46 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/hadoop/blob/5a1db60a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/native/container-executor/impl/container-executor.c ---------------------------------------------------------------------- diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/native/container-executor/impl/container-executor.c b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/native/container-executor/impl/container-executor.c index 5ce6a00..035c694 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/native/container-executor/impl/container-executor.c +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/native/container-executor/impl/container-executor.c @@ -1577,58 +1577,58 @@ int launch_docker_container_as_user(const char * user, const char *app_id, sleep(1); } #endif + } - sprintf(docker_inspect_exitcode_command, - "%s inspect --format {{.State.ExitCode}} %s", - docker_binary, container_id); - fprintf(LOGFILE, "Obtaining the exit code...\n"); - fprintf(LOGFILE, "Docker inspect command: %s\n", docker_inspect_exitcode_command); - FILE* inspect_exitcode_docker = popen(docker_inspect_exitcode_command, "r"); - if(inspect_exitcode_docker == NULL) { - fprintf(ERRORFILE, "Done with inspect_exitcode, inspect_exitcode_docker is null\n"); - fflush(ERRORFILE); - exit_code = -1; - goto cleanup; - } - res = fscanf (inspect_exitcode_docker, "%d", &exit_code); - if (pclose (inspect_exitcode_docker) != 0 || res <= 0) { - fprintf (ERRORFILE, - "Could not inspect docker to get exitcode: %s.\n", docker_inspect_exitcode_command); - fflush(ERRORFILE); - exit_code = -1; - goto cleanup; - } - fprintf(LOGFILE, "Exit code from docker inspect: %d\n", exit_code); - if(exit_code != 0) { - fprintf(ERRORFILE, "Docker container exit code was not zero: %d\n", - exit_code); - snprintf(docker_logs_command, command_size, "%s logs --tail=250 %s", - docker_binary, container_id); - FILE* logs = popen(docker_logs_command, "r"); - if(logs != NULL) { - clearerr(logs); - res = fread(buffer, BUFFER_SIZE, 1, logs); - if(res < 1) { - fprintf(ERRORFILE, "%s %d %d\n", - "Unable to read from docker logs(ferror, feof):", ferror(logs), feof(logs)); - fflush(ERRORFILE); - } - else { - fprintf(ERRORFILE, "%s\n", buffer); - fflush(ERRORFILE); - } - } - else { - fprintf(ERRORFILE, "%s\n", "Failed to get output of docker logs"); - fprintf(ERRORFILE, "Command was '%s'\n", docker_logs_command); - fprintf(ERRORFILE, "%s\n", strerror(errno)); + sprintf(docker_inspect_exitcode_command, + "%s inspect --format {{.State.ExitCode}} %s", + docker_binary, container_id); + fprintf(LOGFILE, "Obtaining the exit code...\n"); + fprintf(LOGFILE, "Docker inspect command: %s\n", docker_inspect_exitcode_command); + FILE* inspect_exitcode_docker = popen(docker_inspect_exitcode_command, "r"); + if(inspect_exitcode_docker == NULL) { + fprintf(ERRORFILE, "Done with inspect_exitcode, inspect_exitcode_docker is null\n"); + fflush(ERRORFILE); + exit_code = -1; + goto cleanup; + } + res = fscanf (inspect_exitcode_docker, "%d", &exit_code); + if (pclose (inspect_exitcode_docker) != 0 || res <= 0) { + fprintf (ERRORFILE, + "Could not inspect docker to get exitcode: %s.\n", docker_inspect_exitcode_command); + fflush(ERRORFILE); + exit_code = -1; + goto cleanup; + } + fprintf(LOGFILE, "Exit code from docker inspect: %d\n", exit_code); + if(exit_code != 0) { + fprintf(ERRORFILE, "Docker container exit code was not zero: %d\n", + exit_code); + snprintf(docker_logs_command, command_size, "%s logs --tail=250 %s", + docker_binary, container_id); + FILE* logs = popen(docker_logs_command, "r"); + if(logs != NULL) { + clearerr(logs); + res = fread(buffer, BUFFER_SIZE, 1, logs); + if(res < 1) { + fprintf(ERRORFILE, "%s %d %d\n", + "Unable to read from docker logs(ferror, feof):", ferror(logs), feof(logs)); fflush(ERRORFILE); } - if(pclose(logs) != 0) { - fprintf(ERRORFILE, "%s\n", "Failed to fetch docker logs"); + else { + fprintf(ERRORFILE, "%s\n", buffer); fflush(ERRORFILE); } } + else { + fprintf(ERRORFILE, "%s\n", "Failed to get output of docker logs"); + fprintf(ERRORFILE, "Command was '%s'\n", docker_logs_command); + fprintf(ERRORFILE, "%s\n", strerror(errno)); + fflush(ERRORFILE); + } + if(pclose(logs) != 0) { + fprintf(ERRORFILE, "%s\n", "Failed to fetch docker logs"); + fflush(ERRORFILE); + } } cleanup: --------------------------------------------------------------------- To unsubscribe, e-mail: common-commits-unsubscr...@hadoop.apache.org For additional commands, e-mail: common-commits-h...@hadoop.apache.org