HADOOP-6769. Add an API in FileSystem to get FileSystem instances based on users
git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@945735 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
175a92850d
commit
759494f3a1
@ -3,6 +3,8 @@ Hadoop Change Log
|
|||||||
Trunk (unreleased changes)
|
Trunk (unreleased changes)
|
||||||
|
|
||||||
IMPROVEMENTS
|
IMPROVEMENTS
|
||||||
|
HADOOP-6769. Add an API in FileSystem to get FileSystem instances based
|
||||||
|
on users(ddas via boryas)
|
||||||
|
|
||||||
HADOOP-6600. mechanism for authorization check for inter-server
|
HADOOP-6600. mechanism for authorization check for inter-server
|
||||||
protocols. (boryas)
|
protocols. (boryas)
|
||||||
|
@ -21,6 +21,7 @@
|
|||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
|
import java.security.PrivilegedExceptionAction;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.EnumSet;
|
import java.util.EnumSet;
|
||||||
@ -96,6 +97,31 @@ public abstract class FileSystem extends Configured implements Closeable {
|
|||||||
*/
|
*/
|
||||||
private Set<Path> deleteOnExit = new TreeSet<Path>();
|
private Set<Path> deleteOnExit = new TreeSet<Path>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a filesystem instance based on the uri, the passed
|
||||||
|
* configuration and the user
|
||||||
|
* @param uri
|
||||||
|
* @param conf
|
||||||
|
* @param user
|
||||||
|
* @return the filesystem instance
|
||||||
|
* @throws IOException
|
||||||
|
* @throws InterruptedException
|
||||||
|
*/
|
||||||
|
public static FileSystem get(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 get(uri, conf);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/** Returns the configured filesystem implementation.*/
|
/** Returns the configured filesystem implementation.*/
|
||||||
public static FileSystem get(Configuration conf) throws IOException {
|
public static FileSystem get(Configuration conf) throws IOException {
|
||||||
return get(getDefaultUri(conf), conf);
|
return get(getDefaultUri(conf), conf);
|
||||||
|
@ -26,6 +26,7 @@
|
|||||||
import java.net.URISyntaxException;
|
import java.net.URISyntaxException;
|
||||||
|
|
||||||
import org.apache.hadoop.conf.Configuration;
|
import org.apache.hadoop.conf.Configuration;
|
||||||
|
import org.apache.hadoop.fs.FileSystem;
|
||||||
import org.apache.hadoop.security.UserGroupInformation;
|
import org.apache.hadoop.security.UserGroupInformation;
|
||||||
import org.apache.hadoop.security.token.Token;
|
import org.apache.hadoop.security.token.Token;
|
||||||
import org.apache.hadoop.security.token.TokenIdentifier;
|
import org.apache.hadoop.security.token.TokenIdentifier;
|
||||||
@ -154,4 +155,13 @@ public FileSystem run() throws Exception {
|
|||||||
assertSame(fsA, fsA1);
|
assertSame(fsA, fsA1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testUserFS() throws Exception {
|
||||||
|
final Configuration conf = new Configuration();
|
||||||
|
|
||||||
|
FileSystem fsU1 = FileSystem.get(new URI("cachedfile://a"), conf, "bar");
|
||||||
|
FileSystem fsU2 = FileSystem.get(new URI("cachedfile://a"), conf, "foo");
|
||||||
|
|
||||||
|
assertNotSame(fsU1, fsU2);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user