Java Code Examples for org.apache.hadoop.fs.FileSystem#modifyAclEntries()

The following examples show how to use org.apache.hadoop.fs.FileSystem#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: BaseTestHttpFSWith.java    From hadoop with Apache License 2.0 4 votes vote down vote up
/**
 * Simple ACL tests on a file:  Set an acl, add an acl, remove one acl,
 * and remove all acls.
 * @throws Exception
 */
private void testFileAcls() throws Exception {
  if ( isLocalFS() ) {
    return;
  }

  final String aclUser1 = "user:foo:rw-";
  final String aclUser2 = "user:bar:r--";
  final String aclGroup1 = "group::r--";
  final String aclSet = "user::rwx," + aclUser1 + ","
          + aclGroup1 + ",other::---";

  FileSystem proxyFs = FileSystem.get(getProxiedFSConf());
  FileSystem httpfs = getHttpFSFileSystem();

  Path path = new Path(getProxiedFSTestDir(), "testAclStatus.txt");
  OutputStream os = proxyFs.create(path);
  os.write(1);
  os.close();

  AclStatus proxyAclStat = proxyFs.getAclStatus(path);
  AclStatus httpfsAclStat = httpfs.getAclStatus(path);
  assertSameAcls(httpfsAclStat, proxyAclStat);

  httpfs.setAcl(path, AclEntry.parseAclSpec(aclSet,true));
  proxyAclStat = proxyFs.getAclStatus(path);
  httpfsAclStat = httpfs.getAclStatus(path);
  assertSameAcls(httpfsAclStat, proxyAclStat);

  httpfs.modifyAclEntries(path, AclEntry.parseAclSpec(aclUser2, true));
  proxyAclStat = proxyFs.getAclStatus(path);
  httpfsAclStat = httpfs.getAclStatus(path);
  assertSameAcls(httpfsAclStat, proxyAclStat);

  httpfs.removeAclEntries(path, AclEntry.parseAclSpec(aclUser1, true));
  proxyAclStat = proxyFs.getAclStatus(path);
  httpfsAclStat = httpfs.getAclStatus(path);
  assertSameAcls(httpfsAclStat, proxyAclStat);

  httpfs.removeAcl(path);
  proxyAclStat = proxyFs.getAclStatus(path);
  httpfsAclStat = httpfs.getAclStatus(path);
  assertSameAcls(httpfsAclStat, proxyAclStat);
}
 
Example 2
Source File: TestEditLog.java    From hadoop with Apache License 2.0 4 votes vote down vote up
/**
 * Edit log op instances are cached internally using thread-local storage.
 * This test checks that the cached instances are reset in between different
 * transactions processed on the same thread, so that we don't accidentally
 * apply incorrect attributes to an inode.
 *
 * @throws IOException if there is an I/O error
 */
@Test
public void testResetThreadLocalCachedOps() throws IOException {
  Configuration conf = new HdfsConfiguration();
  conf.setBoolean(DFSConfigKeys.DFS_NAMENODE_ACLS_ENABLED_KEY, true);
  // Set single handler thread, so all transactions hit same thread-local ops.
  conf.setInt(DFSConfigKeys.DFS_NAMENODE_HANDLER_COUNT_KEY, 1);
  MiniDFSCluster cluster = null;
  FileSystem fileSys = null;
  try {
    cluster = new MiniDFSCluster.Builder(conf).numDataNodes(1).build();
    cluster.waitActive();
    fileSys = cluster.getFileSystem();

    // Create /dir1 with a default ACL.
    Path dir1 = new Path("/dir1");
    fileSys.mkdirs(dir1);
    List<AclEntry> aclSpec = Lists.newArrayList(
        aclEntry(DEFAULT, USER, "foo", READ_EXECUTE));
    fileSys.modifyAclEntries(dir1, aclSpec);

    // /dir1/dir2 is expected to clone the default ACL.
    Path dir2 = new Path("/dir1/dir2");
    fileSys.mkdirs(dir2);

    // /dir1/file1 is expected to clone the default ACL.
    Path file1 = new Path("/dir1/file1");
    fileSys.create(file1).close();

    // /dir3 is not a child of /dir1, so must not clone the default ACL.
    Path dir3 = new Path("/dir3");
    fileSys.mkdirs(dir3);

    // /file2 is not a child of /dir1, so must not clone the default ACL.
    Path file2 = new Path("/file2");
    fileSys.create(file2).close();

    // Restart and assert the above stated expectations.
    IOUtils.cleanup(LOG, fileSys);
    cluster.restartNameNode();
    fileSys = cluster.getFileSystem();
    assertFalse(fileSys.getAclStatus(dir1).getEntries().isEmpty());
    assertFalse(fileSys.getAclStatus(dir2).getEntries().isEmpty());
    assertFalse(fileSys.getAclStatus(file1).getEntries().isEmpty());
    assertTrue(fileSys.getAclStatus(dir3).getEntries().isEmpty());
    assertTrue(fileSys.getAclStatus(file2).getEntries().isEmpty());
  } finally {
    IOUtils.cleanup(LOG, fileSys);
    if (cluster != null) {
      cluster.shutdown();
    }
  }
}
 
Example 3
Source File: TestViewFileSystemDelegation.java    From hadoop with Apache License 2.0 4 votes vote down vote up
/**
 * Tests that ViewFileSystem dispatches calls for every ACL method through the
 * mount table to the correct underlying FileSystem with all Path arguments
 * translated as required.
 */
@Test
public void testAclMethods() throws Exception {
  Configuration conf = ViewFileSystemTestSetup.createConfig();
  FileSystem mockFs1 = setupMockFileSystem(conf, new URI("mockfs1:/"));
  FileSystem mockFs2 = setupMockFileSystem(conf, new URI("mockfs2:/"));
  FileSystem viewFs = FileSystem.get(FsConstants.VIEWFS_URI, conf);

  Path viewFsPath1 = new Path("/mounts/mockfs1/a/b/c");
  Path mockFsPath1 = new Path("/a/b/c");
  Path viewFsPath2 = new Path("/mounts/mockfs2/d/e/f");
  Path mockFsPath2 = new Path("/d/e/f");
  List<AclEntry> entries = Collections.emptyList();

  viewFs.modifyAclEntries(viewFsPath1, entries);
  verify(mockFs1).modifyAclEntries(mockFsPath1, entries);
  viewFs.modifyAclEntries(viewFsPath2, entries);
  verify(mockFs2).modifyAclEntries(mockFsPath2, entries);

  viewFs.removeAclEntries(viewFsPath1, entries);
  verify(mockFs1).removeAclEntries(mockFsPath1, entries);
  viewFs.removeAclEntries(viewFsPath2, entries);
  verify(mockFs2).removeAclEntries(mockFsPath2, entries);

  viewFs.removeDefaultAcl(viewFsPath1);
  verify(mockFs1).removeDefaultAcl(mockFsPath1);
  viewFs.removeDefaultAcl(viewFsPath2);
  verify(mockFs2).removeDefaultAcl(mockFsPath2);

  viewFs.removeAcl(viewFsPath1);
  verify(mockFs1).removeAcl(mockFsPath1);
  viewFs.removeAcl(viewFsPath2);
  verify(mockFs2).removeAcl(mockFsPath2);

  viewFs.setAcl(viewFsPath1, entries);
  verify(mockFs1).setAcl(mockFsPath1, entries);
  viewFs.setAcl(viewFsPath2, entries);
  verify(mockFs2).setAcl(mockFsPath2, entries);

  viewFs.getAclStatus(viewFsPath1);
  verify(mockFs1).getAclStatus(mockFsPath1);
  viewFs.getAclStatus(viewFsPath2);
  verify(mockFs2).getAclStatus(mockFsPath2);
}
 
Example 4
Source File: BaseTestHttpFSWith.java    From big-c with Apache License 2.0 4 votes vote down vote up
/**
 * Simple ACL tests on a file:  Set an acl, add an acl, remove one acl,
 * and remove all acls.
 * @throws Exception
 */
private void testFileAcls() throws Exception {
  if ( isLocalFS() ) {
    return;
  }

  final String aclUser1 = "user:foo:rw-";
  final String aclUser2 = "user:bar:r--";
  final String aclGroup1 = "group::r--";
  final String aclSet = "user::rwx," + aclUser1 + ","
          + aclGroup1 + ",other::---";

  FileSystem proxyFs = FileSystem.get(getProxiedFSConf());
  FileSystem httpfs = getHttpFSFileSystem();

  Path path = new Path(getProxiedFSTestDir(), "testAclStatus.txt");
  OutputStream os = proxyFs.create(path);
  os.write(1);
  os.close();

  AclStatus proxyAclStat = proxyFs.getAclStatus(path);
  AclStatus httpfsAclStat = httpfs.getAclStatus(path);
  assertSameAcls(httpfsAclStat, proxyAclStat);

  httpfs.setAcl(path, AclEntry.parseAclSpec(aclSet,true));
  proxyAclStat = proxyFs.getAclStatus(path);
  httpfsAclStat = httpfs.getAclStatus(path);
  assertSameAcls(httpfsAclStat, proxyAclStat);

  httpfs.modifyAclEntries(path, AclEntry.parseAclSpec(aclUser2, true));
  proxyAclStat = proxyFs.getAclStatus(path);
  httpfsAclStat = httpfs.getAclStatus(path);
  assertSameAcls(httpfsAclStat, proxyAclStat);

  httpfs.removeAclEntries(path, AclEntry.parseAclSpec(aclUser1, true));
  proxyAclStat = proxyFs.getAclStatus(path);
  httpfsAclStat = httpfs.getAclStatus(path);
  assertSameAcls(httpfsAclStat, proxyAclStat);

  httpfs.removeAcl(path);
  proxyAclStat = proxyFs.getAclStatus(path);
  httpfsAclStat = httpfs.getAclStatus(path);
  assertSameAcls(httpfsAclStat, proxyAclStat);
}
 
Example 5
Source File: TestEditLog.java    From big-c with Apache License 2.0 4 votes vote down vote up
/**
 * Edit log op instances are cached internally using thread-local storage.
 * This test checks that the cached instances are reset in between different
 * transactions processed on the same thread, so that we don't accidentally
 * apply incorrect attributes to an inode.
 *
 * @throws IOException if there is an I/O error
 */
@Test
public void testResetThreadLocalCachedOps() throws IOException {
  Configuration conf = new HdfsConfiguration();
  conf.setBoolean(DFSConfigKeys.DFS_NAMENODE_ACLS_ENABLED_KEY, true);
  // Set single handler thread, so all transactions hit same thread-local ops.
  conf.setInt(DFSConfigKeys.DFS_NAMENODE_HANDLER_COUNT_KEY, 1);
  MiniDFSCluster cluster = null;
  FileSystem fileSys = null;
  try {
    cluster = new MiniDFSCluster.Builder(conf).numDataNodes(1).build();
    cluster.waitActive();
    fileSys = cluster.getFileSystem();

    // Create /dir1 with a default ACL.
    Path dir1 = new Path("/dir1");
    fileSys.mkdirs(dir1);
    List<AclEntry> aclSpec = Lists.newArrayList(
        aclEntry(DEFAULT, USER, "foo", READ_EXECUTE));
    fileSys.modifyAclEntries(dir1, aclSpec);

    // /dir1/dir2 is expected to clone the default ACL.
    Path dir2 = new Path("/dir1/dir2");
    fileSys.mkdirs(dir2);

    // /dir1/file1 is expected to clone the default ACL.
    Path file1 = new Path("/dir1/file1");
    fileSys.create(file1).close();

    // /dir3 is not a child of /dir1, so must not clone the default ACL.
    Path dir3 = new Path("/dir3");
    fileSys.mkdirs(dir3);

    // /file2 is not a child of /dir1, so must not clone the default ACL.
    Path file2 = new Path("/file2");
    fileSys.create(file2).close();

    // Restart and assert the above stated expectations.
    IOUtils.cleanup(LOG, fileSys);
    cluster.restartNameNode();
    fileSys = cluster.getFileSystem();
    assertFalse(fileSys.getAclStatus(dir1).getEntries().isEmpty());
    assertFalse(fileSys.getAclStatus(dir2).getEntries().isEmpty());
    assertFalse(fileSys.getAclStatus(file1).getEntries().isEmpty());
    assertTrue(fileSys.getAclStatus(dir3).getEntries().isEmpty());
    assertTrue(fileSys.getAclStatus(file2).getEntries().isEmpty());
  } finally {
    IOUtils.cleanup(LOG, fileSys);
    if (cluster != null) {
      cluster.shutdown();
    }
  }
}
 
Example 6
Source File: TestViewFileSystemDelegation.java    From big-c with Apache License 2.0 4 votes vote down vote up
/**
 * Tests that ViewFileSystem dispatches calls for every ACL method through the
 * mount table to the correct underlying FileSystem with all Path arguments
 * translated as required.
 */
@Test
public void testAclMethods() throws Exception {
  Configuration conf = ViewFileSystemTestSetup.createConfig();
  FileSystem mockFs1 = setupMockFileSystem(conf, new URI("mockfs1:/"));
  FileSystem mockFs2 = setupMockFileSystem(conf, new URI("mockfs2:/"));
  FileSystem viewFs = FileSystem.get(FsConstants.VIEWFS_URI, conf);

  Path viewFsPath1 = new Path("/mounts/mockfs1/a/b/c");
  Path mockFsPath1 = new Path("/a/b/c");
  Path viewFsPath2 = new Path("/mounts/mockfs2/d/e/f");
  Path mockFsPath2 = new Path("/d/e/f");
  List<AclEntry> entries = Collections.emptyList();

  viewFs.modifyAclEntries(viewFsPath1, entries);
  verify(mockFs1).modifyAclEntries(mockFsPath1, entries);
  viewFs.modifyAclEntries(viewFsPath2, entries);
  verify(mockFs2).modifyAclEntries(mockFsPath2, entries);

  viewFs.removeAclEntries(viewFsPath1, entries);
  verify(mockFs1).removeAclEntries(mockFsPath1, entries);
  viewFs.removeAclEntries(viewFsPath2, entries);
  verify(mockFs2).removeAclEntries(mockFsPath2, entries);

  viewFs.removeDefaultAcl(viewFsPath1);
  verify(mockFs1).removeDefaultAcl(mockFsPath1);
  viewFs.removeDefaultAcl(viewFsPath2);
  verify(mockFs2).removeDefaultAcl(mockFsPath2);

  viewFs.removeAcl(viewFsPath1);
  verify(mockFs1).removeAcl(mockFsPath1);
  viewFs.removeAcl(viewFsPath2);
  verify(mockFs2).removeAcl(mockFsPath2);

  viewFs.setAcl(viewFsPath1, entries);
  verify(mockFs1).setAcl(mockFsPath1, entries);
  viewFs.setAcl(viewFsPath2, entries);
  verify(mockFs2).setAcl(mockFsPath2, entries);

  viewFs.getAclStatus(viewFsPath1);
  verify(mockFs1).getAclStatus(mockFsPath1);
  viewFs.getAclStatus(viewFsPath2);
  verify(mockFs2).getAclStatus(mockFsPath2);
}
 
Example 7
Source File: FSOperations.java    From hadoop with Apache License 2.0 2 votes vote down vote up
/**
 * Executes the filesystem operation.
 *
 * @param fs filesystem instance to use.
 *
 * @return void.
 *
 * @throws IOException thrown if an IO error occurred.
 */
@Override
public Void execute(FileSystem fs) throws IOException {
  fs.modifyAclEntries(path, aclEntries);
  return null;
}
 
Example 8
Source File: FSOperations.java    From big-c with Apache License 2.0 2 votes vote down vote up
/**
 * Executes the filesystem operation.
 *
 * @param fs filesystem instance to use.
 *
 * @return void.
 *
 * @throws IOException thrown if an IO error occurred.
 */
@Override
public Void execute(FileSystem fs) throws IOException {
  fs.modifyAclEntries(path, aclEntries);
  return null;
}