YARN-129. Simplify classpath construction for mini YARN tests.
git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1411235 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
c944d0666c
commit
e464607b7d
|
@ -89,11 +89,6 @@
|
||||||
<phase>test-compile</phase>
|
<phase>test-compile</phase>
|
||||||
</execution>
|
</execution>
|
||||||
</executions>
|
</executions>
|
||||||
<configuration>
|
|
||||||
<excludes>
|
|
||||||
<exclude>mrapp-generated-classpath</exclude>
|
|
||||||
</excludes>
|
|
||||||
</configuration>
|
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
<artifactId>maven-antrun-plugin</artifactId>
|
<artifactId>maven-antrun-plugin</artifactId>
|
||||||
|
|
|
@ -18,13 +18,8 @@
|
||||||
|
|
||||||
package org.apache.hadoop.mapreduce.v2.util;
|
package org.apache.hadoop.mapreduce.v2.util;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
|
||||||
import java.io.InputStreamReader;
|
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.net.URL;
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -134,62 +129,24 @@ public class MRApps extends Apps {
|
||||||
|
|
||||||
private static void setMRFrameworkClasspath(
|
private static void setMRFrameworkClasspath(
|
||||||
Map<String, String> environment, Configuration conf) throws IOException {
|
Map<String, String> environment, Configuration conf) throws IOException {
|
||||||
InputStream classpathFileStream = null;
|
// Propagate the system classpath when using the mini cluster
|
||||||
BufferedReader reader = null;
|
if (conf.getBoolean(YarnConfiguration.IS_MINI_YARN_CLUSTER, false)) {
|
||||||
try {
|
Apps.addToEnvironment(environment, Environment.CLASSPATH.name(),
|
||||||
// Get yarn mapreduce-app classpath from generated classpath
|
System.getProperty("java.class.path"));
|
||||||
// Works if compile time env is same as runtime. Mainly tests.
|
}
|
||||||
ClassLoader thisClassLoader =
|
|
||||||
Thread.currentThread().getContextClassLoader();
|
|
||||||
String mrAppGeneratedClasspathFile = "mrapp-generated-classpath";
|
|
||||||
classpathFileStream =
|
|
||||||
thisClassLoader.getResourceAsStream(mrAppGeneratedClasspathFile);
|
|
||||||
|
|
||||||
// Put the file itself on classpath for tasks.
|
// Add standard Hadoop classes
|
||||||
URL classpathResource = thisClassLoader
|
for (String c : conf.getStrings(
|
||||||
.getResource(mrAppGeneratedClasspathFile);
|
YarnConfiguration.YARN_APPLICATION_CLASSPATH,
|
||||||
if (classpathResource != null) {
|
YarnConfiguration.DEFAULT_YARN_APPLICATION_CLASSPATH)) {
|
||||||
String classpathElement = classpathResource.getFile();
|
Apps.addToEnvironment(environment, Environment.CLASSPATH.name(), c
|
||||||
if (classpathElement.contains("!")) {
|
.trim());
|
||||||
classpathElement = classpathElement.substring(0,
|
}
|
||||||
classpathElement.indexOf("!"));
|
for (String c : conf.getStrings(
|
||||||
} else {
|
MRJobConfig.MAPREDUCE_APPLICATION_CLASSPATH,
|
||||||
classpathElement = new File(classpathElement).getParent();
|
MRJobConfig.DEFAULT_MAPREDUCE_APPLICATION_CLASSPATH)) {
|
||||||
}
|
Apps.addToEnvironment(environment, Environment.CLASSPATH.name(), c
|
||||||
Apps.addToEnvironment(environment, Environment.CLASSPATH.name(),
|
.trim());
|
||||||
classpathElement);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (classpathFileStream != null) {
|
|
||||||
reader = new BufferedReader(new InputStreamReader(classpathFileStream,
|
|
||||||
Charsets.UTF_8));
|
|
||||||
String cp = reader.readLine();
|
|
||||||
if (cp != null) {
|
|
||||||
Apps.addToEnvironment(environment, Environment.CLASSPATH.name(),
|
|
||||||
cp.trim());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add standard Hadoop classes
|
|
||||||
for (String c : conf.getStrings(
|
|
||||||
YarnConfiguration.YARN_APPLICATION_CLASSPATH,
|
|
||||||
YarnConfiguration.DEFAULT_YARN_APPLICATION_CLASSPATH)) {
|
|
||||||
Apps.addToEnvironment(environment, Environment.CLASSPATH.name(), c
|
|
||||||
.trim());
|
|
||||||
}
|
|
||||||
for (String c : conf.getStrings(
|
|
||||||
MRJobConfig.MAPREDUCE_APPLICATION_CLASSPATH,
|
|
||||||
MRJobConfig.DEFAULT_MAPREDUCE_APPLICATION_CLASSPATH)) {
|
|
||||||
Apps.addToEnvironment(environment, Environment.CLASSPATH.name(), c
|
|
||||||
.trim());
|
|
||||||
}
|
|
||||||
} finally {
|
|
||||||
if (classpathFileStream != null) {
|
|
||||||
classpathFileStream.close();
|
|
||||||
}
|
|
||||||
if (reader != null) {
|
|
||||||
reader.close();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// TODO: Remove duplicates.
|
// TODO: Remove duplicates.
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,6 +31,7 @@ import org.apache.hadoop.mapred.RunningJob;
|
||||||
|
|
||||||
import org.apache.hadoop.mapreduce.MRConfig;
|
import org.apache.hadoop.mapreduce.MRConfig;
|
||||||
import org.apache.hadoop.security.ssl.KeyStoreTestUtil;
|
import org.apache.hadoop.security.ssl.KeyStoreTestUtil;
|
||||||
|
import org.apache.hadoop.yarn.conf.YarnConfiguration;
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.AfterClass;
|
import org.junit.AfterClass;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
|
@ -52,6 +53,8 @@ public class TestEncryptedShuffle {
|
||||||
private static final String BASEDIR =
|
private static final String BASEDIR =
|
||||||
System.getProperty("test.build.dir", "target/test-dir") + "/" +
|
System.getProperty("test.build.dir", "target/test-dir") + "/" +
|
||||||
TestEncryptedShuffle.class.getSimpleName();
|
TestEncryptedShuffle.class.getSimpleName();
|
||||||
|
|
||||||
|
private String classpathDir;
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void setUp() throws Exception {
|
public static void setUp() throws Exception {
|
||||||
|
@ -62,27 +65,12 @@ public class TestEncryptedShuffle {
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void createCustomYarnClasspath() throws Exception {
|
public void createCustomYarnClasspath() throws Exception {
|
||||||
String classpathDir =
|
classpathDir = KeyStoreTestUtil.getClasspathDir(TestEncryptedShuffle.class);
|
||||||
KeyStoreTestUtil.getClasspathDir(TestEncryptedShuffle.class);
|
|
||||||
|
|
||||||
URL url = Thread.currentThread().getContextClassLoader().
|
|
||||||
getResource("mrapp-generated-classpath");
|
|
||||||
File f = new File(url.getPath());
|
|
||||||
BufferedReader reader = new BufferedReader(new FileReader(f));
|
|
||||||
String cp = reader.readLine();
|
|
||||||
cp = cp + ":" + classpathDir;
|
|
||||||
f = new File(classpathDir, "mrapp-generated-classpath");
|
|
||||||
Writer writer = new FileWriter(f);
|
|
||||||
writer.write(cp);
|
|
||||||
writer.close();
|
|
||||||
new File(classpathDir, "core-site.xml").delete();
|
new File(classpathDir, "core-site.xml").delete();
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@After
|
||||||
public void cleanUpMiniClusterSpecialConfig() throws Exception {
|
public void cleanUpMiniClusterSpecialConfig() throws Exception {
|
||||||
String classpathDir =
|
|
||||||
KeyStoreTestUtil.getClasspathDir(TestEncryptedShuffle.class);
|
|
||||||
new File(classpathDir, "mrapp-generated-classpath").delete();
|
|
||||||
new File(classpathDir, "core-site.xml").delete();
|
new File(classpathDir, "core-site.xml").delete();
|
||||||
String keystoresDir = new File(BASEDIR).getAbsolutePath();
|
String keystoresDir = new File(BASEDIR).getAbsolutePath();
|
||||||
KeyStoreTestUtil.cleanupSSLConfig(keystoresDir, classpathDir);
|
KeyStoreTestUtil.cleanupSSLConfig(keystoresDir, classpathDir);
|
||||||
|
@ -98,6 +86,9 @@ public class TestEncryptedShuffle {
|
||||||
conf.set("dfs.block.access.token.enable", "false");
|
conf.set("dfs.block.access.token.enable", "false");
|
||||||
conf.set("dfs.permissions", "true");
|
conf.set("dfs.permissions", "true");
|
||||||
conf.set("hadoop.security.authentication", "simple");
|
conf.set("hadoop.security.authentication", "simple");
|
||||||
|
String cp = conf.get(YarnConfiguration.YARN_APPLICATION_CLASSPATH) +
|
||||||
|
File.pathSeparator + classpathDir;
|
||||||
|
conf.set(YarnConfiguration.YARN_APPLICATION_CLASSPATH, cp);
|
||||||
dfsCluster = new MiniDFSCluster(conf, 1, true, null);
|
dfsCluster = new MiniDFSCluster(conf, 1, true, null);
|
||||||
FileSystem fileSystem = dfsCluster.getFileSystem();
|
FileSystem fileSystem = dfsCluster.getFileSystem();
|
||||||
fileSystem.mkdirs(new Path("/tmp"));
|
fileSystem.mkdirs(new Path("/tmp"));
|
||||||
|
@ -113,8 +104,6 @@ public class TestEncryptedShuffle {
|
||||||
mrCluster = MiniMRClientClusterFactory.create(this.getClass(), 1, conf);
|
mrCluster = MiniMRClientClusterFactory.create(this.getClass(), 1, conf);
|
||||||
|
|
||||||
// so the minicluster conf is avail to the containers.
|
// so the minicluster conf is avail to the containers.
|
||||||
String classpathDir =
|
|
||||||
KeyStoreTestUtil.getClasspathDir(TestEncryptedShuffle.class);
|
|
||||||
Writer writer = new FileWriter(classpathDir + "/core-site.xml");
|
Writer writer = new FileWriter(classpathDir + "/core-site.xml");
|
||||||
mrCluster.getConfig().writeXml(writer);
|
mrCluster.getConfig().writeXml(writer);
|
||||||
writer.close();
|
writer.close();
|
||||||
|
|
|
@ -703,11 +703,6 @@
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-jar-plugin</artifactId>
|
<artifactId>maven-jar-plugin</artifactId>
|
||||||
<version>2.3.1</version>
|
<version>2.3.1</version>
|
||||||
<configuration>
|
|
||||||
<excludes>
|
|
||||||
<exclude>mrapp-generated-classpath</exclude>
|
|
||||||
</excludes>
|
|
||||||
</configuration>
|
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
@ -802,21 +797,6 @@
|
||||||
</execution>
|
</execution>
|
||||||
</executions>
|
</executions>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
|
||||||
<artifactId>maven-dependency-plugin</artifactId>
|
|
||||||
<executions>
|
|
||||||
<execution>
|
|
||||||
<id>build-classpath</id>
|
|
||||||
<phase>generate-sources</phase>
|
|
||||||
<goals>
|
|
||||||
<goal>build-classpath</goal>
|
|
||||||
</goals>
|
|
||||||
<configuration>
|
|
||||||
<outputFile>target/classes/mrapp-generated-classpath</outputFile>
|
|
||||||
</configuration>
|
|
||||||
</execution>
|
|
||||||
</executions>
|
|
||||||
</plugin>
|
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-surefire-plugin</artifactId>
|
<artifactId>maven-surefire-plugin</artifactId>
|
||||||
|
|
|
@ -71,6 +71,8 @@ Release 2.0.3-alpha - Unreleased
|
||||||
|
|
||||||
YARN-183. Clean up fair scheduler code. (Sandy Ryza via tomwhite)
|
YARN-183. Clean up fair scheduler code. (Sandy Ryza via tomwhite)
|
||||||
|
|
||||||
|
YARN-129. Simplify classpath construction for mini YARN tests. (tomwhite)
|
||||||
|
|
||||||
OPTIMIZATIONS
|
OPTIMIZATIONS
|
||||||
|
|
||||||
BUG FIXES
|
BUG FIXES
|
||||||
|
|
|
@ -90,23 +90,6 @@
|
||||||
</archive>
|
</archive>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
|
||||||
<artifactId>maven-dependency-plugin</artifactId>
|
|
||||||
<executions>
|
|
||||||
<execution>
|
|
||||||
<id>build-classpath</id>
|
|
||||||
<phase>generate-sources</phase>
|
|
||||||
<goals>
|
|
||||||
<goal>build-classpath</goal>
|
|
||||||
</goals>
|
|
||||||
<configuration>
|
|
||||||
<!-- needed to run the unit test for DS to generate the required classpath
|
|
||||||
that is required in the env of the launch container in the mini yarn cluster -->
|
|
||||||
<outputFile>target/classes/yarn-apps-ds-generated-classpath</outputFile>
|
|
||||||
</configuration>
|
|
||||||
</execution>
|
|
||||||
</executions>
|
|
||||||
</plugin>
|
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-surefire-plugin</artifactId>
|
<artifactId>maven-surefire-plugin</artifactId>
|
||||||
|
|
|
@ -494,9 +494,10 @@ public class Client extends YarnClientImpl {
|
||||||
classPathEnv.append(":./log4j.properties");
|
classPathEnv.append(":./log4j.properties");
|
||||||
|
|
||||||
// add the runtime classpath needed for tests to work
|
// add the runtime classpath needed for tests to work
|
||||||
String testRuntimeClassPath = Client.getTestRuntimeClasspath();
|
if (conf.getBoolean(YarnConfiguration.IS_MINI_YARN_CLUSTER, false)) {
|
||||||
classPathEnv.append(':');
|
classPathEnv.append(':');
|
||||||
classPathEnv.append(testRuntimeClassPath);
|
classPathEnv.append(System.getProperty("java.class.path"));
|
||||||
|
}
|
||||||
|
|
||||||
env.put("CLASSPATH", classPathEnv.toString());
|
env.put("CLASSPATH", classPathEnv.toString());
|
||||||
|
|
||||||
|
@ -663,50 +664,4 @@ public class Client extends YarnClientImpl {
|
||||||
super.killApplication(appId);
|
super.killApplication(appId);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String getTestRuntimeClasspath() {
|
|
||||||
|
|
||||||
InputStream classpathFileStream = null;
|
|
||||||
BufferedReader reader = null;
|
|
||||||
String envClassPath = "";
|
|
||||||
|
|
||||||
LOG.info("Trying to generate classpath for app master from current thread's classpath");
|
|
||||||
try {
|
|
||||||
|
|
||||||
// Create classpath from generated classpath
|
|
||||||
// Check maven ppom.xml for generated classpath info
|
|
||||||
// Works if compile time env is same as runtime. Mainly tests.
|
|
||||||
ClassLoader thisClassLoader =
|
|
||||||
Thread.currentThread().getContextClassLoader();
|
|
||||||
String generatedClasspathFile = "yarn-apps-ds-generated-classpath";
|
|
||||||
classpathFileStream =
|
|
||||||
thisClassLoader.getResourceAsStream(generatedClasspathFile);
|
|
||||||
if (classpathFileStream == null) {
|
|
||||||
LOG.info("Could not classpath resource from class loader");
|
|
||||||
return envClassPath;
|
|
||||||
}
|
|
||||||
LOG.info("Readable bytes from stream=" + classpathFileStream.available());
|
|
||||||
reader = new BufferedReader(new InputStreamReader(classpathFileStream));
|
|
||||||
String cp = reader.readLine();
|
|
||||||
if (cp != null) {
|
|
||||||
envClassPath += cp.trim() + ":";
|
|
||||||
}
|
|
||||||
// Put the file itself on classpath for tasks.
|
|
||||||
envClassPath += thisClassLoader.getResource(generatedClasspathFile).getFile();
|
|
||||||
} catch (IOException e) {
|
|
||||||
LOG.info("Could not find the necessary resource to generate class path for tests. Error=" + e.getMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
if (classpathFileStream != null) {
|
|
||||||
classpathFileStream.close();
|
|
||||||
}
|
|
||||||
if (reader != null) {
|
|
||||||
reader.close();
|
|
||||||
}
|
|
||||||
} catch (IOException e) {
|
|
||||||
LOG.info("Failed to close class path file stream or reader. Error=" + e.getMessage());
|
|
||||||
}
|
|
||||||
return envClassPath;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -86,23 +86,6 @@
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
<plugins>
|
<plugins>
|
||||||
<plugin>
|
|
||||||
<artifactId>maven-dependency-plugin</artifactId>
|
|
||||||
<executions>
|
|
||||||
<execution>
|
|
||||||
<id>build-classpath</id>
|
|
||||||
<phase>generate-sources</phase>
|
|
||||||
<goals>
|
|
||||||
<goal>build-classpath</goal>
|
|
||||||
</goals>
|
|
||||||
<configuration>
|
|
||||||
<!-- needed to run the unit test for DS to generate the required classpath
|
|
||||||
that is required in the env of the launch container in the mini yarn cluster -->
|
|
||||||
<outputFile>target/classes/yarn-apps-am-generated-classpath</outputFile>
|
|
||||||
</configuration>
|
|
||||||
</execution>
|
|
||||||
</executions>
|
|
||||||
</plugin>
|
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-surefire-plugin</artifactId>
|
<artifactId>maven-surefire-plugin</artifactId>
|
||||||
|
|
|
@ -18,12 +18,9 @@
|
||||||
|
|
||||||
package org.apache.hadoop.yarn.applications.unmanagedamlauncher;
|
package org.apache.hadoop.yarn.applications.unmanagedamlauncher;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
|
||||||
import java.io.InputStreamReader;
|
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
|
||||||
|
@ -80,51 +77,17 @@ public class TestUnmanagedAMLauncher {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String getTestRuntimeClasspath() {
|
private static String getTestRuntimeClasspath() {
|
||||||
|
|
||||||
InputStream classpathFileStream = null;
|
|
||||||
BufferedReader reader = null;
|
|
||||||
String envClassPath = "";
|
|
||||||
|
|
||||||
LOG.info("Trying to generate classpath for app master from current thread's classpath");
|
LOG.info("Trying to generate classpath for app master from current thread's classpath");
|
||||||
try {
|
String envClassPath = "";
|
||||||
|
String cp = System.getProperty("java.class.path");
|
||||||
// Create classpath from generated classpath
|
if (cp != null) {
|
||||||
// Check maven pom.xml for generated classpath info
|
envClassPath += cp.trim() + File.pathSeparator;
|
||||||
// Works if compile time env is same as runtime. Mainly tests.
|
|
||||||
ClassLoader thisClassLoader = Thread.currentThread()
|
|
||||||
.getContextClassLoader();
|
|
||||||
String generatedClasspathFile = "yarn-apps-am-generated-classpath";
|
|
||||||
classpathFileStream = thisClassLoader
|
|
||||||
.getResourceAsStream(generatedClasspathFile);
|
|
||||||
if (classpathFileStream == null) {
|
|
||||||
LOG.info("Could not classpath resource from class loader");
|
|
||||||
return envClassPath;
|
|
||||||
}
|
|
||||||
LOG.info("Readable bytes from stream=" + classpathFileStream.available());
|
|
||||||
reader = new BufferedReader(new InputStreamReader(classpathFileStream));
|
|
||||||
String cp = reader.readLine();
|
|
||||||
if (cp != null) {
|
|
||||||
envClassPath += cp.trim() + File.pathSeparator;
|
|
||||||
}
|
|
||||||
// yarn-site.xml at this location contains proper config for mini cluster
|
|
||||||
URL url = thisClassLoader.getResource("yarn-site.xml");
|
|
||||||
envClassPath += new File(url.getFile()).getParent();
|
|
||||||
} catch (IOException e) {
|
|
||||||
LOG.info("Could not find the necessary resource to generate class path for tests. Error="
|
|
||||||
+ e.getMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
if (classpathFileStream != null) {
|
|
||||||
classpathFileStream.close();
|
|
||||||
}
|
|
||||||
if (reader != null) {
|
|
||||||
reader.close();
|
|
||||||
}
|
|
||||||
} catch (IOException e) {
|
|
||||||
LOG.info("Failed to close class path file stream or reader. Error="
|
|
||||||
+ e.getMessage());
|
|
||||||
}
|
}
|
||||||
|
// yarn-site.xml at this location contains proper config for mini cluster
|
||||||
|
ClassLoader thisClassLoader = Thread.currentThread()
|
||||||
|
.getContextClassLoader();
|
||||||
|
URL url = thisClassLoader.getResource("yarn-site.xml");
|
||||||
|
envClassPath += new File(url.getFile()).getParent();
|
||||||
return envClassPath;
|
return envClassPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue