Search in sources :

Example 11 with UfsFileStatus

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

the class HdfsUnderFileSystem method getFileStatus.

@Override
public UfsFileStatus getFileStatus(String path) throws IOException {
    Path tPath = new Path(path);
    FileSystem hdfs = getFs();
    FileStatus fs = hdfs.getFileStatus(tPath);
    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());
}
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)

Example 12 with UfsFileStatus

use of alluxio.underfs.UfsFileStatus 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 UfsFileStatus

use of alluxio.underfs.UfsFileStatus 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 UfsFileStatus

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

the class LocalUnderFileSystem method getFileStatus.

@Override
public UfsFileStatus getFileStatus(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 a file", path));
        }
        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));
    } catch (FileSystemException e) {
        throw new FileNotFoundException(e.getMessage());
    }
}
Also used : UfsFileStatus(alluxio.underfs.UfsFileStatus) FileSystemException(java.nio.file.FileSystemException) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) PosixFileAttributes(java.nio.file.attribute.PosixFileAttributes) File(java.io.File)

Example 15 with UfsFileStatus

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

the class FileSystemMasterSyncMetadataTest method setAttributeOwnerGroupOnMetadataUpdate.

@Test
public void setAttributeOwnerGroupOnMetadataUpdate() throws Exception {
    AlluxioURI ufsMount = setupMockUfsS3Mount();
    String fname = "file";
    AlluxioURI uri = new AlluxioURI("/mnt/local/" + fname);
    short mode = ModeUtils.getUMask("0700").toShort();
    // Mock dir1 ufs path
    AlluxioURI filePath = ufsMount.join("file");
    UfsFileStatus fileStatus = new UfsFileStatus("file", "", 0L, System.currentTimeMillis(), "owner1", "owner1", (short) 777, null, 100L);
    Mockito.when(mUfs.getFingerprint(filePath.toString())).thenReturn(Fingerprint.create("s3", fileStatus).serialize());
    Mockito.when(mUfs.exists(filePath.toString())).thenReturn(true);
    Mockito.when(mUfs.isDirectory(filePath.toString())).thenReturn(false);
    Mockito.when(mUfs.isFile(filePath.toString())).thenReturn(true);
    Mockito.when(mUfs.getStatus(filePath.toString())).thenReturn(fileStatus);
    List<FileInfo> f1 = mFileSystemMaster.listStatus(uri, ListStatusContext.mergeFrom(ListStatusPOptions.newBuilder().setCommonOptions(FileSystemMasterCommonPOptions.newBuilder().setSyncIntervalMs(0).build())));
    UfsFileStatus updatedStatus = new UfsFileStatus("file", "", 0, System.currentTimeMillis(), "owner2", "owner2", (short) 777, null, 100);
    Mockito.when(mUfs.getStatus(filePath.toString())).thenReturn(updatedStatus);
    Mockito.when(mUfs.getFingerprint(filePath.toString())).thenReturn(Fingerprint.create("s3", updatedStatus).serialize());
    FileInfo res = mFileSystemMaster.getFileInfo(uri, GetStatusContext.mergeFrom(GetStatusPOptions.newBuilder().setCommonOptions(FileSystemMasterCommonPOptions.newBuilder().setSyncIntervalMs(0).build())));
    assertEquals("owner2", res.getOwner());
    assertEquals("owner2", res.getGroup());
}
Also used : UfsFileStatus(alluxio.underfs.UfsFileStatus) FileInfo(alluxio.wire.FileInfo) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) AlluxioURI(alluxio.AlluxioURI) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

UfsFileStatus (alluxio.underfs.UfsFileStatus)16 UfsDirectoryStatus (alluxio.underfs.UfsDirectoryStatus)7 UfsStatus (alluxio.underfs.UfsStatus)6 UnderFileSystem (alluxio.underfs.UnderFileSystem)4 IOException (java.io.IOException)4 AlluxioURI (alluxio.AlluxioURI)3 File (java.io.File)3 FileNotFoundException (java.io.FileNotFoundException)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 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 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2