Search in sources :

Example 31 with AccessControlException

use of alluxio.exception.AccessControlException in project alluxio by Alluxio.

the class MountTableTest method readOnlyMount.

/**
 * Tests check of readonly mount points.
 */
@Test
public void readOnlyMount() throws Exception {
    MountPOptions options = MountContext.mergeFrom(MountPOptions.newBuilder().setReadOnly(true)).getOptions().build();
    String mountPath = "/mnt/foo";
    AlluxioURI alluxioUri = new AlluxioURI("alluxio://localhost:1234" + mountPath);
    mMountTable.add(NoopJournalContext.INSTANCE, alluxioUri, new AlluxioURI("hdfs://localhost:5678/foo"), 2L, options);
    try {
        mMountTable.checkUnderWritableMountPoint(alluxioUri);
        Assert.fail("Readonly mount point should not be writable.");
    } catch (AccessControlException e) {
        // Exception expected
        Assert.assertEquals(ExceptionMessage.MOUNT_READONLY.getMessage(alluxioUri, mountPath), e.getMessage());
    }
    try {
        String path = mountPath + "/sub/directory";
        alluxioUri = new AlluxioURI("alluxio://localhost:1234" + path);
        mMountTable.checkUnderWritableMountPoint(alluxioUri);
        Assert.fail("Readonly mount point should not be writable.");
    } catch (AccessControlException e) {
        // Exception expected
        Assert.assertEquals(ExceptionMessage.MOUNT_READONLY.getMessage(alluxioUri, mountPath), e.getMessage());
    }
}
Also used : MountPOptions(alluxio.grpc.MountPOptions) AccessControlException(alluxio.exception.AccessControlException) AlluxioURI(alluxio.AlluxioURI) Test(org.junit.Test)

Example 32 with AccessControlException

use of alluxio.exception.AccessControlException in project alluxio by Alluxio.

the class WebInterfaceMemoryServlet method doGet.

/**
   * Populates attributes before redirecting to a jsp.
   *
   * @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
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    if (SecurityUtils.isSecurityEnabled() && AuthenticatedClientUser.get() == null) {
        AuthenticatedClientUser.set(LoginUser.get().getName());
    }
    request.setAttribute("masterNodeAddress", mMaster.getRpcAddress().toString());
    request.setAttribute("fatalError", "");
    request.setAttribute("showPermissions", Configuration.getBoolean(PropertyKey.SECURITY_AUTHORIZATION_PERMISSION_ENABLED));
    List<AlluxioURI> inMemoryFiles = mMaster.getFileSystemMaster().getInMemoryFiles();
    Collections.sort(inMemoryFiles);
    List<UIFileInfo> fileInfos = new ArrayList<>(inMemoryFiles.size());
    for (AlluxioURI file : inMemoryFiles) {
        try {
            long fileId = mMaster.getFileSystemMaster().getFileId(file);
            FileInfo fileInfo = mMaster.getFileSystemMaster().getFileInfo(fileId);
            if (fileInfo != null && fileInfo.getInMemoryPercentage() == 100) {
                fileInfos.add(new UIFileInfo(fileInfo));
            }
        } catch (FileDoesNotExistException e) {
            request.setAttribute("fatalError", "Error: File does not exist " + e.getLocalizedMessage());
            getServletContext().getRequestDispatcher("/memory.jsp").forward(request, response);
            return;
        } catch (AccessControlException e) {
            request.setAttribute("permissionError", "Error: File " + file + " cannot be accessed " + e.getMessage());
            getServletContext().getRequestDispatcher("/memory.jsp").forward(request, response);
            return;
        }
    }
    request.setAttribute("inMemoryFileNum", fileInfos.size());
    // and redirect to "./memory?offset=xxx&limit=xxx"
    if (request.getParameter("offset") == null && request.getParameter("limit") == null) {
        getServletContext().getRequestDispatcher("/memory.jsp").forward(request, response);
        return;
    }
    try {
        int offset = Integer.parseInt(request.getParameter("offset"));
        int limit = Integer.parseInt(request.getParameter("limit"));
        List<UIFileInfo> sub = fileInfos.subList(offset, offset + limit);
        request.setAttribute("fileInfos", sub);
    } catch (NumberFormatException e) {
        request.setAttribute("fatalError", "Error: offset or limit parse error, " + e.getLocalizedMessage());
        getServletContext().getRequestDispatcher("/memory.jsp").forward(request, response);
        return;
    } catch (IndexOutOfBoundsException e) {
        request.setAttribute("fatalError", "Error: offset or offset + limit is out of bound, " + e.getLocalizedMessage());
        getServletContext().getRequestDispatcher("/memory.jsp").forward(request, response);
        return;
    } catch (IllegalArgumentException e) {
        request.setAttribute("fatalError", e.getLocalizedMessage());
        getServletContext().getRequestDispatcher("/memory.jsp").forward(request, response);
        return;
    }
    getServletContext().getRequestDispatcher("/memory.jsp").forward(request, response);
}
Also used : FileDoesNotExistException(alluxio.exception.FileDoesNotExistException) ArrayList(java.util.ArrayList) AccessControlException(alluxio.exception.AccessControlException) FileInfo(alluxio.wire.FileInfo) AlluxioURI(alluxio.AlluxioURI)

Example 33 with AccessControlException

use of alluxio.exception.AccessControlException in project alluxio by Alluxio.

the class CheckpointLatestPlanner method generatePlan.

@Override
public CheckpointPlan generatePlan(LineageStoreView store, FileSystemMasterView fileSystemMasterView) {
    Lineage toCheckpoint = null;
    long latestCreated = 0;
    for (Lineage lineage : store.getAllLineagesInTopologicalOrder()) {
        try {
            if (!LineageStateUtils.isCompleted(lineage, fileSystemMasterView) || LineageStateUtils.isPersisted(lineage, fileSystemMasterView) || LineageStateUtils.needRecompute(lineage, fileSystemMasterView) || LineageStateUtils.isInCheckpointing(lineage, fileSystemMasterView)) {
                continue;
            }
        } catch (FileDoesNotExistException | AccessControlException e) {
            LOG.error("The lineage file does not exist", e);
            continue;
        }
        if (lineage.getCreationTime() > latestCreated) {
            latestCreated = lineage.getCreationTime();
            toCheckpoint = lineage;
        }
    }
    return toCheckpoint == null ? new CheckpointPlan(new ArrayList<Long>()) : new CheckpointPlan(Lists.newArrayList(toCheckpoint.getId()));
}
Also used : FileDoesNotExistException(alluxio.exception.FileDoesNotExistException) Lineage(alluxio.master.lineage.meta.Lineage) ArrayList(java.util.ArrayList) AccessControlException(alluxio.exception.AccessControlException)

Example 34 with AccessControlException

use of alluxio.exception.AccessControlException in project alluxio by Alluxio.

the class ReadOnlyMountIntegrationTest method deleteFile.

@Test
public void deleteFile() throws IOException, AlluxioException {
    AlluxioURI fileUri = new AlluxioURI(FILE_PATH);
    mFileSystem.loadMetadata(fileUri);
    try {
        mFileSystem.delete(fileUri);
        Assert.fail("deleteFile should not succeed under a readonly mount.");
    } catch (AccessControlException e) {
        Assert.assertEquals(e.getMessage(), ExceptionMessage.MOUNT_READONLY.getMessage(fileUri, MOUNT_PATH));
    }
    Assert.assertTrue(mFileSystem.exists(fileUri));
    Assert.assertNotNull(mFileSystem.getStatus(fileUri));
    fileUri = new AlluxioURI(SUB_FILE_PATH);
    mFileSystem.loadMetadata(fileUri, LoadMetadataOptions.defaults().setRecursive(true));
    try {
        mFileSystem.delete(fileUri);
        Assert.fail("deleteFile should not succeed under a readonly mount.");
    } catch (AccessControlException e) {
        Assert.assertEquals(e.getMessage(), ExceptionMessage.MOUNT_READONLY.getMessage(fileUri, MOUNT_PATH));
    }
    Assert.assertTrue(mFileSystem.exists(fileUri));
    Assert.assertNotNull(mFileSystem.getStatus(fileUri));
}
Also used : AccessControlException(alluxio.exception.AccessControlException) AlluxioURI(alluxio.AlluxioURI) Test(org.junit.Test)

Example 35 with AccessControlException

use of alluxio.exception.AccessControlException in project alluxio by Alluxio.

the class ReadOnlyMountIntegrationTest method renameFileSrc.

@Test
public void renameFileSrc() throws IOException, AlluxioException {
    AlluxioURI srcUri = new AlluxioURI(FILE_PATH);
    AlluxioURI dstUri = new AlluxioURI("/tmp");
    try {
        mFileSystem.rename(srcUri, dstUri);
        Assert.fail("rename should not succeed under a readonly mount.");
    } catch (AccessControlException e) {
        Assert.assertEquals(e.getMessage(), ExceptionMessage.MOUNT_READONLY.getMessage(srcUri, MOUNT_PATH));
    }
    srcUri = new AlluxioURI(SUB_FILE_PATH);
    try {
        mFileSystem.rename(srcUri, dstUri);
        Assert.fail("rename should not succeed under a readonly mount.");
    } catch (AccessControlException e) {
        Assert.assertEquals(e.getMessage(), ExceptionMessage.MOUNT_READONLY.getMessage(srcUri, MOUNT_PATH));
    }
}
Also used : AccessControlException(alluxio.exception.AccessControlException) AlluxioURI(alluxio.AlluxioURI) Test(org.junit.Test)

Aggregations

AccessControlException (alluxio.exception.AccessControlException)64 AlluxioURI (alluxio.AlluxioURI)29 LockedInodePath (alluxio.master.file.meta.LockedInodePath)21 Test (org.junit.Test)21 FileDoesNotExistException (alluxio.exception.FileDoesNotExistException)16 LockingScheme (alluxio.master.file.meta.LockingScheme)15 InvalidPathException (alluxio.exception.InvalidPathException)12 BaseIntegrationTest (alluxio.testutils.BaseIntegrationTest)11 IOException (java.io.IOException)11 ArrayList (java.util.ArrayList)10 Inode (alluxio.master.file.meta.Inode)9 MountTable (alluxio.master.file.meta.MountTable)7 FileInfo (alluxio.wire.FileInfo)7 AlluxioException (alluxio.exception.AlluxioException)4 LockedInodePathList (alluxio.master.file.meta.LockedInodePathList)4 Mode (alluxio.security.authorization.Mode)4 UnderFileSystem (alluxio.underfs.UnderFileSystem)4 FileBlockInfo (alluxio.wire.FileBlockInfo)4 DescendantType (alluxio.file.options.DescendantType)3 FileSystemMasterCommonPOptions (alluxio.grpc.FileSystemMasterCommonPOptions)3