HADOOP-6903 Make AbstractFSileSystem methods and some FileContext methods to be public
git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1034480 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
ca3ef069cb
commit
946eac3dac
|
@ -171,6 +171,10 @@ Trunk (unreleased changes)
|
||||||
HADOOP-7024. Create a test method for adding file systems during tests.
|
HADOOP-7024. Create a test method for adding file systems during tests.
|
||||||
(Kan Zhang via jghoman)
|
(Kan Zhang via jghoman)
|
||||||
|
|
||||||
|
HADOOP-6903 Make AbstractFSileSystem methods and some FileContext methods to be public
|
||||||
|
(Sanjay Radia via Sanjay Radia)
|
||||||
|
|
||||||
|
|
||||||
OPTIMIZATIONS
|
OPTIMIZATIONS
|
||||||
|
|
||||||
HADOOP-6884. Add LOG.isDebugEnabled() guard for each LOG.debug(..).
|
HADOOP-6884. Add LOG.isDebugEnabled() guard for each LOG.debug(..).
|
||||||
|
|
|
@ -25,7 +25,6 @@
|
||||||
import java.net.URISyntaxException;
|
import java.net.URISyntaxException;
|
||||||
import java.util.EnumSet;
|
import java.util.EnumSet;
|
||||||
import java.util.IdentityHashMap;
|
import java.util.IdentityHashMap;
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.NoSuchElementException;
|
import java.util.NoSuchElementException;
|
||||||
import java.util.StringTokenizer;
|
import java.util.StringTokenizer;
|
||||||
|
@ -77,7 +76,7 @@ public abstract class AbstractFileSystem {
|
||||||
|
|
||||||
private final URI myUri;
|
private final URI myUri;
|
||||||
|
|
||||||
protected Statistics getStatistics() {
|
public Statistics getStatistics() {
|
||||||
return statistics;
|
return statistics;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -135,7 +134,7 @@ static <T> T newInstance(Class<T> theClass,
|
||||||
* @throws UnsupportedFileSystemException file system for <code>uri</code> is
|
* @throws UnsupportedFileSystemException file system for <code>uri</code> is
|
||||||
* not found
|
* not found
|
||||||
*/
|
*/
|
||||||
private static AbstractFileSystem createFileSystem(URI uri, Configuration conf)
|
public static AbstractFileSystem createFileSystem(URI uri, Configuration conf)
|
||||||
throws UnsupportedFileSystemException {
|
throws UnsupportedFileSystemException {
|
||||||
Class<?> clazz = conf.getClass("fs.AbstractFileSystem." +
|
Class<?> clazz = conf.getClass("fs.AbstractFileSystem." +
|
||||||
uri.getScheme() + ".impl", null);
|
uri.getScheme() + ".impl", null);
|
||||||
|
@ -152,7 +151,7 @@ private static AbstractFileSystem createFileSystem(URI uri, Configuration conf)
|
||||||
* @param cls the class to lookup
|
* @param cls the class to lookup
|
||||||
* @return a statistics object
|
* @return a statistics object
|
||||||
*/
|
*/
|
||||||
protected static synchronized Statistics getStatistics(String scheme,
|
public static synchronized Statistics getStatistics(String scheme,
|
||||||
Class<? extends AbstractFileSystem> cls) {
|
Class<? extends AbstractFileSystem> cls) {
|
||||||
Statistics result = STATISTICS_TABLE.get(cls);
|
Statistics result = STATISTICS_TABLE.get(cls);
|
||||||
if (result == null) {
|
if (result == null) {
|
||||||
|
@ -162,13 +161,13 @@ protected static synchronized Statistics getStatistics(String scheme,
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static synchronized void clearStatistics() {
|
public static synchronized void clearStatistics() {
|
||||||
for(Statistics stat: STATISTICS_TABLE.values()) {
|
for(Statistics stat: STATISTICS_TABLE.values()) {
|
||||||
stat.reset();
|
stat.reset();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static synchronized void printStatistics() {
|
public static synchronized void printStatistics() {
|
||||||
for (Map.Entry<Class<? extends AbstractFileSystem>, Statistics> pair:
|
for (Map.Entry<Class<? extends AbstractFileSystem>, Statistics> pair:
|
||||||
STATISTICS_TABLE.entrySet()) {
|
STATISTICS_TABLE.entrySet()) {
|
||||||
System.out.println(" FileSystem " + pair.getKey().getName() +
|
System.out.println(" FileSystem " + pair.getKey().getName() +
|
||||||
|
@ -193,7 +192,7 @@ protected static synchronized void printStatistics() {
|
||||||
* @throws UnsupportedFileSystemException if the file system for
|
* @throws UnsupportedFileSystemException if the file system for
|
||||||
* <code>uri</code> is not supported.
|
* <code>uri</code> is not supported.
|
||||||
*/
|
*/
|
||||||
static AbstractFileSystem get(final URI uri, final Configuration conf)
|
public static AbstractFileSystem get(final URI uri, final Configuration conf)
|
||||||
throws UnsupportedFileSystemException {
|
throws UnsupportedFileSystemException {
|
||||||
return createFileSystem(uri, conf);
|
return createFileSystem(uri, conf);
|
||||||
}
|
}
|
||||||
|
@ -208,14 +207,19 @@ static AbstractFileSystem get(final URI uri, final Configuration conf)
|
||||||
*
|
*
|
||||||
* @throws URISyntaxException <code>uri</code> has syntax error
|
* @throws URISyntaxException <code>uri</code> has syntax error
|
||||||
*/
|
*/
|
||||||
protected AbstractFileSystem(final URI uri, final String supportedScheme,
|
public AbstractFileSystem(final URI uri, final String supportedScheme,
|
||||||
final boolean authorityNeeded, final int defaultPort)
|
final boolean authorityNeeded, final int defaultPort)
|
||||||
throws URISyntaxException {
|
throws URISyntaxException {
|
||||||
myUri = getUri(uri, supportedScheme, authorityNeeded, defaultPort);
|
myUri = getUri(uri, supportedScheme, authorityNeeded, defaultPort);
|
||||||
statistics = getStatistics(supportedScheme, getClass());
|
statistics = getStatistics(supportedScheme, getClass());
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void checkScheme(URI uri, String supportedScheme) {
|
/**
|
||||||
|
* Check that the Uri's scheme matches
|
||||||
|
* @param uri
|
||||||
|
* @param supportedScheme
|
||||||
|
*/
|
||||||
|
public void checkScheme(URI uri, String supportedScheme) {
|
||||||
String scheme = uri.getScheme();
|
String scheme = uri.getScheme();
|
||||||
if (scheme == null) {
|
if (scheme == null) {
|
||||||
throw new HadoopIllegalArgumentException("Uri without scheme: " + uri);
|
throw new HadoopIllegalArgumentException("Uri without scheme: " + uri);
|
||||||
|
@ -272,14 +276,14 @@ private URI getUri(URI uri, String supportedScheme,
|
||||||
* @return default port of this file system's Uri scheme
|
* @return default port of this file system's Uri scheme
|
||||||
* A uri with a port of -1 => default port;
|
* A uri with a port of -1 => default port;
|
||||||
*/
|
*/
|
||||||
protected abstract int getUriDefaultPort();
|
public abstract int getUriDefaultPort();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a URI whose scheme and authority identify this FileSystem.
|
* Returns a URI whose scheme and authority identify this FileSystem.
|
||||||
*
|
*
|
||||||
* @return the uri of this file system.
|
* @return the uri of this file system.
|
||||||
*/
|
*/
|
||||||
protected URI getUri() {
|
public URI getUri() {
|
||||||
return myUri;
|
return myUri;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -292,7 +296,7 @@ protected URI getUri() {
|
||||||
*
|
*
|
||||||
* @throws InvalidPathException if the path is invalid
|
* @throws InvalidPathException if the path is invalid
|
||||||
*/
|
*/
|
||||||
protected void checkPath(Path path) {
|
public void checkPath(Path path) {
|
||||||
URI uri = path.toUri();
|
URI uri = path.toUri();
|
||||||
String thatScheme = uri.getScheme();
|
String thatScheme = uri.getScheme();
|
||||||
String thatAuthority = uri.getAuthority();
|
String thatAuthority = uri.getAuthority();
|
||||||
|
@ -340,7 +344,7 @@ protected void checkPath(Path path) {
|
||||||
*
|
*
|
||||||
* @return path-part of the Path p
|
* @return path-part of the Path p
|
||||||
*/
|
*/
|
||||||
protected String getUriPath(final Path p) {
|
public String getUriPath(final Path p) {
|
||||||
checkPath(p);
|
checkPath(p);
|
||||||
String s = p.toUri().getPath();
|
String s = p.toUri().getPath();
|
||||||
if (!isValidName(s)) {
|
if (!isValidName(s)) {
|
||||||
|
@ -350,6 +354,16 @@ protected String getUriPath(final Path p) {
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Make the path fully qualified to this file system
|
||||||
|
* @param path
|
||||||
|
* @return the qualified path
|
||||||
|
*/
|
||||||
|
public Path makeQualified(Path path) {
|
||||||
|
checkPath(path);
|
||||||
|
return path.makeQualified(this.getUri(), null);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Some file systems like LocalFileSystem have an initial workingDir
|
* Some file systems like LocalFileSystem have an initial workingDir
|
||||||
* that is used as the starting workingDir. For other file systems
|
* that is used as the starting workingDir. For other file systems
|
||||||
|
@ -358,7 +372,7 @@ protected String getUriPath(final Path p) {
|
||||||
* @return the initial workingDir if the file system has such a notion
|
* @return the initial workingDir if the file system has such a notion
|
||||||
* otherwise return a null.
|
* otherwise return a null.
|
||||||
*/
|
*/
|
||||||
protected Path getInitialWorkingDirectory() {
|
public Path getInitialWorkingDirectory() {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -368,7 +382,7 @@ protected Path getInitialWorkingDirectory() {
|
||||||
*
|
*
|
||||||
* @return current user's home directory.
|
* @return current user's home directory.
|
||||||
*/
|
*/
|
||||||
protected Path getHomeDirectory() {
|
public Path getHomeDirectory() {
|
||||||
return new Path("/user/"+System.getProperty("user.name")).makeQualified(
|
return new Path("/user/"+System.getProperty("user.name")).makeQualified(
|
||||||
getUri(), null);
|
getUri(), null);
|
||||||
}
|
}
|
||||||
|
@ -380,7 +394,7 @@ protected Path getHomeDirectory() {
|
||||||
*
|
*
|
||||||
* @throws IOException an I/O error occurred
|
* @throws IOException an I/O error occurred
|
||||||
*/
|
*/
|
||||||
protected abstract FsServerDefaults getServerDefaults() throws IOException;
|
public abstract FsServerDefaults getServerDefaults() throws IOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The specification of this method matches that of
|
* The specification of this method matches that of
|
||||||
|
@ -388,7 +402,7 @@ protected Path getHomeDirectory() {
|
||||||
* that the Path f must be fully qualified and the permission is absolute
|
* that the Path f must be fully qualified and the permission is absolute
|
||||||
* (i.e. umask has been applied).
|
* (i.e. umask has been applied).
|
||||||
*/
|
*/
|
||||||
protected final FSDataOutputStream create(final Path f,
|
public final FSDataOutputStream create(final Path f,
|
||||||
final EnumSet<CreateFlag> createFlag, Options.CreateOpts... opts)
|
final EnumSet<CreateFlag> createFlag, Options.CreateOpts... opts)
|
||||||
throws AccessControlException, FileAlreadyExistsException,
|
throws AccessControlException, FileAlreadyExistsException,
|
||||||
FileNotFoundException, ParentNotDirectoryException,
|
FileNotFoundException, ParentNotDirectoryException,
|
||||||
|
@ -491,7 +505,7 @@ protected final FSDataOutputStream create(final Path f,
|
||||||
* {@link #create(Path, EnumSet, Options.CreateOpts...)} except that the opts
|
* {@link #create(Path, EnumSet, Options.CreateOpts...)} except that the opts
|
||||||
* have been declared explicitly.
|
* have been declared explicitly.
|
||||||
*/
|
*/
|
||||||
protected abstract FSDataOutputStream createInternal(Path f,
|
public abstract FSDataOutputStream createInternal(Path f,
|
||||||
EnumSet<CreateFlag> flag, FsPermission absolutePermission,
|
EnumSet<CreateFlag> flag, FsPermission absolutePermission,
|
||||||
int bufferSize, short replication, long blockSize, Progressable progress,
|
int bufferSize, short replication, long blockSize, Progressable progress,
|
||||||
int bytesPerChecksum, boolean createParent)
|
int bytesPerChecksum, boolean createParent)
|
||||||
|
@ -505,7 +519,7 @@ protected abstract FSDataOutputStream createInternal(Path f,
|
||||||
* f must be fully qualified and the permission is absolute (i.e.
|
* f must be fully qualified and the permission is absolute (i.e.
|
||||||
* umask has been applied).
|
* umask has been applied).
|
||||||
*/
|
*/
|
||||||
protected abstract void mkdir(final Path dir, final FsPermission permission,
|
public abstract void mkdir(final Path dir, final FsPermission permission,
|
||||||
final boolean createParent) throws AccessControlException,
|
final boolean createParent) throws AccessControlException,
|
||||||
FileAlreadyExistsException, FileNotFoundException,
|
FileAlreadyExistsException, FileNotFoundException,
|
||||||
UnresolvedLinkException, IOException;
|
UnresolvedLinkException, IOException;
|
||||||
|
@ -515,7 +529,7 @@ protected abstract void mkdir(final Path dir, final FsPermission permission,
|
||||||
* {@link FileContext#delete(Path, boolean)} except that Path f must be for
|
* {@link FileContext#delete(Path, boolean)} except that Path f must be for
|
||||||
* this file system.
|
* this file system.
|
||||||
*/
|
*/
|
||||||
protected abstract boolean delete(final Path f, final boolean recursive)
|
public abstract boolean delete(final Path f, final boolean recursive)
|
||||||
throws AccessControlException, FileNotFoundException,
|
throws AccessControlException, FileNotFoundException,
|
||||||
UnresolvedLinkException, IOException;
|
UnresolvedLinkException, IOException;
|
||||||
|
|
||||||
|
@ -524,7 +538,7 @@ protected abstract boolean delete(final Path f, final boolean recursive)
|
||||||
* {@link FileContext#open(Path)} except that Path f must be for this
|
* {@link FileContext#open(Path)} except that Path f must be for this
|
||||||
* file system.
|
* file system.
|
||||||
*/
|
*/
|
||||||
protected FSDataInputStream open(final Path f) throws AccessControlException,
|
public FSDataInputStream open(final Path f) throws AccessControlException,
|
||||||
FileNotFoundException, UnresolvedLinkException, IOException {
|
FileNotFoundException, UnresolvedLinkException, IOException {
|
||||||
return open(f, getServerDefaults().getFileBufferSize());
|
return open(f, getServerDefaults().getFileBufferSize());
|
||||||
}
|
}
|
||||||
|
@ -534,7 +548,7 @@ protected FSDataInputStream open(final Path f) throws AccessControlException,
|
||||||
* {@link FileContext#open(Path, int)} except that Path f must be for this
|
* {@link FileContext#open(Path, int)} except that Path f must be for this
|
||||||
* file system.
|
* file system.
|
||||||
*/
|
*/
|
||||||
protected abstract FSDataInputStream open(final Path f, int bufferSize)
|
public abstract FSDataInputStream open(final Path f, int bufferSize)
|
||||||
throws AccessControlException, FileNotFoundException,
|
throws AccessControlException, FileNotFoundException,
|
||||||
UnresolvedLinkException, IOException;
|
UnresolvedLinkException, IOException;
|
||||||
|
|
||||||
|
@ -543,7 +557,7 @@ protected abstract FSDataInputStream open(final Path f, int bufferSize)
|
||||||
* {@link FileContext#setReplication(Path, short)} except that Path f must be
|
* {@link FileContext#setReplication(Path, short)} except that Path f must be
|
||||||
* for this file system.
|
* for this file system.
|
||||||
*/
|
*/
|
||||||
protected abstract boolean setReplication(final Path f,
|
public abstract boolean setReplication(final Path f,
|
||||||
final short replication) throws AccessControlException,
|
final short replication) throws AccessControlException,
|
||||||
FileNotFoundException, UnresolvedLinkException, IOException;
|
FileNotFoundException, UnresolvedLinkException, IOException;
|
||||||
|
|
||||||
|
@ -552,7 +566,7 @@ protected abstract boolean setReplication(final Path f,
|
||||||
* {@link FileContext#rename(Path, Path, Options.Rename...)} except that Path
|
* {@link FileContext#rename(Path, Path, Options.Rename...)} except that Path
|
||||||
* f must be for this file system.
|
* f must be for this file system.
|
||||||
*/
|
*/
|
||||||
protected final void rename(final Path src, final Path dst,
|
public final void rename(final Path src, final Path dst,
|
||||||
final Options.Rename... options) throws AccessControlException,
|
final Options.Rename... options) throws AccessControlException,
|
||||||
FileAlreadyExistsException, FileNotFoundException,
|
FileAlreadyExistsException, FileNotFoundException,
|
||||||
ParentNotDirectoryException, UnresolvedLinkException, IOException {
|
ParentNotDirectoryException, UnresolvedLinkException, IOException {
|
||||||
|
@ -576,7 +590,7 @@ protected final void rename(final Path src, final Path dst,
|
||||||
* method and can take advantage of the default impl of the other
|
* method and can take advantage of the default impl of the other
|
||||||
* {@link #renameInternal(Path, Path, boolean)}
|
* {@link #renameInternal(Path, Path, boolean)}
|
||||||
*/
|
*/
|
||||||
protected abstract void renameInternal(final Path src, final Path dst)
|
public abstract void renameInternal(final Path src, final Path dst)
|
||||||
throws AccessControlException, FileAlreadyExistsException,
|
throws AccessControlException, FileAlreadyExistsException,
|
||||||
FileNotFoundException, ParentNotDirectoryException,
|
FileNotFoundException, ParentNotDirectoryException,
|
||||||
UnresolvedLinkException, IOException;
|
UnresolvedLinkException, IOException;
|
||||||
|
@ -586,7 +600,7 @@ protected abstract void renameInternal(final Path src, final Path dst)
|
||||||
* {@link FileContext#rename(Path, Path, Options.Rename...)} except that Path
|
* {@link FileContext#rename(Path, Path, Options.Rename...)} except that Path
|
||||||
* f must be for this file system.
|
* f must be for this file system.
|
||||||
*/
|
*/
|
||||||
protected void renameInternal(final Path src, final Path dst,
|
public void renameInternal(final Path src, final Path dst,
|
||||||
boolean overwrite) throws AccessControlException,
|
boolean overwrite) throws AccessControlException,
|
||||||
FileAlreadyExistsException, FileNotFoundException,
|
FileAlreadyExistsException, FileNotFoundException,
|
||||||
ParentNotDirectoryException, UnresolvedLinkException, IOException {
|
ParentNotDirectoryException, UnresolvedLinkException, IOException {
|
||||||
|
@ -640,7 +654,7 @@ protected void renameInternal(final Path src, final Path dst,
|
||||||
/**
|
/**
|
||||||
* Returns true if the file system supports symlinks, false otherwise.
|
* Returns true if the file system supports symlinks, false otherwise.
|
||||||
*/
|
*/
|
||||||
protected boolean supportsSymlinks() {
|
public boolean supportsSymlinks() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -648,7 +662,7 @@ protected boolean supportsSymlinks() {
|
||||||
* The specification of this method matches that of
|
* The specification of this method matches that of
|
||||||
* {@link FileContext#createSymlink(Path, Path, boolean)};
|
* {@link FileContext#createSymlink(Path, Path, boolean)};
|
||||||
*/
|
*/
|
||||||
protected void createSymlink(final Path target, final Path link,
|
public void createSymlink(final Path target, final Path link,
|
||||||
final boolean createParent) throws IOException, UnresolvedLinkException {
|
final boolean createParent) throws IOException, UnresolvedLinkException {
|
||||||
throw new IOException("File system does not support symlinks");
|
throw new IOException("File system does not support symlinks");
|
||||||
}
|
}
|
||||||
|
@ -657,7 +671,7 @@ protected void createSymlink(final Path target, final Path link,
|
||||||
* The specification of this method matches that of
|
* The specification of this method matches that of
|
||||||
* {@link FileContext#getLinkTarget(Path)};
|
* {@link FileContext#getLinkTarget(Path)};
|
||||||
*/
|
*/
|
||||||
protected Path getLinkTarget(final Path f) throws IOException {
|
public Path getLinkTarget(final Path f) throws IOException {
|
||||||
/* We should never get here. Any file system that threw an
|
/* We should never get here. Any file system that threw an
|
||||||
* UnresolvedLinkException, causing this function to be called,
|
* UnresolvedLinkException, causing this function to be called,
|
||||||
* needs to override this method.
|
* needs to override this method.
|
||||||
|
@ -670,7 +684,7 @@ protected Path getLinkTarget(final Path f) throws IOException {
|
||||||
* {@link FileContext#setPermission(Path, FsPermission)} except that Path f
|
* {@link FileContext#setPermission(Path, FsPermission)} except that Path f
|
||||||
* must be for this file system.
|
* must be for this file system.
|
||||||
*/
|
*/
|
||||||
protected abstract void setPermission(final Path f,
|
public abstract void setPermission(final Path f,
|
||||||
final FsPermission permission) throws AccessControlException,
|
final FsPermission permission) throws AccessControlException,
|
||||||
FileNotFoundException, UnresolvedLinkException, IOException;
|
FileNotFoundException, UnresolvedLinkException, IOException;
|
||||||
|
|
||||||
|
@ -679,7 +693,7 @@ protected abstract void setPermission(final Path f,
|
||||||
* {@link FileContext#setOwner(Path, String, String)} except that Path f must
|
* {@link FileContext#setOwner(Path, String, String)} except that Path f must
|
||||||
* be for this file system.
|
* be for this file system.
|
||||||
*/
|
*/
|
||||||
protected abstract void setOwner(final Path f, final String username,
|
public abstract void setOwner(final Path f, final String username,
|
||||||
final String groupname) throws AccessControlException,
|
final String groupname) throws AccessControlException,
|
||||||
FileNotFoundException, UnresolvedLinkException, IOException;
|
FileNotFoundException, UnresolvedLinkException, IOException;
|
||||||
|
|
||||||
|
@ -688,7 +702,7 @@ protected abstract void setOwner(final Path f, final String username,
|
||||||
* {@link FileContext#setTimes(Path, long, long)} except that Path f must be
|
* {@link FileContext#setTimes(Path, long, long)} except that Path f must be
|
||||||
* for this file system.
|
* for this file system.
|
||||||
*/
|
*/
|
||||||
protected abstract void setTimes(final Path f, final long mtime,
|
public abstract void setTimes(final Path f, final long mtime,
|
||||||
final long atime) throws AccessControlException, FileNotFoundException,
|
final long atime) throws AccessControlException, FileNotFoundException,
|
||||||
UnresolvedLinkException, IOException;
|
UnresolvedLinkException, IOException;
|
||||||
|
|
||||||
|
@ -697,7 +711,7 @@ protected abstract void setTimes(final Path f, final long mtime,
|
||||||
* {@link FileContext#getFileChecksum(Path)} except that Path f must be for
|
* {@link FileContext#getFileChecksum(Path)} except that Path f must be for
|
||||||
* this file system.
|
* this file system.
|
||||||
*/
|
*/
|
||||||
protected abstract FileChecksum getFileChecksum(final Path f)
|
public abstract FileChecksum getFileChecksum(final Path f)
|
||||||
throws AccessControlException, FileNotFoundException,
|
throws AccessControlException, FileNotFoundException,
|
||||||
UnresolvedLinkException, IOException;
|
UnresolvedLinkException, IOException;
|
||||||
|
|
||||||
|
@ -707,7 +721,7 @@ protected abstract FileChecksum getFileChecksum(final Path f)
|
||||||
* except that an UnresolvedLinkException may be thrown if a symlink is
|
* except that an UnresolvedLinkException may be thrown if a symlink is
|
||||||
* encountered in the path.
|
* encountered in the path.
|
||||||
*/
|
*/
|
||||||
protected abstract FileStatus getFileStatus(final Path f)
|
public abstract FileStatus getFileStatus(final Path f)
|
||||||
throws AccessControlException, FileNotFoundException,
|
throws AccessControlException, FileNotFoundException,
|
||||||
UnresolvedLinkException, IOException;
|
UnresolvedLinkException, IOException;
|
||||||
|
|
||||||
|
@ -719,7 +733,7 @@ protected abstract FileStatus getFileStatus(final Path f)
|
||||||
* If the file system does not support symlinks then the behavior is
|
* If the file system does not support symlinks then the behavior is
|
||||||
* equivalent to {@link AbstractFileSystem#getFileStatus(Path)}.
|
* equivalent to {@link AbstractFileSystem#getFileStatus(Path)}.
|
||||||
*/
|
*/
|
||||||
protected FileStatus getFileLinkStatus(final Path f)
|
public FileStatus getFileLinkStatus(final Path f)
|
||||||
throws AccessControlException, FileNotFoundException,
|
throws AccessControlException, FileNotFoundException,
|
||||||
UnsupportedFileSystemException, IOException {
|
UnsupportedFileSystemException, IOException {
|
||||||
return getFileStatus(f);
|
return getFileStatus(f);
|
||||||
|
@ -730,7 +744,7 @@ protected FileStatus getFileLinkStatus(final Path f)
|
||||||
* {@link FileContext#getFileBlockLocations(Path, long, long)} except that
|
* {@link FileContext#getFileBlockLocations(Path, long, long)} except that
|
||||||
* Path f must be for this file system.
|
* Path f must be for this file system.
|
||||||
*/
|
*/
|
||||||
protected abstract BlockLocation[] getFileBlockLocations(final Path f,
|
public abstract BlockLocation[] getFileBlockLocations(final Path f,
|
||||||
final long start, final long len) throws AccessControlException,
|
final long start, final long len) throws AccessControlException,
|
||||||
FileNotFoundException, UnresolvedLinkException, IOException;
|
FileNotFoundException, UnresolvedLinkException, IOException;
|
||||||
|
|
||||||
|
@ -739,7 +753,7 @@ protected abstract BlockLocation[] getFileBlockLocations(final Path f,
|
||||||
* {@link FileContext#getFsStatus(Path)} except that Path f must be for this
|
* {@link FileContext#getFsStatus(Path)} except that Path f must be for this
|
||||||
* file system.
|
* file system.
|
||||||
*/
|
*/
|
||||||
protected FsStatus getFsStatus(final Path f) throws AccessControlException,
|
public FsStatus getFsStatus(final Path f) throws AccessControlException,
|
||||||
FileNotFoundException, UnresolvedLinkException, IOException {
|
FileNotFoundException, UnresolvedLinkException, IOException {
|
||||||
// default impl gets FsStatus of root
|
// default impl gets FsStatus of root
|
||||||
return getFsStatus();
|
return getFsStatus();
|
||||||
|
@ -749,7 +763,7 @@ protected FsStatus getFsStatus(final Path f) throws AccessControlException,
|
||||||
* The specification of this method matches that of
|
* The specification of this method matches that of
|
||||||
* {@link FileContext#getFsStatus(Path)}.
|
* {@link FileContext#getFsStatus(Path)}.
|
||||||
*/
|
*/
|
||||||
protected abstract FsStatus getFsStatus() throws AccessControlException,
|
public abstract FsStatus getFsStatus() throws AccessControlException,
|
||||||
FileNotFoundException, IOException;
|
FileNotFoundException, IOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -757,7 +771,7 @@ protected abstract FsStatus getFsStatus() throws AccessControlException,
|
||||||
* {@link FileContext#listStatus(Path)} except that Path f must be for this
|
* {@link FileContext#listStatus(Path)} except that Path f must be for this
|
||||||
* file system.
|
* file system.
|
||||||
*/
|
*/
|
||||||
protected RemoteIterator<FileStatus> listStatusIterator(final Path f)
|
public RemoteIterator<FileStatus> listStatusIterator(final Path f)
|
||||||
throws AccessControlException, FileNotFoundException,
|
throws AccessControlException, FileNotFoundException,
|
||||||
UnresolvedLinkException, IOException {
|
UnresolvedLinkException, IOException {
|
||||||
return new RemoteIterator<FileStatus>() {
|
return new RemoteIterator<FileStatus>() {
|
||||||
|
@ -784,7 +798,7 @@ public FileStatus next() {
|
||||||
* {@link FileContext#listLocatedStatus(Path)} except that Path f
|
* {@link FileContext#listLocatedStatus(Path)} except that Path f
|
||||||
* must be for this file system.
|
* must be for this file system.
|
||||||
*/
|
*/
|
||||||
protected RemoteIterator<LocatedFileStatus> listLocatedStatus(final Path f)
|
public RemoteIterator<LocatedFileStatus> listLocatedStatus(final Path f)
|
||||||
throws AccessControlException, FileNotFoundException,
|
throws AccessControlException, FileNotFoundException,
|
||||||
UnresolvedLinkException, IOException {
|
UnresolvedLinkException, IOException {
|
||||||
return new RemoteIterator<LocatedFileStatus>() {
|
return new RemoteIterator<LocatedFileStatus>() {
|
||||||
|
@ -816,7 +830,7 @@ public LocatedFileStatus next() throws IOException {
|
||||||
* {@link FileContext.Util#listStatus(Path)} except that Path f must be
|
* {@link FileContext.Util#listStatus(Path)} except that Path f must be
|
||||||
* for this file system.
|
* for this file system.
|
||||||
*/
|
*/
|
||||||
protected abstract FileStatus[] listStatus(final Path f)
|
public abstract FileStatus[] listStatus(final Path f)
|
||||||
throws AccessControlException, FileNotFoundException,
|
throws AccessControlException, FileNotFoundException,
|
||||||
UnresolvedLinkException, IOException;
|
UnresolvedLinkException, IOException;
|
||||||
|
|
||||||
|
@ -825,6 +839,6 @@ protected abstract FileStatus[] listStatus(final Path f)
|
||||||
* {@link FileContext#setVerifyChecksum(boolean, Path)} except that Path f
|
* {@link FileContext#setVerifyChecksum(boolean, Path)} except that Path f
|
||||||
* must be for this file system.
|
* must be for this file system.
|
||||||
*/
|
*/
|
||||||
protected abstract void setVerifyChecksum(final boolean verifyChecksum)
|
public abstract void setVerifyChecksum(final boolean verifyChecksum)
|
||||||
throws AccessControlException, IOException;
|
throws AccessControlException, IOException;
|
||||||
}
|
}
|
||||||
|
|
|
@ -358,7 +358,7 @@ protected void writeChunk(byte[] b, int offset, int len, byte[] checksum)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected FSDataOutputStream createInternal(Path f,
|
public FSDataOutputStream createInternal(Path f,
|
||||||
EnumSet<CreateFlag> createFlag, FsPermission absolutePermission,
|
EnumSet<CreateFlag> createFlag, FsPermission absolutePermission,
|
||||||
int bufferSize, short replication, long blockSize, Progressable progress,
|
int bufferSize, short replication, long blockSize, Progressable progress,
|
||||||
int bytesPerChecksum, boolean createParent) throws IOException {
|
int bytesPerChecksum, boolean createParent) throws IOException {
|
||||||
|
@ -481,7 +481,7 @@ public boolean reportChecksumFailure(Path f, FSDataInputStream in,
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected FileStatus[] listStatus(Path f) throws IOException,
|
public FileStatus[] listStatus(Path f) throws IOException,
|
||||||
UnresolvedLinkException {
|
UnresolvedLinkException {
|
||||||
ArrayList<FileStatus> results = new ArrayList<FileStatus>();
|
ArrayList<FileStatus> results = new ArrayList<FileStatus>();
|
||||||
FileStatus[] listing = getMyFs().listStatus(f);
|
FileStatus[] listing = getMyFs().listStatus(f);
|
||||||
|
|
|
@ -50,13 +50,13 @@ protected DelegateToFileSystem(URI theUri, FileSystem theFsImpl,
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Path getInitialWorkingDirectory() {
|
public Path getInitialWorkingDirectory() {
|
||||||
return fsImpl.getInitialWorkingDirectory();
|
return fsImpl.getInitialWorkingDirectory();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@SuppressWarnings("deprecation") // call to primitiveCreate
|
@SuppressWarnings("deprecation") // call to primitiveCreate
|
||||||
protected FSDataOutputStream createInternal (Path f,
|
public FSDataOutputStream createInternal (Path f,
|
||||||
EnumSet<CreateFlag> flag, FsPermission absolutePermission, int bufferSize,
|
EnumSet<CreateFlag> flag, FsPermission absolutePermission, int bufferSize,
|
||||||
short replication, long blockSize, Progressable progress,
|
short replication, long blockSize, Progressable progress,
|
||||||
int bytesPerChecksum, boolean createParent) throws IOException {
|
int bytesPerChecksum, boolean createParent) throws IOException {
|
||||||
|
@ -83,59 +83,59 @@ protected FSDataOutputStream createInternal (Path f,
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean delete(Path f, boolean recursive) throws IOException {
|
public boolean delete(Path f, boolean recursive) throws IOException {
|
||||||
checkPath(f);
|
checkPath(f);
|
||||||
return fsImpl.delete(f, recursive);
|
return fsImpl.delete(f, recursive);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected BlockLocation[] getFileBlockLocations(Path f, long start, long len)
|
public BlockLocation[] getFileBlockLocations(Path f, long start, long len)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
checkPath(f);
|
checkPath(f);
|
||||||
return fsImpl.getFileBlockLocations(f, start, len);
|
return fsImpl.getFileBlockLocations(f, start, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected FileChecksum getFileChecksum(Path f) throws IOException {
|
public FileChecksum getFileChecksum(Path f) throws IOException {
|
||||||
checkPath(f);
|
checkPath(f);
|
||||||
return fsImpl.getFileChecksum(f);
|
return fsImpl.getFileChecksum(f);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected FileStatus getFileStatus(Path f) throws IOException {
|
public FileStatus getFileStatus(Path f) throws IOException {
|
||||||
checkPath(f);
|
checkPath(f);
|
||||||
return fsImpl.getFileStatus(f);
|
return fsImpl.getFileStatus(f);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected FileStatus getFileLinkStatus(final Path f) throws IOException {
|
public FileStatus getFileLinkStatus(final Path f) throws IOException {
|
||||||
return getFileStatus(f);
|
return getFileStatus(f);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected FsStatus getFsStatus() throws IOException {
|
public FsStatus getFsStatus() throws IOException {
|
||||||
return fsImpl.getStatus();
|
return fsImpl.getStatus();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected FsServerDefaults getServerDefaults() throws IOException {
|
public FsServerDefaults getServerDefaults() throws IOException {
|
||||||
return fsImpl.getServerDefaults();
|
return fsImpl.getServerDefaults();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected int getUriDefaultPort() {
|
public int getUriDefaultPort() {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected FileStatus[] listStatus(Path f) throws IOException {
|
public FileStatus[] listStatus(Path f) throws IOException {
|
||||||
checkPath(f);
|
checkPath(f);
|
||||||
return fsImpl.listStatus(f);
|
return fsImpl.listStatus(f);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@SuppressWarnings("deprecation") // call to primitiveMkdir
|
@SuppressWarnings("deprecation") // call to primitiveMkdir
|
||||||
protected void mkdir(Path dir, FsPermission permission, boolean createParent)
|
public void mkdir(Path dir, FsPermission permission, boolean createParent)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
checkPath(dir);
|
checkPath(dir);
|
||||||
fsImpl.primitiveMkdir(dir, permission, createParent);
|
fsImpl.primitiveMkdir(dir, permission, createParent);
|
||||||
|
@ -143,64 +143,64 @@ protected void mkdir(Path dir, FsPermission permission, boolean createParent)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected FSDataInputStream open(Path f, int bufferSize) throws IOException {
|
public FSDataInputStream open(Path f, int bufferSize) throws IOException {
|
||||||
checkPath(f);
|
checkPath(f);
|
||||||
return fsImpl.open(f, bufferSize);
|
return fsImpl.open(f, bufferSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@SuppressWarnings("deprecation") // call to rename
|
@SuppressWarnings("deprecation") // call to rename
|
||||||
protected void renameInternal(Path src, Path dst) throws IOException {
|
public void renameInternal(Path src, Path dst) throws IOException {
|
||||||
checkPath(src);
|
checkPath(src);
|
||||||
checkPath(dst);
|
checkPath(dst);
|
||||||
fsImpl.rename(src, dst, Options.Rename.NONE);
|
fsImpl.rename(src, dst, Options.Rename.NONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void setOwner(Path f, String username, String groupname)
|
public void setOwner(Path f, String username, String groupname)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
checkPath(f);
|
checkPath(f);
|
||||||
fsImpl.setOwner(f, username, groupname);
|
fsImpl.setOwner(f, username, groupname);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void setPermission(Path f, FsPermission permission)
|
public void setPermission(Path f, FsPermission permission)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
checkPath(f);
|
checkPath(f);
|
||||||
fsImpl.setPermission(f, permission);
|
fsImpl.setPermission(f, permission);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean setReplication(Path f, short replication)
|
public boolean setReplication(Path f, short replication)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
checkPath(f);
|
checkPath(f);
|
||||||
return fsImpl.setReplication(f, replication);
|
return fsImpl.setReplication(f, replication);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void setTimes(Path f, long mtime, long atime) throws IOException {
|
public void setTimes(Path f, long mtime, long atime) throws IOException {
|
||||||
checkPath(f);
|
checkPath(f);
|
||||||
fsImpl.setTimes(f, mtime, atime);
|
fsImpl.setTimes(f, mtime, atime);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void setVerifyChecksum(boolean verifyChecksum) throws IOException {
|
public void setVerifyChecksum(boolean verifyChecksum) throws IOException {
|
||||||
fsImpl.setVerifyChecksum(verifyChecksum);
|
fsImpl.setVerifyChecksum(verifyChecksum);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean supportsSymlinks() {
|
public boolean supportsSymlinks() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void createSymlink(Path target, Path link, boolean createParent)
|
public void createSymlink(Path target, Path link, boolean createParent)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
throw new IOException("File system does not support symlinks");
|
throw new IOException("File system does not support symlinks");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Path getLinkTarget(final Path f) throws IOException {
|
public Path getLinkTarget(final Path f) throws IOException {
|
||||||
/* We should never get here. Any file system that threw an
|
/* We should never get here. Any file system that threw an
|
||||||
* UnresolvedLinkException, causing this function to be called,
|
* UnresolvedLinkException, causing this function to be called,
|
||||||
* should override getLinkTarget.
|
* should override getLinkTarget.
|
||||||
|
|
|
@ -26,7 +26,6 @@
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.EnumSet;
|
import java.util.EnumSet;
|
||||||
import java.util.IdentityHashMap;
|
import java.util.IdentityHashMap;
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
@ -306,7 +305,7 @@ private AbstractFileSystem getFSofPath(final Path absOrFqPath)
|
||||||
* @param aConf
|
* @param aConf
|
||||||
* @return new FileContext with specifed FS as default.
|
* @return new FileContext with specifed FS as default.
|
||||||
*/
|
*/
|
||||||
protected static FileContext getFileContext(final AbstractFileSystem defFS,
|
public static FileContext getFileContext(final AbstractFileSystem defFS,
|
||||||
final Configuration aConf) {
|
final Configuration aConf) {
|
||||||
return new FileContext(defFS, FsPermission.getUMask(aConf), aConf);
|
return new FileContext(defFS, FsPermission.getUMask(aConf), aConf);
|
||||||
}
|
}
|
||||||
|
@ -426,21 +425,33 @@ public static FileContext getLocalFSFileContext(final Configuration aConf)
|
||||||
@InterfaceAudience.Private
|
@InterfaceAudience.Private
|
||||||
@InterfaceStability.Unstable /* return type will change to AFS once
|
@InterfaceStability.Unstable /* return type will change to AFS once
|
||||||
HADOOP-6223 is completed */
|
HADOOP-6223 is completed */
|
||||||
protected AbstractFileSystem getDefaultFileSystem() {
|
public AbstractFileSystem getDefaultFileSystem() {
|
||||||
return defaultFS;
|
return defaultFS;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the working directory for wd-relative names (such a "foo/bar").
|
* Set the working directory for wd-relative names (such a "foo/bar"). Working
|
||||||
* @param newWDir
|
* directory feature is provided by simply prefixing relative names with the
|
||||||
* @throws IOException
|
* working dir. Note this is different from Unix where the wd is actually set
|
||||||
|
* to the inode. Hence setWorkingDir does not follow symlinks etc. This works
|
||||||
|
* better in a distributed environment that has multiple independent roots.
|
||||||
|
* {@link #getWorkingDirectory()} should return what setWorkingDir() set.
|
||||||
*
|
*
|
||||||
* newWdir can be one of
|
* @param newWDir new working directory
|
||||||
* - relative path: "foo/bar";
|
* @throws IOException
|
||||||
* - absolute without scheme: "/foo/bar"
|
* <br>
|
||||||
* - fully qualified with scheme: "xx://auth/foo/bar"
|
* NewWdir can be one of:
|
||||||
* Illegal WDs:
|
* <ul>
|
||||||
* - relative with scheme: "xx:foo/bar"
|
* <li>relative path: "foo/bar";</li>
|
||||||
|
* <li>absolute without scheme: "/foo/bar"</li>
|
||||||
|
* <li>fully qualified with scheme: "xx://auth/foo/bar"</li>
|
||||||
|
* </ul>
|
||||||
|
* <br>
|
||||||
|
* Illegal WDs:
|
||||||
|
* <ul>
|
||||||
|
* <li>relative with scheme: "xx:foo/bar"</li>
|
||||||
|
* <li>non existent directory</li>
|
||||||
|
* </ul>
|
||||||
*/
|
*/
|
||||||
public void setWorkingDirectory(final Path newWDir) throws IOException {
|
public void setWorkingDirectory(final Path newWDir) throws IOException {
|
||||||
checkNotSchemeWithRelative(newWDir);
|
checkNotSchemeWithRelative(newWDir);
|
||||||
|
@ -448,7 +459,7 @@ public void setWorkingDirectory(final Path newWDir) throws IOException {
|
||||||
* path is not relative first since resolve requires and returns
|
* path is not relative first since resolve requires and returns
|
||||||
* an absolute path.
|
* an absolute path.
|
||||||
*/
|
*/
|
||||||
final Path newWorkingDir = resolve(new Path(workingDir, newWDir));
|
final Path newWorkingDir = new Path(workingDir, newWDir);
|
||||||
FileStatus status = getFileStatus(newWorkingDir);
|
FileStatus status = getFileStatus(newWorkingDir);
|
||||||
if (status.isFile()) {
|
if (status.isFile()) {
|
||||||
throw new FileNotFoundException("Cannot setWD to a file");
|
throw new FileNotFoundException("Cannot setWD to a file");
|
||||||
|
|
|
@ -56,22 +56,27 @@ protected FilterFs(AbstractFileSystem fs) throws IOException,
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Statistics getStatistics() {
|
public Statistics getStatistics() {
|
||||||
return myFs.getStatistics();
|
return myFs.getStatistics();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Path getInitialWorkingDirectory() {
|
public Path makeQualified(Path path) {
|
||||||
|
return myFs.makeQualified(path);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Path getInitialWorkingDirectory() {
|
||||||
return myFs.getInitialWorkingDirectory();
|
return myFs.getInitialWorkingDirectory();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Path getHomeDirectory() {
|
public Path getHomeDirectory() {
|
||||||
return myFs.getHomeDirectory();
|
return myFs.getHomeDirectory();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected FSDataOutputStream createInternal(Path f,
|
public FSDataOutputStream createInternal(Path f,
|
||||||
EnumSet<CreateFlag> flag, FsPermission absolutePermission, int bufferSize,
|
EnumSet<CreateFlag> flag, FsPermission absolutePermission, int bufferSize,
|
||||||
short replication, long blockSize, Progressable progress,
|
short replication, long blockSize, Progressable progress,
|
||||||
int bytesPerChecksum, boolean createParent)
|
int bytesPerChecksum, boolean createParent)
|
||||||
|
@ -82,85 +87,85 @@ protected FSDataOutputStream createInternal(Path f,
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean delete(Path f, boolean recursive)
|
public boolean delete(Path f, boolean recursive)
|
||||||
throws IOException, UnresolvedLinkException {
|
throws IOException, UnresolvedLinkException {
|
||||||
checkPath(f);
|
checkPath(f);
|
||||||
return myFs.delete(f, recursive);
|
return myFs.delete(f, recursive);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected BlockLocation[] getFileBlockLocations(Path f, long start, long len)
|
public BlockLocation[] getFileBlockLocations(Path f, long start, long len)
|
||||||
throws IOException, UnresolvedLinkException {
|
throws IOException, UnresolvedLinkException {
|
||||||
checkPath(f);
|
checkPath(f);
|
||||||
return myFs.getFileBlockLocations(f, start, len);
|
return myFs.getFileBlockLocations(f, start, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected FileChecksum getFileChecksum(Path f)
|
public FileChecksum getFileChecksum(Path f)
|
||||||
throws IOException, UnresolvedLinkException {
|
throws IOException, UnresolvedLinkException {
|
||||||
checkPath(f);
|
checkPath(f);
|
||||||
return myFs.getFileChecksum(f);
|
return myFs.getFileChecksum(f);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected FileStatus getFileStatus(Path f)
|
public FileStatus getFileStatus(Path f)
|
||||||
throws IOException, UnresolvedLinkException {
|
throws IOException, UnresolvedLinkException {
|
||||||
checkPath(f);
|
checkPath(f);
|
||||||
return myFs.getFileStatus(f);
|
return myFs.getFileStatus(f);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected FileStatus getFileLinkStatus(final Path f)
|
public FileStatus getFileLinkStatus(final Path f)
|
||||||
throws IOException, UnresolvedLinkException {
|
throws IOException, UnresolvedLinkException {
|
||||||
checkPath(f);
|
checkPath(f);
|
||||||
return myFs.getFileLinkStatus(f);
|
return myFs.getFileLinkStatus(f);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected FsStatus getFsStatus(final Path f) throws AccessControlException,
|
public FsStatus getFsStatus(final Path f) throws AccessControlException,
|
||||||
FileNotFoundException, UnresolvedLinkException, IOException {
|
FileNotFoundException, UnresolvedLinkException, IOException {
|
||||||
return myFs.getFsStatus(f);
|
return myFs.getFsStatus(f);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected FsStatus getFsStatus() throws IOException {
|
public FsStatus getFsStatus() throws IOException {
|
||||||
return myFs.getFsStatus();
|
return myFs.getFsStatus();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected FsServerDefaults getServerDefaults() throws IOException {
|
public FsServerDefaults getServerDefaults() throws IOException {
|
||||||
return myFs.getServerDefaults();
|
return myFs.getServerDefaults();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected int getUriDefaultPort() {
|
public int getUriDefaultPort() {
|
||||||
return myFs.getUriDefaultPort();
|
return myFs.getUriDefaultPort();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected URI getUri() {
|
public URI getUri() {
|
||||||
return myFs.getUri();
|
return myFs.getUri();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void checkPath(Path path) {
|
public void checkPath(Path path) {
|
||||||
myFs.checkPath(path);
|
myFs.checkPath(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected String getUriPath(final Path p) {
|
public String getUriPath(final Path p) {
|
||||||
return myFs.getUriPath(p);
|
return myFs.getUriPath(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected FileStatus[] listStatus(Path f)
|
public FileStatus[] listStatus(Path f)
|
||||||
throws IOException, UnresolvedLinkException {
|
throws IOException, UnresolvedLinkException {
|
||||||
checkPath(f);
|
checkPath(f);
|
||||||
return myFs.listStatus(f);
|
return myFs.listStatus(f);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void mkdir(Path dir, FsPermission permission, boolean createParent)
|
public void mkdir(Path dir, FsPermission permission, boolean createParent)
|
||||||
throws IOException, UnresolvedLinkException {
|
throws IOException, UnresolvedLinkException {
|
||||||
checkPath(dir);
|
checkPath(dir);
|
||||||
myFs.mkdir(dir, permission, createParent);
|
myFs.mkdir(dir, permission, createParent);
|
||||||
|
@ -168,21 +173,21 @@ protected void mkdir(Path dir, FsPermission permission, boolean createParent)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected FSDataInputStream open(final Path f) throws AccessControlException,
|
public FSDataInputStream open(final Path f) throws AccessControlException,
|
||||||
FileNotFoundException, UnresolvedLinkException, IOException {
|
FileNotFoundException, UnresolvedLinkException, IOException {
|
||||||
checkPath(f);
|
checkPath(f);
|
||||||
return myFs.open(f);
|
return myFs.open(f);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected FSDataInputStream open(Path f, int bufferSize)
|
public FSDataInputStream open(Path f, int bufferSize)
|
||||||
throws IOException, UnresolvedLinkException {
|
throws IOException, UnresolvedLinkException {
|
||||||
checkPath(f);
|
checkPath(f);
|
||||||
return myFs.open(f, bufferSize);
|
return myFs.open(f, bufferSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void renameInternal(Path src, Path dst)
|
public void renameInternal(Path src, Path dst)
|
||||||
throws IOException, UnresolvedLinkException {
|
throws IOException, UnresolvedLinkException {
|
||||||
checkPath(src);
|
checkPath(src);
|
||||||
checkPath(dst);
|
checkPath(dst);
|
||||||
|
@ -190,7 +195,7 @@ protected void renameInternal(Path src, Path dst)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void renameInternal(final Path src, final Path dst,
|
public void renameInternal(final Path src, final Path dst,
|
||||||
boolean overwrite) throws AccessControlException,
|
boolean overwrite) throws AccessControlException,
|
||||||
FileAlreadyExistsException, FileNotFoundException,
|
FileAlreadyExistsException, FileNotFoundException,
|
||||||
ParentNotDirectoryException, UnresolvedLinkException, IOException {
|
ParentNotDirectoryException, UnresolvedLinkException, IOException {
|
||||||
|
@ -198,7 +203,7 @@ protected void renameInternal(final Path src, final Path dst,
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void setOwner(Path f, String username, String groupname)
|
public void setOwner(Path f, String username, String groupname)
|
||||||
throws IOException, UnresolvedLinkException {
|
throws IOException, UnresolvedLinkException {
|
||||||
checkPath(f);
|
checkPath(f);
|
||||||
myFs.setOwner(f, username, groupname);
|
myFs.setOwner(f, username, groupname);
|
||||||
|
@ -206,45 +211,45 @@ protected void setOwner(Path f, String username, String groupname)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void setPermission(Path f, FsPermission permission)
|
public void setPermission(Path f, FsPermission permission)
|
||||||
throws IOException, UnresolvedLinkException {
|
throws IOException, UnresolvedLinkException {
|
||||||
checkPath(f);
|
checkPath(f);
|
||||||
myFs.setPermission(f, permission);
|
myFs.setPermission(f, permission);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean setReplication(Path f, short replication)
|
public boolean setReplication(Path f, short replication)
|
||||||
throws IOException, UnresolvedLinkException {
|
throws IOException, UnresolvedLinkException {
|
||||||
checkPath(f);
|
checkPath(f);
|
||||||
return myFs.setReplication(f, replication);
|
return myFs.setReplication(f, replication);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void setTimes(Path f, long mtime, long atime)
|
public void setTimes(Path f, long mtime, long atime)
|
||||||
throws IOException, UnresolvedLinkException {
|
throws IOException, UnresolvedLinkException {
|
||||||
checkPath(f);
|
checkPath(f);
|
||||||
myFs.setTimes(f, mtime, atime);
|
myFs.setTimes(f, mtime, atime);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void setVerifyChecksum(boolean verifyChecksum)
|
public void setVerifyChecksum(boolean verifyChecksum)
|
||||||
throws IOException, UnresolvedLinkException {
|
throws IOException, UnresolvedLinkException {
|
||||||
myFs.setVerifyChecksum(verifyChecksum);
|
myFs.setVerifyChecksum(verifyChecksum);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean supportsSymlinks() {
|
public boolean supportsSymlinks() {
|
||||||
return myFs.supportsSymlinks();
|
return myFs.supportsSymlinks();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void createSymlink(Path target, Path link, boolean createParent)
|
public void createSymlink(Path target, Path link, boolean createParent)
|
||||||
throws IOException, UnresolvedLinkException {
|
throws IOException, UnresolvedLinkException {
|
||||||
myFs.createSymlink(target, link, createParent);
|
myFs.createSymlink(target, link, createParent);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Path getLinkTarget(final Path f) throws IOException {
|
public Path getLinkTarget(final Path f) throws IOException {
|
||||||
return myFs.getLinkTarget(f);
|
return myFs.getLinkTarget(f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,4 +33,11 @@ public interface FsConstants {
|
||||||
|
|
||||||
// URI scheme for FTP
|
// URI scheme for FTP
|
||||||
public static final String FTP_SCHEME = "ftp";
|
public static final String FTP_SCHEME = "ftp";
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ViewFs: viewFs file system (ie the mount file system on client side)
|
||||||
|
*/
|
||||||
|
public static final URI VIEWFS_URI = URI.create("viewfs:///");
|
||||||
|
public static final String VIEWFS_SCHEME = "viewfs";
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,12 +52,12 @@ public class FtpFs extends DelegateToFileSystem {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected int getUriDefaultPort() {
|
public int getUriDefaultPort() {
|
||||||
return FTP.DEFAULT_PORT;
|
return FTP.DEFAULT_PORT;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected FsServerDefaults getServerDefaults() throws IOException {
|
public FsServerDefaults getServerDefaults() throws IOException {
|
||||||
return FtpConfigKeys.getServerDefaults();
|
return FtpConfigKeys.getServerDefaults();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,7 +44,7 @@ public class LocalConfigKeys extends CommonConfigurationKeys {
|
||||||
"file.client-write-packet-size";
|
"file.client-write-packet-size";
|
||||||
public static final int CLIENT_WRITE_PACKET_SIZE_DEFAULT = 64*1024;
|
public static final int CLIENT_WRITE_PACKET_SIZE_DEFAULT = 64*1024;
|
||||||
|
|
||||||
protected static FsServerDefaults getServerDefaults() throws IOException {
|
public static FsServerDefaults getServerDefaults() throws IOException {
|
||||||
return new FsServerDefaults(
|
return new FsServerDefaults(
|
||||||
BLOCK_SIZE_DEFAULT,
|
BLOCK_SIZE_DEFAULT,
|
||||||
BYTES_PER_CHECKSUM_DEFAULT,
|
BYTES_PER_CHECKSUM_DEFAULT,
|
||||||
|
|
|
@ -62,22 +62,22 @@ public class RawLocalFs extends DelegateToFileSystem {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected int getUriDefaultPort() {
|
public int getUriDefaultPort() {
|
||||||
return -1; // No default port for file:///
|
return -1; // No default port for file:///
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected FsServerDefaults getServerDefaults() throws IOException {
|
public FsServerDefaults getServerDefaults() throws IOException {
|
||||||
return LocalConfigKeys.getServerDefaults();
|
return LocalConfigKeys.getServerDefaults();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean supportsSymlinks() {
|
public boolean supportsSymlinks() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void createSymlink(Path target, Path link, boolean createParent)
|
public void createSymlink(Path target, Path link, boolean createParent)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
final String targetScheme = target.toUri().getScheme();
|
final String targetScheme = target.toUri().getScheme();
|
||||||
if (targetScheme != null && !"file".equals(targetScheme)) {
|
if (targetScheme != null && !"file".equals(targetScheme)) {
|
||||||
|
@ -123,7 +123,7 @@ private String readLink(Path p) {
|
||||||
* the object the link refers to.
|
* the object the link refers to.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected FileStatus getFileLinkStatus(final Path f) throws IOException {
|
public FileStatus getFileLinkStatus(final Path f) throws IOException {
|
||||||
String target = readLink(f);
|
String target = readLink(f);
|
||||||
try {
|
try {
|
||||||
FileStatus fs = getFileStatus(f);
|
FileStatus fs = getFileStatus(f);
|
||||||
|
@ -160,7 +160,7 @@ protected FileStatus getFileLinkStatus(final Path f) throws IOException {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Path getLinkTarget(Path f) throws IOException {
|
public Path getLinkTarget(Path f) throws IOException {
|
||||||
/* We should never get here. Valid local links are resolved transparently
|
/* We should never get here. Valid local links are resolved transparently
|
||||||
* by the underlying local file system and accessing a dangling link will
|
* by the underlying local file system and accessing a dangling link will
|
||||||
* result in an IOException, not an UnresolvedLinkException, so FileContext
|
* result in an IOException, not an UnresolvedLinkException, so FileContext
|
||||||
|
|
|
@ -91,7 +91,7 @@ public void setUp() throws Exception {
|
||||||
|
|
||||||
@After
|
@After
|
||||||
public void tearDown() throws Exception {
|
public void tearDown() throws Exception {
|
||||||
fc.delete(getTestRootPath(fc, "test"), true);
|
fc.delete(new Path(getAbsoluteTestRootPath(fc), new Path("test")), true);
|
||||||
fc.delete(new Path(LOCAL_FS_ROOT_URI), true);
|
fc.delete(new Path(LOCAL_FS_ROOT_URI), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -125,7 +125,7 @@ public void testFsStatus() throws Exception {
|
||||||
public void testWorkingDirectory() throws Exception {
|
public void testWorkingDirectory() throws Exception {
|
||||||
|
|
||||||
// First we cd to our test root
|
// First we cd to our test root
|
||||||
Path workDir = new Path(getTestRootDir(fc), new Path("test"));
|
Path workDir = new Path(getAbsoluteTestRootPath(fc), new Path("test"));
|
||||||
fc.setWorkingDirectory(workDir);
|
fc.setWorkingDirectory(workDir);
|
||||||
Assert.assertEquals(workDir, fc.getWorkingDirectory());
|
Assert.assertEquals(workDir, fc.getWorkingDirectory());
|
||||||
|
|
||||||
|
@ -138,7 +138,7 @@ public void testWorkingDirectory() throws Exception {
|
||||||
// cd using a relative path
|
// cd using a relative path
|
||||||
|
|
||||||
// Go back to our test root
|
// Go back to our test root
|
||||||
workDir = getTestRootPath(fc, "test");
|
workDir = new Path(getAbsoluteTestRootPath(fc), new Path("test"));
|
||||||
fc.setWorkingDirectory(workDir);
|
fc.setWorkingDirectory(workDir);
|
||||||
Assert.assertEquals(workDir, fc.getWorkingDirectory());
|
Assert.assertEquals(workDir, fc.getWorkingDirectory());
|
||||||
|
|
||||||
|
@ -158,6 +158,11 @@ public void testWorkingDirectory() throws Exception {
|
||||||
fc.create(absolutePath, EnumSet.of(CreateFlag.CREATE)).close();
|
fc.create(absolutePath, EnumSet.of(CreateFlag.CREATE)).close();
|
||||||
fc.open(new Path("foo")).close();
|
fc.open(new Path("foo")).close();
|
||||||
|
|
||||||
|
|
||||||
|
// Now mkdir relative to the dir we cd'ed to
|
||||||
|
fc.mkdir(new Path("newDir"), FileContext.DEFAULT_PERM, true);
|
||||||
|
Assert.assertTrue(isDir(fc, new Path(absoluteDir, "newDir")));
|
||||||
|
|
||||||
absoluteDir = getTestRootPath(fc, "nonexistingPath");
|
absoluteDir = getTestRootPath(fc, "nonexistingPath");
|
||||||
try {
|
try {
|
||||||
fc.setWorkingDirectory(absoluteDir);
|
fc.setWorkingDirectory(absoluteDir);
|
||||||
|
|
|
@ -65,7 +65,7 @@ public abstract class FileContextPermissionBase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static FileContext fc;
|
protected static FileContext fc;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
|
|
|
@ -117,18 +117,13 @@ public void testStatRoot() throws IOException {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
/** Test setWorkingDirectory resolves symlinks */
|
/** Test setWorkingDirectory not resolves symlinks */
|
||||||
public void testSetWDResolvesLinks() throws IOException {
|
public void testSetWDNotResolvesLinks() throws IOException {
|
||||||
Path dir = new Path(testBaseDir1());
|
Path dir = new Path(testBaseDir1());
|
||||||
Path linkToDir = new Path(testBaseDir1()+"/link");
|
Path linkToDir = new Path(testBaseDir1()+"/link");
|
||||||
fc.createSymlink(dir, linkToDir, false);
|
fc.createSymlink(dir, linkToDir, false);
|
||||||
fc.setWorkingDirectory(linkToDir);
|
fc.setWorkingDirectory(linkToDir);
|
||||||
// Local file system does not resolve symlinks, others do.
|
assertEquals(linkToDir.getName(), fc.getWorkingDirectory().getName());
|
||||||
if ("file".equals(getScheme())) {
|
|
||||||
assertEquals(linkToDir.getName(), fc.getWorkingDirectory().getName());
|
|
||||||
} else {
|
|
||||||
assertEquals(dir.getName(), fc.getWorkingDirectory().getName());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -17,23 +17,24 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.hadoop.fs;
|
package org.apache.hadoop.fs;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
|
||||||
import java.io.DataInputStream;
|
import java.io.DataInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.io.InputStreamReader;
|
|
||||||
import java.util.EnumSet;
|
import java.util.EnumSet;
|
||||||
|
|
||||||
import org.apache.hadoop.fs.Options.CreateOpts;
|
import org.apache.hadoop.fs.Options.CreateOpts;
|
||||||
import org.apache.hadoop.fs.Options.CreateOpts.BlockSize;
|
import org.apache.hadoop.fs.Options.CreateOpts.BlockSize;
|
||||||
import org.apache.hadoop.io.IOUtils;
|
import org.apache.hadoop.io.IOUtils;
|
||||||
|
import org.junit.Assert;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper class for unit tests.
|
* Helper class for unit tests.
|
||||||
*/
|
*/
|
||||||
public final class FileContextTestHelper {
|
public final class FileContextTestHelper {
|
||||||
private static final String TEST_ROOT_DIR = System.getProperty("test.build.data",
|
// The test root is relative to the <wd>/build/test/data by default
|
||||||
"build/test/data") + "/test";
|
public static final String TEST_ROOT_DIR =
|
||||||
|
System.getProperty("test.build.data", "build/test/data") + "/test";
|
||||||
private static final int DEFAULT_BLOCK_SIZE = 1024;
|
private static final int DEFAULT_BLOCK_SIZE = 1024;
|
||||||
private static final int DEFAULT_NUM_BLOCKS = 2;
|
private static final int DEFAULT_NUM_BLOCKS = 2;
|
||||||
private static String absTestRootDir = null;
|
private static String absTestRootDir = null;
|
||||||
|
@ -61,20 +62,24 @@ public static Path getTestRootPath(FileContext fc, String pathString) {
|
||||||
return fc.makeQualified(new Path(TEST_ROOT_DIR, pathString));
|
return fc.makeQualified(new Path(TEST_ROOT_DIR, pathString));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// the getAbsolutexxx method is needed because the root test dir
|
||||||
|
// can be messed up by changing the working dir.
|
||||||
|
|
||||||
public static String getAbsoluteTestRootDir(FileContext fc)
|
public static String getAbsoluteTestRootDir(FileContext fc)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
if (absTestRootDir == null) {
|
if (absTestRootDir == null) {
|
||||||
if (TEST_ROOT_DIR.startsWith("/")) {
|
if (TEST_ROOT_DIR.startsWith("/")) {
|
||||||
absTestRootDir = TEST_ROOT_DIR;
|
absTestRootDir = TEST_ROOT_DIR;
|
||||||
} else {
|
} else {
|
||||||
absTestRootDir = getDefaultWorkingDirectory(fc).toString() + "/"
|
absTestRootDir = fc.getWorkingDirectory().toString() + "/"
|
||||||
+ TEST_ROOT_DIR;
|
+ TEST_ROOT_DIR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return absTestRootDir;
|
return absTestRootDir;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Path getTestRootDir(FileContext fc) throws IOException {
|
public static Path getAbsoluteTestRootPath(FileContext fc) throws IOException {
|
||||||
return fc.makeQualified(new Path(getAbsoluteTestRootDir(fc)));
|
return fc.makeQualified(new Path(getAbsoluteTestRootDir(fc)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -117,6 +122,11 @@ public static Path createFile(FileContext fc, String name) throws IOException {
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void createFileNonRecursive(FileContext fc, String name)
|
||||||
|
throws IOException {
|
||||||
|
Path path = getTestRootPath(fc, name);
|
||||||
|
createFileNonRecursive(fc, path);
|
||||||
|
}
|
||||||
public static void createFileNonRecursive(FileContext fc, Path path)
|
public static void createFileNonRecursive(FileContext fc, Path path)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
createFile(fc, path, DEFAULT_NUM_BLOCKS, CreateOpts.donotCreateParent());
|
createFile(fc, path, DEFAULT_NUM_BLOCKS, CreateOpts.donotCreateParent());
|
||||||
|
@ -150,18 +160,71 @@ public static boolean isSymlink(FileContext fc, Path p) throws IOException {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void writeFile(FileContext fc, Path path,byte b[]) throws Exception {
|
public static void writeFile(FileContext fc, Path path, byte b[])
|
||||||
|
throws Exception {
|
||||||
FSDataOutputStream out =
|
FSDataOutputStream out =
|
||||||
fc.create(path,EnumSet.of(CreateFlag.CREATE), CreateOpts.createParent());
|
fc.create(path,EnumSet.of(CreateFlag.CREATE), CreateOpts.createParent());
|
||||||
out.write(b);
|
out.write(b);
|
||||||
out.close();
|
out.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static byte[] readFile(FileContext fc, Path path, int len ) throws Exception {
|
public static byte[] readFile(FileContext fc, Path path, int len)
|
||||||
|
throws Exception {
|
||||||
DataInputStream dis = fc.open(path);
|
DataInputStream dis = fc.open(path);
|
||||||
byte[] buffer = new byte[len];
|
byte[] buffer = new byte[len];
|
||||||
IOUtils.readFully(dis, buffer, 0, len);
|
IOUtils.readFully(dis, buffer, 0, len);
|
||||||
dis.close();
|
dis.close();
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
|
public static FileStatus containsPath(FileContext fc, Path path,
|
||||||
|
FileStatus[] dirList)
|
||||||
|
throws IOException {
|
||||||
|
return containsPath(getTestRootPath(fc, path.toString()), dirList);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static FileStatus containsPath(Path path,
|
||||||
|
FileStatus[] dirList)
|
||||||
|
throws IOException {
|
||||||
|
for(int i = 0; i < dirList.length; i ++) {
|
||||||
|
if (path.equals(dirList[i].getPath()))
|
||||||
|
return dirList[i];
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static FileStatus containsPath(FileContext fc, String path,
|
||||||
|
FileStatus[] dirList)
|
||||||
|
throws IOException {
|
||||||
|
return containsPath(fc, new Path(path), dirList);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static enum fileType {isDir, isFile, isSymlink};
|
||||||
|
|
||||||
|
public static void checkFileStatus(FileContext aFc, String path,
|
||||||
|
fileType expectedType) throws IOException {
|
||||||
|
FileStatus s = aFc.getFileStatus(new Path(path));
|
||||||
|
Assert.assertNotNull(s);
|
||||||
|
if (expectedType == fileType.isDir) {
|
||||||
|
Assert.assertTrue(s.isDirectory());
|
||||||
|
} else if (expectedType == fileType.isFile) {
|
||||||
|
Assert.assertTrue(s.isFile());
|
||||||
|
} else if (expectedType == fileType.isSymlink) {
|
||||||
|
Assert.assertTrue(s.isSymlink());
|
||||||
|
}
|
||||||
|
Assert.assertEquals(aFc.makeQualified(new Path(path)), s.getPath());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void checkFileLinkStatus(FileContext aFc, String path,
|
||||||
|
fileType expectedType) throws IOException {
|
||||||
|
FileStatus s = aFc.getFileLinkStatus(new Path(path));
|
||||||
|
Assert.assertNotNull(s);
|
||||||
|
if (expectedType == fileType.isDir) {
|
||||||
|
Assert.assertTrue(s.isDirectory());
|
||||||
|
} else if (expectedType == fileType.isFile) {
|
||||||
|
Assert.assertTrue(s.isFile());
|
||||||
|
} else if (expectedType == fileType.isSymlink) {
|
||||||
|
Assert.assertTrue(s.isSymlink());
|
||||||
|
}
|
||||||
|
Assert.assertEquals(aFc.makeQualified(new Path(path)), s.getPath());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue