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());
}
}
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);
}
}
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();
}
}
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);
}
}
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();
}
}
Aggregations