use of alluxio.wire.FileInfo in project alluxio by Alluxio.
the class FileSystemMasterTest method getFileInfo.
/**
* Tests the {@link FileSystemMaster#getFileInfo(AlluxioURI)} method.
*/
@Test
public void getFileInfo() throws Exception {
createFileWithSingleBlock(NESTED_FILE_URI);
long fileId;
FileInfo info;
fileId = mFileSystemMaster.getFileId(ROOT_URI);
info = mFileSystemMaster.getFileInfo(fileId);
Assert.assertEquals(ROOT_URI.getPath(), info.getPath());
Assert.assertEquals(ROOT_URI.getPath(), mFileSystemMaster.getFileInfo(ROOT_URI).getPath());
fileId = mFileSystemMaster.getFileId(NESTED_URI);
info = mFileSystemMaster.getFileInfo(fileId);
Assert.assertEquals(NESTED_URI.getPath(), info.getPath());
Assert.assertEquals(NESTED_URI.getPath(), mFileSystemMaster.getFileInfo(NESTED_URI).getPath());
fileId = mFileSystemMaster.getFileId(NESTED_FILE_URI);
info = mFileSystemMaster.getFileInfo(fileId);
Assert.assertEquals(NESTED_FILE_URI.getPath(), info.getPath());
Assert.assertEquals(NESTED_FILE_URI.getPath(), mFileSystemMaster.getFileInfo(NESTED_FILE_URI).getPath());
// Test non-existent id.
try {
mFileSystemMaster.getFileInfo(fileId + 1234);
Assert.fail("getFileInfo() for a non-existent id should fail.");
} catch (FileDoesNotExistException e) {
// Expected case.
}
// Test non-existent URIs.
try {
mFileSystemMaster.getFileInfo(ROOT_FILE_URI);
Assert.fail("getFileInfo() for a non-existent URI should fail.");
} catch (FileDoesNotExistException e) {
// Expected case.
}
try {
mFileSystemMaster.getFileInfo(TEST_URI);
Assert.fail("getFileInfo() for a non-existent URI should fail.");
} catch (FileDoesNotExistException e) {
// Expected case.
}
try {
mFileSystemMaster.getFileInfo(NESTED_URI.join("DNE"));
Assert.fail("getFileInfo() for a non-existent URI should fail.");
} catch (FileDoesNotExistException e) {
// Expected case.
}
}
use of alluxio.wire.FileInfo in project alluxio by Alluxio.
the class FileSystemMasterTest method listStatusWithLoadMetadataNever.
@Test
public void listStatusWithLoadMetadataNever() throws Exception {
AlluxioURI ufsMount = new AlluxioURI(mTestFolder.newFolder().getAbsolutePath());
mFileSystemMaster.createDirectory(new AlluxioURI("/mnt/"), CreateDirectoryOptions.defaults());
// Create ufs file
Files.createDirectory(Paths.get(ufsMount.join("dir1").getPath()));
Files.createFile(Paths.get(ufsMount.join("dir1").join("file1").getPath()));
Files.createFile(Paths.get(ufsMount.join("dir1").join("file2").getPath()));
mFileSystemMaster.mount(new AlluxioURI("/mnt/local"), ufsMount, MountOptions.defaults());
// 3 directories exist.
Assert.assertEquals(3, mFileSystemMaster.getNumberOfPaths());
// getFileId should load metadata automatically.
AlluxioURI uri = new AlluxioURI("/mnt/local/dir1");
List<FileInfo> fileInfoList = mFileSystemMaster.listStatus(uri, ListStatusOptions.defaults().setLoadMetadataType(LoadMetadataType.Never));
Assert.assertEquals(0, fileInfoList.size());
Assert.assertEquals(4, mFileSystemMaster.getNumberOfPaths());
}
use of alluxio.wire.FileInfo in project alluxio by Alluxio.
the class PermissionCheckTest method verifySetState.
private SetAttributeOptions verifySetState(TestUser user, String path, SetAttributeOptions options) throws Exception {
try (SetAndRestoreAuthenticatedUser u = new SetAndRestoreAuthenticatedUser(user.getUser())) {
mFileSystemMaster.setAttribute(new AlluxioURI(path), options);
FileInfo fileInfo = mFileSystemMaster.getFileInfo(new AlluxioURI(path));
return SetAttributeOptions.defaults().setPinned(fileInfo.isPinned()).setTtl(fileInfo.getTtl()).setPersisted(fileInfo.isPersisted());
}
}
use of alluxio.wire.FileInfo in project alluxio by Alluxio.
the class PermissionCheckTest method verifyCreateFile.
private void verifyCreateFile(TestUser user, String path, boolean recursive) throws Exception {
try (SetAndRestoreAuthenticatedUser u = new SetAndRestoreAuthenticatedUser(user.getUser())) {
CreateFileOptions options = CreateFileOptions.defaults().setRecursive(recursive).setOwner(SecurityUtils.getOwnerFromThriftClient()).setGroup(SecurityUtils.getGroupFromThriftClient()).setPersisted(true);
long fileId = mFileSystemMaster.createFile(new AlluxioURI(path), options);
FileInfo fileInfo = mFileSystemMaster.getFileInfo(fileId);
String[] pathComponents = path.split("/");
Assert.assertEquals(pathComponents[pathComponents.length - 1], fileInfo.getName());
Assert.assertEquals(user.getUser(), fileInfo.getOwner());
}
}
use of alluxio.wire.FileInfo in project alluxio by Alluxio.
the class FileSystemMaster method getFileInfoInternal.
/**
* @param inodePath the {@link LockedInodePath} to get the {@link FileInfo} for
* @return the {@link FileInfo} for the given inode
* @throws FileDoesNotExistException if the file does not exist
* @throws AccessControlException if permission denied
*/
private FileInfo getFileInfoInternal(LockedInodePath inodePath) throws FileDoesNotExistException, AccessControlException {
Inode<?> inode = inodePath.getInode();
AlluxioURI uri = inodePath.getUri();
FileInfo fileInfo = inode.generateClientFileInfo(uri.toString());
fileInfo.setInMemoryPercentage(getInMemoryPercentage(inode));
if (inode instanceof InodeFile) {
try {
fileInfo.setFileBlockInfos(getFileBlockInfoListInternal(inodePath));
} catch (InvalidPathException e) {
throw new FileDoesNotExistException(e.getMessage(), e);
}
}
MountTable.Resolution resolution;
try {
resolution = mMountTable.resolve(uri);
} catch (InvalidPathException e) {
throw new FileDoesNotExistException(e.getMessage(), e);
}
AlluxioURI resolvedUri = resolution.getUri();
// Only set the UFS path if the path is nested under a mount point.
if (!uri.equals(resolvedUri)) {
fileInfo.setUfsPath(resolvedUri.toString());
}
Metrics.FILE_INFOS_GOT.inc();
return fileInfo;
}
Aggregations