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;
}
}
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);
}
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);
}
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);
}
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;
}
}
Aggregations