use of alluxio.AlluxioURI in project alluxio by Alluxio.
the class PermissionCheckerTest method createAndSetPermission.
// Helper function to create a path and set the permission to what specified in option.
private static void createAndSetPermission(String path, CreateFileOptions option) throws Exception {
try (LockedInodePath inodePath = sTree.lockInodePath(new AlluxioURI(path), InodeTree.LockMode.WRITE)) {
InodeTree.CreatePathResult result = sTree.createPath(inodePath, option);
((InodeFile) result.getCreated().get(result.getCreated().size() - 1)).setOwner(option.getOwner()).setGroup(option.getGroup()).setMode(option.getMode().toShort());
}
}
use of alluxio.AlluxioURI in project alluxio by Alluxio.
the class WebInterfaceDownloadServlet method doGet.
/**
* Prepares for downloading a file.
*
* @param request the {@link HttpServletRequest} object
* @param response the {@link HttpServletResponse} object
* @throws ServletException if the target resource throws this exception
* @throws IOException if the target resource throws this exception
*/
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
if (SecurityUtils.isSecurityEnabled() && AuthenticatedClientUser.get() == null) {
AuthenticatedClientUser.set(LoginUser.get().getName());
}
String requestPath = request.getParameter("path");
if (requestPath == null || requestPath.isEmpty()) {
requestPath = AlluxioURI.SEPARATOR;
}
AlluxioURI currentPath = new AlluxioURI(requestPath);
try {
long fileId = mFsMaster.getFileId(currentPath);
FileInfo fileInfo = mFsMaster.getFileInfo(fileId);
if (fileInfo == null) {
throw new FileDoesNotExistException(currentPath.toString());
}
downloadFile(new AlluxioURI(fileInfo.getPath()), request, response);
} catch (FileDoesNotExistException e) {
request.setAttribute("invalidPathError", "Error: Invalid Path " + e.getMessage());
getServletContext().getRequestDispatcher("/browse.jsp").forward(request, response);
} catch (InvalidPathException e) {
request.setAttribute("invalidPathError", "Error: Invalid Path " + e.getLocalizedMessage());
getServletContext().getRequestDispatcher("/browse.jsp").forward(request, response);
} catch (AlluxioException e) {
request.setAttribute("invalidPathError", "Error: " + e.getLocalizedMessage());
getServletContext().getRequestDispatcher("/browse.jsp").forward(request, response);
}
}
use of alluxio.AlluxioURI in project alluxio by Alluxio.
the class FileSystemMasterTest method loadMetadata.
@Test
public void loadMetadata() throws Exception {
AlluxioURI ufsMount = new AlluxioURI(mTestFolder.newFolder().getAbsolutePath());
mFileSystemMaster.createDirectory(new AlluxioURI("/mnt/"), CreateDirectoryOptions.defaults());
// Create ufs file
Files.createFile(Paths.get(ufsMount.join("file").getPath()));
// Created nested file
Files.createDirectory(Paths.get(ufsMount.join("nested").getPath()));
Files.createFile(Paths.get(ufsMount.join("nested").join("file").getPath()));
mFileSystemMaster.mount(new AlluxioURI("/mnt/local"), ufsMount, MountOptions.defaults());
// Test simple file.
AlluxioURI uri = new AlluxioURI("/mnt/local/file");
mFileSystemMaster.loadMetadata(uri, LoadMetadataOptions.defaults().setCreateAncestors(false));
Assert.assertNotNull(mFileSystemMaster.getFileInfo(uri));
// Test nested file.
uri = new AlluxioURI("/mnt/local/nested/file");
try {
mFileSystemMaster.loadMetadata(uri, LoadMetadataOptions.defaults().setCreateAncestors(false));
Assert.fail("loadMetadata() without recursive, for a nested file should fail.");
} catch (FileDoesNotExistException e) {
// Expected case.
}
// Test the nested file with recursive flag.
mFileSystemMaster.loadMetadata(uri, LoadMetadataOptions.defaults().setCreateAncestors(true));
Assert.assertNotNull(mFileSystemMaster.getFileInfo(uri));
}
use of alluxio.AlluxioURI in project alluxio by Alluxio.
the class FileSystemMasterTest method testLoadMetadata.
/**
* Tests load metadata logic.
*/
@Test
public void testLoadMetadata() throws Exception {
FileUtils.createDir(Paths.get(mUnderFS).resolve("a").toString());
mFileSystemMaster.loadMetadata(new AlluxioURI("alluxio:/a"), LoadMetadataOptions.defaults().setCreateAncestors(true));
mFileSystemMaster.loadMetadata(new AlluxioURI("alluxio:/a"), LoadMetadataOptions.defaults().setCreateAncestors(true));
// TODO(peis): Avoid this hack by adding an option in getFileInfo to skip loading metadata.
try {
mFileSystemMaster.createDirectory(new AlluxioURI("alluxio:/a"), CreateDirectoryOptions.defaults());
Assert.fail("createDirectory was expected to fail with FileAlreadyExistsException");
} catch (FileAlreadyExistsException e) {
Assert.assertEquals(ExceptionMessage.FILE_ALREADY_EXISTS.getMessage(new AlluxioURI("alluxio:/a")), e.getMessage());
}
FileUtils.createFile(Paths.get(mUnderFS).resolve("a/f1").toString());
FileUtils.createFile(Paths.get(mUnderFS).resolve("a/f2").toString());
mFileSystemMaster.loadMetadata(new AlluxioURI("alluxio:/a/f1"), LoadMetadataOptions.defaults().setCreateAncestors(true));
// This should not throw file exists exception those a/f1 is loaded.
mFileSystemMaster.loadMetadata(new AlluxioURI("alluxio:/a"), LoadMetadataOptions.defaults().setCreateAncestors(true).setLoadDirectChildren(true));
// TODO(peis): Avoid this hack by adding an option in getFileInfo to skip loading metadata.
try {
mFileSystemMaster.createFile(new AlluxioURI("alluxio:/a/f2"), CreateFileOptions.defaults());
Assert.fail("createDirectory was expected to fail with FileAlreadyExistsException");
} catch (FileAlreadyExistsException e) {
Assert.assertEquals(ExceptionMessage.FILE_ALREADY_EXISTS.getMessage(new AlluxioURI("alluxio:/a/f2")), e.getMessage());
}
mFileSystemMaster.loadMetadata(new AlluxioURI("alluxio:/a"), LoadMetadataOptions.defaults().setCreateAncestors(true).setLoadDirectChildren(true));
}
use of alluxio.AlluxioURI in project alluxio by Alluxio.
the class LineageFileSystemTest method reportLostFile.
/**
* Tests that reporting a lost file from the file system informs the client about this file.
*/
@Test
public void reportLostFile() throws Exception {
AlluxioURI path = new AlluxioURI("test");
mAlluxioLineageFileSystem.reportLostFile(path);
Mockito.verify(mLineageMasterClient).reportLostFile("test");
// verify client is released
Mockito.verify(mLineageContext).releaseMasterClient(mLineageMasterClient);
}
Aggregations