Search in sources :

Example 56 with FileInfo

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;
    }
}
Also used : LockedInodePath(alluxio.master.file.meta.LockedInodePath) LoadMetadataOptions(alluxio.master.file.options.LoadMetadataOptions) InodeDirectory(alluxio.master.file.meta.InodeDirectory) TempInodePathForDescendant(alluxio.master.file.meta.TempInodePathForDescendant) FileInfo(alluxio.wire.FileInfo) ArrayList(java.util.ArrayList)

Example 57 with FileInfo

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();
}
Also used : FileInfo(alluxio.wire.FileInfo) FileSystemMaster(alluxio.master.file.FileSystemMaster) URIStatus(alluxio.client.file.URIStatus) AlluxioURI(alluxio.AlluxioURI)

Example 58 with FileInfo

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();
}
Also used : FileInfo(alluxio.wire.FileInfo) FileSystemMaster(alluxio.master.file.FileSystemMaster) URIStatus(alluxio.client.file.URIStatus) AlluxioURI(alluxio.AlluxioURI)

Example 59 with FileInfo

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());
}
Also used : FileInfo(alluxio.wire.FileInfo) FileInfoTest(alluxio.wire.FileInfoTest) Test(org.junit.Test)

Example 60 with FileInfo

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;
}
Also used : FileInfo(alluxio.wire.FileInfo) FileSystem(alluxio.client.file.FileSystem) UnderFileSystem(alluxio.underfs.UnderFileSystem) URIStatus(alluxio.client.file.URIStatus) UnderFileSystem(alluxio.underfs.UnderFileSystem) AlluxioURI(alluxio.AlluxioURI)

Aggregations

FileInfo (alluxio.wire.FileInfo)81 AlluxioURI (alluxio.AlluxioURI)60 Test (org.junit.Test)54 URIStatus (alluxio.client.file.URIStatus)12 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)12 CreateFileOptions (alluxio.master.file.options.CreateFileOptions)9 ArrayList (java.util.ArrayList)9 FileDoesNotExistException (alluxio.exception.FileDoesNotExistException)7 RestApiTest (alluxio.rest.RestApiTest)7 TestCase (alluxio.rest.TestCase)7 SetAndRestoreAuthenticatedUser (alluxio.SetAndRestoreAuthenticatedUser)6 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)5 FileSystemMaster (alluxio.master.file.FileSystemMaster)4 CreateOptions (alluxio.underfs.options.CreateOptions)4 OutputStream (java.io.OutputStream)4 InvalidPathException (alluxio.exception.InvalidPathException)3 FileSystemMasterView (alluxio.master.file.meta.FileSystemMasterView)3 LockedInodePath (alluxio.master.file.meta.LockedInodePath)3 FileBlockInfo (alluxio.wire.FileBlockInfo)3 IOException (java.io.IOException)3