Search in sources :

Example 1 with UnderFileStatus

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;
    }
}
Also used : UnderFileStatus(alluxio.underfs.UnderFileStatus) File(java.io.File)

Example 2 with UnderFileStatus

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;
}
Also used : FileStatus(org.apache.hadoop.fs.FileStatus) UnderFileStatus(alluxio.underfs.UnderFileStatus) UnderFileStatus(alluxio.underfs.UnderFileStatus)

Example 3 with UnderFileStatus

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;
}
Also used : UnderFileStatus(alluxio.underfs.UnderFileStatus) UnderFileSystem(alluxio.underfs.UnderFileSystem)

Example 4 with UnderFileStatus

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());
}
Also used : Random(java.util.Random) UnderFileStatus(alluxio.underfs.UnderFileStatus) Test(org.junit.Test)

Example 5 with UnderFileStatus

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;
    }
}
Also used : LoadMetadataOptions(alluxio.master.file.options.LoadMetadataOptions) InodeDirectory(alluxio.master.file.meta.InodeDirectory) TempInodePathForChild(alluxio.master.file.meta.TempInodePathForChild) UnderFileStatus(alluxio.underfs.UnderFileStatus) IOException(java.io.IOException) MountTable(alluxio.master.file.meta.MountTable) UnderFileSystem(alluxio.underfs.UnderFileSystem) AlluxioURI(alluxio.AlluxioURI)

Aggregations

UnderFileStatus (alluxio.underfs.UnderFileStatus)7 UnderFileSystem (alluxio.underfs.UnderFileSystem)3 Test (org.junit.Test)2 AlluxioURI (alluxio.AlluxioURI)1 InodeDirectory (alluxio.master.file.meta.InodeDirectory)1 MountTable (alluxio.master.file.meta.MountTable)1 TempInodePathForChild (alluxio.master.file.meta.TempInodePathForChild)1 LoadMetadataOptions (alluxio.master.file.options.LoadMetadataOptions)1 JournalWriter (alluxio.master.journal.JournalWriter)1 ReadWriteJournal (alluxio.master.journal.ReadWriteJournal)1 File (java.io.File)1 IOException (java.io.IOException)1 Random (java.util.Random)1 FileStatus (org.apache.hadoop.fs.FileStatus)1 Matchers.anyString (org.mockito.Matchers.anyString)1