List of usage examples for org.apache.hadoop.fs Path Path
public Path(URI aUri)
From source file:alluxio.hadoop.AbstractFileSystem.java
License:Apache License
@Override public FileStatus[] listStatus(Path path) throws IOException { LOG.info("listStatus({})", path); if (mStatistics != null) { mStatistics.incrementReadOps(1); }// w w w. j a va2s . c om AlluxioURI uri = new AlluxioURI(HadoopUtils.getPathWithoutScheme(path)); List<URIStatus> statuses; try { statuses = sFileSystem.listStatus(uri); } catch (FileDoesNotExistException e) { throw new FileNotFoundException(HadoopUtils.getPathWithoutScheme(path)); } catch (AlluxioException e) { throw new IOException(e); } FileStatus[] ret = new FileStatus[statuses.size()]; for (int k = 0; k < statuses.size(); k++) { URIStatus status = statuses.get(k); // TODO(hy): Replicate 3 with the number of disk replications. ret[k] = new FileStatus(status.getLength(), status.isFolder(), 3, status.getBlockSizeBytes(), status.getCreationTimeMs(), status.getCreationTimeMs(), null, null, null, new Path(mAlluxioHeader + status.getPath())); } return ret; }
From source file:alluxio.hadoop.FileSystemAclIntegrationTest.java
License:Apache License
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 w w w . j a va2s . c o m*/ } }
From source file:alluxio.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. *//* w ww.j a va2s .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.exists(PathUtils.concatPath(sUfsRoot, fileA))); // Default permission should be 0644 Assert.assertEquals((short) 0644, fs.getPermission().toShort()); if (CommonUtils.isUfsObjectStorage(sUfsRoot)) { // For object storage ufs, setMode is not supported. mThrown.expect(IOException.class); mThrown.expectMessage("setOwner/setMode is not supported to object storage UFS via Alluxio."); sTFS.setPermission(fileA, FsPermission.createImmutable((short) 0755)); return; } sTFS.setPermission(fileA, FsPermission.createImmutable((short) 0755)); Assert.assertEquals((short) 0755, sTFS.getFileStatus(fileA).getPermission().toShort()); }
From source file:alluxio.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. *///w w w. j av a 2s . co m @Test public void changeNonexistentOwnerForLocal() throws Exception { if (!(sUfs instanceof LocalUnderFileSystem)) { // Skip non-local UFSs. return; } 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.getOwner(PathUtils.concatPath(sUfsRoot, fileA))); Assert.assertEquals(defaultGroup, sUfs.getGroup(PathUtils.concatPath(sUfsRoot, fileA))); 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.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 . java 2s . c o m*/ @Test public void changeNonexistentGroupForLocal() throws Exception { if (!(sUfs instanceof LocalUnderFileSystem)) { // Skip non-local UFSs. return; } 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.getOwner(PathUtils.concatPath(sUfsRoot, fileB))); Assert.assertEquals(defaultGroup, sUfs.getGroup(PathUtils.concatPath(sUfsRoot, fileB))); 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.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 2s. co m @Test public void changeNonexistentOwnerAndGroupForLocal() throws Exception { if (!(sUfs instanceof LocalUnderFileSystem)) { // Skip non-local UFSs. return; } 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.getOwner(PathUtils.concatPath(sUfsRoot, fileC))); Assert.assertEquals(defaultGroup, sUfs.getGroup(PathUtils.concatPath(sUfsRoot, fileC))); Assert.assertNotEquals(defaultOwner, nonexistentOwner); Assert.assertNotEquals(defaultGroup, nonexistentGroup); mThrown.expect(IOException.class); mThrown.expectMessage("Could not setOwner for UFS file"); sTFS.setOwner(fileC, nonexistentOwner, nonexistentGroup); }
From source file:alluxio.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 . com*/ @Test public void changeNonexistentOwnerForHdfs() throws Exception { if (!(sUfs instanceof HdfsUnderFileSystem)) { // Skip non-HDFS UFSs. return; } 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.getOwner(PathUtils.concatPath(sUfsRoot, fileA))); // 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()); Assert.assertEquals(testOwner, sUfs.getOwner(PathUtils.concatPath(sUfsRoot, fileA))); Assert.assertEquals(defaultGroup, sUfs.getGroup(PathUtils.concatPath(sUfsRoot, fileA))); }
From source file:alluxio.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 2s. co m*/ @Test public void changeNonexistentGroupForHdfs() throws Exception { if (!(sUfs instanceof HdfsUnderFileSystem)) { // Skip non-HDFS UFSs. return; } 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.getOwner(PathUtils.concatPath(sUfsRoot, fileB))); // 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()); Assert.assertEquals(defaultOwner, sUfs.getOwner(PathUtils.concatPath(sUfsRoot, fileB))); Assert.assertEquals(testGroup, sUfs.getGroup(PathUtils.concatPath(sUfsRoot, fileB))); }
From source file:alluxio.hadoop.FileSystemAclIntegrationTest.java
License:Apache License
/** * Test for {@link FileSystem#setOwner(Path, String, String)} with HDFS UFS. It will test * changing both owner and group of file using TFS and propagate the change to UFS. *//* w w w . j a v a2s. com*/ @Test public void changeNonexistentOwnerAndGroupForHdfs() throws Exception { if (!(sUfs instanceof HdfsUnderFileSystem)) { // Skip non-HDFS UFSs. return; } Path fileC = new Path("/chownfileC-hdfs"); final String testOwner = "test-user1"; final String testGroup = "test-group1"; create(sTFS, fileC); FileStatus fs = sTFS.getFileStatus(fileC); String defaultOwner = fs.getOwner(); String defaultGroup = fs.getGroup(); Assert.assertEquals(defaultOwner, sUfs.getOwner(PathUtils.concatPath(sUfsRoot, fileC))); // 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(fileC, testOwner, testGroup); fs = sTFS.getFileStatus(fileC); Assert.assertEquals(testOwner, fs.getOwner()); Assert.assertEquals(testGroup, fs.getGroup()); Assert.assertEquals(testOwner, sUfs.getOwner(PathUtils.concatPath(sUfsRoot, fileC))); Assert.assertEquals(testGroup, sUfs.getGroup(PathUtils.concatPath(sUfsRoot, fileC))); }
From source file:alluxio.hadoop.FileSystemAclIntegrationTest.java
License:Apache License
/** * Tests the directory permission propagation to UFS. */// w w w. j a v a 2 s . c o m @Test public void directoryPermissionForUfs() throws IOException { if (!(sUfs instanceof LocalUnderFileSystem) && !(sUfs instanceof HdfsUnderFileSystem)) { // Skip non-local and non-HDFS UFSs. return; } Path dir = new Path("/root/dir/"); sTFS.mkdirs(dir); FileStatus fs = sTFS.getFileStatus(dir); String defaultOwner = fs.getOwner(); Short dirMode = fs.getPermission().toShort(); FileStatus parentFs = sTFS.getFileStatus(dir.getParent()); Short parentMode = parentFs.getPermission().toShort(); Assert.assertEquals(defaultOwner, sUfs.getOwner(PathUtils.concatPath(sUfsRoot, dir))); Assert.assertEquals((int) dirMode, (int) sUfs.getMode(PathUtils.concatPath(sUfsRoot, dir))); Assert.assertEquals((int) parentMode, (int) sUfs.getMode(PathUtils.concatPath(sUfsRoot, dir.getParent()))); short newMode = (short) 0755; FsPermission newPermission = new FsPermission(newMode); sTFS.setPermission(dir, newPermission); Assert.assertEquals((int) newMode, (int) sUfs.getMode(PathUtils.concatPath(sUfsRoot, dir))); }