AbstractLauncher { public ContainerLaunchContext completeContainerLaunch() throws IOException { String cmdStr = ServiceUtils.join(commands, " ", false); log.debug("Completed setting up container command {}", cmdStr); containerLaunchContext.setCommands(commands); if (log.isDebugEnabled()) { log.debug("Environment variables"); for (Map.Entry<String, String> envPair : envVars.entrySet()) { log.debug(" \"{}\"=\"{}\"", envPair.getKey(), envPair.getValue()); } } containerLaunchContext.setEnvironment(envVars); if (log.isDebugEnabled()) { log.debug("Service Data size"); for (Map.Entry<String, ByteBuffer> entry : serviceData.entrySet()) { log.debug("\"{}\"=> {} bytes of data", entry.getKey(), entry.getValue().array().length); } } containerLaunchContext.setServiceData(serviceData); dumpLocalResources(); containerLaunchContext.setLocalResources(localResources); if (context.tokens != null) { containerLaunchContext.setTokens(context.tokens.duplicate()); } if(yarnDockerMode){ Map<String, String> env = containerLaunchContext.getEnvironment(); env.put("YARN_CONTAINER_RUNTIME_TYPE", "docker"); env.put("YARN_CONTAINER_RUNTIME_DOCKER_IMAGE", dockerImage); if (ServiceUtils.isSet(dockerNetwork)) { env.put("YARN_CONTAINER_RUNTIME_DOCKER_CONTAINER_NETWORK", dockerNetwork); } env.put("YARN_CONTAINER_RUNTIME_DOCKER_CONTAINER_HOSTNAME", dockerHostname); if (runPrivilegedContainer) { env.put("YARN_CONTAINER_RUNTIME_DOCKER_RUN_PRIVILEGED_CONTAINER", "true"); } if (!mountPaths.isEmpty()) { StringBuilder sb = new StringBuilder(); if (env.get(ENV_DOCKER_CONTAINER_MOUNTS) != null) { sb.append(env.get(ENV_DOCKER_CONTAINER_MOUNTS)); } for (Entry<String, String> mount : mountPaths.entrySet()) { if (sb.length() > 0) { sb.append(","); } sb.append(mount.getKey()).append(":"); sb.append(mount.getValue()).append(":ro"); } env.put(ENV_DOCKER_CONTAINER_MOUNTS, sb.toString()); } log.info("yarn docker env var has been set {}", containerLaunchContext.getEnvironment().toString()); } return containerLaunchContext; } AbstractLauncher(ServiceContext context); void setYarnDockerMode(boolean yarnDockerMode); Map<String, String> getEnv(); List<String> getCommands(); void addLocalResource(String subPath, LocalResource resource); void addLocalResource(String subPath, LocalResource resource, String mountPath); void addCommand(String cmd); ContainerLaunchContext completeContainerLaunch(); void setRetryContext(int maxRetries, int retryInterval,
      long failuresValidityInterval); void setClasspath(ClasspathConstructor classpath); void setEnv(String var, String value); void putEnv(Map<String, String> map); void setDockerImage(String dockerImage); void setDockerNetwork(String dockerNetwork); void setDockerHostname(String dockerHostname); void setRunPrivilegedContainer(boolean runPrivilegedContainer); @VisibleForTesting String getDockerImage(); static final String CLASSPATH; static final String ENV_DOCKER_CONTAINER_MOUNTS; }
@Test public void testDockerContainerMounts() throws IOException { launcher.yarnDockerMode = true; launcher.envVars.put(AbstractLauncher.ENV_DOCKER_CONTAINER_MOUNTS, "s1:t1:ro"); launcher.mountPaths.put("s2", "t2"); launcher.completeContainerLaunch(); String dockerContainerMounts = launcher.containerLaunchContext .getEnvironment().get(AbstractLauncher.ENV_DOCKER_CONTAINER_MOUNTS); Assert.assertEquals("s1:t1:ro,s2:t2:ro", dockerContainerMounts); }