commit b0f6d612e374dbb1325cd2a4728f6e6ec3273123 Author: Gera Shegalov Date: Thu Dec 26 17:06:19 2013 -0800 YARN-1542.v02 diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/util/TestFSDownload.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/util/TestFSDownload.java index 86909e7..db589b5 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/util/TestFSDownload.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/util/TestFSDownload.java @@ -51,6 +51,7 @@ import org.apache.commons.logging.LogFactory; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.CommonConfigurationKeys; +import org.apache.hadoop.fs.FsConstants; import org.apache.hadoop.fs.FSDataOutputStream; import org.apache.hadoop.fs.FileContext; import org.apache.hadoop.fs.FileStatus; @@ -58,6 +59,7 @@ import org.apache.hadoop.fs.LocalDirAllocator; import org.apache.hadoop.fs.Path; import org.apache.hadoop.fs.permission.FsPermission; +import org.apache.hadoop.fs.viewfs.ConfigUtil; import org.apache.hadoop.security.UserGroupInformation; import org.apache.hadoop.yarn.api.records.LocalResource; import org.apache.hadoop.yarn.api.records.LocalResourceType; @@ -583,4 +585,51 @@ public void testUniqueDestinationPath() throws Exception { // destination directory (passed as an argument) + file name. Assert.assertEquals(destPath, rPath.get().getParent()); } -} \ No newline at end of file + + @Test + public void testViewFsResource() throws Exception { + final Configuration conf = new Configuration(); + final FileContext files = FileContext.getLocalFSFileContext(conf); + final Path basedir = files.makeQualified(new Path("target", + getClass().getSimpleName())); + files.mkdir(basedir, null, true); + conf.setStrings(getClass().getName(), basedir.toString()); + + // create a public cache file + // + final Path cacheDir = new Path(basedir, "public-cache"); + files.mkdir(cacheDir, null, false); + ConfigUtil.addLink(conf, "/pubcache", cacheDir.toUri()); + final FileSystem vfs = FileSystem.get(FsConstants.VIEWFS_URI, conf); + final Path vfsCacheFile = vfs.makeQualified( + new Path("/pubcache/cache.txt")); + final Random rand = new Random(); + final long seed = rand.nextLong(); + rand.setSeed(seed); + System.out.println("SEED: " + seed); + final LocalResource rsrc = + createFile(files, vfsCacheFile, 100, rand, + LocalResourceVisibility.PUBLIC); + + final FsPermission oldPermissions = + files.getFileStatus(cacheDir).getPermission(); + try { + // -x-x-x- + files.setPermission(cacheDir, FsPermission.createImmutable((short) 0111)); + + // set destination path + // + final LocalDirAllocator dirs = new LocalDirAllocator(getClass().getName()); + final Path destPath = dirs.getLocalPathForWrite(basedir.toString(), conf); + final FSDownload fsd = new FSDownload(files, + UserGroupInformation.getCurrentUser(), conf, destPath, rsrc); + fsd.call(); + } finally { + try { + files.setPermission(cacheDir, oldPermissions); + } catch (Throwable t) { + LOG.error(cacheDir + ": Failed to restore default permissions", t); + } + } + } +}