Search in sources :

Example 6 with AlluxioURI

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());
    }
}
Also used : LockedInodePath(alluxio.master.file.meta.LockedInodePath) InodeFile(alluxio.master.file.meta.InodeFile) InodeTree(alluxio.master.file.meta.InodeTree) AlluxioURI(alluxio.AlluxioURI)

Example 7 with AlluxioURI

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);
    }
}
Also used : FileDoesNotExistException(alluxio.exception.FileDoesNotExistException) FileInfo(alluxio.wire.FileInfo) InvalidPathException(alluxio.exception.InvalidPathException) AlluxioURI(alluxio.AlluxioURI) AlluxioException(alluxio.exception.AlluxioException)

Example 8 with AlluxioURI

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));
}
Also used : FileDoesNotExistException(alluxio.exception.FileDoesNotExistException) AlluxioURI(alluxio.AlluxioURI) Test(org.junit.Test)

Example 9 with AlluxioURI

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));
}
Also used : FileAlreadyExistsException(alluxio.exception.FileAlreadyExistsException) AlluxioURI(alluxio.AlluxioURI) Test(org.junit.Test)

Example 10 with AlluxioURI

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);
}
Also used : AlluxioURI(alluxio.AlluxioURI) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

AlluxioURI (alluxio.AlluxioURI)1552 Test (org.junit.Test)1094 URIStatus (alluxio.client.file.URIStatus)356 BaseIntegrationTest (alluxio.testutils.BaseIntegrationTest)303 IOException (java.io.IOException)154 FileInStream (alluxio.client.file.FileInStream)152 FileInfo (alluxio.wire.FileInfo)130 AbstractFileSystemShellTest (alluxio.client.cli.fs.AbstractFileSystemShellTest)124 ArrayList (java.util.ArrayList)120 FileDoesNotExistException (alluxio.exception.FileDoesNotExistException)119 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)114 File (java.io.File)107 FileSystem (alluxio.client.file.FileSystem)99 FileOutStream (alluxio.client.file.FileOutStream)97 AlluxioException (alluxio.exception.AlluxioException)92 CreateFilePOptions (alluxio.grpc.CreateFilePOptions)76 InvalidPathException (alluxio.exception.InvalidPathException)68 AbstractAlluxioShellTest (alluxio.shell.AbstractAlluxioShellTest)63 UnderFileSystem (alluxio.underfs.UnderFileSystem)63 FileAlreadyExistsException (alluxio.exception.FileAlreadyExistsException)62