Example usage for org.apache.hadoop.fs.viewfs ViewFileSystem resolvePath

List of usage examples for org.apache.hadoop.fs.viewfs ViewFileSystem resolvePath

Introduction

In this page you can find the example usage for org.apache.hadoop.fs.viewfs ViewFileSystem resolvePath.

Prototype

@Override
    public Path resolvePath(final Path f) throws IOException 

Source Link

Usage

From source file:org.apache.carbondata.core.util.path.HDFSLeaseUtils.java

License:Apache License

/**
 * This method will make attempts to recover lease on a file using the
 * distributed file system utility.//  w  w w. j  ava2s  .  c om
 *
 * @param filePath
 * @return
 * @throws IOException
 */
public static boolean recoverFileLease(String filePath) throws IOException {
    LOGGER.info("Trying to recover lease on file: " + filePath);
    FileFactory.FileType fileType = FileFactory.getFileType(filePath);
    switch (fileType) {
    case ALLUXIO:
    case HDFS:
    case S3:
        Path path = FileFactory.getPath(filePath);
        FileSystem fs = FileFactory.getFileSystem(path);
        return recoverLeaseOnFile(filePath, path, (DistributedFileSystem) fs);
    case VIEWFS:
        path = FileFactory.getPath(filePath);
        fs = FileFactory.getFileSystem(path);
        ViewFileSystem viewFileSystem = (ViewFileSystem) fs;
        Path targetFileSystemPath = viewFileSystem.resolvePath(path);
        FileSystem targetFileSystem = FileFactory.getFileSystem(targetFileSystemPath);
        if (targetFileSystem instanceof DistributedFileSystem) {
            return recoverLeaseOnFile(filePath, path, (DistributedFileSystem) targetFileSystem);
        } else {
            LOGGER.error(
                    "Invalid file type. Lease recovery is not supported on filesystem with file: " + filePath);
            return false;
        }
    default:
        LOGGER.error("Invalid file type. Lease recovery is not supported on filesystem with file: " + filePath);
        return false;
    }
}