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());
}
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;
}
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());
}
}
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());
}
}
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;
}
Aggregations