use of alluxio.wire.FileInfo in project alluxio by Alluxio.
the class FileSystemMaster method listStatus.
/**
* Returns a list of {@link FileInfo} for a given path. If the given path is a file, the list only
* contains a single object. If it is a directory, the resulting list contains all direct children
* of the directory.
* <p>
* This operation requires users to have
* {@link Mode.Bits#READ} permission on the path, and also
* {@link Mode.Bits#EXECUTE} permission on the path if it is a directory.
*
* @param path the path to get the {@link FileInfo} list for
* @param listStatusOptions the {@link alluxio.master.file.options.ListStatusOptions}
* @return the list of {@link FileInfo}s
* @throws AccessControlException if permission checking fails
* @throws FileDoesNotExistException if the file does not exist
* @throws InvalidPathException if the path is invalid
*/
public List<FileInfo> listStatus(AlluxioURI path, ListStatusOptions listStatusOptions) throws AccessControlException, FileDoesNotExistException, InvalidPathException {
Metrics.GET_FILE_INFO_OPS.inc();
try (JournalContext journalContext = createJournalContext();
LockedInodePath inodePath = mInodeTree.lockInodePath(path, InodeTree.LockMode.WRITE)) {
// This is WRITE locked, since loading metadata is possible.
mPermissionChecker.checkPermission(Mode.Bits.READ, inodePath);
LoadMetadataOptions loadMetadataOptions = LoadMetadataOptions.defaults().setCreateAncestors(true).setLoadDirectChildren(listStatusOptions.getLoadMetadataType() != LoadMetadataType.Never);
Inode<?> inode;
if (inodePath.fullPathExists()) {
inode = inodePath.getInode();
if (inode.isDirectory() && listStatusOptions.getLoadMetadataType() != LoadMetadataType.Always && ((InodeDirectory) inode).isDirectChildrenLoaded()) {
loadMetadataOptions.setLoadDirectChildren(false);
}
}
loadMetadataIfNotExistAndJournal(inodePath, loadMetadataOptions, journalContext);
mInodeTree.ensureFullInodePath(inodePath, InodeTree.LockMode.READ);
inode = inodePath.getInode();
List<FileInfo> ret = new ArrayList<>();
if (inode.isDirectory()) {
TempInodePathForDescendant tempInodePath = new TempInodePathForDescendant(inodePath);
mPermissionChecker.checkPermission(Mode.Bits.EXECUTE, inodePath);
for (Inode<?> child : ((InodeDirectory) inode).getChildren()) {
child.lockReadAndCheckParent(inode);
try {
// the path to child for getPath should already be locked.
tempInodePath.setDescendant(child, mInodeTree.getPath(child));
ret.add(getFileInfoInternal(tempInodePath));
} finally {
child.unlockRead();
}
}
} else {
ret.add(getFileInfoInternal(inodePath));
}
Metrics.FILE_INFOS_GOT.inc();
return ret;
}
}
use of alluxio.wire.FileInfo in project alluxio by Alluxio.
the class JournalIntegrationTest method aclTestUtil.
private void aclTestUtil(URIStatus status, String user) throws Exception {
FileSystemMaster fsMaster = createFsMasterFromJournal();
AuthenticatedClientUser.set(user);
FileInfo info = fsMaster.getFileInfo(new AlluxioURI("/file"));
Assert.assertEquals(status, new URIStatus(info));
fsMaster.stop();
}
use of alluxio.wire.FileInfo in project alluxio by Alluxio.
the class JournalIntegrationTest method pinTestUtil.
private void pinTestUtil(URIStatus directory, URIStatus file0, URIStatus file1) throws AccessControlException, IOException, InvalidPathException, FileDoesNotExistException {
FileSystemMaster fsMaster = createFsMasterFromJournal();
FileInfo info = fsMaster.getFileInfo(fsMaster.getFileId(new AlluxioURI("/myFolder")));
Assert.assertEquals(directory, new URIStatus(info));
Assert.assertTrue(info.isPinned());
info = fsMaster.getFileInfo(fsMaster.getFileId(new AlluxioURI("/myFolder/file0")));
Assert.assertEquals(file0, new URIStatus(info));
Assert.assertFalse(info.isPinned());
info = fsMaster.getFileInfo(fsMaster.getFileId(new AlluxioURI("/myFolder/file1")));
Assert.assertEquals(file1, new URIStatus(info));
Assert.assertTrue(info.isPinned());
fsMaster.stop();
}
use of alluxio.wire.FileInfo in project alluxio by Alluxio.
the class URIStatusTest method testEquals.
@Test
public void testEquals() throws Exception {
FileInfo fileInfo = FileInfoTest.createRandom();
URIStatus uriStatus1 = new URIStatus(fileInfo);
URIStatus uriStatus2 = new URIStatus(fileInfo);
Assert.assertTrue(uriStatus1.equals(uriStatus2));
Assert.assertEquals(uriStatus1.hashCode(), uriStatus2.hashCode());
}
use of alluxio.wire.FileInfo in project alluxio by Alluxio.
the class FileDataManager method prepareUfsFilePath.
/**
* Prepares the destination file path of the given file id. Also creates the parent folder if it
* does not exist.
*
* @param fileId the file id
* @return the path for persistence
* @throws AlluxioException if an unexpected Alluxio exception is thrown
* @throws IOException if the folder creation fails
*/
private String prepareUfsFilePath(long fileId) throws AlluxioException, IOException {
FileInfo fileInfo = mBlockWorker.getFileInfo(fileId);
AlluxioURI alluxioPath = new AlluxioURI(fileInfo.getPath());
FileSystem fs = FileSystem.Factory.get();
URIStatus status = fs.getStatus(alluxioPath);
String ufsPath = status.getUfsPath();
UnderFileSystem ufs = UnderFileSystem.Factory.get(ufsPath);
UnderFileSystemUtils.prepareFilePath(alluxioPath, ufsPath, fs, ufs);
return ufsPath;
}
Aggregations