YARN-8916. Define a constant docker string in ContainerRuntimeConstants.java for better maintainability. (Zhankun Tang via wangda)
Change-Id: I1349e740037f81afdbe30edbe741f20e88fd0a90
(cherry picked from commit 5e02b4915b
)
This commit is contained in:
parent
bd08554aa4
commit
9ed9e185d7
|
@ -266,7 +266,8 @@ public class DockerLinuxContainerRuntime implements LinuxContainerRuntime {
|
||||||
if (type == null) {
|
if (type == null) {
|
||||||
type = daemonConf.get(YarnConfiguration.LINUX_CONTAINER_RUNTIME_TYPE);
|
type = daemonConf.get(YarnConfiguration.LINUX_CONTAINER_RUNTIME_TYPE);
|
||||||
}
|
}
|
||||||
return type != null && type.equals("docker");
|
return type != null && type.equals(
|
||||||
|
ContainerRuntimeConstants.CONTAINER_RUNTIME_DOCKER);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -30,4 +30,8 @@ public class ContainerRuntimeConstants {
|
||||||
@Private
|
@Private
|
||||||
public static final String ENV_CONTAINER_TYPE =
|
public static final String ENV_CONTAINER_TYPE =
|
||||||
"YARN_CONTAINER_RUNTIME_TYPE";
|
"YARN_CONTAINER_RUNTIME_TYPE";
|
||||||
|
|
||||||
|
@Private
|
||||||
|
public static final String CONTAINER_RUNTIME_DOCKER =
|
||||||
|
"docker";
|
||||||
}
|
}
|
||||||
|
|
|
@ -1587,7 +1587,8 @@ public class TestContainer {
|
||||||
|
|
||||||
public void setupDockerContainerEnv() {
|
public void setupDockerContainerEnv() {
|
||||||
Map<String, String> env = new HashMap<>();
|
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);
|
when(this.ctxt.getEnvironment()).thenReturn(env);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -124,7 +124,8 @@ public class TestGpuResourceHandler {
|
||||||
ContainerLaunchContext clc = mock(ContainerLaunchContext.class);
|
ContainerLaunchContext clc = mock(ContainerLaunchContext.class);
|
||||||
Map<String, String> env = new HashMap<>();
|
Map<String, String> env = new HashMap<>();
|
||||||
if (dockerContainerEnabled) {
|
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(clc.getEnvironment()).thenReturn(env);
|
||||||
when(c.getLaunchContext()).thenReturn(clc);
|
when(c.getLaunchContext()).thenReturn(clc);
|
||||||
|
|
|
@ -63,7 +63,7 @@ public class TestDelegatingLinuxContainerRuntime {
|
||||||
@Test
|
@Test
|
||||||
public void testIsRuntimeAllowedDocker() throws Exception {
|
public void testIsRuntimeAllowedDocker() throws Exception {
|
||||||
conf.set(YarnConfiguration.LINUX_CONTAINER_RUNTIME_ALLOWED_RUNTIMES,
|
conf.set(YarnConfiguration.LINUX_CONTAINER_RUNTIME_ALLOWED_RUNTIMES,
|
||||||
"docker");
|
ContainerRuntimeConstants.CONTAINER_RUNTIME_DOCKER);
|
||||||
delegatingLinuxContainerRuntime.initialize(conf, null);
|
delegatingLinuxContainerRuntime.initialize(conf, null);
|
||||||
assertTrue(delegatingLinuxContainerRuntime.isRuntimeAllowed(
|
assertTrue(delegatingLinuxContainerRuntime.isRuntimeAllowed(
|
||||||
LinuxContainerRuntimeConstants.RuntimeType.DOCKER.name()));
|
LinuxContainerRuntimeConstants.RuntimeType.DOCKER.name()));
|
||||||
|
@ -153,7 +153,8 @@ public class TestDelegatingLinuxContainerRuntime {
|
||||||
@Test
|
@Test
|
||||||
public void testJavaSandboxNotAllowedButPermissiveDockerRequested()
|
public void testJavaSandboxNotAllowedButPermissiveDockerRequested()
|
||||||
throws Exception {
|
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,
|
conf.set(YarnConfiguration.LINUX_CONTAINER_RUNTIME_ALLOWED_RUNTIMES,
|
||||||
"default,docker");
|
"default,docker");
|
||||||
conf.set(YarnConfiguration.YARN_CONTAINER_SANDBOX, "permissive");
|
conf.set(YarnConfiguration.YARN_CONTAINER_SANDBOX, "permissive");
|
||||||
|
|
|
@ -305,7 +305,8 @@ public class TestDockerContainerRuntime {
|
||||||
Map<String, String> envDockerType = new HashMap<>();
|
Map<String, String> envDockerType = new HashMap<>();
|
||||||
Map<String, String> envOtherType = 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");
|
envOtherType.put(ContainerRuntimeConstants.ENV_CONTAINER_TYPE, "other");
|
||||||
|
|
||||||
Assert.assertEquals(false, DockerLinuxContainerRuntime
|
Assert.assertEquals(false, DockerLinuxContainerRuntime
|
||||||
|
@ -321,8 +322,10 @@ public class TestDockerContainerRuntime {
|
||||||
Map<String, String> envDockerType = new HashMap<>();
|
Map<String, String> envDockerType = new HashMap<>();
|
||||||
Map<String, String> envOtherType = new HashMap<>();
|
Map<String, String> envOtherType = new HashMap<>();
|
||||||
|
|
||||||
conf.set(YarnConfiguration.LINUX_CONTAINER_RUNTIME_TYPE, "docker");
|
conf.set(YarnConfiguration.LINUX_CONTAINER_RUNTIME_TYPE,
|
||||||
envDockerType.put(ContainerRuntimeConstants.ENV_CONTAINER_TYPE, "docker");
|
ContainerRuntimeConstants.CONTAINER_RUNTIME_DOCKER);
|
||||||
|
envDockerType.put(ContainerRuntimeConstants.ENV_CONTAINER_TYPE,
|
||||||
|
ContainerRuntimeConstants.CONTAINER_RUNTIME_DOCKER);
|
||||||
envOtherType.put(ContainerRuntimeConstants.ENV_CONTAINER_TYPE, "other");
|
envOtherType.put(ContainerRuntimeConstants.ENV_CONTAINER_TYPE, "other");
|
||||||
|
|
||||||
Assert.assertEquals(true, DockerLinuxContainerRuntime
|
Assert.assertEquals(true, DockerLinuxContainerRuntime
|
||||||
|
@ -339,7 +342,8 @@ public class TestDockerContainerRuntime {
|
||||||
Map<String, String> envOtherType = new HashMap<>();
|
Map<String, String> envOtherType = new HashMap<>();
|
||||||
|
|
||||||
conf.set(YarnConfiguration.LINUX_CONTAINER_RUNTIME_TYPE, "default");
|
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");
|
envOtherType.put(ContainerRuntimeConstants.ENV_CONTAINER_TYPE, "other");
|
||||||
|
|
||||||
Assert.assertEquals(false, DockerLinuxContainerRuntime
|
Assert.assertEquals(false, DockerLinuxContainerRuntime
|
||||||
|
|
Loading…
Reference in New Issue