Search in sources :

Example 1 with LockedInodePath

use of alluxio.master.file.meta.LockedInodePath 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 2 with LockedInodePath

use of alluxio.master.file.meta.LockedInodePath in project alluxio by Alluxio.

the class PermissionCheckTest method getPermissionOwner.

@Test
public void getPermissionOwner() throws Exception {
    ArrayList<Triple<String, String, Mode>> permissions = new ArrayList<>();
    permissions.add(new ImmutableTriple<>(TEST_USER_1.getUser(), TEST_USER_1.getGroup(), new Mode((short) 0754)));
    LockedInodePath lockedInodePath = getLockedInodePath(permissions);
    try (SetAndRestoreAuthenticatedUser u = new SetAndRestoreAuthenticatedUser(TEST_USER_1.getUser())) {
        PermissionChecker checker = new PermissionChecker(mInodeTree);
        Mode.Bits actual = checker.getPermission(lockedInodePath);
        Assert.assertEquals(Mode.Bits.ALL, actual);
    }
}
Also used : Triple(org.apache.commons.lang3.tuple.Triple) ImmutableTriple(org.apache.commons.lang3.tuple.ImmutableTriple) MutableLockedInodePath(alluxio.master.file.meta.MutableLockedInodePath) LockedInodePath(alluxio.master.file.meta.LockedInodePath) SetAndRestoreAuthenticatedUser(alluxio.SetAndRestoreAuthenticatedUser) Mode(alluxio.security.authorization.Mode) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 3 with LockedInodePath

use of alluxio.master.file.meta.LockedInodePath in project alluxio by Alluxio.

the class FileSystemMaster method mount.

/**
   * Mounts a UFS path onto an Alluxio path.
   * <p>
   * This operation requires users to have {@link Mode.Bits#WRITE} permission on the parent
   * of the Alluxio path.
   *
   * @param alluxioPath the Alluxio path to mount to
   * @param ufsPath the UFS path to mount
   * @param options the mount options
   * @throws FileAlreadyExistsException if the path to be mounted to already exists
   * @throws FileDoesNotExistException if the parent of the path to be mounted to does not exist
   * @throws InvalidPathException if an invalid path is encountered
   * @throws IOException if an I/O error occurs
   * @throws AccessControlException if the permission check fails
   */
public void mount(AlluxioURI alluxioPath, AlluxioURI ufsPath, MountOptions options) throws FileAlreadyExistsException, FileDoesNotExistException, InvalidPathException, IOException, AccessControlException {
    Metrics.MOUNT_OPS.inc();
    try (JournalContext journalContext = createJournalContext();
        LockedInodePath inodePath = mInodeTree.lockInodePath(alluxioPath, InodeTree.LockMode.WRITE)) {
        mPermissionChecker.checkParentPermission(Mode.Bits.WRITE, inodePath);
        mMountTable.checkUnderWritableMountPoint(alluxioPath);
        mountAndJournal(inodePath, ufsPath, options, journalContext);
        Metrics.PATHS_MOUNTED.inc();
    }
}
Also used : LockedInodePath(alluxio.master.file.meta.LockedInodePath)

Example 4 with LockedInodePath

use of alluxio.master.file.meta.LockedInodePath in project alluxio by Alluxio.

the class FileSystemMaster method delete.

/**
   * Deletes a given path.
   * <p>
   * This operation requires user to have {@link Mode.Bits#WRITE}
   * permission on the parent of the path.
   *
   * @param path the path to delete
   * @param options method options
   * @throws DirectoryNotEmptyException if recursive is false and the file is a nonempty directory
   * @throws FileDoesNotExistException if the file does not exist
   * @throws IOException if an I/O error occurs
   * @throws AccessControlException if permission checking fails
   * @throws InvalidPathException if the path is invalid
   */
public void delete(AlluxioURI path, DeleteOptions options) throws IOException, FileDoesNotExistException, DirectoryNotEmptyException, InvalidPathException, AccessControlException {
    Metrics.DELETE_PATHS_OPS.inc();
    // Delete should lock the parent to remove the child inode.
    try (JournalContext journalContext = createJournalContext();
        LockedInodePath inodePath = mInodeTree.lockFullInodePath(path, InodeTree.LockMode.WRITE_PARENT)) {
        mPermissionChecker.checkParentPermission(Mode.Bits.WRITE, inodePath);
        mMountTable.checkUnderWritableMountPoint(path);
        deleteAndJournal(inodePath, options, journalContext);
    }
}
Also used : LockedInodePath(alluxio.master.file.meta.LockedInodePath)

Example 5 with LockedInodePath

use of alluxio.master.file.meta.LockedInodePath in project alluxio by Alluxio.

the class FileSystemMaster method loadMetadata.

/**
   * Loads metadata for the object identified by the given path from UFS into Alluxio.
   * <p>
   * This operation requires users to have {@link Mode.Bits#WRITE} permission on the path
   * and its parent path if path is a file, or {@link Mode.Bits#WRITE} permission on the
   * parent path if path is a directory.
   *
   * @param path the path for which metadata should be loaded
   * @param options the load metadata options
   * @return the file id of the loaded path
   * @throws BlockInfoException if an invalid block size is encountered
   * @throws FileDoesNotExistException if there is no UFS path
   * @throws InvalidPathException if invalid path is encountered
   * @throws InvalidFileSizeException if invalid file size is encountered
   * @throws FileAlreadyCompletedException if the file is already completed
   * @throws IOException if an I/O error occurs
   * @throws AccessControlException if permission checking fails
   */
public long loadMetadata(AlluxioURI path, LoadMetadataOptions options) throws BlockInfoException, FileDoesNotExistException, InvalidPathException, InvalidFileSizeException, FileAlreadyCompletedException, IOException, AccessControlException {
    try (JournalContext journalContext = createJournalContext();
        LockedInodePath inodePath = mInodeTree.lockInodePath(path, InodeTree.LockMode.WRITE)) {
        mPermissionChecker.checkParentPermission(Mode.Bits.WRITE, inodePath);
        loadMetadataAndJournal(inodePath, options, journalContext);
        return inodePath.getInode().getId();
    }
}
Also used : LockedInodePath(alluxio.master.file.meta.LockedInodePath)

Aggregations

LockedInodePath (alluxio.master.file.meta.LockedInodePath)79 AlluxioURI (alluxio.AlluxioURI)27 AccessControlException (alluxio.exception.AccessControlException)24 FileDoesNotExistException (alluxio.exception.FileDoesNotExistException)23 InvalidPathException (alluxio.exception.InvalidPathException)18 LockingScheme (alluxio.master.file.meta.LockingScheme)16 Inode (alluxio.master.file.meta.Inode)15 ArrayList (java.util.ArrayList)13 Test (org.junit.Test)11 Mode (alluxio.security.authorization.Mode)10 LockedInodePathList (alluxio.master.file.meta.LockedInodePathList)9 BlockInfoException (alluxio.exception.BlockInfoException)8 FileAlreadyExistsException (alluxio.exception.FileAlreadyExistsException)8 IOException (java.io.IOException)8 FileAlreadyCompletedException (alluxio.exception.FileAlreadyCompletedException)7 InvalidFileSizeException (alluxio.exception.InvalidFileSizeException)7 LoadMetadataContext (alluxio.master.file.contexts.LoadMetadataContext)7 InodeFile (alluxio.master.file.meta.InodeFile)7 MountTable (alluxio.master.file.meta.MountTable)7 UnexpectedAlluxioException (alluxio.exception.UnexpectedAlluxioException)6