Example usage for org.apache.hadoop.fs FileSystemLinkResolver FileSystemLinkResolver

List of usage examples for org.apache.hadoop.fs FileSystemLinkResolver FileSystemLinkResolver

Introduction

In this page you can find the example usage for org.apache.hadoop.fs FileSystemLinkResolver FileSystemLinkResolver.

Prototype

FileSystemLinkResolver

Source Link

Usage

From source file:com.mellanox.r4h.DistributedFileSystem.java

License:Apache License

@Override
public BlockLocation[] getFileBlockLocations(Path p, final long start, final long len) throws IOException {
    statistics.incrementReadOps(1);//from  w  ww.  j  a va 2  s  . com
    final Path absF = fixRelativePart(p);
    return new FileSystemLinkResolver<BlockLocation[]>() {
        @Override
        public BlockLocation[] doCall(final Path p) throws IOException, UnresolvedLinkException {
            return dfs.getBlockLocations(getPathName(p), start, len);
        }

        @Override
        public BlockLocation[] next(final FileSystem fs, final Path p) throws IOException {
            return fs.getFileBlockLocations(p, start, len);
        }
    }.resolve(this, absF);
}

From source file:com.mellanox.r4h.DistributedFileSystem.java

License:Apache License

/**
 * Start the lease recovery of a file/*from w ww .j a  v a2  s . co m*/
 * 
 * @param f
 *            a file
 * @return true if the file is already closed
 * @throws IOException
 *             if an error occurs
 */
public boolean recoverLease(final Path f) throws IOException {
    Path absF = fixRelativePart(f);
    return new FileSystemLinkResolver<Boolean>() {
        @Override
        public Boolean doCall(final Path p) throws IOException, UnresolvedLinkException {
            return dfs.recoverLease(getPathName(p));
        }

        @Override
        public Boolean next(final FileSystem fs, final Path p) throws IOException {
            if (fs instanceof DistributedFileSystem) {
                DistributedFileSystem myDfs = (DistributedFileSystem) fs;
                return myDfs.recoverLease(p);
            }
            throw new UnsupportedOperationException("Cannot recoverLease through"
                    + " a symlink to a non-DistributedFileSystem: " + f + " -> " + p);
        }
    }.resolve(this, absF);
}

From source file:com.mellanox.r4h.DistributedFileSystem.java

License:Apache License

@Override
public FSDataInputStream open(Path f, final int bufferSize) throws IOException {
    statistics.incrementReadOps(1);//from   w  w w.j a v  a 2  s  . c  om
    Path absF = fixRelativePart(f);
    return new FileSystemLinkResolver<FSDataInputStream>() {
        @Override
        public FSDataInputStream doCall(final Path p) throws IOException, UnresolvedLinkException {
            final DFSInputStream dfsis = dfs.open(getPathName(p), bufferSize, verifyChecksum);
            return dfs.createWrappedInputStream(dfsis);
        }

        @Override
        public FSDataInputStream next(final FileSystem fs, final Path p) throws IOException {
            return fs.open(p, bufferSize);
        }
    }.resolve(this, absF);
}

From source file:com.mellanox.r4h.DistributedFileSystem.java

License:Apache License

/**
 * Append to an existing file (optional operation).
 * /*from  ww w .  ja v  a2  s  . co m*/
 * @param f
 *            the existing file to be appended.
 * @param flag
 *            Flags for the Append operation. CreateFlag.APPEND is mandatory
 *            to be present.
 * @param bufferSize
 *            the size of the buffer to be used.
 * @param progress
 *            for reporting progress if it is not null.
 * @return Returns instance of {@link FSDataOutputStream}
 * @throws IOException
 */
public FSDataOutputStream append(Path f, final EnumSet<CreateFlag> flag, final int bufferSize,
        final Progressable progress) throws IOException {
    statistics.incrementWriteOps(1);
    Path absF = fixRelativePart(f);
    return new FileSystemLinkResolver<FSDataOutputStream>() {
        @Override
        public FSDataOutputStream doCall(final Path p) throws IOException {
            return dfs.append(getPathName(p), bufferSize, flag, progress, statistics);
        }

        @Override
        public FSDataOutputStream next(final FileSystem fs, final Path p) throws IOException {
            return fs.append(p, bufferSize);
        }
    }.resolve(this, absF);
}

From source file:com.mellanox.r4h.DistributedFileSystem.java

License:Apache License

/**
 * Append to an existing file (optional operation).
 * //from   w w  w .java 2  s.  c  o  m
 * @param f
 *            the existing file to be appended.
 * @param flag
 *            Flags for the Append operation. CreateFlag.APPEND is mandatory
 *            to be present.
 * @param bufferSize
 *            the size of the buffer to be used.
 * @param progress
 *            for reporting progress if it is not null.
 * @param favoredNodes
 *            Favored nodes for new blocks
 * @return Returns instance of {@link FSDataOutputStream}
 * @throws IOException
 */
public FSDataOutputStream append(Path f, final EnumSet<CreateFlag> flag, final int bufferSize,
        final Progressable progress, final InetSocketAddress[] favoredNodes) throws IOException {
    statistics.incrementWriteOps(1);
    Path absF = fixRelativePart(f);
    return new FileSystemLinkResolver<FSDataOutputStream>() {
        @Override
        public FSDataOutputStream doCall(final Path p) throws IOException {
            return dfs.append(getPathName(p), bufferSize, flag, progress, statistics, favoredNodes);
        }

        @Override
        public FSDataOutputStream next(final FileSystem fs, final Path p) throws IOException {
            return fs.append(p, bufferSize);
        }
    }.resolve(this, absF);
}

From source file:com.mellanox.r4h.DistributedFileSystem.java

License:Apache License

/**
 * Same as {@link #create(Path, FsPermission, boolean, int, short, long, Progressable)} with the addition of favoredNodes that is a hint to
 * where the namenode should place the file blocks.
 * The favored nodes hint is not persisted in HDFS. Hence it may be honored
 * at the creation time only. And with favored nodes, blocks will be pinned
 * on the datanodes to prevent balancing move the block. HDFS could move the
 * blocks during replication, to move the blocks from favored nodes. A value
 * of null means no favored nodes for this create
 *///w  w  w .j a v a2 s . c  om
public HdfsDataOutputStream create(final Path f, final FsPermission permission, final boolean overwrite,
        final int bufferSize, final short replication, final long blockSize, final Progressable progress,
        final InetSocketAddress[] favoredNodes) throws IOException {
    statistics.incrementWriteOps(1);
    Path absF = fixRelativePart(f);
    return new FileSystemLinkResolver<HdfsDataOutputStream>() {
        @Override
        public HdfsDataOutputStream doCall(final Path p) throws IOException, UnresolvedLinkException {
            final DFSOutputStream out = dfs.create(getPathName(f), permission,
                    overwrite ? EnumSet.of(CreateFlag.CREATE, CreateFlag.OVERWRITE)
                            : EnumSet.of(CreateFlag.CREATE),
                    true, replication, blockSize, progress, bufferSize, null, favoredNodes);
            return dfs.createWrappedOutputStream(out, statistics);
        }

        @Override
        public HdfsDataOutputStream next(final FileSystem fs, final Path p) throws IOException {
            if (fs instanceof DistributedFileSystem) {
                DistributedFileSystem myDfs = (DistributedFileSystem) fs;
                return myDfs.create(p, permission, overwrite, bufferSize, replication, blockSize, progress,
                        favoredNodes);
            }
            throw new UnsupportedOperationException("Cannot create with"
                    + " favoredNodes through a symlink to a non-DistributedFileSystem: " + f + " -> " + p);
        }
    }.resolve(this, absF);
}

From source file:com.mellanox.r4h.DistributedFileSystem.java

License:Apache License

@Override
public FSDataOutputStream create(final Path f, final FsPermission permission, final EnumSet<CreateFlag> cflags,
        final int bufferSize, final short replication, final long blockSize, final Progressable progress,
        final ChecksumOpt checksumOpt) throws IOException {
    statistics.incrementWriteOps(1);/* w ww. j ava2 s. co m*/
    Path absF = fixRelativePart(f);
    return new FileSystemLinkResolver<FSDataOutputStream>() {
        @Override
        public FSDataOutputStream doCall(final Path p) throws IOException, UnresolvedLinkException {
            final DFSOutputStream dfsos = dfs.create(getPathName(p), permission, cflags, replication, blockSize,
                    progress, bufferSize, checksumOpt);
            return dfs.createWrappedOutputStream(dfsos, statistics);
        }

        @Override
        public FSDataOutputStream next(final FileSystem fs, final Path p) throws IOException {
            return fs.create(p, permission, cflags, bufferSize, replication, blockSize, progress, checksumOpt);
        }
    }.resolve(this, absF);
}

From source file:com.mellanox.r4h.DistributedFileSystem.java

License:Apache License

/**
 * Same as create(), except fails if parent directory doesn't already exist.
 *///ww  w  . j a v a  2 s  . c  o m
@Override
@SuppressWarnings("deprecation")
public FSDataOutputStream createNonRecursive(final Path f, final FsPermission permission,
        final EnumSet<CreateFlag> flag, final int bufferSize, final short replication, final long blockSize,
        final Progressable progress) throws IOException {
    statistics.incrementWriteOps(1);
    if (flag.contains(CreateFlag.OVERWRITE)) {
        flag.add(CreateFlag.CREATE);
    }
    Path absF = fixRelativePart(f);
    return new FileSystemLinkResolver<FSDataOutputStream>() {
        @Override
        public FSDataOutputStream doCall(final Path p) throws IOException, UnresolvedLinkException {
            final DFSOutputStream dfsos = dfs.create(getPathName(p), permission, flag, false, replication,
                    blockSize, progress, bufferSize, null);
            return dfs.createWrappedOutputStream(dfsos, statistics);
        }

        @Override
        public FSDataOutputStream next(final FileSystem fs, final Path p) throws IOException {
            return fs.createNonRecursive(p, permission, flag, bufferSize, replication, blockSize, progress);
        }
    }.resolve(this, absF);
}

From source file:com.mellanox.r4h.DistributedFileSystem.java

License:Apache License

@Override
public boolean setReplication(Path src, final short replication) throws IOException {
    statistics.incrementWriteOps(1);//from w w w. j a  va  2 s .  c  om
    Path absF = fixRelativePart(src);
    return new FileSystemLinkResolver<Boolean>() {
        @Override
        public Boolean doCall(final Path p) throws IOException, UnresolvedLinkException {
            return dfs.setReplication(getPathName(p), replication);
        }

        @Override
        public Boolean next(final FileSystem fs, final Path p) throws IOException {
            return fs.setReplication(p, replication);
        }
    }.resolve(this, absF);
}

From source file:com.mellanox.r4h.DistributedFileSystem.java

License:Apache License

/**
 * Set the source path to the specified storage policy.
 * //from w  w  w.j  av a  2 s .  com
 * @param src
 *            The source path referring to either a directory or a file.
 * @param policyName
 *            The name of the storage policy.
 */
public void setStoragePolicy(final Path src, final String policyName) throws IOException {
    statistics.incrementWriteOps(1);
    Path absF = fixRelativePart(src);
    new FileSystemLinkResolver<Void>() {
        @Override
        public Void doCall(final Path p) throws IOException, UnresolvedLinkException {
            dfs.setStoragePolicy(getPathName(p), policyName);
            return null;
        }

        @Override
        public Void next(final FileSystem fs, final Path p) throws IOException {
            if (fs instanceof DistributedFileSystem) {
                ((DistributedFileSystem) fs).setStoragePolicy(p, policyName);
                return null;
            } else {
                throw new UnsupportedOperationException(
                        "Cannot perform setStoragePolicy on a non-DistributedFileSystem: " + src + " -> " + p);
            }
        }
    }.resolve(this, absF);
}