use of alluxio.underfs.UnderFileSystem in project alluxio by Alluxio.
the class Format method formatFolder.
private static boolean formatFolder(String name, String folder) throws IOException {
UnderFileSystem ufs = UnderFileSystem.Factory.get(folder);
LOG.info("Formatting {}:{}", name, folder);
if (ufs.isDirectory(folder)) {
for (UnderFileStatus p : ufs.listStatus(folder)) {
String childPath = PathUtils.concatPath(folder, p.getName());
boolean failedToDelete;
if (p.isDirectory()) {
failedToDelete = !ufs.deleteDirectory(childPath, DeleteOptions.defaults().setRecursive(true));
} else {
failedToDelete = !ufs.deleteFile(childPath);
}
if (failedToDelete) {
LOG.info("Failed to delete {}", childPath);
return false;
}
}
} else if (!ufs.mkdirs(folder)) {
LOG.info("Failed to create {}:{}", name, folder);
return false;
}
return true;
}
use of alluxio.underfs.UnderFileSystem in project alluxio by Alluxio.
the class CheckConsistencyIntegrationTest method largeTree.
/**
* Tests the {@link FileSystemMaster#checkConsistency(AlluxioURI, CheckConsistencyOptions)} method
* when some files are consistent in a larger inode tree.
*/
@Test
public void largeTree() throws Exception {
CreateDirectoryOptions dirOptions = CreateDirectoryOptions.defaults().setWriteType(WriteType.CACHE_THROUGH);
CreateFileOptions fileOptions = CreateFileOptions.defaults().setWriteType(WriteType.CACHE_THROUGH);
AlluxioURI nestedDir = DIRECTORY.join("/dir2");
AlluxioURI topLevelFile = new AlluxioURI("/file");
AlluxioURI thirdLevelFile = nestedDir.join("/file");
mFileSystem.createDirectory(nestedDir, dirOptions);
mFileSystem.createFile(topLevelFile, fileOptions).close();
mFileSystem.createFile(thirdLevelFile, fileOptions).close();
String ufsDirectory = mFileSystem.getStatus(nestedDir).getUfsPath();
UnderFileSystem ufs = UnderFileSystem.Factory.get(ufsDirectory);
ufs.deleteDirectory(ufsDirectory, DeleteOptions.defaults().setRecursive(true));
List<AlluxioURI> expected = Lists.newArrayList(nestedDir, thirdLevelFile);
List<AlluxioURI> result = mFileSystemMaster.checkConsistency(new AlluxioURI("/"), CheckConsistencyOptions.defaults());
Collections.sort(expected);
Collections.sort(result);
Assert.assertEquals(expected, result);
}
use of alluxio.underfs.UnderFileSystem in project alluxio by Alluxio.
the class CheckConsistencyIntegrationTest method partiallyInconsistent.
/**
* Tests the {@link FileSystemMaster#checkConsistency(AlluxioURI, CheckConsistencyOptions)} method
* when some files are consistent.
*/
@Test
public void partiallyInconsistent() throws Exception {
String ufsFile = mFileSystem.getStatus(FILE).getUfsPath();
UnderFileSystem ufs = UnderFileSystem.Factory.get(ufsFile);
ufs.deleteFile(ufsFile);
List<AlluxioURI> expected = Lists.newArrayList(FILE);
Assert.assertEquals(expected, mFileSystemMaster.checkConsistency(new AlluxioURI("/"), CheckConsistencyOptions.defaults()));
}
use of alluxio.underfs.UnderFileSystem in project alluxio by Alluxio.
the class CheckConsistencyIntegrationTest method inconsistentFile.
/**
* Tests the {@link FileSystemMaster#checkConsistency(AlluxioURI, CheckConsistencyOptions)} method
* when running on a file that is inconsistent.
*/
@Test
public void inconsistentFile() throws Exception {
String ufsFile = mFileSystem.getStatus(FILE).getUfsPath();
UnderFileSystem ufs = UnderFileSystem.Factory.get(ufsFile);
ufs.deleteFile(ufsFile);
List<AlluxioURI> expected = Lists.newArrayList(FILE);
Assert.assertEquals(expected, mFileSystemMaster.checkConsistency(FILE, CheckConsistencyOptions.defaults()));
}
use of alluxio.underfs.UnderFileSystem in project alluxio by Alluxio.
the class MountPointInfo method setUfsInfo.
/**
* Sets information related to under filesystem, including its uri, type, storage usage.
*
* @param ufsUri the under filesystem uri
*/
public void setUfsInfo(String ufsUri) {
mUfsUri = ufsUri;
UnderFileSystem ufs = UnderFileSystem.Factory.get(mUfsUri);
mUfsType = ufs.getUnderFSType();
try {
mUfsCapacityBytes = ufs.getSpace(mUfsUri, UnderFileSystem.SpaceType.SPACE_TOTAL);
} catch (IOException e) {
mUfsCapacityBytes = UNKNOWN_CAPACITY_BYTES;
}
try {
mUfsUsedBytes = ufs.getSpace(mUfsUri, UnderFileSystem.SpaceType.SPACE_USED);
} catch (IOException e) {
mUfsUsedBytes = UNKNOWN_USED_BYTES;
}
}
Aggregations