MAPREDUCE-2073. TestTrackerDistributedCacheManager should be up-front about requirements on build environment. Contributed by Todd Lipcon.
git-svn-id: https://svn.apache.org/repos/asf/hadoop/mapreduce/trunk@1033720 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/CHANGES.txt b/CHANGES.txt
index 0cb361d..54fa676 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -161,6 +161,9 @@
MAPREDUCE-1592. Generate Eclipse's .classpath file from Ivy config.
(tomwhite via nigel)
+ MAPREDUCE-2073. TestTrackerDistributedCacheManager should be up-front
+ about requirements on build environment. (Todd Lipcon via tomwhite)
+
OPTIMIZATIONS
MAPREDUCE-1354. Enhancements to JobTracker for better performance and
diff --git a/src/java/org/apache/hadoop/mapreduce/filecache/TrackerDistributedCacheManager.java b/src/java/org/apache/hadoop/mapreduce/filecache/TrackerDistributedCacheManager.java
index c529112..ae8cf31 100644
--- a/src/java/org/apache/hadoop/mapreduce/filecache/TrackerDistributedCacheManager.java
+++ b/src/java/org/apache/hadoop/mapreduce/filecache/TrackerDistributedCacheManager.java
@@ -359,7 +359,17 @@
if (!checkPermissionOfOther(fs, current, FsAction.READ)) {
return false;
}
- current = current.getParent();
+ return ancestorsHaveExecutePermissions(fs, current.getParent());
+ }
+
+ /**
+ * Returns true if all ancestors of the specified path have the 'execute'
+ * permission set for all users (i.e. that other users can traverse
+ * the directory heirarchy to the given path)
+ */
+ static boolean ancestorsHaveExecutePermissions(FileSystem fs, Path path)
+ throws IOException {
+ Path current = path;
while (current != null) {
//the subdirs in the path should have execute permissions for others
if (!checkPermissionOfOther(fs, current, FsAction.EXECUTE)) {
@@ -369,6 +379,7 @@
}
return true;
}
+
/**
* Checks for a given path whether the Other permissions on it
* imply the permission in the passed FsAction
diff --git a/src/test/mapred/org/apache/hadoop/mapreduce/filecache/TestTrackerDistributedCacheManager.java b/src/test/mapred/org/apache/hadoop/mapreduce/filecache/TestTrackerDistributedCacheManager.java
index 1686660..6fa540e 100644
--- a/src/test/mapred/org/apache/hadoop/mapreduce/filecache/TestTrackerDistributedCacheManager.java
+++ b/src/test/mapred/org/apache/hadoop/mapreduce/filecache/TestTrackerDistributedCacheManager.java
@@ -87,6 +87,19 @@
TEST_ROOT.mkdirs();
}
+ conf = new Configuration();
+ conf.set(FileSystem.FS_DEFAULT_NAME_KEY, "file:///");
+ fs = FileSystem.get(conf);
+
+ // This test suite will fail if any ancestor directory of the
+ // test directory is not world-searchable (ie +x).
+ // We prefer to fail the test in an obvious manner up front
+ // during setUp() rather than in a subtle way later.
+ assertTrue("Test root directory " + TEST_ROOT + " and all of its " +
+ "parent directories must have a+x permissions",
+ TrackerDistributedCacheManager.ancestorsHaveExecutePermissions(
+ fs, new Path(TEST_ROOT.toString())));
+
// Prepare the tests' mapred-local-dir
ROOT_MAPRED_LOCAL_DIR = new File(TEST_ROOT_DIR, "mapred/local");
ROOT_MAPRED_LOCAL_DIR.mkdirs();
@@ -98,10 +111,7 @@
localDir.mkdir();
}
- conf = new Configuration();
conf.setStrings(MRConfig.LOCAL_DIR, localDirs);
- conf.set(FileSystem.FS_DEFAULT_NAME_KEY, "file:///");
- fs = FileSystem.get(conf);
Class<? extends TaskController> taskControllerClass = conf.getClass(
TTConfig.TT_TASK_CONTROLLER, DefaultTaskController.class,
TaskController.class);