|
@@ -31,6 +31,8 @@ import org.apache.hadoop.yarn.server.nodemanager.containermanager.container.Cont
|
|
|
import org.apache.hadoop.yarn.server.nodemanager.containermanager.linux.privileged.PrivilegedOperation;
|
|
|
import org.apache.hadoop.yarn.server.nodemanager.containermanager.linux.privileged.PrivilegedOperationException;
|
|
|
import org.apache.hadoop.yarn.server.nodemanager.containermanager.linux.privileged.PrivilegedOperationExecutor;
|
|
|
+import org.apache.hadoop.yarn.server.nodemanager.containermanager.linux.resources.CGroupsHandler;
|
|
|
+import org.apache.hadoop.yarn.server.nodemanager.containermanager.linux.runtime.docker.DockerRunCommand;
|
|
|
import org.apache.hadoop.yarn.server.nodemanager.containermanager.runtime.ContainerExecutionException;
|
|
|
import org.apache.hadoop.yarn.server.nodemanager.containermanager.runtime.ContainerRuntimeConstants;
|
|
|
import org.apache.hadoop.yarn.server.nodemanager.containermanager.runtime.ContainerRuntimeContext;
|
|
@@ -62,6 +64,7 @@ public class TestDockerContainerRuntime {
|
|
|
.getLog(TestDockerContainerRuntime.class);
|
|
|
private Configuration conf;
|
|
|
PrivilegedOperationExecutor mockExecutor;
|
|
|
+ CGroupsHandler mockCGroupsHandler;
|
|
|
String containerId;
|
|
|
Container container;
|
|
|
ContainerId cId;
|
|
@@ -94,6 +97,7 @@ public class TestDockerContainerRuntime {
|
|
|
|
|
|
mockExecutor = Mockito
|
|
|
.mock(PrivilegedOperationExecutor.class);
|
|
|
+ mockCGroupsHandler = Mockito.mock(CGroupsHandler.class);
|
|
|
containerId = "container_id";
|
|
|
container = mock(Container.class);
|
|
|
cId = mock(ContainerId.class);
|
|
@@ -118,7 +122,7 @@ public class TestDockerContainerRuntime {
|
|
|
pidFilePath = new Path("/test_pid_file_path");
|
|
|
localDirs = new ArrayList<>();
|
|
|
logDirs = new ArrayList<>();
|
|
|
- resourcesOptions = "cgroups:none";
|
|
|
+ resourcesOptions = "cgroups=none";
|
|
|
|
|
|
localDirs.add("/test_local_dir");
|
|
|
logDirs.add("/test_log_dir");
|
|
@@ -204,7 +208,7 @@ public class TestDockerContainerRuntime {
|
|
|
throws ContainerExecutionException, PrivilegedOperationException,
|
|
|
IOException {
|
|
|
DockerLinuxContainerRuntime runtime = new DockerLinuxContainerRuntime(
|
|
|
- mockExecutor);
|
|
|
+ mockExecutor, mockCGroupsHandler);
|
|
|
runtime.initialize(conf);
|
|
|
|
|
|
String[] testCapabilities = {"NET_BIND_SERVICE", "SYS_CHROOT"};
|
|
@@ -256,7 +260,7 @@ public class TestDockerContainerRuntime {
|
|
|
throws ContainerExecutionException, PrivilegedOperationException,
|
|
|
IOException{
|
|
|
DockerLinuxContainerRuntime runtime = new DockerLinuxContainerRuntime(
|
|
|
- mockExecutor);
|
|
|
+ mockExecutor, mockCGroupsHandler);
|
|
|
runtime.initialize(conf);
|
|
|
|
|
|
env.put("YARN_CONTAINER_RUNTIME_DOCKER_RUN_PRIVILEGED_CONTAINER",
|
|
@@ -284,7 +288,7 @@ public class TestDockerContainerRuntime {
|
|
|
throws ContainerExecutionException, PrivilegedOperationException,
|
|
|
IOException{
|
|
|
DockerLinuxContainerRuntime runtime = new DockerLinuxContainerRuntime(
|
|
|
- mockExecutor);
|
|
|
+ mockExecutor, mockCGroupsHandler);
|
|
|
runtime.initialize(conf);
|
|
|
|
|
|
env.put("YARN_CONTAINER_RUNTIME_DOCKER_RUN_PRIVILEGED_CONTAINER",
|
|
@@ -307,7 +311,7 @@ public class TestDockerContainerRuntime {
|
|
|
true);
|
|
|
|
|
|
DockerLinuxContainerRuntime runtime = new DockerLinuxContainerRuntime(
|
|
|
- mockExecutor);
|
|
|
+ mockExecutor, mockCGroupsHandler);
|
|
|
runtime.initialize(conf);
|
|
|
|
|
|
env.put("YARN_CONTAINER_RUNTIME_DOCKER_RUN_PRIVILEGED_CONTAINER",
|
|
@@ -338,7 +342,7 @@ public class TestDockerContainerRuntime {
|
|
|
whitelistedUser);
|
|
|
|
|
|
DockerLinuxContainerRuntime runtime = new DockerLinuxContainerRuntime(
|
|
|
- mockExecutor);
|
|
|
+ mockExecutor, mockCGroupsHandler);
|
|
|
runtime.initialize(conf);
|
|
|
|
|
|
env.put("YARN_CONTAINER_RUNTIME_DOCKER_RUN_PRIVILEGED_CONTAINER",
|
|
@@ -365,7 +369,7 @@ public class TestDockerContainerRuntime {
|
|
|
submittingUser);
|
|
|
|
|
|
DockerLinuxContainerRuntime runtime = new DockerLinuxContainerRuntime(
|
|
|
- mockExecutor);
|
|
|
+ mockExecutor, mockCGroupsHandler);
|
|
|
runtime.initialize(conf);
|
|
|
|
|
|
env.put("YARN_CONTAINER_RUNTIME_DOCKER_RUN_PRIVILEGED_CONTAINER",
|
|
@@ -388,4 +392,34 @@ public class TestDockerContainerRuntime {
|
|
|
+ ": " + command, command.contains("--privileged"));
|
|
|
}
|
|
|
|
|
|
+ @Test
|
|
|
+ public void testCGroupParent() throws ContainerExecutionException {
|
|
|
+ String hierarchy = "hadoop-yarn-test";
|
|
|
+ conf.set(YarnConfiguration.NM_LINUX_CONTAINER_CGROUPS_HIERARCHY,
|
|
|
+ hierarchy);
|
|
|
+
|
|
|
+ DockerLinuxContainerRuntime runtime = new DockerLinuxContainerRuntime
|
|
|
+ (mockExecutor, mockCGroupsHandler);
|
|
|
+ runtime.initialize(conf);
|
|
|
+
|
|
|
+ String resourceOptionsNone = "cgroups=none";
|
|
|
+ DockerRunCommand command = Mockito.mock(DockerRunCommand.class);
|
|
|
+
|
|
|
+ Mockito.when(mockCGroupsHandler.getRelativePathForCGroup(containerId))
|
|
|
+ .thenReturn(hierarchy + "/" + containerIdStr);
|
|
|
+ runtime.addCGroupParentIfRequired(resourceOptionsNone, containerIdStr,
|
|
|
+ command);
|
|
|
+
|
|
|
+ //no --cgroup-parent should be added here
|
|
|
+ Mockito.verifyZeroInteractions(command);
|
|
|
+
|
|
|
+ String resourceOptionsCpu = "/sys/fs/cgroup/cpu/" + hierarchy +
|
|
|
+ containerIdStr;
|
|
|
+ runtime.addCGroupParentIfRequired(resourceOptionsCpu, containerIdStr,
|
|
|
+ command);
|
|
|
+
|
|
|
+ //--cgroup-parent should be added for the containerId in question
|
|
|
+ String expectedPath = "/" + hierarchy + "/" + containerIdStr;
|
|
|
+ Mockito.verify(command).setCGroupParent(expectedPath);
|
|
|
+ }
|
|
|
}
|