Java Code Examples for org.apache.hadoop.hdfs.DistributedFileSystem#modifyAclEntries()

The following examples show how to use org.apache.hadoop.hdfs.DistributedFileSystem#modifyAclEntries() . 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: TestFSImageWithAcl.java    From hadoop with Apache License 2.0 4 votes vote down vote up
private void testAcl(boolean persistNamespace) throws IOException {
  Path p = new Path("/p");
  DistributedFileSystem fs = cluster.getFileSystem();
  fs.create(p).close();
  fs.mkdirs(new Path("/23"));

  AclEntry e = new AclEntry.Builder().setName("foo")
      .setPermission(READ_EXECUTE).setScope(ACCESS).setType(USER).build();
  fs.modifyAclEntries(p, Lists.newArrayList(e));

  restart(fs, persistNamespace);

  AclStatus s = cluster.getNamesystem().getAclStatus(p.toString());
  AclEntry[] returned = Lists.newArrayList(s.getEntries()).toArray(
      new AclEntry[0]);
  Assert.assertArrayEquals(new AclEntry[] {
      aclEntry(ACCESS, USER, "foo", READ_EXECUTE),
      aclEntry(ACCESS, GROUP, READ) }, returned);

  fs.removeAcl(p);

  if (persistNamespace) {
    fs.setSafeMode(SafeModeAction.SAFEMODE_ENTER);
    fs.saveNamespace();
    fs.setSafeMode(SafeModeAction.SAFEMODE_LEAVE);
  }

  cluster.restartNameNode();
  cluster.waitActive();

  s = cluster.getNamesystem().getAclStatus(p.toString());
  returned = Lists.newArrayList(s.getEntries()).toArray(new AclEntry[0]);
  Assert.assertArrayEquals(new AclEntry[] { }, returned);

  fs.modifyAclEntries(p, Lists.newArrayList(e));
  s = cluster.getNamesystem().getAclStatus(p.toString());
  returned = Lists.newArrayList(s.getEntries()).toArray(new AclEntry[0]);
  Assert.assertArrayEquals(new AclEntry[] {
      aclEntry(ACCESS, USER, "foo", READ_EXECUTE),
      aclEntry(ACCESS, GROUP, READ) }, returned);
}
 
Example 2
Source File: TestFSImageWithAcl.java    From hadoop with Apache License 2.0 4 votes vote down vote up
private void doTestDefaultAclNewChildren(boolean persistNamespace)
    throws IOException {
  Path dirPath = new Path("/dir");
  Path filePath = new Path(dirPath, "file1");
  Path subdirPath = new Path(dirPath, "subdir1");
  DistributedFileSystem fs = cluster.getFileSystem();
  fs.mkdirs(dirPath);
  List<AclEntry> aclSpec = Lists.newArrayList(
    aclEntry(DEFAULT, USER, "foo", ALL));
  fs.setAcl(dirPath, aclSpec);

  fs.create(filePath).close();
  fs.mkdirs(subdirPath);

  AclEntry[] fileExpected = new AclEntry[] {
    aclEntry(ACCESS, USER, "foo", ALL),
    aclEntry(ACCESS, GROUP, READ_EXECUTE) };
  AclEntry[] subdirExpected = new AclEntry[] {
    aclEntry(ACCESS, USER, "foo", ALL),
    aclEntry(ACCESS, GROUP, READ_EXECUTE),
    aclEntry(DEFAULT, USER, ALL),
    aclEntry(DEFAULT, USER, "foo", ALL),
    aclEntry(DEFAULT, GROUP, READ_EXECUTE),
    aclEntry(DEFAULT, MASK, ALL),
    aclEntry(DEFAULT, OTHER, READ_EXECUTE) };

  AclEntry[] fileReturned = fs.getAclStatus(filePath).getEntries()
    .toArray(new AclEntry[0]);
  Assert.assertArrayEquals(fileExpected, fileReturned);
  AclEntry[] subdirReturned = fs.getAclStatus(subdirPath).getEntries()
    .toArray(new AclEntry[0]);
  Assert.assertArrayEquals(subdirExpected, subdirReturned);
  assertPermission(fs, subdirPath, (short)010755);

  restart(fs, persistNamespace);

  fileReturned = fs.getAclStatus(filePath).getEntries()
    .toArray(new AclEntry[0]);
  Assert.assertArrayEquals(fileExpected, fileReturned);
  subdirReturned = fs.getAclStatus(subdirPath).getEntries()
    .toArray(new AclEntry[0]);
  Assert.assertArrayEquals(subdirExpected, subdirReturned);
  assertPermission(fs, subdirPath, (short)010755);

  aclSpec = Lists.newArrayList(aclEntry(DEFAULT, USER, "foo", READ_WRITE));
  fs.modifyAclEntries(dirPath, aclSpec);

  fileReturned = fs.getAclStatus(filePath).getEntries()
    .toArray(new AclEntry[0]);
  Assert.assertArrayEquals(fileExpected, fileReturned);
  subdirReturned = fs.getAclStatus(subdirPath).getEntries()
    .toArray(new AclEntry[0]);
  Assert.assertArrayEquals(subdirExpected, subdirReturned);
  assertPermission(fs, subdirPath, (short)010755);

  restart(fs, persistNamespace);

  fileReturned = fs.getAclStatus(filePath).getEntries()
    .toArray(new AclEntry[0]);
  Assert.assertArrayEquals(fileExpected, fileReturned);
  subdirReturned = fs.getAclStatus(subdirPath).getEntries()
    .toArray(new AclEntry[0]);
  Assert.assertArrayEquals(subdirExpected, subdirReturned);
  assertPermission(fs, subdirPath, (short)010755);

  fs.removeAcl(dirPath);

  fileReturned = fs.getAclStatus(filePath).getEntries()
    .toArray(new AclEntry[0]);
  Assert.assertArrayEquals(fileExpected, fileReturned);
  subdirReturned = fs.getAclStatus(subdirPath).getEntries()
    .toArray(new AclEntry[0]);
  Assert.assertArrayEquals(subdirExpected, subdirReturned);
  assertPermission(fs, subdirPath, (short)010755);

  restart(fs, persistNamespace);

  fileReturned = fs.getAclStatus(filePath).getEntries()
    .toArray(new AclEntry[0]);
  Assert.assertArrayEquals(fileExpected, fileReturned);
  subdirReturned = fs.getAclStatus(subdirPath).getEntries()
    .toArray(new AclEntry[0]);
  Assert.assertArrayEquals(subdirExpected, subdirReturned);
  assertPermission(fs, subdirPath, (short)010755);
}
 
Example 3
Source File: TestFSImageWithAcl.java    From big-c with Apache License 2.0 4 votes vote down vote up
private void testAcl(boolean persistNamespace) throws IOException {
  Path p = new Path("/p");
  DistributedFileSystem fs = cluster.getFileSystem();
  fs.create(p).close();
  fs.mkdirs(new Path("/23"));

  AclEntry e = new AclEntry.Builder().setName("foo")
      .setPermission(READ_EXECUTE).setScope(ACCESS).setType(USER).build();
  fs.modifyAclEntries(p, Lists.newArrayList(e));

  restart(fs, persistNamespace);

  AclStatus s = cluster.getNamesystem().getAclStatus(p.toString());
  AclEntry[] returned = Lists.newArrayList(s.getEntries()).toArray(
      new AclEntry[0]);
  Assert.assertArrayEquals(new AclEntry[] {
      aclEntry(ACCESS, USER, "foo", READ_EXECUTE),
      aclEntry(ACCESS, GROUP, READ) }, returned);

  fs.removeAcl(p);

  if (persistNamespace) {
    fs.setSafeMode(SafeModeAction.SAFEMODE_ENTER);
    fs.saveNamespace();
    fs.setSafeMode(SafeModeAction.SAFEMODE_LEAVE);
  }

  cluster.restartNameNode();
  cluster.waitActive();

  s = cluster.getNamesystem().getAclStatus(p.toString());
  returned = Lists.newArrayList(s.getEntries()).toArray(new AclEntry[0]);
  Assert.assertArrayEquals(new AclEntry[] { }, returned);

  fs.modifyAclEntries(p, Lists.newArrayList(e));
  s = cluster.getNamesystem().getAclStatus(p.toString());
  returned = Lists.newArrayList(s.getEntries()).toArray(new AclEntry[0]);
  Assert.assertArrayEquals(new AclEntry[] {
      aclEntry(ACCESS, USER, "foo", READ_EXECUTE),
      aclEntry(ACCESS, GROUP, READ) }, returned);
}
 
Example 4
Source File: TestFSImageWithAcl.java    From big-c with Apache License 2.0 4 votes vote down vote up
private void doTestDefaultAclNewChildren(boolean persistNamespace)
    throws IOException {
  Path dirPath = new Path("/dir");
  Path filePath = new Path(dirPath, "file1");
  Path subdirPath = new Path(dirPath, "subdir1");
  DistributedFileSystem fs = cluster.getFileSystem();
  fs.mkdirs(dirPath);
  List<AclEntry> aclSpec = Lists.newArrayList(
    aclEntry(DEFAULT, USER, "foo", ALL));
  fs.setAcl(dirPath, aclSpec);

  fs.create(filePath).close();
  fs.mkdirs(subdirPath);

  AclEntry[] fileExpected = new AclEntry[] {
    aclEntry(ACCESS, USER, "foo", ALL),
    aclEntry(ACCESS, GROUP, READ_EXECUTE) };
  AclEntry[] subdirExpected = new AclEntry[] {
    aclEntry(ACCESS, USER, "foo", ALL),
    aclEntry(ACCESS, GROUP, READ_EXECUTE),
    aclEntry(DEFAULT, USER, ALL),
    aclEntry(DEFAULT, USER, "foo", ALL),
    aclEntry(DEFAULT, GROUP, READ_EXECUTE),
    aclEntry(DEFAULT, MASK, ALL),
    aclEntry(DEFAULT, OTHER, READ_EXECUTE) };

  AclEntry[] fileReturned = fs.getAclStatus(filePath).getEntries()
    .toArray(new AclEntry[0]);
  Assert.assertArrayEquals(fileExpected, fileReturned);
  AclEntry[] subdirReturned = fs.getAclStatus(subdirPath).getEntries()
    .toArray(new AclEntry[0]);
  Assert.assertArrayEquals(subdirExpected, subdirReturned);
  assertPermission(fs, subdirPath, (short)010755);

  restart(fs, persistNamespace);

  fileReturned = fs.getAclStatus(filePath).getEntries()
    .toArray(new AclEntry[0]);
  Assert.assertArrayEquals(fileExpected, fileReturned);
  subdirReturned = fs.getAclStatus(subdirPath).getEntries()
    .toArray(new AclEntry[0]);
  Assert.assertArrayEquals(subdirExpected, subdirReturned);
  assertPermission(fs, subdirPath, (short)010755);

  aclSpec = Lists.newArrayList(aclEntry(DEFAULT, USER, "foo", READ_WRITE));
  fs.modifyAclEntries(dirPath, aclSpec);

  fileReturned = fs.getAclStatus(filePath).getEntries()
    .toArray(new AclEntry[0]);
  Assert.assertArrayEquals(fileExpected, fileReturned);
  subdirReturned = fs.getAclStatus(subdirPath).getEntries()
    .toArray(new AclEntry[0]);
  Assert.assertArrayEquals(subdirExpected, subdirReturned);
  assertPermission(fs, subdirPath, (short)010755);

  restart(fs, persistNamespace);

  fileReturned = fs.getAclStatus(filePath).getEntries()
    .toArray(new AclEntry[0]);
  Assert.assertArrayEquals(fileExpected, fileReturned);
  subdirReturned = fs.getAclStatus(subdirPath).getEntries()
    .toArray(new AclEntry[0]);
  Assert.assertArrayEquals(subdirExpected, subdirReturned);
  assertPermission(fs, subdirPath, (short)010755);

  fs.removeAcl(dirPath);

  fileReturned = fs.getAclStatus(filePath).getEntries()
    .toArray(new AclEntry[0]);
  Assert.assertArrayEquals(fileExpected, fileReturned);
  subdirReturned = fs.getAclStatus(subdirPath).getEntries()
    .toArray(new AclEntry[0]);
  Assert.assertArrayEquals(subdirExpected, subdirReturned);
  assertPermission(fs, subdirPath, (short)010755);

  restart(fs, persistNamespace);

  fileReturned = fs.getAclStatus(filePath).getEntries()
    .toArray(new AclEntry[0]);
  Assert.assertArrayEquals(fileExpected, fileReturned);
  subdirReturned = fs.getAclStatus(subdirPath).getEntries()
    .toArray(new AclEntry[0]);
  Assert.assertArrayEquals(subdirExpected, subdirReturned);
  assertPermission(fs, subdirPath, (short)010755);
}