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/resources/CGroupsHandler.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/resources/CGroupsHandler.java index 82bd36650c7..5f4d3e42b52 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/resources/CGroupsHandler.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/resources/CGroupsHandler.java @@ -173,4 +173,10 @@ public interface CGroupsHandler { */ String getCGroupParam(CGroupController controller, String cGroupId, String param) throws ResourceHandlerException; + + /** + * Returns CGroup Mount Path. + * @return parameter value as read from the parameter file + */ + String getCGroupMountPath(); } 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/resources/CGroupsHandlerImpl.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/resources/CGroupsHandlerImpl.java index f37dfd375b7..1c6385dd048 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/resources/CGroupsHandlerImpl.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/resources/CGroupsHandlerImpl.java @@ -603,4 +603,9 @@ class CGroupsHandlerImpl implements CGroupsHandler { "Unable to read from " + cGroupParamPath); } } + + @Override + public String getCGroupMountPath() { + return cGroupMountPath; + } } \ No newline at end of file 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 82175645c9b..1ccd365a532 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 @@ -167,13 +167,12 @@ public class DockerLinuxContainerRuntime implements LinuxContainerRuntime { public static final String ENV_DOCKER_CONTAINER_LOCAL_RESOURCE_MOUNTS = "YARN_CONTAINER_RUNTIME_DOCKER_LOCAL_RESOURCE_MOUNTS"; - static final String CGROUPS_ROOT_DIRECTORY = "/sys/fs/cgroup"; - private Configuration conf; private DockerClient dockerClient; private PrivilegedOperationExecutor privilegedOperationExecutor; private Set allowedNetworks = new HashSet<>(); private String defaultNetwork; + private String cgroupsRootDirectory; private CGroupsHandler cGroupsHandler; private AccessControlList privilegedContainersAcl; @@ -228,6 +227,7 @@ public class DockerLinuxContainerRuntime implements LinuxContainerRuntime { LOG.info("cGroupsHandler is null - cgroups not in use."); } else { this.cGroupsHandler = cGroupsHandler; + this.cgroupsRootDirectory = cGroupsHandler.getCGroupMountPath(); } } @@ -486,9 +486,12 @@ public class DockerLinuxContainerRuntime implements LinuxContainerRuntime { .setContainerWorkDir(containerWorkDir.toString()) .setNetworkType(network); setHostname(runCommand, containerIdStr, hostname); - runCommand.setCapabilities(capabilities) - .addMountLocation(CGROUPS_ROOT_DIRECTORY, - CGROUPS_ROOT_DIRECTORY + ":ro", false); + runCommand.setCapabilities(capabilities); + + if(cgroupsRootDirectory != null) { + runCommand.addMountLocation(cgroupsRootDirectory, + cgroupsRootDirectory + ":ro", false); + } List allDirs = new ArrayList<>(containerLocalDirs); allDirs.addAll(filecacheDirs); 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 d57d33cbd2c..3f4bb5cfc2c 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 @@ -33,6 +33,7 @@ import org.apache.hadoop.yarn.server.nodemanager.containermanager.linux.privileg 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.resources.ResourceHandlerModule; 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; @@ -261,12 +262,18 @@ public class TestDockerContainerRuntime { } private String getExpectedCGroupsMountString() { + CGroupsHandler cgroupsHandler = ResourceHandlerModule.getCGroupsHandler(); + if(cgroupsHandler == null) { + return ""; + } + + String cgroupMountPath = cgroupsHandler.getCGroupMountPath(); boolean cGroupsMountExists = new File( - DockerLinuxContainerRuntime.CGROUPS_ROOT_DIRECTORY).exists(); + cgroupMountPath).exists(); if(cGroupsMountExists) { - return "-v " + DockerLinuxContainerRuntime.CGROUPS_ROOT_DIRECTORY - + ":" + DockerLinuxContainerRuntime.CGROUPS_ROOT_DIRECTORY + ":ro "; + return "-v " + cgroupMountPath + + ":" + cgroupMountPath + ":ro "; } else { return ""; }