Return-Path: X-Original-To: apmail-hadoop-common-commits-archive@www.apache.org Delivered-To: apmail-hadoop-common-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 2E9F9607D for ; Wed, 1 Jun 2011 03:27:50 +0000 (UTC) Received: (qmail 24564 invoked by uid 500); 1 Jun 2011 03:27:49 -0000 Delivered-To: apmail-hadoop-common-commits-archive@hadoop.apache.org Received: (qmail 24534 invoked by uid 500); 1 Jun 2011 03:27:48 -0000 Mailing-List: contact common-commits-help@hadoop.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: common-dev@hadoop.apache.org Delivered-To: mailing list common-commits@hadoop.apache.org Received: (qmail 24516 invoked by uid 99); 1 Jun 2011 03:27:47 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 01 Jun 2011 03:27:47 +0000 X-ASF-Spam-Status: No, hits=-1998.0 required=5.0 tests=ALL_TRUSTED,FB_GET_MEDS X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 01 Jun 2011 03:27:44 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 8ED9923889F7; Wed, 1 Jun 2011 03:27:24 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1129989 - in /hadoop/common/trunk: ./ src/java/org/apache/hadoop/fs/ src/java/org/apache/hadoop/fs/shell/ src/java/org/apache/hadoop/fs/viewfs/ src/test/core/org/apache/hadoop/fs/ src/test/core/org/apache/hadoop/fs/viewfs/ Date: Wed, 01 Jun 2011 03:27:24 -0000 To: common-commits@hadoop.apache.org From: sradia@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20110601032724.8ED9923889F7@eris.apache.org> Author: sradia Date: Wed Jun 1 03:27:23 2011 New Revision: 1129989 URL: http://svn.apache.org/viewvc?rev=1129989&view=rev Log: HADOOP-7284 Trash and shell's rm does not work for viewfs Added: hadoop/common/trunk/src/test/core/org/apache/hadoop/fs/viewfs/TestViewFsTrash.java Modified: hadoop/common/trunk/CHANGES.txt hadoop/common/trunk/src/java/org/apache/hadoop/fs/Trash.java hadoop/common/trunk/src/java/org/apache/hadoop/fs/shell/Delete.java hadoop/common/trunk/src/java/org/apache/hadoop/fs/viewfs/ChRootedFileSystem.java hadoop/common/trunk/src/java/org/apache/hadoop/fs/viewfs/ConfigUtil.java hadoop/common/trunk/src/java/org/apache/hadoop/fs/viewfs/Constants.java hadoop/common/trunk/src/java/org/apache/hadoop/fs/viewfs/InodeTree.java hadoop/common/trunk/src/java/org/apache/hadoop/fs/viewfs/ViewFileSystem.java hadoop/common/trunk/src/java/org/apache/hadoop/fs/viewfs/ViewFs.java hadoop/common/trunk/src/test/core/org/apache/hadoop/fs/TestTrash.java hadoop/common/trunk/src/test/core/org/apache/hadoop/fs/viewfs/TestChRootedFileSystem.java hadoop/common/trunk/src/test/core/org/apache/hadoop/fs/viewfs/TestChRootedFs.java hadoop/common/trunk/src/test/core/org/apache/hadoop/fs/viewfs/TestFSMainOperationsLocalFileSystem.java hadoop/common/trunk/src/test/core/org/apache/hadoop/fs/viewfs/ViewFileSystemTestSetup.java Modified: hadoop/common/trunk/CHANGES.txt URL: http://svn.apache.org/viewvc/hadoop/common/trunk/CHANGES.txt?rev=1129989&r1=1129988&r2=1129989&view=diff ============================================================================== --- hadoop/common/trunk/CHANGES.txt (original) +++ hadoop/common/trunk/CHANGES.txt Wed Jun 1 03:27:23 2011 @@ -264,6 +264,8 @@ Trunk (unreleased changes) HADOOP-7336. TestFileContextResolveAfs will fail with default test.build.data property. (jitendra) + HADOOP-7284 Trash and shell's rm does not work for viewfs (Sanjay Radia) + Release 0.22.0 - Unreleased INCOMPATIBLE CHANGES Modified: hadoop/common/trunk/src/java/org/apache/hadoop/fs/Trash.java URL: http://svn.apache.org/viewvc/hadoop/common/trunk/src/java/org/apache/hadoop/fs/Trash.java?rev=1129989&r1=1129988&r2=1129989&view=diff ============================================================================== --- hadoop/common/trunk/src/java/org/apache/hadoop/fs/Trash.java (original) +++ hadoop/common/trunk/src/java/org/apache/hadoop/fs/Trash.java Wed Jun 1 03:27:23 2011 @@ -17,6 +17,11 @@ */ package org.apache.hadoop.fs; +import static org.apache.hadoop.fs.CommonConfigurationKeysPublic.FS_TRASH_CHECKPOINT_INTERVAL_DEFAULT; +import static org.apache.hadoop.fs.CommonConfigurationKeysPublic.FS_TRASH_CHECKPOINT_INTERVAL_KEY; +import static org.apache.hadoop.fs.CommonConfigurationKeysPublic.FS_TRASH_INTERVAL_DEFAULT; +import static org.apache.hadoop.fs.CommonConfigurationKeysPublic.FS_TRASH_INTERVAL_KEY; + import java.io.FileNotFoundException; import java.io.IOException; import java.text.DateFormat; @@ -30,7 +35,6 @@ import org.apache.hadoop.classification. import org.apache.hadoop.classification.InterfaceStability; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configured; -import static org.apache.hadoop.fs.CommonConfigurationKeys.*; import org.apache.hadoop.fs.permission.FsAction; import org.apache.hadoop.fs.permission.FsPermission; import org.apache.hadoop.util.StringUtils; @@ -86,7 +90,31 @@ public class Trash extends Configured { FS_TRASH_INTERVAL_DEFAULT) * MSECS_PER_MINUTE); } - + + /** + * In case of the symlinks or mount points, one has to move the appropriate + * trashbin in the actual volume of the path p being deleted. + * + * Hence we get the file system of the fully-qualified resolved-path and + * then move the path p to the trashbin in that volume, + * @param fs - the filesystem of path p + * @param p - the path being deleted - to be moved to trasg + * @param conf - configuration + * @return false if the item is already in the trash or trash is disabled + * @throws IOException on error + */ + public static boolean moveToAppropriateTrash(FileSystem fs, Path p, + Configuration conf) throws IOException { + Path fullyResolvedPath = fs.resolvePath(p); + Trash trash = new Trash(FileSystem.get(fullyResolvedPath.toUri(), conf), conf); + boolean success = trash.moveToTrash(fullyResolvedPath); + if (success) { + System.out.println("Moved: '" + p + "' to trash at: " + + trash.getCurrentTrashDir() ); + } + return success; + } + private Trash(Path home, Configuration conf) throws IOException { super(conf); this.fs = home.getFileSystem(conf); @@ -122,7 +150,7 @@ public class Trash extends Configured { if (!fs.exists(path)) // check that path exists throw new FileNotFoundException(path.toString()); - String qpath = path.makeQualified(fs).toString(); + String qpath = fs.makeQualified(path).toString(); if (qpath.startsWith(trash.toString())) { return false; // already in trash Modified: hadoop/common/trunk/src/java/org/apache/hadoop/fs/shell/Delete.java URL: http://svn.apache.org/viewvc/hadoop/common/trunk/src/java/org/apache/hadoop/fs/shell/Delete.java?rev=1129989&r1=1129988&r2=1129989&view=diff ============================================================================== --- hadoop/common/trunk/src/java/org/apache/hadoop/fs/shell/Delete.java (original) +++ hadoop/common/trunk/src/java/org/apache/hadoop/fs/shell/Delete.java Wed Jun 1 03:27:23 2011 @@ -74,7 +74,6 @@ class Delete extends FsCommand { // etc), then the path will just be deleted because moveToTrash returns // false and it falls thru to fs.delete. this doesn't seem right if (moveToTrash(item)) { - out.println("Moved to trash: " + item); return; } if (!item.fs.delete(item.path, deleteDirs)) { @@ -86,8 +85,7 @@ class Delete extends FsCommand { private boolean moveToTrash(PathData item) throws IOException { boolean success = false; if (!skipTrash) { - Trash trash = new Trash(item.fs, getConf()); - success = (trash.isEnabled() && trash.moveToTrash(item.path)); + success = Trash.moveToAppropriateTrash(item.fs, item.path, getConf()); } return success; } Modified: hadoop/common/trunk/src/java/org/apache/hadoop/fs/viewfs/ChRootedFileSystem.java URL: http://svn.apache.org/viewvc/hadoop/common/trunk/src/java/org/apache/hadoop/fs/viewfs/ChRootedFileSystem.java?rev=1129989&r1=1129988&r2=1129989&view=diff ============================================================================== --- hadoop/common/trunk/src/java/org/apache/hadoop/fs/viewfs/ChRootedFileSystem.java (original) +++ hadoop/common/trunk/src/java/org/apache/hadoop/fs/viewfs/ChRootedFileSystem.java Wed Jun 1 03:27:23 2011 @@ -116,8 +116,7 @@ class ChRootedFileSystem extends FileSys chRootPathPart.toString().substring(1)); workingDir = getHomeDirectory(); - // We don't use the wd of the myFs, (lets set it to root anyway) - myFs.setWorkingDirectory(chRootPathPart); + // We don't use the wd of the myFs } /** Modified: hadoop/common/trunk/src/java/org/apache/hadoop/fs/viewfs/ConfigUtil.java URL: http://svn.apache.org/viewvc/hadoop/common/trunk/src/java/org/apache/hadoop/fs/viewfs/ConfigUtil.java?rev=1129989&r1=1129988&r2=1129989&view=diff ============================================================================== --- hadoop/common/trunk/src/java/org/apache/hadoop/fs/viewfs/ConfigUtil.java (original) +++ hadoop/common/trunk/src/java/org/apache/hadoop/fs/viewfs/ConfigUtil.java Wed Jun 1 03:27:23 2011 @@ -67,4 +67,51 @@ public class ConfigUtil { addLink( conf, Constants.CONFIG_VIEWFS_DEFAULT_MOUNT_TABLE, src, target); } + + /** + * Add config variable for homedir for default mount table + * @param conf - add to this conf + * @param homedir - the home dir path starting with slash + */ + public static void setHomeDirConf(final Configuration conf, + final String homedir) { + setHomeDirConf( conf, + Constants.CONFIG_VIEWFS_DEFAULT_MOUNT_TABLE, homedir); + } + + /** + * Add config variable for homedir the specified mount table + * @param conf - add to this conf + * @param homedir - the home dir path starting with slash + */ + public static void setHomeDirConf(final Configuration conf, + final String mountTableName, final String homedir) { + if (!homedir.startsWith("/")) { + throw new IllegalArgumentException("Home dir should start with /:" + + homedir); + } + conf.set(getConfigViewFsPrefix(mountTableName) + "." + + Constants.CONFIG_VIEWFS_HOMEDIR, homedir); + } + + /** + * Get the value of the home dir conf value for default mount table + * @param conf - from this conf + * @return home dir value, null if variable is not in conf + */ + public static String getHomeDirValue(final Configuration conf) { + return getHomeDirValue(conf, Constants.CONFIG_VIEWFS_DEFAULT_MOUNT_TABLE); + } + + /** + * Get the value of the home dir conf value for specfied mount table + * @param conf - from this conf + * @param mountTableName - the mount table + * @return home dir value, null if variable is not in conf + */ + public static String getHomeDirValue(final Configuration conf, + final String mountTableName) { + return conf.get(getConfigViewFsPrefix(mountTableName) + "." + + Constants.CONFIG_VIEWFS_HOMEDIR); + } } Modified: hadoop/common/trunk/src/java/org/apache/hadoop/fs/viewfs/Constants.java URL: http://svn.apache.org/viewvc/hadoop/common/trunk/src/java/org/apache/hadoop/fs/viewfs/Constants.java?rev=1129989&r1=1129988&r2=1129989&view=diff ============================================================================== --- hadoop/common/trunk/src/java/org/apache/hadoop/fs/viewfs/Constants.java (original) +++ hadoop/common/trunk/src/java/org/apache/hadoop/fs/viewfs/Constants.java Wed Jun 1 03:27:23 2011 @@ -30,6 +30,12 @@ public interface Constants { * Prefix for the config variable prefix for the ViewFs mount-table */ public static final String CONFIG_VIEWFS_PREFIX = "fs.viewfs.mounttable"; + + /** + * Prefix for the home dir for the mount table - if not specified + * then the hadoop default value (/user) is used. + */ + public static final String CONFIG_VIEWFS_HOMEDIR = "homedir"; /** * Config variable name for the default mount table. Modified: hadoop/common/trunk/src/java/org/apache/hadoop/fs/viewfs/InodeTree.java URL: http://svn.apache.org/viewvc/hadoop/common/trunk/src/java/org/apache/hadoop/fs/viewfs/InodeTree.java?rev=1129989&r1=1129988&r2=1129989&view=diff ============================================================================== --- hadoop/common/trunk/src/java/org/apache/hadoop/fs/viewfs/InodeTree.java (original) +++ hadoop/common/trunk/src/java/org/apache/hadoop/fs/viewfs/InodeTree.java Wed Jun 1 03:27:23 2011 @@ -62,6 +62,8 @@ abstract class InodeTree { final INodeDir root; // the root of the mount table + final String homedirPrefix; // the homedir config value for this mount table + List> mountPoints = new ArrayList>(); @@ -298,6 +300,7 @@ abstract class InodeTree { if (vName == null) { vName = Constants.CONFIG_VIEWFS_DEFAULT_MOUNT_TABLE; } + homedirPrefix = ConfigUtil.getHomeDirValue(config, vName); root = new INodeDir("/", UserGroupInformation.getCurrentUser()); root.InodeDirFs = getTargetFileSystem(root); root.isRoot = true; @@ -319,6 +322,9 @@ abstract class InodeTree { } else if (src.startsWith(linkMergePrefix)) { // A merge link isMergeLink = true; src = src.substring(linkMergePrefix.length()); + } else if (src.startsWith(Constants.CONFIG_VIEWFS_HOMEDIR)) { + // ignore - we set home dir from config + continue; } else { throw new IOException( "ViewFs: Cannot initialize: Invalid entry in Mount table in config: "+ @@ -442,4 +448,13 @@ abstract class InodeTree { List> getMountPoints() { return mountPoints; } + + /** + * + * @return home dir value from mount table; null if no config value + * was found. + */ + String getHomeDirPrefixValue() { + return homedirPrefix; + } } Modified: hadoop/common/trunk/src/java/org/apache/hadoop/fs/viewfs/ViewFileSystem.java URL: http://svn.apache.org/viewvc/hadoop/common/trunk/src/java/org/apache/hadoop/fs/viewfs/ViewFileSystem.java?rev=1129989&r1=1129988&r2=1129989&view=diff ============================================================================== --- hadoop/common/trunk/src/java/org/apache/hadoop/fs/viewfs/ViewFileSystem.java (original) +++ hadoop/common/trunk/src/java/org/apache/hadoop/fs/viewfs/ViewFileSystem.java Wed Jun 1 03:27:23 2011 @@ -90,6 +90,7 @@ public class ViewFileSystem extends File private Path workingDir; Configuration config; InodeTree fsState; // the fs state; ie the mount table + Path homeDir = null; /** * Prohibits names which contain a ".", "..", ":" or "/" @@ -157,8 +158,6 @@ public class ViewFileSystem extends File final String authority = theUri.getAuthority(); try { myUri = new URI(FsConstants.VIEWFS_SCHEME, authority, "/", null, null); - workingDir = - this.makeQualified(new Path("/user/" + ugi.getShortUserName())); fsState = new InodeTree(conf, authority) { @Override @@ -184,6 +183,7 @@ public class ViewFileSystem extends File // return MergeFs.createMergeFs(mergeFsURIList, config); } }; + workingDir = this.getHomeDirectory(); } catch (URISyntaxException e) { throw new IOException("URISyntax exception: " + theUri); } @@ -235,6 +235,19 @@ public class ViewFileSystem extends File } @Override + public Path getHomeDirectory() { + if (homeDir == null) { + String base = fsState.getHomeDirPrefixValue(); + if (base == null) { + base = "/user"; + } + homeDir = + this.makeQualified(new Path(base + "/" + ugi.getShortUserName())); + } + return homeDir; + } + + @Override public Path getWorkingDirectory() { return workingDir; } Modified: hadoop/common/trunk/src/java/org/apache/hadoop/fs/viewfs/ViewFs.java URL: http://svn.apache.org/viewvc/hadoop/common/trunk/src/java/org/apache/hadoop/fs/viewfs/ViewFs.java?rev=1129989&r1=1129988&r2=1129989&view=diff ============================================================================== --- hadoop/common/trunk/src/java/org/apache/hadoop/fs/viewfs/ViewFs.java (original) +++ hadoop/common/trunk/src/java/org/apache/hadoop/fs/viewfs/ViewFs.java Wed Jun 1 03:27:23 2011 @@ -146,6 +146,7 @@ public class ViewFs extends AbstractFile final UserGroupInformation ugi; // the user/group of user who created mtable final Configuration config; InodeTree fsState; // the fs state; ie the mount table + Path homeDir = null; static AccessControlException readOnlyMountTable(final String operation, final String p) { @@ -235,6 +236,19 @@ public class ViewFs extends AbstractFile } @Override + public Path getHomeDirectory() { + if (homeDir == null) { + String base = fsState.getHomeDirPrefixValue(); + if (base == null) { + base = "/user"; + } + homeDir = + this.makeQualified(new Path(base + "/" + ugi.getShortUserName())); + } + return homeDir; + } + + @Override public Path resolvePath(final Path f) throws FileNotFoundException, AccessControlException, UnresolvedLinkException, IOException { final InodeTree.ResolveResult res; Modified: hadoop/common/trunk/src/test/core/org/apache/hadoop/fs/TestTrash.java URL: http://svn.apache.org/viewvc/hadoop/common/trunk/src/test/core/org/apache/hadoop/fs/TestTrash.java?rev=1129989&r1=1129988&r2=1129989&view=diff ============================================================================== --- hadoop/common/trunk/src/test/core/org/apache/hadoop/fs/TestTrash.java (original) +++ hadoop/common/trunk/src/test/core/org/apache/hadoop/fs/TestTrash.java Wed Jun 1 03:27:23 2011 @@ -24,7 +24,6 @@ import java.io.DataOutputStream; import java.io.File; import java.io.IOException; import java.net.URI; -import java.util.Arrays; import java.util.HashSet; import java.util.Set; @@ -57,10 +56,10 @@ public class TestTrash extends TestCase } // check that the specified file is in Trash - protected static void checkTrash(FileSystem fs, Path trashRoot, + protected static void checkTrash(FileSystem trashFs, Path trashRoot, Path path) throws IOException { Path p = new Path(trashRoot+"/"+ path.toUri().getPath()); - assertTrue(fs.exists(p)); + assertTrue("Could not find file in trash: "+ p , trashFs.exists(p)); } // counts how many instances of the file are in the Trash @@ -89,11 +88,33 @@ public class TestTrash extends TestCase Path p = new Path(trashRoot+"/"+ new Path(pathname).getName()); assertTrue(!fs.exists(p)); } - + + /** + * Test trash for the shell's delete command for the file system fs + * @param fs + * @param base - the base path where files are created + * @throws IOException + */ protected static void trashShell(final FileSystem fs, final Path base) - throws IOException { + throws IOException { Configuration conf = new Configuration(); - conf.set("fs.default.name", fs.getUri().toString()); + conf.set("fs.defaultFS", fs.getUri().toString()); + trashShell(conf, base, null, null); + } + + /** + * + * Test trash for the shell's delete command for the default file system + * specified in the paramter conf + * @param conf + * @param base - the base path where files are created + * @param trashRoot - the expected place where the trashbin resides + * @throws IOException + */ + public static void trashShell(final Configuration conf, final Path base, + FileSystem trashRootFs, Path trashRoot) + throws IOException { + FileSystem fs = FileSystem.get(conf); conf.set(FS_TRASH_INTERVAL_KEY, "0"); // disabled assertFalse(new Trash(conf).isEnabled()); @@ -103,7 +124,12 @@ public class TestTrash extends TestCase FsShell shell = new FsShell(); shell.setConf(conf); - Path trashRoot = null; + if (trashRoot == null) { + trashRoot = shell.getCurrentTrashDir(); + } + if (trashRootFs == null) { + trashRootFs = fs; + } // First create a new directory with mkdirs Path myPath = new Path(base, "test/mkdirs"); @@ -143,8 +169,8 @@ public class TestTrash extends TestCase } assertTrue(val == 0); - trashRoot = shell.getCurrentTrashDir(); - checkTrash(fs, trashRoot, myFile); + + checkTrash(trashRootFs, trashRoot, fs.makeQualified(myFile)); } // Verify that we can recreate the file @@ -206,7 +232,7 @@ public class TestTrash extends TestCase { Path toErase = new Path(trashRoot, "toErase"); int retVal = -1; - writeFile(fs, toErase); + writeFile(trashRootFs, toErase); try { retVal = shell.run(new String[] {"-rm", toErase.toString()}); } catch (Exception e) { @@ -214,8 +240,8 @@ public class TestTrash extends TestCase e.getLocalizedMessage()); } assertTrue(retVal == 0); - checkNotInTrash (fs, trashRoot, toErase.toString()); - checkNotInTrash (fs, trashRoot, toErase.toString()+".1"); + checkNotInTrash (trashRootFs, trashRoot, toErase.toString()); + checkNotInTrash (trashRootFs, trashRoot, toErase.toString()+".1"); } // simulate Trash removal @@ -233,7 +259,7 @@ public class TestTrash extends TestCase } // verify that after expunging the Trash, it really goes away - checkNotInTrash(fs, trashRoot, new Path(base, "test/mkdirs/myFile").toString()); + checkNotInTrash(trashRootFs, trashRoot, new Path(base, "test/mkdirs/myFile").toString()); // recreate directory and file mkdir(fs, myPath); @@ -252,7 +278,7 @@ public class TestTrash extends TestCase e.getLocalizedMessage()); } assertTrue(val == 0); - checkTrash(fs, trashRoot, myFile); + checkTrash(trashRootFs, trashRoot, myFile); args = new String[2]; args[0] = "-rmr"; @@ -265,7 +291,7 @@ public class TestTrash extends TestCase e.getLocalizedMessage()); } assertTrue(val == 0); - checkTrash(fs, trashRoot, myPath); + checkTrash(trashRootFs, trashRoot, myPath); } // attempt to remove parent of trash @@ -281,7 +307,7 @@ public class TestTrash extends TestCase e.getLocalizedMessage()); } assertEquals("exit code", 1, val); - assertTrue(fs.exists(trashRoot)); + assertTrue(trashRootFs.exists(trashRoot)); } // Verify skip trash option really works @@ -299,7 +325,8 @@ public class TestTrash extends TestCase int val = -1; try { // Clear out trash - assertEquals(0, shell.run(new String [] { "-expunge" } )); + assertEquals("-expunge failed", + 0, shell.run(new String [] { "-expunge" } )); val = shell.run(args); @@ -307,7 +334,10 @@ public class TestTrash extends TestCase System.err.println("Exception raised from Trash.run " + e.getLocalizedMessage()); } - assertFalse(fs.exists(trashRoot)); // No new Current should be created + assertFalse("Expected TrashRoot (" + trashRoot + + ") to exist in file system:" + + trashRootFs.getUri(), + trashRootFs.exists(trashRoot)); // No new Current should be created assertFalse(fs.exists(myFile)); assertTrue(val == 0); } @@ -335,7 +365,7 @@ public class TestTrash extends TestCase e.getLocalizedMessage()); } - assertFalse(fs.exists(trashRoot)); // No new Current should be created + assertFalse(trashRootFs.exists(trashRoot)); // No new Current should be created assertFalse(fs.exists(myPath)); assertFalse(fs.exists(myFile)); assertTrue(val == 0); @@ -420,7 +450,7 @@ public class TestTrash extends TestCase public void testNonDefaultFS() throws IOException { Configuration conf = new Configuration(); conf.setClass("fs.file.impl", TestLFS.class, FileSystem.class); - conf.set("fs.default.name", "invalid://host/bar/foo"); + conf.set("fs.defaultFS", "invalid://host/bar/foo"); trashNonDefaultFS(conf); } @@ -438,7 +468,7 @@ public class TestTrash extends TestCase emptierThread.start(); FileSystem fs = FileSystem.getLocal(conf); - conf.set("fs.default.name", fs.getUri().toString()); + conf.set("fs.defaultFS", fs.getUri().toString()); FsShell shell = new FsShell(); shell.setConf(conf); shell.init(); @@ -521,7 +551,7 @@ public class TestTrash extends TestCase conf.setClass("fs.file.impl", TestLFS.class, FileSystem.class); FileSystem fs = FileSystem.getLocal(conf); - conf.set("fs.default.name", fs.getUri().toString()); + conf.set("fs.defaultFS", fs.getUri().toString()); conf.set(FS_TRASH_INTERVAL_KEY, "10"); //minutes.. FsShell shell = new FsShell(); shell.setConf(conf); Modified: hadoop/common/trunk/src/test/core/org/apache/hadoop/fs/viewfs/TestChRootedFileSystem.java URL: http://svn.apache.org/viewvc/hadoop/common/trunk/src/test/core/org/apache/hadoop/fs/viewfs/TestChRootedFileSystem.java?rev=1129989&r1=1129988&r2=1129989&view=diff ============================================================================== --- hadoop/common/trunk/src/test/core/org/apache/hadoop/fs/viewfs/TestChRootedFileSystem.java (original) +++ hadoop/common/trunk/src/test/core/org/apache/hadoop/fs/viewfs/TestChRootedFileSystem.java Wed Jun 1 03:27:23 2011 @@ -17,6 +17,7 @@ */ package org.apache.hadoop.fs.viewfs; +import java.io.FileNotFoundException; import java.io.IOException; import java.net.URI; @@ -287,5 +288,21 @@ public class TestChRootedFileSystem { Assert.assertEquals(absoluteDir, fSys.getWorkingDirectory()); } - + + /* + * Test resolvePath(p) + */ + + @Test + public void testResolvePath() throws IOException { + Assert.assertEquals(chrootedTo, fSys.resolvePath(new Path("/"))); + FileSystemTestHelper.createFile(fSys, "/foo"); + Assert.assertEquals(new Path(chrootedTo, "foo"), + fSys.resolvePath(new Path("/foo"))); + } + + @Test(expected=FileNotFoundException.class) + public void testResolvePathNonExisting() throws IOException { + fSys.resolvePath(new Path("/nonExisting")); + } } Modified: hadoop/common/trunk/src/test/core/org/apache/hadoop/fs/viewfs/TestChRootedFs.java URL: http://svn.apache.org/viewvc/hadoop/common/trunk/src/test/core/org/apache/hadoop/fs/viewfs/TestChRootedFs.java?rev=1129989&r1=1129988&r2=1129989&view=diff ============================================================================== --- hadoop/common/trunk/src/test/core/org/apache/hadoop/fs/viewfs/TestChRootedFs.java (original) +++ hadoop/common/trunk/src/test/core/org/apache/hadoop/fs/viewfs/TestChRootedFs.java Wed Jun 1 03:27:23 2011 @@ -17,6 +17,7 @@ */ package org.apache.hadoop.fs.viewfs; +import java.io.FileNotFoundException; import java.io.IOException; import java.net.URI; import java.util.EnumSet; @@ -288,5 +289,22 @@ public class TestChRootedFs { Assert.assertEquals(absoluteDir, fc.getWorkingDirectory()); } + + /* + * Test resolvePath(p) + */ + + @Test + public void testResolvePath() throws IOException { + Assert.assertEquals(chrootedTo, fc.getDefaultFileSystem().resolvePath(new Path("/"))); + FileContextTestHelper.createFile(fc, "/foo"); + Assert.assertEquals(new Path(chrootedTo, "foo"), + fc.getDefaultFileSystem().resolvePath(new Path("/foo"))); + } + + @Test(expected=FileNotFoundException.class) + public void testResolvePathNonExisting() throws IOException { + fc.getDefaultFileSystem().resolvePath(new Path("/nonExisting")); + } } Modified: hadoop/common/trunk/src/test/core/org/apache/hadoop/fs/viewfs/TestFSMainOperationsLocalFileSystem.java URL: http://svn.apache.org/viewvc/hadoop/common/trunk/src/test/core/org/apache/hadoop/fs/viewfs/TestFSMainOperationsLocalFileSystem.java?rev=1129989&r1=1129988&r2=1129989&view=diff ============================================================================== --- hadoop/common/trunk/src/test/core/org/apache/hadoop/fs/viewfs/TestFSMainOperationsLocalFileSystem.java (original) +++ hadoop/common/trunk/src/test/core/org/apache/hadoop/fs/viewfs/TestFSMainOperationsLocalFileSystem.java Wed Jun 1 03:27:23 2011 @@ -37,7 +37,8 @@ public class TestFSMainOperationsLocalFi public void setUp() throws Exception { Configuration conf = new Configuration(); fcTarget = FileSystem.getLocal(conf); - fSys = ViewFileSystemTestSetup.setupForViewFs(fcTarget); + fSys = ViewFileSystemTestSetup.setupForViewFs( + ViewFileSystemTestSetup.configWithViewfsScheme(), fcTarget); super.setUp(); } Added: hadoop/common/trunk/src/test/core/org/apache/hadoop/fs/viewfs/TestViewFsTrash.java URL: http://svn.apache.org/viewvc/hadoop/common/trunk/src/test/core/org/apache/hadoop/fs/viewfs/TestViewFsTrash.java?rev=1129989&view=auto ============================================================================== --- hadoop/common/trunk/src/test/core/org/apache/hadoop/fs/viewfs/TestViewFsTrash.java (added) +++ hadoop/common/trunk/src/test/core/org/apache/hadoop/fs/viewfs/TestViewFsTrash.java Wed Jun 1 03:27:23 2011 @@ -0,0 +1,112 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.hadoop.fs.viewfs; + + +import java.io.IOException; + +import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.fs.FileSystem; +import org.apache.hadoop.fs.FileSystemTestHelper; +import org.apache.hadoop.fs.FsConstants; +import org.apache.hadoop.fs.LocalFileSystem; +import org.apache.hadoop.fs.Path; +import org.apache.hadoop.fs.TestTrash; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.mortbay.log.Log; + +public class TestViewFsTrash { + FileSystem fsTarget; // the target file system - the mount will point here + FileSystem fsView; + Path targetTestRoot; + Configuration conf; + + static class TestLFS extends LocalFileSystem { + Path home; + TestLFS() throws IOException { + this(new Path(FileSystemTestHelper.TEST_ROOT_DIR)); + } + TestLFS(Path home) throws IOException { + super(); + this.home = home; + } + public Path getHomeDirectory() { + return home; + } + } + + @Before + public void setUp() throws Exception { + fsTarget = FileSystem.getLocal(new Configuration()); + targetTestRoot = FileSystemTestHelper.getAbsoluteTestRootPath(fsTarget); + // In case previous test was killed before cleanup + fsTarget.delete(targetTestRoot, true); + // cleanup trash from previous run if it stuck around + fsTarget.delete(new Path(fsTarget.getHomeDirectory(), ".Trash/Current"), + true); + + fsTarget.mkdirs(targetTestRoot); + fsTarget.mkdirs(new Path(targetTestRoot,"dir1")); + + + // Now we use the mount fs to set links to user and dir + // in the test root + + // Set up the defaultMT in the config with our mount point links + + + conf = ViewFileSystemTestSetup.configWithViewfsScheme(); + + // create a link for home directory so that trash path works + // set up viewfs's home dir root to point to home dir root on target + // But home dir is different on linux, mac etc. + // Figure it out by calling home dir on target + + String homeDir = fsTarget.getHomeDirectory().toUri().getPath(); + int indexOf2ndSlash = homeDir.indexOf('/', 1); + String homeDirRoot = homeDir.substring(0, indexOf2ndSlash); + ConfigUtil.addLink(conf, homeDirRoot, + fsTarget.makeQualified(new Path(homeDirRoot)).toUri()); + ConfigUtil.setHomeDirConf(conf, homeDirRoot); + Log.info("Home dir base " + homeDirRoot); + + fsView = ViewFileSystemTestSetup.setupForViewFs(conf, fsTarget); + + // set working dir so that relative paths + //fsView.setWorkingDirectory(new Path(fsTarget.getWorkingDirectory().toUri().getPath())); + conf.set("fs.defaultFS", FsConstants.VIEWFS_URI.toString()); + } + + + @After + public void tearDown() throws Exception { + fsTarget.delete(targetTestRoot, true); + fsTarget.delete(new Path(fsTarget.getHomeDirectory(), ".Trash/Current"), + true); + } + + + @Test + public void testTrash() throws IOException { + TestTrash.trashShell(conf, FileSystemTestHelper.getTestRootPath(fsView), + fsTarget, new Path(fsTarget.getHomeDirectory(), ".Trash/Current")); + } + +} Modified: hadoop/common/trunk/src/test/core/org/apache/hadoop/fs/viewfs/ViewFileSystemTestSetup.java URL: http://svn.apache.org/viewvc/hadoop/common/trunk/src/test/core/org/apache/hadoop/fs/viewfs/ViewFileSystemTestSetup.java?rev=1129989&r1=1129988&r2=1129989&view=diff ============================================================================== --- hadoop/common/trunk/src/test/core/org/apache/hadoop/fs/viewfs/ViewFileSystemTestSetup.java (original) +++ hadoop/common/trunk/src/test/core/org/apache/hadoop/fs/viewfs/ViewFileSystemTestSetup.java Wed Jun 1 03:27:23 2011 @@ -32,7 +32,8 @@ import org.apache.hadoop.fs.viewfs.Confi * If tests launched via ant (build.xml) the test root is absolute path * If tests launched via eclipse, the test root is * is a test dir below the working directory. (see FileSystemTestHelper). - * Since viewFs has no built-in wd, its wd is /user/. + * Since viewFs has no built-in wd, its wd is /user/ + * (or /User/ on mac) * * We set a viewFileSystems with mount point for * /" pointing to the target fs's testdir @@ -45,32 +46,28 @@ public class ViewFileSystemTestSetup { * @return return the ViewFS File context to be used for tests * @throws Exception */ - static public FileSystem setupForViewFs(FileSystem fsTarget) throws Exception { + static public FileSystem setupForViewFs(Configuration conf, FileSystem fsTarget) throws Exception { /** * create the test root on local_fs - the mount table will point here */ - Configuration conf = configWithViewfsScheme(); Path targetOfTests = FileSystemTestHelper.getTestRootPath(fsTarget); // In case previous test was killed before cleanup fsTarget.delete(targetOfTests, true); fsTarget.mkdirs(targetOfTests); - String srcTestFirstDir; - if (FileSystemTestHelper.TEST_ROOT_DIR.startsWith("/")) { - int indexOf2ndSlash = FileSystemTestHelper.TEST_ROOT_DIR.indexOf('/', 1); - srcTestFirstDir = FileSystemTestHelper.TEST_ROOT_DIR.substring(0, indexOf2ndSlash); - } else { - srcTestFirstDir = "/user"; - - } - //System.out.println("srcTestFirstDir=" + srcTestFirstDir); - - // Set up the defaultMT in the config with mount point links - // The test dir is root is below /user/ - ConfigUtil.addLink(conf, srcTestFirstDir, - targetOfTests.toUri()); + // Now set up a link from viewfs to targetfs for the first component of + // path of testdir. For example, if testdir is /user//xx then + // a link from /user to targetfs://user. + + String testDir = FileSystemTestHelper.getTestRootPath(fsTarget).toUri().getPath(); + int indexOf2ndSlash = testDir.indexOf('/', 1); + String testDirFirstComponent = testDir.substring(0, indexOf2ndSlash); + + + ConfigUtil.addLink(conf, testDirFirstComponent, + fsTarget.makeQualified(new Path(testDirFirstComponent)).toUri()); FileSystem fsView = FileSystem.get(FsConstants.VIEWFS_URI, conf); //System.out.println("SRCOfTests = "+ getTestRootPath(fs, "test"));