YARN-8916. Define a constant docker string in ContainerRuntimeConstants.java for better maintainability. (Zhankun Tang via wangda)

Change-Id: I1349e740037f81afdbe30edbe741f20e88fd0a90
This commit is contained in:
Wangda Tan 2018-10-19 09:44:45 -07:00
parent 071b9e19aa
commit 5e02b4915b
6 changed files with 21 additions and 9 deletions

View File

@ -266,7 +266,8 @@ public static boolean isDockerContainerRequested(Configuration daemonConf,
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);
}
/**

View File

@ -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";
}

View File

@ -1587,7 +1587,8 @@ public void dockerContainerResourcesCleanup() {
public void setupDockerContainerEnv() {
Map<String, String> 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);
}

View File

@ -124,7 +124,8 @@ private static Container mockContainerWithGpuRequest(int id, int numGpuRequest,
ContainerLaunchContext clc = mock(ContainerLaunchContext.class);
Map<String, String> 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);

View File

@ -63,7 +63,7 @@ public void testIsRuntimeAllowedDefault() throws Exception {
@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 void testJavaSandboxNotAllowedButPermissive() throws Exception {
@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");

View File

@ -334,7 +334,8 @@ public void testSelectDockerContainerType() {
Map<String, String> envDockerType = new HashMap<>();
Map<String, String> 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
@ -350,8 +351,10 @@ public void testSelectDockerContainerTypeWithDockerAsDefault() {
Map<String, String> envDockerType = new HashMap<>();
Map<String, String> 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
@ -368,7 +371,8 @@ public void testSelectDockerContainerTypeWithDefaultSet() {
Map<String, String> 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