Java Code Examples for org.apache.hadoop.fs.permission.FsPermission#createImmutable()

The following examples show how to use org.apache.hadoop.fs.permission.FsPermission#createImmutable() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestINodeFile.java    From hadoop with Apache License 2.0 6 votes vote down vote up
/**
 * 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
}
 
Example 2
Source File: HadoopIgfs20FileSystemAbstractSelfTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/** @throws Exception If failed. */
@SuppressWarnings("OctalInteger")
@Test
public void testMkdirs() throws Exception {
    Path fsHome = new Path(primaryFileSystemUriPath());
    Path dir = new Path(fsHome, "/tmp/staging");
    Path nestedDir = new Path(dir, "nested");

    FsPermission dirPerm = FsPermission.createImmutable((short)0700);
    FsPermission nestedDirPerm = FsPermission.createImmutable((short)111);

    fs.mkdir(dir, dirPerm, true);
    fs.mkdir(nestedDir, nestedDirPerm, true);

    assertEquals(dirPerm, fs.getFileStatus(dir).getPermission());
    assertEquals(nestedDirPerm, fs.getFileStatus(nestedDir).getPermission());

    assertEquals(getClientFsUser(), fs.getFileStatus(dir).getOwner());
    assertEquals(getClientFsUser(), fs.getFileStatus(nestedDir).getOwner());
}
 
Example 3
Source File: IgniteHadoopFileSystemAbstractSelfTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/** @throws Exception If failed. */
@SuppressWarnings("OctalInteger")
@Test
public void testMkdirs() throws Exception {
    Path fsHome = new Path(PRIMARY_URI);
    final Path dir = new Path(fsHome, "/tmp/staging");
    final Path nestedDir = new Path(dir, "nested");

    final FsPermission dirPerm = FsPermission.createImmutable((short)0700);
    final FsPermission nestedDirPerm = FsPermission.createImmutable((short)111);

    assertTrue(fs.mkdirs(dir, dirPerm));
    assertTrue(fs.mkdirs(nestedDir, nestedDirPerm));

    assertEquals(dirPerm, fs.getFileStatus(dir).getPermission());
    assertEquals(nestedDirPerm, fs.getFileStatus(nestedDir).getPermission());

    assertEquals(getClientFsUser(), fs.getFileStatus(dir).getOwner());
    assertEquals(getClientFsUser(), fs.getFileStatus(nestedDir).getOwner());
}
 
Example 4
Source File: SentryAuthorizationProvider.java    From incubator-sentry with Apache License 2.0 6 votes vote down vote up
@Override
public FsPermission getFsPermission(
    INodeAuthorizationInfo node, int snapshotId) {
  FsPermission permission;
  String[] pathElements = getPathElements(node);
  if (!isSentryManaged(pathElements)) {
    permission = defaultAuthzProvider.getFsPermission(node, snapshotId);
  } else {
    FsPermission returnPerm = this.permission;
    // Handle case when prefix directory is itself associated with an
    // authorizable object (default db directory in hive)
    // An executable permission needs to be set on the the prefix directory
    // in this case.. else, subdirectories (which map to other dbs) will
    // not be travesible.
    for (String [] prefixPath : authzInfo.getPathPrefixes()) {
      if (Arrays.equals(prefixPath, pathElements)) {
        returnPerm = FsPermission.createImmutable((short)(returnPerm.toShort() | 0x01));
        break;
      }
    }
    permission = returnPerm;
  }
  return permission;
}
 
Example 5
Source File: Client.java    From XLearning with Apache License 2.0 5 votes vote down vote up
private Client(String[] args) throws IOException, ParseException, ClassNotFoundException {
  this.conf = new XLearningConfiguration();
  this.dfs = FileSystem.get(conf);
  this.clientArguments = new ClientArguments(args);
  this.isRunning = new AtomicBoolean(false);
  this.appFilesRemotePath = new StringBuffer(1000);
  this.appLibJarsRemotePath = new StringBuffer(1000);
  this.inputPaths = new ConcurrentHashMap<>();
  this.outputPaths = new ConcurrentHashMap<>();
  JOB_FILE_PERMISSION = FsPermission.createImmutable((short) 0644);
  this.appMasterUserEnv = new HashMap<>();
  this.containerUserEnv = new HashMap<>();

}
 
Example 6
Source File: NativeAzureFileSystemBaseTest.java    From big-c with Apache License 2.0 5 votes vote down vote up
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.
}
 
Example 7
Source File: NativeAzureFileSystemBaseTest.java    From big-c with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example 8
Source File: NativeAzureFileSystemBaseTest.java    From big-c with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example 9
Source File: TestINodeFile.java    From big-c with Apache License 2.0 5 votes vote down vote up
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
  }
}
 
Example 10
Source File: TestPseudoDistributedFileSystem.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
@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("/"));

  final FileStatus[] fooBarStatusList = new FileStatus[] { fooBarDirStatus, fooBarFile1Status, fooBarFile2Status };
  final FileStatus[] fooStatusList = new FileStatus[] { fooBarStatus };
  final FileStatus[] rootStatusList = new FileStatus[] { fooStatus };

  // listStatusIterator mocks.
  doThrow(new FileNotFoundException()).when(mockRemoteFS).listStatusIterator(any(Path.class));
  doReturn(new MockRemoteStatusIterator(fooBarStatusList)).when(mockRemoteFS).listStatusIterator(new Path("/foo/bar"));
  doReturn(new MockRemoteStatusIterator(fooStatusList)).when(mockRemoteFS).listStatusIterator(new Path("/foo"));
  doReturn(new MockRemoteStatusIterator(rootStatusList)).when(mockRemoteFS).listStatusIterator(new Path("/"));

  // listStatus mocks.
  doThrow(new FileNotFoundException()).when(mockRemoteFS).listStatus(any(Path.class));
  doReturn(fooBarStatusList).when(mockRemoteFS).listStatus(new Path("/foo/bar"));
  doReturn(fooStatusList).when(mockRemoteFS).listStatus(new Path("/foo"));
  doReturn(rootStatusList).when(mockRemoteFS).listStatus(new Path("/"));
}
 
Example 11
Source File: TestPseudoDistributedFileSystem.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
@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("/"));

  final FileStatus[] fooBarStatusList = new FileStatus[] { fooBarDirStatus, fooBarFile1Status, fooBarFile2Status };
  final FileStatus[] fooStatusList = new FileStatus[] { fooBarStatus };
  final FileStatus[] rootStatusList = new FileStatus[] { fooStatus };

  // listStatusIterator mocks.
  doThrow(new FileNotFoundException()).when(mockLocalFS).listStatusIterator(any(Path.class));
  doReturn(new MockRemoteStatusIterator(fooBarStatusList)).when(mockLocalFS).listStatusIterator(new Path("/foo/bar"));
  doReturn(new MockRemoteStatusIterator(fooStatusList)).when(mockLocalFS).listStatusIterator(new Path("/foo"));
  doReturn(new MockRemoteStatusIterator(rootStatusList)).when(mockLocalFS).listStatusIterator(new Path("/"));

  // listStatus mocks.
  doThrow(new FileNotFoundException()).when(mockLocalFS).listStatus(any(Path.class));
  doReturn(fooBarStatusList).when(mockLocalFS).listStatus(new Path("/foo/bar"));
  doReturn(fooStatusList).when(mockLocalFS).listStatus(new Path("/foo"));
  doReturn(rootStatusList).when(mockLocalFS).listStatus(new Path("/"));
}
 
Example 12
Source File: NativeAzureFileSystemBaseTest.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@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));
}
 
Example 13
Source File: NativeAzureFileSystemBaseTest.java    From hadoop with Apache License 2.0 5 votes vote down vote up
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.
}
 
Example 14
Source File: NativeAzureFileSystemBaseTest.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example 15
Source File: NativeAzureFileSystemBaseTest.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example 16
Source File: TestMasterRules.java    From tajo with Apache License 2.0 5 votes vote down vote up
protected void createTajoDirectories(TajoConf tajoConf) throws Exception {
  Path tajoRootDir = new Path(rootFilePath, "tajo-root");
  FileSystem rootFs = tajoRootDir.getFileSystem(tajoConf);
  FsPermission defaultPermission = FsPermission.createImmutable((short)0700);
  
  if (!rootFs.exists(tajoRootDir)) {
    rootFs.mkdirs(tajoRootDir, new FsPermission(defaultPermission));
  }
  
  tajoConf.setVar(ConfVars.ROOT_DIR, tajoRootDir.toUri().toString());
  
  Path tajoSystemDir = new Path(tajoRootDir, TajoConstants.SYSTEM_DIR_NAME);
  if (!rootFs.exists(tajoSystemDir)) {
    rootFs.mkdirs(tajoSystemDir, new FsPermission(defaultPermission));
  }
  
  Path tajoSystemResourceDir = new Path(tajoSystemDir, TajoConstants.SYSTEM_RESOURCE_DIR_NAME);
  if (!rootFs.exists(tajoSystemResourceDir)) {
    rootFs.mkdirs(tajoSystemResourceDir, new FsPermission(defaultPermission));
  }
  
  Path tajoWarehouseDir = new Path(tajoRootDir, TajoConstants.WAREHOUSE_DIR_NAME);
  if (!rootFs.exists(tajoWarehouseDir)) {
    rootFs.mkdirs(tajoWarehouseDir, new FsPermission(defaultPermission));
  }
  
  Path tajoStagingDir = new Path(tajoRootDir, "staging");
  if (!rootFs.exists(tajoStagingDir)) {
    rootFs.mkdirs(tajoStagingDir, new FsPermission(defaultPermission));
  }
  tajoConf.setVar(ConfVars.STAGING_ROOT_DIR, tajoStagingDir.toUri().toString());
}
 
Example 17
Source File: TestINodeFile.java    From hadoop with Apache License 2.0 5 votes vote down vote up
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
  }
}
 
Example 18
Source File: HdfsEnvironment.java    From presto with Apache License 2.0 5 votes vote down vote up
@Inject
public HdfsEnvironment(
        HdfsConfiguration hdfsConfiguration,
        HdfsConfig config,
        HdfsAuthentication hdfsAuthentication)
{
    this.hdfsConfiguration = requireNonNull(hdfsConfiguration, "hdfsConfiguration is null");
    requireNonNull(config, "config is null");
    this.newDirectoryPermissions = FsPermission.createImmutable(Shorts.checkedCast(parseUnsignedInt(config.getNewDirectoryPermissions(), 8)));
    this.verifyChecksum = config.isVerifyChecksum();
    this.hdfsAuthentication = requireNonNull(hdfsAuthentication, "hdfsAuthentication is null");
}
 
Example 19
Source File: RemoteNodeFileSystem.java    From dremio-oss with Apache License 2.0 4 votes vote down vote up
static FsPermission toFsPermission(final Integer permissionValue) {
  return permissionValue != null ? FsPermission.createImmutable(permissionValue.shortValue()) : null;
}
 
Example 20
Source File: TestINodeFile.java    From hadoop with Apache License 2.0 4 votes vote down vote up
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));
}