From 9ed9e185d75ba303e04fd4a675c59dbc28670faf Mon Sep 17 00:00:00 2001 From: Wangda Tan Date: Fri, 19 Oct 2018 09:44:45 -0700 Subject: [PATCH] YARN-8916. Define a constant docker string in ContainerRuntimeConstants.java for better maintainability. (Zhankun Tang via wangda) Change-Id: I1349e740037f81afdbe30edbe741f20e88fd0a90 (cherry picked from commit 5e02b4915b876eab943b30cf728cfc26ba832188) --- .../linux/runtime/DockerLinuxContainerRuntime.java | 3 ++- .../runtime/ContainerRuntimeConstants.java | 4 ++++ .../containermanager/container/TestContainer.java | 3 ++- .../linux/resources/gpu/TestGpuResourceHandler.java | 3 ++- .../runtime/TestDelegatingLinuxContainerRuntime.java | 5 +++-- .../linux/runtime/TestDockerContainerRuntime.java | 12 ++++++++---- 6 files changed, 21 insertions(+), 9 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 c86ed537874..91a348d635a 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 @@ -266,7 +266,8 @@ public class DockerLinuxContainerRuntime implements LinuxContainerRuntime { if (type == null) { type = daemonConf.get(YarnConfiguration.LINUX_CONTAINER_RUNTIME_TYPE); } - return type != null && type.equals("docker"); + return type != null && type.equals( + ContainerRuntimeConstants.CONTAINER_RUNTIME_DOCKER); } /** 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/ContainerRuntimeConstants.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/ContainerRuntimeConstants.java index 4473856a2d6..a8b295ddb32 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/ContainerRuntimeConstants.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/ContainerRuntimeConstants.java @@ -30,4 +30,8 @@ public class ContainerRuntimeConstants { @Private public static final String ENV_CONTAINER_TYPE = "YARN_CONTAINER_RUNTIME_TYPE"; + + @Private + public static final String CONTAINER_RUNTIME_DOCKER = + "docker"; } 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/container/TestContainer.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/container/TestContainer.java index 71cabdd23ec..5cabd6d3ec3 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/container/TestContainer.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/container/TestContainer.java @@ -1587,7 +1587,8 @@ public class TestContainer { public void setupDockerContainerEnv() { Map env = new HashMap<>(); - env.put(ContainerRuntimeConstants.ENV_CONTAINER_TYPE, "docker"); + env.put(ContainerRuntimeConstants.ENV_CONTAINER_TYPE, + ContainerRuntimeConstants.CONTAINER_RUNTIME_DOCKER); when(this.ctxt.getEnvironment()).thenReturn(env); } 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/resources/gpu/TestGpuResourceHandler.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/resources/gpu/TestGpuResourceHandler.java index 301c3e580ee..10e5cd1c850 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/resources/gpu/TestGpuResourceHandler.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/resources/gpu/TestGpuResourceHandler.java @@ -124,7 +124,8 @@ public class TestGpuResourceHandler { ContainerLaunchContext clc = mock(ContainerLaunchContext.class); Map env = new HashMap<>(); if (dockerContainerEnabled) { - env.put(ContainerRuntimeConstants.ENV_CONTAINER_TYPE, "docker"); + env.put(ContainerRuntimeConstants.ENV_CONTAINER_TYPE, + ContainerRuntimeConstants.CONTAINER_RUNTIME_DOCKER); } when(clc.getEnvironment()).thenReturn(env); when(c.getLaunchContext()).thenReturn(clc); 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/TestDelegatingLinuxContainerRuntime.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/TestDelegatingLinuxContainerRuntime.java index fc34d9cb786..fdccff83856 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/TestDelegatingLinuxContainerRuntime.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/TestDelegatingLinuxContainerRuntime.java @@ -63,7 +63,7 @@ public class TestDelegatingLinuxContainerRuntime { @Test public void testIsRuntimeAllowedDocker() throws Exception { conf.set(YarnConfiguration.LINUX_CONTAINER_RUNTIME_ALLOWED_RUNTIMES, - "docker"); + ContainerRuntimeConstants.CONTAINER_RUNTIME_DOCKER); delegatingLinuxContainerRuntime.initialize(conf, null); assertTrue(delegatingLinuxContainerRuntime.isRuntimeAllowed( LinuxContainerRuntimeConstants.RuntimeType.DOCKER.name())); @@ -153,7 +153,8 @@ public class TestDelegatingLinuxContainerRuntime { @Test public void testJavaSandboxNotAllowedButPermissiveDockerRequested() throws Exception { - env.put(ContainerRuntimeConstants.ENV_CONTAINER_TYPE, "docker"); + env.put(ContainerRuntimeConstants.ENV_CONTAINER_TYPE, + ContainerRuntimeConstants.CONTAINER_RUNTIME_DOCKER); conf.set(YarnConfiguration.LINUX_CONTAINER_RUNTIME_ALLOWED_RUNTIMES, "default,docker"); conf.set(YarnConfiguration.YARN_CONTAINER_SANDBOX, "permissive"); 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 a880ba9c884..ed530caa36a 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 @@ -305,7 +305,8 @@ public class TestDockerContainerRuntime { Map envDockerType = new HashMap<>(); Map envOtherType = new HashMap<>(); - envDockerType.put(ContainerRuntimeConstants.ENV_CONTAINER_TYPE, "docker"); + envDockerType.put(ContainerRuntimeConstants.ENV_CONTAINER_TYPE, + ContainerRuntimeConstants.CONTAINER_RUNTIME_DOCKER); envOtherType.put(ContainerRuntimeConstants.ENV_CONTAINER_TYPE, "other"); Assert.assertEquals(false, DockerLinuxContainerRuntime @@ -321,8 +322,10 @@ public class TestDockerContainerRuntime { Map envDockerType = new HashMap<>(); Map envOtherType = new HashMap<>(); - conf.set(YarnConfiguration.LINUX_CONTAINER_RUNTIME_TYPE, "docker"); - envDockerType.put(ContainerRuntimeConstants.ENV_CONTAINER_TYPE, "docker"); + conf.set(YarnConfiguration.LINUX_CONTAINER_RUNTIME_TYPE, + ContainerRuntimeConstants.CONTAINER_RUNTIME_DOCKER); + envDockerType.put(ContainerRuntimeConstants.ENV_CONTAINER_TYPE, + ContainerRuntimeConstants.CONTAINER_RUNTIME_DOCKER); envOtherType.put(ContainerRuntimeConstants.ENV_CONTAINER_TYPE, "other"); Assert.assertEquals(true, DockerLinuxContainerRuntime @@ -339,7 +342,8 @@ public class TestDockerContainerRuntime { Map envOtherType = new HashMap<>(); conf.set(YarnConfiguration.LINUX_CONTAINER_RUNTIME_TYPE, "default"); - envDockerType.put(ContainerRuntimeConstants.ENV_CONTAINER_TYPE, "docker"); + envDockerType.put(ContainerRuntimeConstants.ENV_CONTAINER_TYPE, + ContainerRuntimeConstants.CONTAINER_RUNTIME_DOCKER); envOtherType.put(ContainerRuntimeConstants.ENV_CONTAINER_TYPE, "other"); Assert.assertEquals(false, DockerLinuxContainerRuntime