From 10d7493587643b52cee5fde87eca9ef99c422a70 Mon Sep 17 00:00:00 2001 From: Jason Lowe Date: Thu, 21 Sep 2017 08:38:08 -0500 Subject: [PATCH] YARN-6968. Hardcoded absolute pathname in DockerLinuxContainerRuntime. Contributed by Eric Badger --- .../linux/resources/CGroupsHandler.java | 6 ++++++ .../linux/resources/CGroupsHandlerImpl.java | 5 +++++ .../linux/runtime/DockerLinuxContainerRuntime.java | 13 ++++++++----- .../linux/runtime/TestDockerContainerRuntime.java | 13 ++++++++++--- 4 files changed, 29 insertions(+), 8 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/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 82bd36650c..5f4d3e42b5 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 @@ void updateCGroupParam(CGroupController controller, String cGroupId, */ 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 f37dfd375b..1c6385dd04 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 @@ public String getCGroupParam(CGroupController controller, String cGroupId, "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 82175645c9..1ccd365a53 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 DockerLinuxContainerRuntime(PrivilegedOperationExecutor LOG.info("cGroupsHandler is null - cgroups not in use."); } else { this.cGroupsHandler = cGroupsHandler; + this.cgroupsRootDirectory = cGroupsHandler.getCGroupMountPath(); } } @@ -486,9 +486,12 @@ public void launchContainer(ContainerRuntimeContext ctx) .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 d57d33cbd2..3f4bb5cfc2 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.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 @@ private String getExpectedTestCapabilitiesArgumentString() { } 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 ""; }