Search in sources :

Example 6 with UfsFileStatus

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

the class LocalUnderFileSystem method listStatus.

@Override
public UfsStatus[] listStatus(String path) throws IOException {
    path = stripPath(path);
    File file = new File(path);
    // By default, exists follows symlinks. If the symlink is invalid .exists() returns false
    File[] files = mSkipBrokenSymlinks ? file.listFiles(File::exists) : file.listFiles();
    if (files != null) {
        UfsStatus[] rtn = new UfsStatus[files.length];
        int i = 0;
        for (File f : files) {
            // TODO(adit): do we need extra call for attributes?
            PosixFileAttributes attr = Files.readAttributes(Paths.get(f.getPath()), PosixFileAttributes.class);
            short mode = FileUtils.translatePosixPermissionToMode(attr.permissions());
            UfsStatus retStatus;
            if (f.isDirectory()) {
                retStatus = new UfsDirectoryStatus(f.getName(), attr.owner().getName(), attr.group().getName(), mode, f.lastModified());
            } else {
                String contentHash = UnderFileSystemUtils.approximateContentHash(f.length(), f.lastModified());
                retStatus = new UfsFileStatus(f.getName(), contentHash, f.length(), f.lastModified(), attr.owner().getName(), attr.group().getName(), mode, mUfsConf.getBytes(PropertyKey.USER_BLOCK_SIZE_BYTES_DEFAULT));
            }
            rtn[i++] = retStatus;
        }
        return rtn;
    } else {
        return null;
    }
}
Also used : UfsFileStatus(alluxio.underfs.UfsFileStatus) UfsStatus(alluxio.underfs.UfsStatus) PosixFileAttributes(java.nio.file.attribute.PosixFileAttributes) File(java.io.File) UfsDirectoryStatus(alluxio.underfs.UfsDirectoryStatus)

Example 7 with UfsFileStatus

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

the class CephFSUnderFileSystem method getFileStatus.

/**
 * Gets stat information on a file. This does not fill owner or group, as
 * Ceph's support for these is a bit different.
 *
 * @param path The path to stat
 * @return FileStatus object containing the stat information
 * @throws FileNotFoundException if the path could not be resolved
 */
@Override
public UfsFileStatus getFileStatus(String path) throws IOException {
    path = stripPath(path);
    CephStat stat = new CephStat();
    lstat(path, stat);
    String contentHash = UnderFileSystemUtils.approximateContentHash(stat.size, stat.m_time);
    return new UfsFileStatus(path, contentHash, stat.size, stat.m_time, "", "", (short) stat.mode);
}
Also used : UfsFileStatus(alluxio.underfs.UfsFileStatus) CephStat(com.ceph.fs.CephStat)

Example 8 with UfsFileStatus

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

the class UnderFileSystemCommonOperations method createThenGetExistingStatusTest.

/**
 * Test for getting existing status.
 */
@RelatedS3Operations(operations = {})
public void createThenGetExistingStatusTest() throws IOException {
    String testFile = PathUtils.concatPath(mTopLevelTestDirectory, "testFile");
    createTestBytesFile(testFile);
    UfsStatus status = mUfs.getExistingStatus(testFile);
    if (!(status instanceof UfsFileStatus)) {
        throw new IOException("Failed to get ufs file status");
    }
}
Also used : UfsFileStatus(alluxio.underfs.UfsFileStatus) UfsStatus(alluxio.underfs.UfsStatus) IOException(java.io.IOException)

Example 9 with UfsFileStatus

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

the class WebUnderFileSystem method getStatus.

/**
 * Get the file status of a http url.
 *
 * @param path the http url
 * @param fileName the file name
 * @return a UfsStatus object related to the http url
 */
private UfsStatus getStatus(String path, String fileName) throws IOException {
    long contentLength = 0;
    long lastModified = new Date().getTime();
    Header[] headers = HttpUtils.head(path, mTimeout);
    if (headers == null) {
        throw new IOException("Failed to getStatus: " + path);
    }
    for (Header header : headers) {
        String headerName = header.getName();
        if (headerName.equalsIgnoreCase("Content-Length")) {
            contentLength = Long.parseLong(header.getValue());
        } else if (headerName.equalsIgnoreCase("Last-Modified")) {
            lastModified = parseTimestamp(header.getValue(), mUfsConf.getString(PropertyKey.UNDERFS_WEB_HEADER_LAST_MODIFIED));
        }
    }
    if (isFile(path)) {
        // Return file status.
        String contentHash = UnderFileSystemUtils.approximateContentHash(contentLength, lastModified);
        return new UfsFileStatus(fileName == null ? path : fileName, contentHash, contentLength, lastModified, "", "", (short) 288, mUfsConf.getBytes(PropertyKey.USER_BLOCK_SIZE_BYTES_DEFAULT));
    }
    // Return directory status.
    return new UfsDirectoryStatus(fileName == null ? path : fileName, "", "", (short) 800, lastModified);
}
Also used : UfsFileStatus(alluxio.underfs.UfsFileStatus) Header(org.apache.http.Header) IOException(java.io.IOException) Date(java.util.Date) UfsDirectoryStatus(alluxio.underfs.UfsDirectoryStatus)

Example 10 with UfsFileStatus

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

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