本文整理汇总了Java中org.apache.hadoop.fs.permission.FsPermission.createImmutable方法的典型用法代码示例。如果您正苦于以下问题:Java FsPermission.createImmutable方法的具体用法?Java FsPermission.createImmutable怎么用?Java FsPermission.createImmutable使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.hadoop.fs.permission.FsPermission
的用法示例。
在下文中一共展示了FsPermission.createImmutable方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getFileStatus
import org.apache.hadoop.fs.permission.FsPermission; //导入方法依赖的package包/类
@Override
public FileStatus getFileStatus(Path path) throws IOException {
File file = pathToFile(path);
if (!file.exists()) {
throw new FileNotFoundException("Can't find " + path);
}
// get close enough
short mod = 0;
if (file.canRead()) {
mod |= 0444;
}
if (file.canWrite()) {
mod |= 0200;
}
if (file.canExecute()) {
mod |= 0111;
}
ShimLoader.getHadoopShims();
return new FileStatus(file.length(), file.isDirectory(), 1, 1024,
file.lastModified(), file.lastModified(),
FsPermission.createImmutable(mod), "owen", "users", path);
}
示例2: chmod
import org.apache.hadoop.fs.permission.FsPermission; //导入方法依赖的package包/类
@Override
public void chmod(String path, int mode) throws IOException {
File f = new File(path);
FsPermission perm = FsPermission.createImmutable((short)mode);
LinkedList<String> args = new LinkedList<String>();
args.add("/usr/bin/setfacl");
args.add("-m");
args.add(
"u::" + perm.getUserAction().SYMBOL +
",g::" + perm.getGroupAction().SYMBOL +
",o::" + perm.getOtherAction().SYMBOL);
args.add(FileUtil.makeShellPath(f, true));
org.apache.hadoop.fs.util.Shell.runPrivileged(args.toArray(new String[0]));
// Set default acls on directories so children can inherit.
if(f.isDirectory()) {
args.add(1, "-d");
org.apache.hadoop.fs.util.Shell.runPrivileged(args.toArray(new String[0]));
}
}
示例3: createTreeOfInodes
import org.apache.hadoop.fs.permission.FsPermission; //导入方法依赖的package包/类
/**
* For a given path, build a tree of INodes and return the leaf node.
*/
private INode createTreeOfInodes(String path) throws QuotaExceededException {
byte[][] components = INode.getPathComponents(path);
FsPermission perm = FsPermission.createImmutable((short)0755);
PermissionStatus permstatus = PermissionStatus.createImmutable("", "", perm);
long id = 0;
INodeDirectory prev = new INodeDirectory(++id, new byte[0], permstatus, 0);
INodeDirectory dir = null;
for (byte[] component : components) {
if (component.length == 0) {
continue;
}
System.out.println("Adding component " + DFSUtil.bytes2String(component));
dir = new INodeDirectory(++id, component, permstatus, 0);
prev.addChild(dir, false, Snapshot.CURRENT_STATE_ID);
prev = dir;
}
return dir; // Last Inode in the chain
}
示例4: setupFileSystem
import org.apache.hadoop.fs.permission.FsPermission; //导入方法依赖的package包/类
private static FSNamesystem setupFileSystem() throws IOException {
Configuration conf = new Configuration();
conf.setLong(DFS_NAMENODE_ACCESSTIME_PRECISION_KEY, 1L);
FSEditLog editlog = mock(FSEditLog.class);
FSImage image = mock(FSImage.class);
when(image.getEditLog()).thenReturn(editlog);
final FSNamesystem fsn = new FSNamesystem(conf, image, true);
final FSDirectory fsd = fsn.getFSDirectory();
INodesInPath iip = fsd.getINodesInPath("/", true);
PermissionStatus perm = new PermissionStatus(
"hdfs", "supergroup",
FsPermission.createImmutable((short) 0x1ff));
final INodeFile file = new INodeFile(
MOCK_INODE_ID, FILE_NAME.getBytes(Charsets.UTF_8),
perm, 1, 1, new BlockInfoContiguous[] {}, (short) 1,
DFS_BLOCK_SIZE_DEFAULT);
fsn.getFSDirectory().addINode(iip, file);
return fsn;
}
示例5: setUpLocalFS
import org.apache.hadoop.fs.permission.FsPermission; //导入方法依赖的package包/类
@Before
public void setUpLocalFS() throws IOException {
final FileStatus rootStatus = new FileStatus(4096, true, 0, 0, 37, 42, FsPermission.createImmutable((short) 0555), "root", "wheel", new Path("sabot://10.0.0.1:1234/"));
final FileStatus fooStatus = new FileStatus(38214, true, 0, 0, 45, 67, FsPermission.createImmutable((short) 0755), "root", "wheel", new Path("sabot://10.0.0.1:1234/foo"));
final FileStatus fooBarStatus = new FileStatus(67128, true, 1, 4096, 69, 68, FsPermission.createImmutable((short) 0644), "root", "wheel", new Path("sabot://10.0.0.1:1234/foo/bar"));
final FileStatus fooBarDirStatus = new FileStatus(47, true, 0, 0, 1234, 3645, FsPermission.createImmutable((short) 0755), "admin", "admin", new Path("sabot://10.0.0.1:1234/foo/bar/dir"));
final FileStatus fooBarFile1Status = new FileStatus(1024, false, 1, 4096, 37, 42, FsPermission.createImmutable((short) 0644), "root", "wheel", new Path("sabot://10.0.0.1:1234/foo/bar/file1"));
final FileStatus fooBarFile2Status = new FileStatus(2048, false, 1, 4096, 37, 42, FsPermission.createImmutable((short) 0644), "root", "wheel", new Path("sabot://10.0.0.1:1234/foo/bar/file2"));
doReturn(rootStatus).when(mockLocalFS).getFileStatus(new Path("/"));
doThrow(new FileNotFoundException()).when(mockLocalFS).getFileStatus(any(Path.class));
doReturn(fooBarFile2Status).when(mockLocalFS).getFileStatus(new Path("/foo/bar/file2"));
doReturn(fooBarFile1Status).when(mockLocalFS).getFileStatus(new Path("/foo/bar/file1"));
doReturn(fooBarDirStatus).when(mockLocalFS).getFileStatus(new Path("/foo/bar/dir"));
doReturn(fooBarStatus).when(mockLocalFS).getFileStatus(new Path("/foo/bar"));
doReturn(fooStatus).when(mockLocalFS).getFileStatus(new Path("/foo"));
doReturn(rootStatus).when(mockLocalFS).getFileStatus(new Path("/"));
doThrow(new FileNotFoundException()).when(mockLocalFS).listStatus(any(Path.class));
doReturn(new FileStatus[] { fooBarDirStatus, fooBarFile1Status, fooBarFile2Status }).when(mockLocalFS).listStatus(new Path("/foo/bar"));
doReturn(new FileStatus[] { fooBarStatus }).when(mockLocalFS).listStatus(new Path("/foo"));
doReturn(new FileStatus[] { fooStatus }).when(mockLocalFS).listStatus(new Path("/"));
}
示例6: setUpRemoteFS
import org.apache.hadoop.fs.permission.FsPermission; //导入方法依赖的package包/类
@Before
public void setUpRemoteFS() throws IOException {
final FileStatus rootStatus = new FileStatus(4096, true, 0, 0, 38, 43, FsPermission.createImmutable((short) 0555), "root", "wheel", new Path("sabot://10.0.0.2:1234/"));
final FileStatus fooStatus = new FileStatus(37126, true, 0, 0, 41, 87, FsPermission.createImmutable((short) 0755), "root", "wheel", new Path("sabot://10.0.0.2:1234/foo"));
final FileStatus fooBarStatus = new FileStatus(67128, true, 1, 4096, 54, 90, FsPermission.createImmutable((short) 0644), "root", "wheel", new Path("sabot://10.0.0.2:1234/foo/bar"));
final FileStatus fooBarDirStatus = new FileStatus(47, true, 0, 0, 1234, 3645, FsPermission.createImmutable((short) 0755), "admin", "admin", new Path("sabot://10.0.0.2:1234/foo/bar/dir"));
final FileStatus fooBarFile1Status = new FileStatus(1027, false, 1, 4096, 37, 42, FsPermission.createImmutable((short) 0644), "root", "wheel", new Path("sabot://10.0.0.2:1234/foo/bar/file1"));
final FileStatus fooBarFile2Status = new FileStatus(2049, false, 1, 4096, 37, 42, FsPermission.createImmutable((short) 0644), "root", "wheel", new Path("sabot://10.0.0.2:1234/foo/bar/file3"));
doThrow(new FileNotFoundException()).when(mockRemoteFS).getFileStatus(any(Path.class));
doReturn(fooBarFile2Status).when(mockRemoteFS).getFileStatus(new Path("/foo/bar/file2"));
doReturn(fooBarFile1Status).when(mockRemoteFS).getFileStatus(new Path("/foo/bar/file1"));
doReturn(fooBarDirStatus).when(mockRemoteFS).getFileStatus(new Path("/foo/bar/dir"));
doReturn(fooBarStatus).when(mockRemoteFS).getFileStatus(new Path("/foo/bar"));
doReturn(fooStatus).when(mockRemoteFS).getFileStatus(new Path("/foo"));
doReturn(rootStatus).when(mockRemoteFS).getFileStatus(new Path("/"));
doThrow(new FileNotFoundException()).when(mockRemoteFS).listStatus(any(Path.class));
doReturn(new FileStatus[] { fooBarDirStatus, fooBarFile1Status, fooBarFile2Status }).when(mockRemoteFS).listStatus(new Path("/foo/bar"));
doReturn(new FileStatus[] { fooBarStatus }).when(mockRemoteFS).listStatus(new Path("/foo"));
doReturn(new FileStatus[] { fooStatus }).when(mockRemoteFS).listStatus(new Path("/"));
}
示例7: testInvalidSymlinkTarget
import org.apache.hadoop.fs.permission.FsPermission; //导入方法依赖的package包/类
private void testInvalidSymlinkTarget(NamenodeProtocols nnRpc,
String invalidTarget, String link) throws IOException {
try {
FsPermission perm = FsPermission.createImmutable((short)0755);
nnRpc.createSymlink(invalidTarget, link, perm, false);
fail("Symbolic link creation of target " + invalidTarget + " should fail");
} catch (InvalidPathException expected) {
// Expected
}
}
示例8: testFilePermissions
import org.apache.hadoop.fs.permission.FsPermission; //导入方法依赖的package包/类
@Test
public void testFilePermissions() throws Exception {
Path testFile = new Path("permissionTestFile");
FsPermission permission = FsPermission.createImmutable((short) 644);
createEmptyFile(testFile, permission);
FileStatus ret = fs.getFileStatus(testFile);
assertEqualsIgnoreStickyBit(permission, ret.getPermission());
fs.delete(testFile, true);
}
示例9: testFolderPermissions
import org.apache.hadoop.fs.permission.FsPermission; //导入方法依赖的package包/类
@Test
public void testFolderPermissions() throws Exception {
Path testFolder = new Path("permissionTestFolder");
FsPermission permission = FsPermission.createImmutable((short) 644);
fs.mkdirs(testFolder, permission);
FileStatus ret = fs.getFileStatus(testFolder);
assertEqualsIgnoreStickyBit(permission, ret.getPermission());
fs.delete(testFolder, true);
}
示例10: testDeepFileCreationBase
import org.apache.hadoop.fs.permission.FsPermission; //导入方法依赖的package包/类
void testDeepFileCreationBase(String testFilePath, String firstDirPath, String middleDirPath,
short permissionShort, short umaskedPermissionShort) throws Exception {
Path testFile = new Path(testFilePath);
Path firstDir = new Path(firstDirPath);
Path middleDir = new Path(middleDirPath);
FsPermission permission = FsPermission.createImmutable(permissionShort);
FsPermission umaskedPermission = FsPermission.createImmutable(umaskedPermissionShort);
createEmptyFile(testFile, permission);
FsPermission rootPerm = fs.getFileStatus(firstDir.getParent()).getPermission();
FsPermission inheritPerm = FsPermission.createImmutable((short)(rootPerm.toShort() | 0300));
assertTrue(fs.exists(testFile));
assertTrue(fs.exists(firstDir));
assertTrue(fs.exists(middleDir));
// verify that the indirectly created directory inherited its permissions from the root directory
FileStatus directoryStatus = fs.getFileStatus(middleDir);
assertTrue(directoryStatus.isDirectory());
assertEqualsIgnoreStickyBit(inheritPerm, directoryStatus.getPermission());
// verify that the file itself has the permissions as specified
FileStatus fileStatus = fs.getFileStatus(testFile);
assertFalse(fileStatus.isDirectory());
assertEqualsIgnoreStickyBit(umaskedPermission, fileStatus.getPermission());
assertTrue(fs.delete(firstDir, true));
assertFalse(fs.exists(testFile));
// An alternative test scenario would've been to delete the file first,
// and then check for the existence of the upper folders still. But that
// doesn't actually work as expected right now.
}
示例11: testRenameImplicitFolder
import org.apache.hadoop.fs.permission.FsPermission; //导入方法依赖的package包/类
@Test
public void testRenameImplicitFolder() throws Exception {
Path testFile = new Path("deep/file/rename/test");
FsPermission permission = FsPermission.createImmutable((short) 644);
createEmptyFile(testFile, permission);
boolean renameResult = fs.rename(new Path("deep/file"), new Path("deep/renamed"));
assertTrue(renameResult);
assertFalse(fs.exists(testFile));
FileStatus newStatus = fs.getFileStatus(new Path("deep/renamed/rename/test"));
assertNotNull(newStatus);
assertEqualsIgnoreStickyBit(permission, newStatus.getPermission());
assertTrue(fs.delete(new Path("deep"), true));
}
示例12: testValidSymlinkTarget
import org.apache.hadoop.fs.permission.FsPermission; //导入方法依赖的package包/类
private void testValidSymlinkTarget(NamenodeProtocols nnRpc, String target,
String link) throws IOException {
FsPermission perm = FsPermission.createImmutable((short)0755);
nnRpc.createSymlink(target, link, perm, false);
assertEquals(target, nnRpc.getLinkTarget(link));
}
示例13: toFsPermission
import org.apache.hadoop.fs.permission.FsPermission; //导入方法依赖的package包/类
static FsPermission toFsPermission(final Integer permissionValue) {
return permissionValue != null ? FsPermission.createImmutable(permissionValue.shortValue()) : null;
}