|
@@ -18,6 +18,15 @@
|
|
|
|
|
|
package org.apache.hadoop.mapreduce.v2.util;
|
|
package org.apache.hadoop.mapreduce.v2.util;
|
|
|
|
|
|
|
|
+import static org.junit.Assert.assertEquals;
|
|
|
|
+import static org.junit.Assert.assertFalse;
|
|
|
|
+import static org.junit.Assert.assertNotNull;
|
|
|
|
+import static org.junit.Assert.assertNull;
|
|
|
|
+import static org.junit.Assert.assertTrue;
|
|
|
|
+import static org.junit.Assert.fail;
|
|
|
|
+import static org.mockito.Mockito.mock;
|
|
|
|
+import static org.mockito.Mockito.when;
|
|
|
|
+
|
|
import java.io.File;
|
|
import java.io.File;
|
|
import java.io.FileOutputStream;
|
|
import java.io.FileOutputStream;
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
@@ -33,6 +42,7 @@ import org.apache.hadoop.fs.Path;
|
|
import org.apache.hadoop.mapred.InvalidJobConfException;
|
|
import org.apache.hadoop.mapred.InvalidJobConfException;
|
|
import org.apache.hadoop.mapreduce.Job;
|
|
import org.apache.hadoop.mapreduce.Job;
|
|
import org.apache.hadoop.mapreduce.JobID;
|
|
import org.apache.hadoop.mapreduce.JobID;
|
|
|
|
+import org.apache.hadoop.mapreduce.MRConfig;
|
|
import org.apache.hadoop.mapreduce.MRJobConfig;
|
|
import org.apache.hadoop.mapreduce.MRJobConfig;
|
|
import org.apache.hadoop.mapreduce.filecache.DistributedCache;
|
|
import org.apache.hadoop.mapreduce.filecache.DistributedCache;
|
|
import org.apache.hadoop.mapreduce.v2.api.records.JobId;
|
|
import org.apache.hadoop.mapreduce.v2.api.records.JobId;
|
|
@@ -40,7 +50,6 @@ import org.apache.hadoop.mapreduce.v2.api.records.TaskAttemptId;
|
|
import org.apache.hadoop.mapreduce.v2.api.records.TaskId;
|
|
import org.apache.hadoop.mapreduce.v2.api.records.TaskId;
|
|
import org.apache.hadoop.mapreduce.v2.api.records.TaskState;
|
|
import org.apache.hadoop.mapreduce.v2.api.records.TaskState;
|
|
import org.apache.hadoop.mapreduce.v2.api.records.TaskType;
|
|
import org.apache.hadoop.mapreduce.v2.api.records.TaskType;
|
|
-import org.apache.hadoop.mapreduce.v2.util.MRApps;
|
|
|
|
import org.apache.hadoop.util.StringUtils;
|
|
import org.apache.hadoop.util.StringUtils;
|
|
import org.apache.hadoop.yarn.api.ApplicationConstants;
|
|
import org.apache.hadoop.yarn.api.ApplicationConstants;
|
|
import org.apache.hadoop.yarn.api.records.ApplicationId;
|
|
import org.apache.hadoop.yarn.api.records.ApplicationId;
|
|
@@ -51,8 +60,6 @@ import org.apache.hadoop.yarn.factory.providers.RecordFactoryProvider;
|
|
import org.junit.AfterClass;
|
|
import org.junit.AfterClass;
|
|
import org.junit.BeforeClass;
|
|
import org.junit.BeforeClass;
|
|
import org.junit.Test;
|
|
import org.junit.Test;
|
|
-import static org.junit.Assert.*;
|
|
|
|
-import static org.mockito.Mockito.*;
|
|
|
|
|
|
|
|
public class TestMRApps {
|
|
public class TestMRApps {
|
|
private static File testWorkDir = null;
|
|
private static File testWorkDir = null;
|
|
@@ -178,27 +185,32 @@ public class TestMRApps {
|
|
|
|
|
|
@Test (timeout = 120000)
|
|
@Test (timeout = 120000)
|
|
public void testSetClasspath() throws IOException {
|
|
public void testSetClasspath() throws IOException {
|
|
- Job job = Job.getInstance();
|
|
|
|
|
|
+ Configuration conf = new Configuration();
|
|
|
|
+ conf.setBoolean(MRConfig.MAPREDUCE_APP_SUBMISSION_CROSS_PLATFORM, true);
|
|
|
|
+ Job job = Job.getInstance(conf);
|
|
Map<String, String> environment = new HashMap<String, String>();
|
|
Map<String, String> environment = new HashMap<String, String>();
|
|
MRApps.setClasspath(environment, job.getConfiguration());
|
|
MRApps.setClasspath(environment, job.getConfiguration());
|
|
assertTrue(environment.get("CLASSPATH").startsWith(
|
|
assertTrue(environment.get("CLASSPATH").startsWith(
|
|
- ApplicationConstants.Environment.PWD.$() + File.pathSeparator));
|
|
|
|
|
|
+ ApplicationConstants.Environment.PWD.$$()
|
|
|
|
+ + ApplicationConstants.CLASS_PATH_SEPARATOR));
|
|
String yarnAppClasspath = job.getConfiguration().get(
|
|
String yarnAppClasspath = job.getConfiguration().get(
|
|
YarnConfiguration.YARN_APPLICATION_CLASSPATH,
|
|
YarnConfiguration.YARN_APPLICATION_CLASSPATH,
|
|
StringUtils.join(",",
|
|
StringUtils.join(",",
|
|
- YarnConfiguration.DEFAULT_YARN_APPLICATION_CLASSPATH));
|
|
|
|
|
|
+ YarnConfiguration.DEFAULT_YARN_CROSS_PLATFORM_APPLICATION_CLASSPATH));
|
|
if (yarnAppClasspath != null) {
|
|
if (yarnAppClasspath != null) {
|
|
- yarnAppClasspath = yarnAppClasspath.replaceAll(",\\s*", File.pathSeparator)
|
|
|
|
- .trim();
|
|
|
|
|
|
+ yarnAppClasspath =
|
|
|
|
+ yarnAppClasspath.replaceAll(",\\s*",
|
|
|
|
+ ApplicationConstants.CLASS_PATH_SEPARATOR).trim();
|
|
}
|
|
}
|
|
assertTrue(environment.get("CLASSPATH").contains(yarnAppClasspath));
|
|
assertTrue(environment.get("CLASSPATH").contains(yarnAppClasspath));
|
|
String mrAppClasspath =
|
|
String mrAppClasspath =
|
|
job.getConfiguration().get(
|
|
job.getConfiguration().get(
|
|
MRJobConfig.MAPREDUCE_APPLICATION_CLASSPATH,
|
|
MRJobConfig.MAPREDUCE_APPLICATION_CLASSPATH,
|
|
- MRJobConfig.DEFAULT_MAPREDUCE_APPLICATION_CLASSPATH);
|
|
|
|
|
|
+ MRJobConfig.DEFAULT_MAPREDUCE_CROSS_PLATFORM_APPLICATION_CLASSPATH);
|
|
if (mrAppClasspath != null) {
|
|
if (mrAppClasspath != null) {
|
|
- mrAppClasspath = mrAppClasspath.replaceAll(",\\s*", File.pathSeparator)
|
|
|
|
- .trim();
|
|
|
|
|
|
+ mrAppClasspath =
|
|
|
|
+ mrAppClasspath.replaceAll(",\\s*",
|
|
|
|
+ ApplicationConstants.CLASS_PATH_SEPARATOR).trim();
|
|
}
|
|
}
|
|
assertTrue(environment.get("CLASSPATH").contains(mrAppClasspath));
|
|
assertTrue(environment.get("CLASSPATH").contains(mrAppClasspath));
|
|
}
|
|
}
|
|
@@ -209,8 +221,10 @@ public class TestMRApps {
|
|
FileOutputStream out = new FileOutputStream(testTGZ);
|
|
FileOutputStream out = new FileOutputStream(testTGZ);
|
|
out.write(0);
|
|
out.write(0);
|
|
out.close();
|
|
out.close();
|
|
- Job job = Job.getInstance();
|
|
|
|
- Configuration conf = job.getConfiguration();
|
|
|
|
|
|
+ Configuration conf = new Configuration();
|
|
|
|
+ conf.setBoolean(MRConfig.MAPREDUCE_APP_SUBMISSION_CROSS_PLATFORM, true);
|
|
|
|
+ Job job = Job.getInstance(conf);
|
|
|
|
+ conf = job.getConfiguration();
|
|
String testTGZQualifiedPath = FileSystem.getLocal(conf).makeQualified(new Path(
|
|
String testTGZQualifiedPath = FileSystem.getLocal(conf).makeQualified(new Path(
|
|
testTGZ.getAbsolutePath())).toString();
|
|
testTGZ.getAbsolutePath())).toString();
|
|
conf.set(MRJobConfig.CLASSPATH_ARCHIVES, testTGZQualifiedPath);
|
|
conf.set(MRJobConfig.CLASSPATH_ARCHIVES, testTGZQualifiedPath);
|
|
@@ -218,13 +232,13 @@ public class TestMRApps {
|
|
Map<String, String> environment = new HashMap<String, String>();
|
|
Map<String, String> environment = new HashMap<String, String>();
|
|
MRApps.setClasspath(environment, conf);
|
|
MRApps.setClasspath(environment, conf);
|
|
assertTrue(environment.get("CLASSPATH").startsWith(
|
|
assertTrue(environment.get("CLASSPATH").startsWith(
|
|
- ApplicationConstants.Environment.PWD.$() + File.pathSeparator));
|
|
|
|
|
|
+ ApplicationConstants.Environment.PWD.$$() + ApplicationConstants.CLASS_PATH_SEPARATOR));
|
|
String confClasspath = job.getConfiguration().get(
|
|
String confClasspath = job.getConfiguration().get(
|
|
YarnConfiguration.YARN_APPLICATION_CLASSPATH,
|
|
YarnConfiguration.YARN_APPLICATION_CLASSPATH,
|
|
StringUtils.join(",",
|
|
StringUtils.join(",",
|
|
- YarnConfiguration.DEFAULT_YARN_APPLICATION_CLASSPATH));
|
|
|
|
|
|
+ YarnConfiguration.DEFAULT_YARN_CROSS_PLATFORM_APPLICATION_CLASSPATH));
|
|
if (confClasspath != null) {
|
|
if (confClasspath != null) {
|
|
- confClasspath = confClasspath.replaceAll(",\\s*", File.pathSeparator)
|
|
|
|
|
|
+ confClasspath = confClasspath.replaceAll(",\\s*", ApplicationConstants.CLASS_PATH_SEPARATOR)
|
|
.trim();
|
|
.trim();
|
|
}
|
|
}
|
|
assertTrue(environment.get("CLASSPATH").contains(confClasspath));
|
|
assertTrue(environment.get("CLASSPATH").contains(confClasspath));
|
|
@@ -234,6 +248,7 @@ public class TestMRApps {
|
|
@Test (timeout = 120000)
|
|
@Test (timeout = 120000)
|
|
public void testSetClasspathWithUserPrecendence() {
|
|
public void testSetClasspathWithUserPrecendence() {
|
|
Configuration conf = new Configuration();
|
|
Configuration conf = new Configuration();
|
|
|
|
+ conf.setBoolean(MRConfig.MAPREDUCE_APP_SUBMISSION_CROSS_PLATFORM, true);
|
|
conf.setBoolean(MRJobConfig.MAPREDUCE_JOB_USER_CLASSPATH_FIRST, true);
|
|
conf.setBoolean(MRJobConfig.MAPREDUCE_JOB_USER_CLASSPATH_FIRST, true);
|
|
Map<String, String> env = new HashMap<String, String>();
|
|
Map<String, String> env = new HashMap<String, String>();
|
|
try {
|
|
try {
|
|
@@ -242,10 +257,10 @@ public class TestMRApps {
|
|
fail("Got exception while setting classpath");
|
|
fail("Got exception while setting classpath");
|
|
}
|
|
}
|
|
String env_str = env.get("CLASSPATH");
|
|
String env_str = env.get("CLASSPATH");
|
|
- String expectedClasspath = StringUtils.join(File.pathSeparator,
|
|
|
|
- Arrays.asList(ApplicationConstants.Environment.PWD.$(), "job.jar/job.jar",
|
|
|
|
|
|
+ String expectedClasspath = StringUtils.join(ApplicationConstants.CLASS_PATH_SEPARATOR,
|
|
|
|
+ Arrays.asList(ApplicationConstants.Environment.PWD.$$(), "job.jar/job.jar",
|
|
"job.jar/classes/", "job.jar/lib/*",
|
|
"job.jar/classes/", "job.jar/lib/*",
|
|
- ApplicationConstants.Environment.PWD.$() + "/*"));
|
|
|
|
|
|
+ ApplicationConstants.Environment.PWD.$$() + "/*"));
|
|
assertTrue("MAPREDUCE_JOB_USER_CLASSPATH_FIRST set, but not taking effect!",
|
|
assertTrue("MAPREDUCE_JOB_USER_CLASSPATH_FIRST set, but not taking effect!",
|
|
env_str.startsWith(expectedClasspath));
|
|
env_str.startsWith(expectedClasspath));
|
|
}
|
|
}
|
|
@@ -253,6 +268,7 @@ public class TestMRApps {
|
|
@Test (timeout = 120000)
|
|
@Test (timeout = 120000)
|
|
public void testSetClasspathWithNoUserPrecendence() {
|
|
public void testSetClasspathWithNoUserPrecendence() {
|
|
Configuration conf = new Configuration();
|
|
Configuration conf = new Configuration();
|
|
|
|
+ conf.setBoolean(MRConfig.MAPREDUCE_APP_SUBMISSION_CROSS_PLATFORM, true);
|
|
conf.setBoolean(MRJobConfig.MAPREDUCE_JOB_USER_CLASSPATH_FIRST, false);
|
|
conf.setBoolean(MRJobConfig.MAPREDUCE_JOB_USER_CLASSPATH_FIRST, false);
|
|
Map<String, String> env = new HashMap<String, String>();
|
|
Map<String, String> env = new HashMap<String, String>();
|
|
try {
|
|
try {
|
|
@@ -261,9 +277,9 @@ public class TestMRApps {
|
|
fail("Got exception while setting classpath");
|
|
fail("Got exception while setting classpath");
|
|
}
|
|
}
|
|
String env_str = env.get("CLASSPATH");
|
|
String env_str = env.get("CLASSPATH");
|
|
- String expectedClasspath = StringUtils.join(File.pathSeparator,
|
|
|
|
|
|
+ String expectedClasspath = StringUtils.join(ApplicationConstants.CLASS_PATH_SEPARATOR,
|
|
Arrays.asList("job.jar/job.jar", "job.jar/classes/", "job.jar/lib/*",
|
|
Arrays.asList("job.jar/job.jar", "job.jar/classes/", "job.jar/lib/*",
|
|
- ApplicationConstants.Environment.PWD.$() + "/*"));
|
|
|
|
|
|
+ ApplicationConstants.Environment.PWD.$$() + "/*"));
|
|
assertTrue("MAPREDUCE_JOB_USER_CLASSPATH_FIRST false, and job.jar is not in"
|
|
assertTrue("MAPREDUCE_JOB_USER_CLASSPATH_FIRST false, and job.jar is not in"
|
|
+ " the classpath!", env_str.contains(expectedClasspath));
|
|
+ " the classpath!", env_str.contains(expectedClasspath));
|
|
assertFalse("MAPREDUCE_JOB_USER_CLASSPATH_FIRST false, but taking effect!",
|
|
assertFalse("MAPREDUCE_JOB_USER_CLASSPATH_FIRST false, but taking effect!",
|
|
@@ -273,19 +289,20 @@ public class TestMRApps {
|
|
@Test (timeout = 120000)
|
|
@Test (timeout = 120000)
|
|
public void testSetClasspathWithJobClassloader() throws IOException {
|
|
public void testSetClasspathWithJobClassloader() throws IOException {
|
|
Configuration conf = new Configuration();
|
|
Configuration conf = new Configuration();
|
|
|
|
+ conf.setBoolean(MRConfig.MAPREDUCE_APP_SUBMISSION_CROSS_PLATFORM, true);
|
|
conf.setBoolean(MRJobConfig.MAPREDUCE_JOB_CLASSLOADER, true);
|
|
conf.setBoolean(MRJobConfig.MAPREDUCE_JOB_CLASSLOADER, true);
|
|
Map<String, String> env = new HashMap<String, String>();
|
|
Map<String, String> env = new HashMap<String, String>();
|
|
MRApps.setClasspath(env, conf);
|
|
MRApps.setClasspath(env, conf);
|
|
String cp = env.get("CLASSPATH");
|
|
String cp = env.get("CLASSPATH");
|
|
String appCp = env.get("APP_CLASSPATH");
|
|
String appCp = env.get("APP_CLASSPATH");
|
|
assertFalse("MAPREDUCE_JOB_CLASSLOADER true, but job.jar is in the"
|
|
assertFalse("MAPREDUCE_JOB_CLASSLOADER true, but job.jar is in the"
|
|
- + " classpath!", cp.contains("jar" + File.pathSeparator + "job"));
|
|
|
|
|
|
+ + " classpath!", cp.contains("jar" + ApplicationConstants.CLASS_PATH_SEPARATOR + "job"));
|
|
assertFalse("MAPREDUCE_JOB_CLASSLOADER true, but PWD is in the classpath!",
|
|
assertFalse("MAPREDUCE_JOB_CLASSLOADER true, but PWD is in the classpath!",
|
|
cp.contains("PWD"));
|
|
cp.contains("PWD"));
|
|
- String expectedAppClasspath = StringUtils.join(File.pathSeparator,
|
|
|
|
- Arrays.asList(ApplicationConstants.Environment.PWD.$(), "job.jar/job.jar",
|
|
|
|
|
|
+ String expectedAppClasspath = StringUtils.join(ApplicationConstants.CLASS_PATH_SEPARATOR,
|
|
|
|
+ Arrays.asList(ApplicationConstants.Environment.PWD.$$(), "job.jar/job.jar",
|
|
"job.jar/classes/", "job.jar/lib/*",
|
|
"job.jar/classes/", "job.jar/lib/*",
|
|
- ApplicationConstants.Environment.PWD.$() + "/*"));
|
|
|
|
|
|
+ ApplicationConstants.Environment.PWD.$$() + "/*"));
|
|
assertEquals("MAPREDUCE_JOB_CLASSLOADER true, but job.jar is not in the app"
|
|
assertEquals("MAPREDUCE_JOB_CLASSLOADER true, but job.jar is not in the app"
|
|
+ " classpath!", expectedAppClasspath, appCp);
|
|
+ " classpath!", expectedAppClasspath, appCp);
|
|
}
|
|
}
|
|
@@ -295,6 +312,7 @@ public class TestMRApps {
|
|
final String FRAMEWORK_NAME = "some-framework-name";
|
|
final String FRAMEWORK_NAME = "some-framework-name";
|
|
final String FRAMEWORK_PATH = "some-framework-path#" + FRAMEWORK_NAME;
|
|
final String FRAMEWORK_PATH = "some-framework-path#" + FRAMEWORK_NAME;
|
|
Configuration conf = new Configuration();
|
|
Configuration conf = new Configuration();
|
|
|
|
+ conf.setBoolean(MRConfig.MAPREDUCE_APP_SUBMISSION_CROSS_PLATFORM, true);
|
|
conf.set(MRJobConfig.MAPREDUCE_APPLICATION_FRAMEWORK_PATH, FRAMEWORK_PATH);
|
|
conf.set(MRJobConfig.MAPREDUCE_APPLICATION_FRAMEWORK_PATH, FRAMEWORK_PATH);
|
|
Map<String, String> env = new HashMap<String, String>();
|
|
Map<String, String> env = new HashMap<String, String>();
|
|
try {
|
|
try {
|
|
@@ -310,11 +328,11 @@ public class TestMRApps {
|
|
final String FRAMEWORK_CLASSPATH = FRAMEWORK_NAME + "/*.jar";
|
|
final String FRAMEWORK_CLASSPATH = FRAMEWORK_NAME + "/*.jar";
|
|
conf.set(MRJobConfig.MAPREDUCE_APPLICATION_CLASSPATH, FRAMEWORK_CLASSPATH);
|
|
conf.set(MRJobConfig.MAPREDUCE_APPLICATION_CLASSPATH, FRAMEWORK_CLASSPATH);
|
|
MRApps.setClasspath(env, conf);
|
|
MRApps.setClasspath(env, conf);
|
|
- final String stdClasspath = StringUtils.join(File.pathSeparator,
|
|
|
|
|
|
+ final String stdClasspath = StringUtils.join(ApplicationConstants.CLASS_PATH_SEPARATOR,
|
|
Arrays.asList("job.jar/job.jar", "job.jar/classes/", "job.jar/lib/*",
|
|
Arrays.asList("job.jar/job.jar", "job.jar/classes/", "job.jar/lib/*",
|
|
- ApplicationConstants.Environment.PWD.$() + "/*"));
|
|
|
|
- String expectedClasspath = StringUtils.join(File.pathSeparator,
|
|
|
|
- Arrays.asList(ApplicationConstants.Environment.PWD.$(),
|
|
|
|
|
|
+ ApplicationConstants.Environment.PWD.$$() + "/*"));
|
|
|
|
+ String expectedClasspath = StringUtils.join(ApplicationConstants.CLASS_PATH_SEPARATOR,
|
|
|
|
+ Arrays.asList(ApplicationConstants.Environment.PWD.$$(),
|
|
FRAMEWORK_CLASSPATH, stdClasspath));
|
|
FRAMEWORK_CLASSPATH, stdClasspath));
|
|
assertEquals("Incorrect classpath with framework and no user precedence",
|
|
assertEquals("Incorrect classpath with framework and no user precedence",
|
|
expectedClasspath, env.get("CLASSPATH"));
|
|
expectedClasspath, env.get("CLASSPATH"));
|
|
@@ -322,8 +340,8 @@ public class TestMRApps {
|
|
env.clear();
|
|
env.clear();
|
|
conf.setBoolean(MRJobConfig.MAPREDUCE_JOB_USER_CLASSPATH_FIRST, true);
|
|
conf.setBoolean(MRJobConfig.MAPREDUCE_JOB_USER_CLASSPATH_FIRST, true);
|
|
MRApps.setClasspath(env, conf);
|
|
MRApps.setClasspath(env, conf);
|
|
- expectedClasspath = StringUtils.join(File.pathSeparator,
|
|
|
|
- Arrays.asList(ApplicationConstants.Environment.PWD.$(),
|
|
|
|
|
|
+ expectedClasspath = StringUtils.join(ApplicationConstants.CLASS_PATH_SEPARATOR,
|
|
|
|
+ Arrays.asList(ApplicationConstants.Environment.PWD.$$(),
|
|
stdClasspath, FRAMEWORK_CLASSPATH));
|
|
stdClasspath, FRAMEWORK_CLASSPATH));
|
|
assertEquals("Incorrect classpath with framework and user precedence",
|
|
assertEquals("Incorrect classpath with framework and user precedence",
|
|
expectedClasspath, env.get("CLASSPATH"));
|
|
expectedClasspath, env.get("CLASSPATH"));
|