Search in sources :

Example 11 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 12 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 13 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 14 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)

Example 15 with AccessControlException

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

the class FileSystemMaster method processJournalEntry.

@Override
public void processJournalEntry(JournalEntry entry) throws IOException {
    if (entry.hasInodeFile()) {
        mInodeTree.addInodeFileFromJournal(entry.getInodeFile());
        // Add the file to TTL buckets, the insert automatically rejects files w/ Constants.NO_TTL
        InodeFileEntry inodeFileEntry = entry.getInodeFile();
        if (inodeFileEntry.hasTtl()) {
            mTtlBuckets.insert(InodeFile.fromJournalEntry(inodeFileEntry));
        }
    } else if (entry.hasInodeDirectory()) {
        try {
            // Add the directory to TTL buckets, the insert automatically rejects directory
            // w/ Constants.NO_TTL
            InodeDirectoryEntry inodeDirectoryEntry = entry.getInodeDirectory();
            if (inodeDirectoryEntry.hasTtl()) {
                mTtlBuckets.insert(InodeDirectory.fromJournalEntry(inodeDirectoryEntry));
            }
            mInodeTree.addInodeDirectoryFromJournal(entry.getInodeDirectory());
        } catch (AccessControlException e) {
            throw new RuntimeException(e);
        }
    } else if (entry.hasInodeLastModificationTime()) {
        InodeLastModificationTimeEntry modTimeEntry = entry.getInodeLastModificationTime();
        try (LockedInodePath inodePath = mInodeTree.lockFullInodePath(modTimeEntry.getId(), InodeTree.LockMode.WRITE)) {
            inodePath.getInode().setLastModificationTimeMs(modTimeEntry.getLastModificationTimeMs(), true);
        } catch (FileDoesNotExistException e) {
            throw new RuntimeException(e);
        }
    } else if (entry.hasPersistDirectory()) {
        PersistDirectoryEntry typedEntry = entry.getPersistDirectory();
        try (LockedInodePath inodePath = mInodeTree.lockFullInodePath(typedEntry.getId(), InodeTree.LockMode.WRITE)) {
            inodePath.getInode().setPersistenceState(PersistenceState.PERSISTED);
        } catch (FileDoesNotExistException e) {
            throw new RuntimeException(e);
        }
    } else if (entry.hasCompleteFile()) {
        try {
            completeFileFromEntry(entry.getCompleteFile());
        } catch (InvalidPathException | InvalidFileSizeException | FileAlreadyCompletedException e) {
            throw new RuntimeException(e);
        }
    } else if (entry.hasSetAttribute()) {
        try {
            setAttributeFromEntry(entry.getSetAttribute());
        } catch (AccessControlException | FileDoesNotExistException | InvalidPathException e) {
            throw new RuntimeException(e);
        }
    } else if (entry.hasDeleteFile()) {
        deleteFromEntry(entry.getDeleteFile());
    } else if (entry.hasRename()) {
        renameFromEntry(entry.getRename());
    } else if (entry.hasInodeDirectoryIdGenerator()) {
        mDirectoryIdGenerator.initFromJournalEntry(entry.getInodeDirectoryIdGenerator());
    } else if (entry.hasReinitializeFile()) {
        resetBlockFileFromEntry(entry.getReinitializeFile());
    } else if (entry.hasAddMountPoint()) {
        try {
            mountFromEntry(entry.getAddMountPoint());
        } catch (FileAlreadyExistsException | InvalidPathException e) {
            throw new RuntimeException(e);
        }
    } else if (entry.hasDeleteMountPoint()) {
        try {
            unmountFromEntry(entry.getDeleteMountPoint());
        } catch (InvalidPathException e) {
            throw new RuntimeException(e);
        }
    } else if (entry.hasAsyncPersistRequest()) {
        try {
            long fileId = (entry.getAsyncPersistRequest()).getFileId();
            try (LockedInodePath inodePath = mInodeTree.lockFullInodePath(fileId, InodeTree.LockMode.WRITE)) {
                scheduleAsyncPersistenceInternal(inodePath);
            }
            // NOTE: persistence is asynchronous so there is no guarantee the path will still exist
            mAsyncPersistHandler.scheduleAsyncPersistence(getPath(fileId));
        } catch (AlluxioException e) {
            // It's possible that rescheduling the async persist calls fails, because the blocks may no
            // longer be in the memory
            LOG.error(e.getMessage());
        }
    } else {
        throw new IOException(ExceptionMessage.UNEXPECTED_JOURNAL_ENTRY.getMessage(entry));
    }
}
Also used : FileDoesNotExistException(alluxio.exception.FileDoesNotExistException) FileAlreadyExistsException(alluxio.exception.FileAlreadyExistsException) InodeFileEntry(alluxio.proto.journal.File.InodeFileEntry) AccessControlException(alluxio.exception.AccessControlException) IOException(java.io.IOException) InodeLastModificationTimeEntry(alluxio.proto.journal.File.InodeLastModificationTimeEntry) PersistDirectoryEntry(alluxio.proto.journal.File.PersistDirectoryEntry) InvalidPathException(alluxio.exception.InvalidPathException) LockedInodePath(alluxio.master.file.meta.LockedInodePath) InodeDirectoryEntry(alluxio.proto.journal.File.InodeDirectoryEntry) InvalidFileSizeException(alluxio.exception.InvalidFileSizeException) FileAlreadyCompletedException(alluxio.exception.FileAlreadyCompletedException) AlluxioException(alluxio.exception.AlluxioException) UnexpectedAlluxioException(alluxio.exception.UnexpectedAlluxioException)

Aggregations

AccessControlException (alluxio.exception.AccessControlException)18 AlluxioURI (alluxio.AlluxioURI)11 Test (org.junit.Test)9 FileDoesNotExistException (alluxio.exception.FileDoesNotExistException)5 InvalidPathException (alluxio.exception.InvalidPathException)3 Inode (alluxio.master.file.meta.Inode)3 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 AlluxioException (alluxio.exception.AlluxioException)2 FileInfo (alluxio.wire.FileInfo)2 CreateFileOptions (alluxio.client.file.options.CreateFileOptions)1 FileAlreadyCompletedException (alluxio.exception.FileAlreadyCompletedException)1 FileAlreadyExistsException (alluxio.exception.FileAlreadyExistsException)1 InvalidFileSizeException (alluxio.exception.InvalidFileSizeException)1 UnexpectedAlluxioException (alluxio.exception.UnexpectedAlluxioException)1 InodeFile (alluxio.master.file.meta.InodeFile)1 LockedInodePath (alluxio.master.file.meta.LockedInodePath)1 MountTable (alluxio.master.file.meta.MountTable)1 MountInfo (alluxio.master.file.meta.options.MountInfo)1 MountOptions (alluxio.master.file.options.MountOptions)1