use of alluxio.security.authorization.Mode in project alluxio by Alluxio.
the class FileSystemAclIntegrationTest method loadFileMetadataMode.
/**
* Tests the loaded file metadata from UFS having the same mode as that in the UFS.
*/
@Test
public void loadFileMetadataMode() throws Exception {
// Skip non-local and non-HDFS-2 UFSs.
Assume.assumeTrue(UnderFileSystemUtils.isLocal(sUfs) || (UnderFileSystemUtils.isHdfs(sUfs) && HadoopClientTestUtils.isHadoop2x()));
List<Integer> permissionValues = Lists.newArrayList(0111, 0222, 0333, 0444, 0555, 0666, 0777, 0755, 0733, 0644, 0533, 0511);
for (int value : permissionValues) {
Path file = new Path("/loadFileMetadataMode" + value);
sTFS.delete(file, false);
// Create a file directly in UFS and set the corresponding mode.
String ufsPath = PathUtils.concatPath(sUfsRoot, file);
sUfs.create(ufsPath, CreateOptions.defaults().setOwner("testuser").setGroup("testgroup").setMode(new Mode((short) value))).close();
Assert.assertTrue(sUfs.isFile(PathUtils.concatPath(sUfsRoot, file)));
// Check the mode is consistent in Alluxio namespace once it's loaded from UFS to Alluxio.
Assert.assertEquals(new Mode((short) value).toString(), new Mode(sTFS.getFileStatus(file).getPermission().toShort()).toString());
}
}
use of alluxio.security.authorization.Mode in project alluxio by Alluxio.
the class UnderFileSystemUtils method prepareFilePath.
/**
* Creates parent directories for path with correct permissions if required.
*
* @param alluxioPath Alluxio path
* @param ufsPath path in the under file system
* @param fs file system master client
* @param ufs the under file system
* @throws AlluxioException if an unexpected Alluxio exception is thrown
* @throws IOException if folder creation fails
*/
public static void prepareFilePath(AlluxioURI alluxioPath, String ufsPath, FileSystem fs, UnderFileSystem ufs) throws AlluxioException, IOException {
AlluxioURI dstPath = new AlluxioURI(ufsPath);
String parentPath = dstPath.getParent().getPath();
// creates the parent folder if it does not exist
if (!ufs.isDirectory(parentPath)) {
// Create ancestor directories from top to the bottom. We cannot use recursive create parents
// here because the permission for the ancestors can be different.
Stack<Pair<String, MkdirsOptions>> ufsDirsToMakeWithOptions = new Stack<>();
AlluxioURI curAlluxioPath = alluxioPath.getParent();
AlluxioURI curUfsPath = dstPath.getParent();
// Stop at Alluxio mount point because the mapped directory in UFS may not exist.
while (curUfsPath != null && !ufs.isDirectory(curUfsPath.toString()) && curAlluxioPath != null) {
URIStatus curDirStatus = fs.getStatus(curAlluxioPath);
if (curDirStatus.isMountPoint()) {
throw new IOException(ExceptionMessage.UFS_PATH_DOES_NOT_EXIST.getMessage(curUfsPath));
}
ufsDirsToMakeWithOptions.push(new Pair<>(curUfsPath.toString(), MkdirsOptions.defaults().setCreateParent(false).setOwner(curDirStatus.getOwner()).setGroup(curDirStatus.getGroup()).setMode(new Mode((short) curDirStatus.getMode()))));
curAlluxioPath = curAlluxioPath.getParent();
curUfsPath = curUfsPath.getParent();
}
while (!ufsDirsToMakeWithOptions.empty()) {
Pair<String, MkdirsOptions> ufsDirAndPerm = ufsDirsToMakeWithOptions.pop();
// and assume the directory is already prepared, regardless of permission matching.
if (!ufs.mkdirs(ufsDirAndPerm.getFirst(), ufsDirAndPerm.getSecond()) && !ufs.isDirectory(ufsDirAndPerm.getFirst())) {
throw new IOException("Failed to create dir: " + ufsDirAndPerm.getFirst());
}
}
}
}
use of alluxio.security.authorization.Mode in project alluxio by Alluxio.
the class CompleteUfsFileOptionsTest method toThrift.
/**
* Tests conversion to thrift representation.
*/
@Test
public void toThrift() throws IOException {
Random random = new Random();
String owner = CommonUtils.randomAlphaNumString(10);
String group = CommonUtils.randomAlphaNumString(10);
Mode mode = new Mode((short) random.nextInt());
CompleteUfsFileOptions options = CompleteUfsFileOptions.defaults();
options.setOwner(owner);
options.setGroup(group);
options.setMode(mode);
CompleteUfsFileTOptions thriftOptions = options.toThrift();
Assert.assertEquals(owner, thriftOptions.getOwner());
Assert.assertEquals(group, thriftOptions.getGroup());
Assert.assertEquals(mode.toShort(), thriftOptions.getMode());
}
use of alluxio.security.authorization.Mode in project alluxio by Alluxio.
the class ChmodCommand method chmod.
/**
* Changes the permissions of directory or file with the path specified in args.
*
* @param path The {@link AlluxioURI} path as the input of the command
* @param modeStr The new permission to be updated to the file or directory
* @param recursive Whether change the permission recursively
* @throws AlluxioException when Alluxio exception occurs
* @throws IOException when non-Alluxio exception occurs
*/
private void chmod(AlluxioURI path, String modeStr, boolean recursive) throws AlluxioException, IOException {
Mode mode = mParser.parse(modeStr);
SetAttributeOptions options = SetAttributeOptions.defaults().setMode(mode).setRecursive(recursive);
mFileSystem.setAttribute(path, options);
System.out.println("Changed permission of " + path + " to " + Integer.toOctalString(mode.toShort()));
}
use of alluxio.security.authorization.Mode in project alluxio by Alluxio.
the class PersistCommandTest method persistWithAncestorPermission.
@Test
public void persistWithAncestorPermission() throws Exception {
String ufsRoot = PathUtils.concatPath(Configuration.get(PropertyKey.UNDERFS_ADDRESS));
UnderFileSystem ufs = UnderFileSystem.Factory.get(ufsRoot);
// Skip non-local and non-HDFS UFSs.
Assume.assumeTrue(UnderFileSystemUtils.isLocal(ufs) || UnderFileSystemUtils.isHdfs(ufs));
AlluxioURI testFile = new AlluxioURI("/grand/parent/file");
AlluxioURI grandParent = new AlluxioURI("/grand");
Mode grandParentMode = new Mode((short) 0777);
FileSystemTestUtils.createByteFile(mFileSystem, testFile, WriteType.MUST_CACHE, 10);
URIStatus status = mFileSystem.getStatus(testFile);
Assert.assertFalse(status.isPersisted());
mFileSystem.setAttribute(grandParent, SetAttributeOptions.defaults().setMode(grandParentMode));
int ret = mFsShell.run("persist", testFile.toString());
Assert.assertEquals(0, ret);
checkFilePersisted(testFile, 10);
// Check the permission of the created file and ancestor dir are in-sync between Alluxio and UFS
short fileMode = (short) status.getMode();
short parentMode = (short) mFileSystem.getStatus(testFile.getParent()).getMode();
Assert.assertEquals(fileMode, ufs.getMode(PathUtils.concatPath(ufsRoot, testFile)));
Assert.assertEquals(parentMode, ufs.getMode(PathUtils.concatPath(ufsRoot, testFile.getParent())));
Assert.assertEquals(grandParentMode, new Mode(ufs.getMode(PathUtils.concatPath(ufsRoot, grandParent))));
}
Aggregations