Author: boryas
Date: Mon Jun 7 22:55:13 2010
New Revision: 952471
URL: http://svn.apache.org/viewvc?rev=952471&view=rev
Log:
HADOOP-6813. Add a new newInstance method in FileSystem that takes a user as
argument
Modified:
hadoop/common/trunk/CHANGES.txt
hadoop/common/trunk/src/java/org/apache/hadoop/fs/FileSystem.java
hadoop/common/trunk/src/test/core/org/apache/hadoop/fs/TestFileSystemCaching.java
Modified: hadoop/common/trunk/CHANGES.txt
URL:
http://svn.apache.org/viewvc/hadoop/common/trunk/CHANGES.txt?rev=952471&r1=952470&r2=952471&view=diff
==============================================================================
--- hadoop/common/trunk/CHANGES.txt (original)
+++ hadoop/common/trunk/CHANGES.txt Mon Jun 7 22:55:13 2010
@@ -44,6 +44,9 @@ Trunk (unreleased changes)
HADOOP-6674. Makes use of the SASL authentication options in the
SASL RPC. (Jitendra Pandey via ddas)
+ HADOOP-6813. Add a new newInstance method in FileSystem that takes
+ a "user" as argument (ddas via boryas)
+
BUG FIXES
HADOOP-6638. try to relogin in a case of failed RPC connection (expired
tgt)
only in case the subject is loginUser or proxyUgi.realUser. (boryas)
Modified: hadoop/common/trunk/src/java/org/apache/hadoop/fs/FileSystem.java
URL:
http://svn.apache.org/viewvc/hadoop/common/trunk/src/java/org/apache/hadoop/fs/FileSystem.java?rev=952471&r1=952470&r2=952471&view=diff
==============================================================================
--- hadoop/common/trunk/src/java/org/apache/hadoop/fs/FileSystem.java (original)
+++ hadoop/common/trunk/src/java/org/apache/hadoop/fs/FileSystem.java Mon Jun
7 22:55:13 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<FileSystem>() {
+ 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,
* <tt>fs.<i>scheme</i>.class</tt> whose value names the FileSystem class.
Modified:
hadoop/common/trunk/src/test/core/org/apache/hadoop/fs/TestFileSystemCaching.java
URL:
http://svn.apache.org/viewvc/hadoop/common/trunk/src/test/core/org/apache/hadoop/fs/TestFileSystemCaching.java?rev=952471&r1=952470&r2=952471&view=diff
==============================================================================
---
hadoop/common/trunk/src/test/core/org/apache/hadoop/fs/TestFileSystemCaching.java
(original)
+++
hadoop/common/trunk/src/test/core/org/apache/hadoop/fs/TestFileSystemCaching.java
Mon Jun 7 22:55:13 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();
+ }
}