YARN-6968. Hardcoded absolute pathname in DockerLinuxContainerRuntime. Contributed by Eric Badger

This commit is contained in:
Jason Lowe 2017-09-21 08:38:08 -05:00
parent 50849ec9eb
commit 10d7493587
4 changed files with 29 additions and 8 deletions

View File

@ -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();
}

View File

@ -603,4 +603,9 @@ class CGroupsHandlerImpl implements CGroupsHandler {
"Unable to read from " + cGroupParamPath);
}
}
@Override
public String getCGroupMountPath() {
return cGroupMountPath;
}
}

View File

@ -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<String> 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<String> allDirs = new ArrayList<>(containerLocalDirs);
allDirs.addAll(filecacheDirs);

View File

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