List of usage examples for org.apache.hadoop.fs Path Path
public Path(URI aUri)
From source file:alluxio.client.hadoop.DFSIOIntegrationTest.java
License:Apache License
private void cleanup(org.apache.hadoop.fs.FileSystem fs) throws IOException { LOG.info("Cleaning up test files"); fs.delete(new Path(getBaseDir(mConfig)), true); }
From source file:alluxio.client.hadoop.FileSystemAclIntegrationTest.java
License:Apache License
/** * Deletes files in the given filesystem. * * @param fs given filesystem//from w w w .ja v a 2 s.com */ public static void cleanup(org.apache.hadoop.fs.FileSystem fs) throws IOException { FileStatus[] statuses = fs.listStatus(new Path("/")); for (FileStatus f : statuses) { fs.delete(f.getPath(), true); } }
From source file:alluxio.client.hadoop.FileSystemAclIntegrationTest.java
License:Apache License
@Test public void createFileWithPermission() throws Exception { List<Integer> permissionValues = Lists.newArrayList(0111, 0222, 0333, 0444, 0555, 0666, 0777, 0755, 0733, 0644, 0533, 0511);//from w w w .j a v a 2 s . com for (int value : permissionValues) { Path file = new Path("/createfile" + value); FsPermission permission = FsPermission.createImmutable((short) value); FSDataOutputStream o = sTFS.create(file, permission, false /* ignored */, 10 /* ignored */, (short) 1 /* ignored */, 512 /* ignored */, null /* ignored */); o.writeBytes("Test Bytes"); o.close(); FileStatus fs = sTFS.getFileStatus(file); Assert.assertEquals(permission, fs.getPermission()); } }
From source file:alluxio.client.hadoop.FileSystemAclIntegrationTest.java
License:Apache License
@Test public void mkdirsWithPermission() throws Exception { List<Integer> permissionValues = Lists.newArrayList(0111, 0222, 0333, 0444, 0555, 0666, 0777, 0755, 0733, 0644, 0533, 0511);/*from w ww .ja v a2 s . c om*/ for (int value : permissionValues) { Path dir = new Path("/createDir" + value); FsPermission permission = FsPermission.createImmutable((short) value); sTFS.mkdirs(dir, permission); FileStatus fs = sTFS.getFileStatus(dir); Assert.assertEquals(permission, fs.getPermission()); } }
From source file:alluxio.client.hadoop.FileSystemAclIntegrationTest.java
License:Apache License
/** * Test for {@link FileSystem#setPermission(Path, org.apache.hadoop.fs.permission.FsPermission)}. * It will test changing the permission of file using TFS. *//*from w ww .ja va 2 s. c o m*/ @Test public void chmod() throws Exception { Path fileA = new Path("/chmodfileA"); create(sTFS, fileA); FileStatus fs = sTFS.getFileStatus(fileA); Assert.assertTrue(sUfs.isFile(PathUtils.concatPath(sUfsRoot, fileA))); if (UnderFileSystemUtils.isHdfs(sUfs) && HadoopClientTestUtils.isHadoop1x()) { // If the UFS is hadoop 1.0, the org.apache.hadoop.fs.FileSystem.create uses default // permission option 0777. Assert.assertEquals((short) 0777, fs.getPermission().toShort()); } else { // Default permission should be 0644. Assert.assertEquals((short) 0644, fs.getPermission().toShort()); } sTFS.setPermission(fileA, FsPermission.createImmutable((short) 0755)); Assert.assertEquals((short) 0755, sTFS.getFileStatus(fileA).getPermission().toShort()); }
From source file:alluxio.client.hadoop.FileSystemAclIntegrationTest.java
License:Apache License
/** * Test for {@link FileSystem#setOwner(Path, String, String)} with local UFS. It will test only * changing the owner of file using TFS and propagate the change to UFS. Since the arbitrary * owner does not exist in the local UFS, the operation would fail. *///from w ww.j a v a 2 s . co m @Test public void changeNonexistentOwnerForLocal() throws Exception { // Skip non-local UFSs. Assume.assumeTrue(UnderFileSystemUtils.isLocal(sUfs)); Path fileA = new Path("/chownfileA-local"); final String nonexistentOwner = "nonexistent-user1"; final String nonexistentGroup = "nonexistent-group1"; create(sTFS, fileA); FileStatus fs = sTFS.getFileStatus(fileA); String defaultOwner = fs.getOwner(); String defaultGroup = fs.getGroup(); Assert.assertEquals(defaultOwner, sUfs.getFileStatus(PathUtils.concatPath(sUfsRoot, fileA)).getOwner()); // Group can different because local FS user to group mapping can be different from that // in Alluxio. Assert.assertNotEquals(defaultOwner, nonexistentOwner); Assert.assertNotEquals(defaultGroup, nonexistentGroup); // Expect a IOException for not able to setOwner for UFS with invalid owner name. mThrown.expect(IOException.class); mThrown.expectMessage("Could not setOwner for UFS file"); sTFS.setOwner(fileA, nonexistentOwner, null); }
From source file:alluxio.client.hadoop.FileSystemAclIntegrationTest.java
License:Apache License
/** * Test for {@link FileSystem#setOwner(Path, String, String)} with local UFS. It will test only * changing the group of file using TFS and propagate the change to UFS. Since the arbitrary * group does not exist in the local UFS, the operation would fail. */// w w w . j a v a2 s .c om @Test public void changeNonexistentGroupForLocal() throws Exception { // Skip non-local UFSs. Assume.assumeTrue(UnderFileSystemUtils.isLocal(sUfs)); Path fileB = new Path("/chownfileB-local"); final String nonexistentOwner = "nonexistent-user1"; final String nonexistentGroup = "nonexistent-group1"; create(sTFS, fileB); FileStatus fs = sTFS.getFileStatus(fileB); String defaultOwner = fs.getOwner(); String defaultGroup = fs.getGroup(); Assert.assertEquals(defaultOwner, sUfs.getFileStatus(PathUtils.concatPath(sUfsRoot, fileB)).getOwner()); // Group can different because local FS user to group mapping can be different from that // in Alluxio. Assert.assertNotEquals(defaultOwner, nonexistentOwner); Assert.assertNotEquals(defaultGroup, nonexistentGroup); // Expect a IOException for not able to setOwner for UFS with invalid group name. mThrown.expect(IOException.class); mThrown.expectMessage("Could not setOwner for UFS file"); sTFS.setOwner(fileB, null, nonexistentGroup); }
From source file:alluxio.client.hadoop.FileSystemAclIntegrationTest.java
License:Apache License
/** * Test for {@link FileSystem#setOwner(Path, String, String)} with local UFS. It will test * changing both owner and group of file using TFS and propagate the change to UFS. Since the * arbitrary owner and group do not exist in the local UFS, the operation would fail. *///from w ww . j a va 2 s . c o m @Test public void changeNonexistentOwnerAndGroupForLocal() throws Exception { // Skip non-local UFSs. Assume.assumeTrue(UnderFileSystemUtils.isLocal(sUfs)); Path fileC = new Path("/chownfileC-local"); final String nonexistentOwner = "nonexistent-user1"; final String nonexistentGroup = "nonexistent-group1"; create(sTFS, fileC); FileStatus fs = sTFS.getFileStatus(fileC); String defaultOwner = fs.getOwner(); String defaultGroup = fs.getGroup(); Assert.assertEquals(defaultOwner, sUfs.getFileStatus(PathUtils.concatPath(sUfsRoot, fileC)).getOwner()); // Group can different because local FS user to group mapping can be different from that // in Alluxio. Assert.assertNotEquals(defaultOwner, nonexistentOwner); Assert.assertNotEquals(defaultGroup, nonexistentGroup); mThrown.expect(IOException.class); mThrown.expectMessage("Could not update owner"); sTFS.setOwner(fileC, nonexistentOwner, nonexistentGroup); }
From source file:alluxio.client.hadoop.FileSystemAclIntegrationTest.java
License:Apache License
/** * Test for {@link FileSystem#setOwner(Path, String, String)} with HDFS UFS. It will test only * changing the owner of file using TFS and propagate the change to UFS. *//*from w w w . j a va 2s . c om*/ @Test public void changeNonexistentOwnerForHdfs() throws Exception { // Skip non-HDFS UFSs. Assume.assumeTrue(UnderFileSystemUtils.isHdfs(sUfs)); Path fileA = new Path("/chownfileA-hdfs"); final String testOwner = "test-user1"; final String testGroup = "test-group1"; create(sTFS, fileA); FileStatus fs = sTFS.getFileStatus(fileA); String defaultOwner = fs.getOwner(); String defaultGroup = fs.getGroup(); Assert.assertEquals(defaultOwner, sUfs.getFileStatus(PathUtils.concatPath(sUfsRoot, fileA)).getOwner()); // Group can different because HDFS user to group mapping can be different from that in Alluxio. Assert.assertNotEquals(defaultOwner, testOwner); Assert.assertNotEquals(defaultGroup, testGroup); // Expect a IOException for not able to setOwner for UFS with invalid owner name. sTFS.setOwner(fileA, testOwner, null); fs = sTFS.getFileStatus(fileA); Assert.assertEquals(testOwner, fs.getOwner()); Assert.assertEquals(defaultGroup, fs.getGroup()); UfsStatus ufsStatus = sUfs.getFileStatus(PathUtils.concatPath(sUfsRoot, fileA)); Assert.assertEquals(testOwner, ufsStatus.getOwner()); Assert.assertEquals(defaultGroup, ufsStatus.getGroup()); }
From source file:alluxio.client.hadoop.FileSystemAclIntegrationTest.java
License:Apache License
/** * Test for {@link FileSystem#setOwner(Path, String, String)} with HDFS UFS. It will test only * changing the group of file using TFS and propagate the change to UFS. *///from w w w . j a v a 2 s . c o m @Test public void changeNonexistentGroupForHdfs() throws Exception { // Skip non-HDFS UFSs. Assume.assumeTrue(UnderFileSystemUtils.isHdfs(sUfs)); Path fileB = new Path("/chownfileB-hdfs"); final String testOwner = "test-user1"; final String testGroup = "test-group1"; create(sTFS, fileB); FileStatus fs = sTFS.getFileStatus(fileB); String defaultOwner = fs.getOwner(); String defaultGroup = fs.getGroup(); Assert.assertEquals(defaultOwner, sUfs.getFileStatus(PathUtils.concatPath(sUfsRoot, fileB)).getOwner()); // Group can different because HDFS user to group mapping can be different from that in Alluxio. Assert.assertNotEquals(defaultOwner, testOwner); Assert.assertNotEquals(defaultGroup, testGroup); sTFS.setOwner(fileB, null, testGroup); fs = sTFS.getFileStatus(fileB); Assert.assertEquals(defaultOwner, fs.getOwner()); Assert.assertEquals(testGroup, fs.getGroup()); UfsStatus ufsStatus = sUfs.getFileStatus(PathUtils.concatPath(sUfsRoot, fileB)); Assert.assertEquals(defaultOwner, ufsStatus.getOwner()); Assert.assertEquals(testGroup, ufsStatus.getGroup()); }