Search in sources :

Example 11 with UfsStatus

use of alluxio.underfs.UfsStatus in project alluxio by Alluxio.

the class LocalUnderFileSystemTest method testBrokenSymlinkSkip.

@Test
public void testBrokenSymlinkSkip() throws IOException {
    InstancedConfiguration c = new InstancedConfiguration(sConf.copyProperties());
    c.set(PropertyKey.UNDERFS_LOCAL_SKIP_BROKEN_SYMLINKS, true);
    mLocalUfs = UnderFileSystem.Factory.create(mLocalUfsRoot, UnderFileSystemConfiguration.defaults(c));
    Path linkPath = createNonExistentSymlink();
    assertTrue(Files.exists(linkPath, LinkOption.NOFOLLOW_LINKS));
    assertFalse(Files.exists(linkPath));
    UfsStatus[] statuses = mLocalUfs.listStatus(mLocalUfsRoot);
    assertNotNull(statuses);
    assertEquals(0, statuses.length);
}
Also used : Path(java.nio.file.Path) InstancedConfiguration(alluxio.conf.InstancedConfiguration) UfsStatus(alluxio.underfs.UfsStatus) Test(org.junit.Test)

Example 12 with UfsStatus

use of alluxio.underfs.UfsStatus in project alluxio by Alluxio.

the class LocalUnderFileSystem method listStatus.

@Override
public UfsStatus[] listStatus(String path) throws IOException {
    path = stripPath(path);
    File file = new File(path);
    // By default, exists follows symlinks. If the symlink is invalid .exists() returns false
    File[] files = mSkipBrokenSymlinks ? file.listFiles(File::exists) : file.listFiles();
    if (files != null) {
        UfsStatus[] rtn = new UfsStatus[files.length];
        int i = 0;
        for (File f : files) {
            // TODO(adit): do we need extra call for attributes?
            PosixFileAttributes attr = Files.readAttributes(Paths.get(f.getPath()), PosixFileAttributes.class);
            short mode = FileUtils.translatePosixPermissionToMode(attr.permissions());
            UfsStatus retStatus;
            if (f.isDirectory()) {
                retStatus = new UfsDirectoryStatus(f.getName(), attr.owner().getName(), attr.group().getName(), mode, f.lastModified());
            } else {
                String contentHash = UnderFileSystemUtils.approximateContentHash(f.length(), f.lastModified());
                retStatus = new UfsFileStatus(f.getName(), contentHash, f.length(), f.lastModified(), attr.owner().getName(), attr.group().getName(), mode, mUfsConf.getBytes(PropertyKey.USER_BLOCK_SIZE_BYTES_DEFAULT));
            }
            rtn[i++] = retStatus;
        }
        return rtn;
    } else {
        return null;
    }
}
Also used : UfsFileStatus(alluxio.underfs.UfsFileStatus) UfsStatus(alluxio.underfs.UfsStatus) PosixFileAttributes(java.nio.file.attribute.PosixFileAttributes) File(java.io.File) UfsDirectoryStatus(alluxio.underfs.UfsDirectoryStatus)

Example 13 with UfsStatus

use of alluxio.underfs.UfsStatus in project alluxio by Alluxio.

the class FileSystemAclIntegrationTest method directoryPermissionForUfs.

/**
 * Tests the directory permission propagation to UFS.
 */
@Test
public void directoryPermissionForUfs() throws IOException {
    // Skip non-local and non-HDFS UFSs.
    Assume.assumeTrue(UnderFileSystemUtils.isLocal(sUfs) || UnderFileSystemUtils.isHdfs(sUfs));
    Path dir = new Path("/root/directoryPermissionForUfsDir");
    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();
    UfsStatus ufsStatus = sUfs.getDirectoryStatus(PathUtils.concatPath(sUfsRoot, dir));
    Assert.assertEquals(defaultOwner, ufsStatus.getOwner());
    Assert.assertEquals((int) dirMode, (int) ufsStatus.getMode());
    Assert.assertEquals((int) parentMode, (int) sUfs.getDirectoryStatus(PathUtils.concatPath(sUfsRoot, dir.getParent())).getMode());
    short newMode = (short) 0755;
    FsPermission newPermission = new FsPermission(newMode);
    sTFS.setPermission(dir, newPermission);
    Assert.assertEquals((int) newMode, (int) sUfs.getDirectoryStatus(PathUtils.concatPath(sUfsRoot, dir)).getMode());
}
Also used : Path(org.apache.hadoop.fs.Path) FileStatus(org.apache.hadoop.fs.FileStatus) UfsStatus(alluxio.underfs.UfsStatus) FsPermission(org.apache.hadoop.fs.permission.FsPermission) BaseIntegrationTest(alluxio.testutils.BaseIntegrationTest) Test(org.junit.Test)

Example 14 with UfsStatus

use of alluxio.underfs.UfsStatus in project alluxio by Alluxio.

the class FileSystemAclIntegrationTest method changeNonexistentOwnerAndGroupForHdfs.

/**
 * 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.
 */
@Test
public void changeNonexistentOwnerAndGroupForHdfs() throws Exception {
    // Skip non-HDFS UFSs.
    Assume.assumeTrue(UnderFileSystemUtils.isHdfs(sUfs));
    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.getFileStatus(PathUtils.concatPath(sUfsRoot, fileC)).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(fileC, testOwner, testGroup);
    fs = sTFS.getFileStatus(fileC);
    Assert.assertEquals(testOwner, fs.getOwner());
    Assert.assertEquals(testGroup, fs.getGroup());
    UfsStatus ufsStatus = sUfs.getFileStatus(PathUtils.concatPath(sUfsRoot, fileC));
    Assert.assertEquals(testOwner, ufsStatus.getOwner());
    Assert.assertEquals(testGroup, ufsStatus.getGroup());
}
Also used : Path(org.apache.hadoop.fs.Path) FileStatus(org.apache.hadoop.fs.FileStatus) UfsStatus(alluxio.underfs.UfsStatus) BaseIntegrationTest(alluxio.testutils.BaseIntegrationTest) Test(org.junit.Test)

Example 15 with UfsStatus

use of alluxio.underfs.UfsStatus in project alluxio by Alluxio.

the class FileSystemAclIntegrationTest method swiftGetPermission.

@Test
public void swiftGetPermission() throws Exception {
    Assume.assumeTrue(UnderFileSystemUtils.isSwift(sUfs));
    Path fileA = new Path("/swiftGetPermissionFile");
    create(sTFS, fileA);
    Assert.assertTrue(sUfs.isFile(PathUtils.concatPath(sUfsRoot, fileA)));
    UfsStatus ufsStatus = sUfs.getFileStatus(PathUtils.concatPath(sUfsRoot, fileA));
    Assert.assertNotEquals("", ufsStatus.getOwner());
    Assert.assertNotEquals("", ufsStatus.getGroup());
    Assert.assertEquals((short) 0700, ufsStatus.getMode());
}
Also used : Path(org.apache.hadoop.fs.Path) UfsStatus(alluxio.underfs.UfsStatus) BaseIntegrationTest(alluxio.testutils.BaseIntegrationTest) Test(org.junit.Test)

Aggregations

UfsStatus (alluxio.underfs.UfsStatus)40 UnderFileSystem (alluxio.underfs.UnderFileSystem)12 IOException (java.io.IOException)12 Test (org.junit.Test)11 BaseIntegrationTest (alluxio.testutils.BaseIntegrationTest)10 Path (org.apache.hadoop.fs.Path)9 AlluxioURI (alluxio.AlluxioURI)8 Inode (alluxio.master.file.meta.Inode)7 MountTable (alluxio.master.file.meta.MountTable)7 UfsFileStatus (alluxio.underfs.UfsFileStatus)6 UfsDirectoryStatus (alluxio.underfs.UfsDirectoryStatus)5 ArrayList (java.util.ArrayList)5 FileStatus (org.apache.hadoop.fs.FileStatus)5 BlockInfoException (alluxio.exception.BlockInfoException)4 FileDoesNotExistException (alluxio.exception.FileDoesNotExistException)4 FileNotFoundException (java.io.FileNotFoundException)4 Fingerprint (alluxio.underfs.Fingerprint)3 URI (java.net.URI)3 InvalidPathException (alluxio.exception.InvalidPathException)2 LoadMetadataContext (alluxio.master.file.contexts.LoadMetadataContext)2