use of alluxio.underfs.UnderFileStatus in project alluxio by Alluxio.
the class LocalUnderFileSystem method listStatus.
@Override
public UnderFileStatus[] listStatus(String path) throws IOException {
path = stripPath(path);
File file = new File(path);
File[] files = file.listFiles();
if (files != null) {
UnderFileStatus[] rtn = new UnderFileStatus[files.length];
int i = 0;
for (File f : files) {
rtn[i++] = new UnderFileStatus(f.getName(), f.isDirectory());
}
return rtn;
} else {
return null;
}
}
use of alluxio.underfs.UnderFileStatus in project alluxio by Alluxio.
the class HdfsUnderFileSystem method listStatus.
@Override
public UnderFileStatus[] listStatus(String path) throws IOException {
FileStatus[] files = listStatusInternal(path);
if (files == null) {
return null;
}
UnderFileStatus[] rtn = new UnderFileStatus[files.length];
int i = 0;
for (FileStatus status : files) {
// only return the relative path, to keep consistent with java.io.File.list()
rtn[i++] = new UnderFileStatus(status.getPath().getName(), status.isDir());
}
return rtn;
}
use of alluxio.underfs.UnderFileStatus in project alluxio by Alluxio.
the class DefaultAlluxioMaster method isJournalFormatted.
/**
* Checks to see if the journal directory is formatted.
*
* @param journalDirectory the journal directory to check
* @return true if the journal directory was formatted previously, false otherwise
* @throws IOException if an I/O error occurs
*/
private boolean isJournalFormatted(String journalDirectory) throws IOException {
UnderFileSystem ufs = UnderFileSystem.Factory.get(journalDirectory);
UnderFileStatus[] files = ufs.listStatus(journalDirectory);
if (files == null) {
return false;
}
// Search for the format file.
String formatFilePrefix = Configuration.get(PropertyKey.MASTER_FORMAT_FILE_PREFIX);
for (UnderFileStatus file : files) {
if (file.getName().startsWith(formatFilePrefix)) {
return true;
}
}
return false;
}
use of alluxio.underfs.UnderFileStatus in project alluxio by Alluxio.
the class LoadMetadataOptionsTest method fields.
@Test
public void fields() {
Random random = new Random();
boolean isCreateAncestors = random.nextBoolean();
boolean isLoadDirectChildren = random.nextBoolean();
boolean isDirectory = random.nextBoolean();
LoadMetadataOptions options = LoadMetadataOptions.defaults();
options.setCreateAncestors(isCreateAncestors);
options.setLoadDirectChildren(isLoadDirectChildren);
options.setUnderFileStatus(new UnderFileStatus("dummy", isDirectory));
Assert.assertEquals(isCreateAncestors, options.isCreateAncestors());
Assert.assertEquals(isLoadDirectChildren, options.isLoadDirectChildren());
Assert.assertEquals(isDirectory, options.getUnderFileStatus().isDirectory());
}
use of alluxio.underfs.UnderFileStatus in project alluxio by Alluxio.
the class FileSystemMaster method loadMetadataAndJournal.
/**
* Loads metadata for the object identified by the given path from UFS into Alluxio.
* <p>
* Writes to the journal.
*
* @param inodePath the path for which metadata should be loaded
* @param options the load metadata options
* @param journalContext the journal context
* @throws InvalidPathException if invalid path is encountered
* @throws FileDoesNotExistException if there is no UFS path
* @throws BlockInfoException if an invalid block size is encountered
* @throws FileAlreadyCompletedException if the file is already completed
* @throws InvalidFileSizeException if invalid file size is encountered
* @throws AccessControlException if permission checking fails
* @throws IOException if an I/O error occurs
*/
private void loadMetadataAndJournal(LockedInodePath inodePath, LoadMetadataOptions options, JournalContext journalContext) throws InvalidPathException, FileDoesNotExistException, BlockInfoException, FileAlreadyCompletedException, InvalidFileSizeException, AccessControlException, IOException {
AlluxioURI path = inodePath.getUri();
MountTable.Resolution resolution = mMountTable.resolve(path);
AlluxioURI ufsUri = resolution.getUri();
UnderFileSystem ufs = resolution.getUfs();
try {
if (options.getUnderFileStatus() == null && !ufs.exists(ufsUri.toString())) {
// uri does not exist in ufs
InodeDirectory inode = (InodeDirectory) inodePath.getInode();
inode.setDirectChildrenLoaded(true);
}
boolean isFile;
if (options.getUnderFileStatus() != null) {
isFile = options.getUnderFileStatus().isFile();
} else {
isFile = ufs.isFile(ufsUri.toString());
}
if (isFile) {
loadFileMetadataAndJournal(inodePath, resolution, options, journalContext);
} else {
loadDirectoryMetadataAndJournal(inodePath, options, journalContext);
InodeDirectory inode = (InodeDirectory) inodePath.getInode();
if (options.isLoadDirectChildren()) {
UnderFileStatus[] files = ufs.listStatus(ufsUri.toString());
for (UnderFileStatus file : files) {
if (PathUtils.isTemporaryFileName(file.getName()) || inode.getChild(file.getName()) != null) {
continue;
}
TempInodePathForChild tempInodePath = new TempInodePathForChild(inodePath, file.getName());
LoadMetadataOptions loadMetadataOptions = LoadMetadataOptions.defaults().setLoadDirectChildren(false).setCreateAncestors(false).setUnderFileStatus(file);
loadMetadataAndJournal(tempInodePath, loadMetadataOptions, journalContext);
}
inode.setDirectChildrenLoaded(true);
}
}
} catch (IOException e) {
LOG.error(ExceptionUtils.getStackTrace(e));
throw e;
}
}
Aggregations