Search in sources :

Example 11 with UfsDirectoryStatus

use of alluxio.underfs.UfsDirectoryStatus in project alluxio by Alluxio.

the class HdfsUnderFileSystem method getStatus.

@Override
public UfsStatus getStatus(String path) throws IOException {
    Path tPath = new Path(path);
    FileSystem hdfs = getFs();
    FileStatus fs = hdfs.getFileStatus(tPath);
    if (!fs.isDir()) {
        // Return file status.
        String contentHash = UnderFileSystemUtils.approximateContentHash(fs.getLen(), fs.getModificationTime());
        return new UfsFileStatus(path, contentHash, fs.getLen(), fs.getModificationTime(), fs.getOwner(), fs.getGroup(), fs.getPermission().toShort(), fs.getBlockSize());
    }
    // Return directory status.
    return new UfsDirectoryStatus(path, fs.getOwner(), fs.getGroup(), fs.getPermission().toShort(), fs.getModificationTime());
}
Also used : Path(org.apache.hadoop.fs.Path) UfsFileStatus(alluxio.underfs.UfsFileStatus) FileStatus(org.apache.hadoop.fs.FileStatus) UfsFileStatus(alluxio.underfs.UfsFileStatus) FileSystem(org.apache.hadoop.fs.FileSystem) UnderFileSystem(alluxio.underfs.UnderFileSystem) ConsistentUnderFileSystem(alluxio.underfs.ConsistentUnderFileSystem) DistributedFileSystem(org.apache.hadoop.hdfs.DistributedFileSystem) UfsDirectoryStatus(alluxio.underfs.UfsDirectoryStatus)

Example 12 with UfsDirectoryStatus

use of alluxio.underfs.UfsDirectoryStatus in project alluxio by Alluxio.

the class CephFSUnderFileSystem method listStatus.

/**
 * Each string is a name rather than a complete path.
 *
 * @param path the path to list
 * @return An array with the statuses of the files and directories in the directory
 * denoted by this path. The array will be empty if the directory is empty. Returns
 * null if this path does not denote a directory
 */
@Override
@Nullable
public UfsStatus[] listStatus(String path) throws IOException {
    path = stripPath(path);
    String[] lst = listDirectory(path);
    if (lst != null) {
        UfsStatus[] status = new UfsStatus[lst.length];
        for (int i = 0; i < status.length; i++) {
            CephStat stat = new CephStat();
            lstat(PathUtils.concatPath(path, lst[i]), stat);
            if (!stat.isDir()) {
                String contentHash = UnderFileSystemUtils.approximateContentHash(stat.size, stat.m_time);
                status[i] = new UfsFileStatus(lst[i], contentHash, stat.size, stat.m_time, "", "", (short) stat.mode);
            } else {
                status[i] = new UfsDirectoryStatus(lst[i], "", "", (short) stat.mode);
            }
        }
        return status;
    }
    return null;
}
Also used : UfsFileStatus(alluxio.underfs.UfsFileStatus) UfsStatus(alluxio.underfs.UfsStatus) CephStat(com.ceph.fs.CephStat) UfsDirectoryStatus(alluxio.underfs.UfsDirectoryStatus) Nullable(javax.annotation.Nullable)

Example 13 with UfsDirectoryStatus

use of alluxio.underfs.UfsDirectoryStatus in project alluxio by Alluxio.

the class LocalUnderFileSystem method getStatus.

@Override
public UfsStatus getStatus(String path) throws IOException {
    String tpath = stripPath(path);
    File file = new File(tpath);
    try {
        PosixFileAttributes attr = Files.readAttributes(Paths.get(file.getPath()), PosixFileAttributes.class);
        if (file.isFile()) {
            // Return file status.
            String contentHash = UnderFileSystemUtils.approximateContentHash(file.length(), file.lastModified());
            return new UfsFileStatus(path, contentHash, file.length(), file.lastModified(), attr.owner().getName(), attr.group().getName(), FileUtils.translatePosixPermissionToMode(attr.permissions()), mUfsConf.getBytes(PropertyKey.USER_BLOCK_SIZE_BYTES_DEFAULT));
        }
        // Return directory status.
        return new UfsDirectoryStatus(path, attr.owner().getName(), attr.group().getName(), FileUtils.translatePosixPermissionToMode(attr.permissions()), file.lastModified());
    } catch (FileSystemException e) {
        throw new FileNotFoundException(e.getMessage());
    }
}
Also used : UfsFileStatus(alluxio.underfs.UfsFileStatus) FileSystemException(java.nio.file.FileSystemException) FileNotFoundException(java.io.FileNotFoundException) PosixFileAttributes(java.nio.file.attribute.PosixFileAttributes) File(java.io.File) UfsDirectoryStatus(alluxio.underfs.UfsDirectoryStatus)

Example 14 with UfsDirectoryStatus

use of alluxio.underfs.UfsDirectoryStatus in project alluxio by Alluxio.

the class LocalUnderFileSystem method getDirectoryStatus.

@Override
public UfsDirectoryStatus getDirectoryStatus(String path) throws IOException {
    String tpath = stripPath(path);
    File file = new File(tpath);
    try {
        PosixFileAttributes attr = Files.readAttributes(Paths.get(file.getPath()), PosixFileAttributes.class);
        if (!attr.isDirectory()) {
            throw new IOException(String.format("path %s is not directory", path));
        }
        return new UfsDirectoryStatus(path, attr.owner().getName(), attr.group().getName(), FileUtils.translatePosixPermissionToMode(attr.permissions()), file.lastModified());
    } catch (FileSystemException e) {
        throw new FileNotFoundException(e.getMessage());
    }
}
Also used : FileSystemException(java.nio.file.FileSystemException) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) PosixFileAttributes(java.nio.file.attribute.PosixFileAttributes) File(java.io.File) UfsDirectoryStatus(alluxio.underfs.UfsDirectoryStatus)

Example 15 with UfsDirectoryStatus

use of alluxio.underfs.UfsDirectoryStatus in project alluxio by Alluxio.

the class FileSystemMasterSyncMetadataTest method setupMockUfsS3Mount.

private AlluxioURI setupMockUfsS3Mount() throws IOException, FileDoesNotExistException, FileAlreadyExistsException, AccessControlException, InvalidPathException {
    mFileSystemMaster.createDirectory(new AlluxioURI("/mnt/"), CreateDirectoryContext.defaults());
    // Mock ufs mount
    AlluxioURI ufsMount = new AlluxioURI("s3a://bucket/");
    Mockito.when(mUfs.getUnderFSType()).thenReturn("s3");
    Mockito.when(mUfs.isObjectStorage()).thenReturn(true);
    Mockito.when(mUfs.isDirectory(ufsMount.toString())).thenReturn(true);
    short mode = ModeUtils.getUMask("0700").toShort();
    Mockito.when(mUfs.getExistingDirectoryStatus(ufsMount.toString())).thenReturn(new UfsDirectoryStatus(ufsMount.toString(), "", "", mode));
    Mockito.when(mUfs.resolveUri(Mockito.eq(ufsMount), anyString())).thenAnswer(invocation -> new AlluxioURI(ufsMount, PathUtils.concatPath(ufsMount.getPath(), invocation.getArgument(1, String.class)), false));
    // Mount
    AlluxioURI mountLocal = new AlluxioURI("/mnt/local");
    mFileSystemMaster.mount(mountLocal, ufsMount, MountContext.defaults());
    return ufsMount;
}
Also used : ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) UfsDirectoryStatus(alluxio.underfs.UfsDirectoryStatus) AlluxioURI(alluxio.AlluxioURI)

Aggregations

UfsDirectoryStatus (alluxio.underfs.UfsDirectoryStatus)15 UfsFileStatus (alluxio.underfs.UfsFileStatus)8 UfsStatus (alluxio.underfs.UfsStatus)5 IOException (java.io.IOException)5 AlluxioURI (alluxio.AlluxioURI)3 UnderFileSystem (alluxio.underfs.UnderFileSystem)3 File (java.io.File)3 PosixFileAttributes (java.nio.file.attribute.PosixFileAttributes)3 FileStatus (org.apache.hadoop.fs.FileStatus)3 Test (org.junit.Test)3 ConsistentUnderFileSystem (alluxio.underfs.ConsistentUnderFileSystem)2 FileInfo (alluxio.wire.FileInfo)2 CephStat (com.ceph.fs.CephStat)2 FileNotFoundException (java.io.FileNotFoundException)2 FileSystemException (java.nio.file.FileSystemException)2 Nullable (javax.annotation.Nullable)2 FileSystem (org.apache.hadoop.fs.FileSystem)2 Path (org.apache.hadoop.fs.Path)2 DistributedFileSystem (org.apache.hadoop.hdfs.DistributedFileSystem)2 AccessControlException (alluxio.exception.AccessControlException)1