Return-Path: Delivered-To: apmail-hadoop-common-commits-archive@www.apache.org Received: (qmail 12195 invoked from network); 11 Jun 2010 21:13:54 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 11 Jun 2010 21:13:54 -0000 Received: (qmail 8957 invoked by uid 500); 11 Jun 2010 21:13:54 -0000 Delivered-To: apmail-hadoop-common-commits-archive@hadoop.apache.org Received: (qmail 8928 invoked by uid 500); 11 Jun 2010 21:13:53 -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 8921 invoked by uid 99); 11 Jun 2010 21:13:53 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 11 Jun 2010 21:13:53 +0000 X-ASF-Spam-Status: No, hits=-1725.0 required=10.0 tests=ALL_TRUSTED,AWL 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; Fri, 11 Jun 2010 21:13:52 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id EB1A023889C5; Fri, 11 Jun 2010 21:13:10 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r953872 - in /hadoop/common/branches/branch-0.21: CHANGES.txt src/java/org/apache/hadoop/fs/FileSystem.java src/test/core/org/apache/hadoop/fs/TestFileSystemCaching.java Date: Fri, 11 Jun 2010 21:13:10 -0000 To: common-commits@hadoop.apache.org From: tomwhite@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20100611211310.EB1A023889C5@eris.apache.org> Author: tomwhite Date: Fri Jun 11 21:13:10 2010 New Revision: 953872 URL: http://svn.apache.org/viewvc?rev=953872&view=rev Log: Merge -r 952470:952471 from trunk to branch-0.21. Fixes: HADOOP-6813 Modified: hadoop/common/branches/branch-0.21/CHANGES.txt hadoop/common/branches/branch-0.21/src/java/org/apache/hadoop/fs/FileSystem.java hadoop/common/branches/branch-0.21/src/test/core/org/apache/hadoop/fs/TestFileSystemCaching.java Modified: hadoop/common/branches/branch-0.21/CHANGES.txt URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-0.21/CHANGES.txt?rev=953872&r1=953871&r2=953872&view=diff ============================================================================== --- hadoop/common/branches/branch-0.21/CHANGES.txt (original) +++ hadoop/common/branches/branch-0.21/CHANGES.txt Fri Jun 11 21:13:10 2010 @@ -861,6 +861,9 @@ Release 0.21.0 - Unreleased HADOOP-6769. Add an API in FileSystem to get FileSystem instances based on users(ddas via boryas) + HADOOP-6813. Add a new newInstance method in FileSystem that takes + a "user" as argument (ddas via boryas) + OPTIMIZATIONS HADOOP-5595. NameNode does not need to run a replicator to choose a Modified: hadoop/common/branches/branch-0.21/src/java/org/apache/hadoop/fs/FileSystem.java URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-0.21/src/java/org/apache/hadoop/fs/FileSystem.java?rev=953872&r1=953871&r2=953872&view=diff ============================================================================== --- hadoop/common/branches/branch-0.21/src/java/org/apache/hadoop/fs/FileSystem.java (original) +++ hadoop/common/branches/branch-0.21/src/java/org/apache/hadoop/fs/FileSystem.java Fri Jun 11 21:13:10 2010 @@ -230,6 +230,30 @@ public abstract class FileSystem extends return CACHE.get(uri, conf); } + /** + * Returns the FileSystem for this URI's scheme and authority and the + * passed user. Internally invokes {@link #newInstance(URI, Configuration)} + * @param uri + * @param conf + * @param user + * @return filesystem instance + * @throws IOException + * @throws InterruptedException + */ + public static FileSystem newInstance(final URI uri, final Configuration conf, + final String user) throws IOException, InterruptedException { + UserGroupInformation ugi; + if (user == null) { + ugi = UserGroupInformation.getCurrentUser(); + } else { + ugi = UserGroupInformation.createRemoteUser(user); + } + return ugi.doAs(new PrivilegedExceptionAction() { + public FileSystem run() throws IOException { + return newInstance(uri,conf); + } + }); + } /** Returns the FileSystem for this URI's scheme and authority. The scheme * of the URI determines a configuration property name, * fs.scheme.class whose value names the FileSystem class. Modified: hadoop/common/branches/branch-0.21/src/test/core/org/apache/hadoop/fs/TestFileSystemCaching.java URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-0.21/src/test/core/org/apache/hadoop/fs/TestFileSystemCaching.java?rev=953872&r1=953871&r2=953872&view=diff ============================================================================== --- hadoop/common/branches/branch-0.21/src/test/core/org/apache/hadoop/fs/TestFileSystemCaching.java (original) +++ hadoop/common/branches/branch-0.21/src/test/core/org/apache/hadoop/fs/TestFileSystemCaching.java Fri Jun 11 21:13:10 2010 @@ -35,7 +35,7 @@ import java.security.PrivilegedException import java.util.concurrent.Semaphore; import static org.mockito.Mockito.mock; - +import static junit.framework.Assert.assertTrue; public class TestFileSystemCaching { @@ -158,10 +158,27 @@ public class TestFileSystemCaching { @Test public void testUserFS() throws Exception { final Configuration conf = new Configuration(); - + conf.set("fs.cachedfile.impl", conf.get("fs.file.impl")); FileSystem fsU1 = FileSystem.get(new URI("cachedfile://a"), conf, "bar"); FileSystem fsU2 = FileSystem.get(new URI("cachedfile://a"), conf, "foo"); assertNotSame(fsU1, fsU2); } + + @Test + public void testFsUniqueness() throws Exception { + final Configuration conf = new Configuration(); + conf.set("fs.cachedfile.impl", conf.get("fs.file.impl")); + // multiple invocations of FileSystem.get return the same object. + FileSystem fs1 = FileSystem.get(conf); + FileSystem fs2 = FileSystem.get(conf); + assertTrue(fs1 == fs2); + + // multiple invocations of FileSystem.newInstance return different objects + fs1 = FileSystem.newInstance(new URI("cachedfile://a"), conf, "bar"); + fs2 = FileSystem.newInstance(new URI("cachedfile://a"), conf, "bar"); + assertTrue(fs1 != fs2 && !fs1.equals(fs2)); + fs1.close(); + fs2.close(); + } }