From 5cc2541a163591181b80bf2ec42c1e7e7f8929f5 Mon Sep 17 00:00:00 2001 From: Eric Yang Date: Mon, 2 Jul 2018 13:37:51 -0400 Subject: [PATCH] YARN-8465. Fixed docker container status for node manager restart. Contributed by Shane Kumpf --- .../linux/runtime/DockerLinuxContainerRuntime.java | 4 ++-- .../runtime/ContainerExecutionException.java | 6 ++++++ .../linux/runtime/TestDockerContainerRuntime.java | 10 ++++++++-- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/linux/runtime/DockerLinuxContainerRuntime.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/linux/runtime/DockerLinuxContainerRuntime.java index f13ba59b00b..c89d5fb136e 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/linux/runtime/DockerLinuxContainerRuntime.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/linux/runtime/DockerLinuxContainerRuntime.java @@ -1027,7 +1027,6 @@ public class DockerLinuxContainerRuntime implements LinuxContainerRuntime { handleContainerKill(ctx, env, signal); } } catch (ContainerExecutionException e) { - LOG.warn("Signal docker container failed. Exception: ", e); throw new ContainerExecutionException("Signal docker container failed", e.getExitCode(), e.getOutput(), e.getErrorOutput()); } @@ -1201,7 +1200,8 @@ public class DockerLinuxContainerRuntime implements LinuxContainerRuntime { if (!new File(procFs + File.separator + pid).exists()) { String msg = "Liveliness check failed for PID: " + pid + ". Container may have already completed."; - throw new ContainerExecutionException(msg); + throw new ContainerExecutionException(msg, + PrivilegedOperation.ResultCode.INVALID_CONTAINER_PID.getValue()); } } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/runtime/ContainerExecutionException.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/runtime/ContainerExecutionException.java index 31472777042..735db1f6082 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/runtime/ContainerExecutionException.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/runtime/ContainerExecutionException.java @@ -53,6 +53,12 @@ public class ContainerExecutionException extends YarnException { errorOutput = OUTPUT_UNSET; } + public ContainerExecutionException(String message, int exitCode) { + super(message); + this.exitCode = exitCode; + this.output = OUTPUT_UNSET; + this.errorOutput = OUTPUT_UNSET; + } public ContainerExecutionException(String message, int exitCode, String output, String errorOutput) { diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/linux/runtime/TestDockerContainerRuntime.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/linux/runtime/TestDockerContainerRuntime.java index d85c403f1fd..855ec44c2ae 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/linux/runtime/TestDockerContainerRuntime.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/linux/runtime/TestDockerContainerRuntime.java @@ -1492,7 +1492,7 @@ public class TestDockerContainerRuntime { runtime.signalContainer(builder.build()); } - @Test(expected = ContainerExecutionException.class) + @Test public void testContainerLivelinessNoFileException() throws Exception { DockerLinuxContainerRuntime runtime = new DockerLinuxContainerRuntime( mockExecutor, mockCGroupsHandler); @@ -1501,7 +1501,13 @@ public class TestDockerContainerRuntime { .setExecutionAttribute(PID, signalPid) .setExecutionAttribute(SIGNAL, ContainerExecutor.Signal.NULL); runtime.initialize(enableMockContainerExecutor(conf), null); - runtime.signalContainer(builder.build()); + try { + runtime.signalContainer(builder.build()); + } catch (ContainerExecutionException e) { + Assert.assertEquals( + PrivilegedOperation.ResultCode.INVALID_CONTAINER_PID.getValue(), + e.getExitCode()); + } } @Test