Search in sources :

Example 1 with ViewFileSystem

use of org.apache.hadoop.fs.viewfs.ViewFileSystem in project carbondata by apache.

the class ViewFSCarbonFile method renameForce.

@Override
public boolean renameForce(String changetoName) {
    FileSystem fs;
    try {
        fs = fileStatus.getPath().getFileSystem(FileFactory.getConfiguration());
        if (fs instanceof ViewFileSystem) {
            fs.delete(new Path(changetoName), true);
            fs.rename(fileStatus.getPath(), new Path(changetoName));
            return true;
        } else {
            return false;
        }
    } catch (IOException e) {
        LOGGER.error("Exception occured" + e.getMessage());
        return false;
    }
}
Also used : ViewFileSystem(org.apache.hadoop.fs.viewfs.ViewFileSystem) Path(org.apache.hadoop.fs.Path) FileSystem(org.apache.hadoop.fs.FileSystem) ViewFileSystem(org.apache.hadoop.fs.viewfs.ViewFileSystem) IOException(java.io.IOException)

Example 2 with ViewFileSystem

use of org.apache.hadoop.fs.viewfs.ViewFileSystem in project flink by apache.

the class HadoopRecoverableFsDataOutputStream method revokeLeaseByFileSystem.

/**
 * Resolve the real path of FileSystem if it is {@link ViewFileSystem} and revoke the lease of
 * the file we are resuming with different FileSystem.
 *
 * @param path The path to the file we want to resume writing to.
 */
private static boolean revokeLeaseByFileSystem(final FileSystem fs, final Path path) throws IOException {
    if (fs instanceof ViewFileSystem) {
        final ViewFileSystem vfs = (ViewFileSystem) fs;
        final Path resolvePath = vfs.resolvePath(path);
        final FileSystem resolveFs = resolvePath.getFileSystem(fs.getConf());
        return waitUntilLeaseIsRevoked(resolveFs, resolvePath);
    }
    return waitUntilLeaseIsRevoked(fs, path);
}
Also used : ViewFileSystem(org.apache.hadoop.fs.viewfs.ViewFileSystem) Path(org.apache.hadoop.fs.Path) DistributedFileSystem(org.apache.hadoop.hdfs.DistributedFileSystem) FileSystem(org.apache.hadoop.fs.FileSystem) ViewFileSystem(org.apache.hadoop.fs.viewfs.ViewFileSystem)

Example 3 with ViewFileSystem

use of org.apache.hadoop.fs.viewfs.ViewFileSystem in project carbondata by apache.

the class ViewFsCarbonFileTest method testlistFilesWithoutFilter.

@Test
public void testlistFilesWithoutFilter() {
    CarbonFileFilter carbonFileFilter = new CarbonFileFilter() {

        @Override
        public boolean accept(CarbonFile file) {
            return false;
        }
    };
    new MockUp<Path>() {

        @Mock
        public FileSystem getFileSystem(Configuration conf) throws IOException {
            return new ViewFileSystem();
        }
    };
    new MockUp<ViewFileSystem>() {

        @Mock
        public FileStatus[] listStatus(Path var1) throws IOException {
            return new FileStatus[] { new FileStatus(12L, true, 60, 120l, 180L, new Path(fileName)) };
        }
    };
    viewFSCarbonFile = new ViewFSCarbonFile(fileStatus);
    assertTrue(viewFSCarbonFile.listFiles(carbonFileFilter).length == 0);
}
Also used : ViewFileSystem(org.apache.hadoop.fs.viewfs.ViewFileSystem) Path(org.apache.hadoop.fs.Path) FileStatus(org.apache.hadoop.fs.FileStatus) Configuration(org.apache.hadoop.conf.Configuration) MockUp(mockit.MockUp) Test(org.junit.Test)

Example 4 with ViewFileSystem

use of org.apache.hadoop.fs.viewfs.ViewFileSystem in project carbondata by apache.

the class ViewFsCarbonFileTest method testListDirectory.

@Test
public void testListDirectory() {
    viewFSCarbonFile = new ViewFSCarbonFile(fileStatus);
    new MockUp<Path>() {

        @Mock
        public FileSystem getFileSystem(Configuration conf) throws IOException {
            return new ViewFileSystem();
        }
    };
    new MockUp<ViewFileSystem>() {

        @Mock
        public FileStatus[] listStatus(Path var1) throws IOException {
            return new FileStatus[] { new FileStatus(12L, true, 60, 120l, 180L, new Path(fileName)) };
        }
    };
    assertTrue(viewFSCarbonFile.listFiles().length == 1);
}
Also used : ViewFileSystem(org.apache.hadoop.fs.viewfs.ViewFileSystem) Path(org.apache.hadoop.fs.Path) FileStatus(org.apache.hadoop.fs.FileStatus) Configuration(org.apache.hadoop.conf.Configuration) MockUp(mockit.MockUp) Test(org.junit.Test)

Example 5 with ViewFileSystem

use of org.apache.hadoop.fs.viewfs.ViewFileSystem in project carbondata by apache.

the class HDFSLeaseUtils method recoverFileLease.

/**
 * This method will make attempts to recover lease on a file using the
 * distributed file system utility.
 *
 * @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;
    }
}
Also used : Path(org.apache.hadoop.fs.Path) ViewFileSystem(org.apache.hadoop.fs.viewfs.ViewFileSystem) DistributedFileSystem(org.apache.hadoop.hdfs.DistributedFileSystem) FileSystem(org.apache.hadoop.fs.FileSystem) ViewFileSystem(org.apache.hadoop.fs.viewfs.ViewFileSystem) DistributedFileSystem(org.apache.hadoop.hdfs.DistributedFileSystem) FileFactory(org.apache.carbondata.core.datastore.impl.FileFactory)

Aggregations

Path (org.apache.hadoop.fs.Path)5 ViewFileSystem (org.apache.hadoop.fs.viewfs.ViewFileSystem)5 FileSystem (org.apache.hadoop.fs.FileSystem)3 MockUp (mockit.MockUp)2 Configuration (org.apache.hadoop.conf.Configuration)2 FileStatus (org.apache.hadoop.fs.FileStatus)2 DistributedFileSystem (org.apache.hadoop.hdfs.DistributedFileSystem)2 Test (org.junit.Test)2 IOException (java.io.IOException)1 FileFactory (org.apache.carbondata.core.datastore.impl.FileFactory)1