Search in sources :

Example 16 with UfsStatus

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

the class FileSystemAclIntegrationTest method ossGetPermission.

@Test
public void ossGetPermission() throws Exception {
    Assume.assumeTrue(UnderFileSystemUtils.isOss(sUfs));
    Path fileA = new Path("/objectfileA");
    create(sTFS, fileA);
    Assert.assertTrue(sUfs.isFile(PathUtils.concatPath(sUfsRoot, fileA)));
    // Verify the owner, group and permission of OSS UFS is not supported and thus returns default
    // values.
    UfsStatus ufsStatus = sUfs.getFileStatus(PathUtils.concatPath(sUfsRoot, fileA));
    Assert.assertNotEquals("", ufsStatus.getOwner());
    Assert.assertNotEquals("", ufsStatus.getGroup());
    Assert.assertEquals(Constants.DEFAULT_FILE_SYSTEM_MODE, ufsStatus.getMode());
}
Also used : Path(org.apache.hadoop.fs.Path) UfsStatus(alluxio.underfs.UfsStatus) BaseIntegrationTest(alluxio.testutils.BaseIntegrationTest) Test(org.junit.Test)

Example 17 with UfsStatus

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

the class FileSystemAclIntegrationTest method changeNonexistentOwnerForHdfs.

/**
 * 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.
 */
@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());
}
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 18 with UfsStatus

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

the class FileSystemAclIntegrationTest method gcsGetPermission.

@Test
public void gcsGetPermission() throws Exception {
    Assume.assumeTrue(UnderFileSystemUtils.isGcs(sUfs));
    ServerConfiguration.unset(PropertyKey.UNDERFS_GCS_OWNER_ID_TO_USERNAME_MAPPING);
    Path fileA = new Path("/gcsGetPermissionFile");
    create(sTFS, fileA);
    Assert.assertTrue(sUfs.isFile(PathUtils.concatPath(sUfsRoot, fileA)));
    // Without providing "alluxio.underfs.gcs.owner.id.to.username.mapping", the default
    // display name of the GCS owner account is empty. The owner will be the GCS account id, which
    // is not empty.
    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)

Example 19 with UfsStatus

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

the class WebUnderFileSystem method listStatus.

@Override
public UfsStatus[] listStatus(String path) throws IOException {
    Document doc;
    try {
        doc = Jsoup.connect(path).get();
    } catch (Exception e) {
        LOG.error("Failed to get content from URL {}", path, e);
        return null;
    }
    Elements bodyElements = doc.select("body");
    if (bodyElements.size() == 0) {
        return null;
    }
    Element bodyElement = bodyElements.first();
    Elements bodyChildNodes = bodyElement.children();
    Elements listElements = null;
    for (Element bodyChildNode : bodyChildNodes) {
        listElements = bodyChildNode.select("a");
        if (listElements.size() > 0) {
            break;
        }
    }
    if (listElements == null || listElements.size() == 0) {
        return null;
    }
    List<String> parentNames = mUfsConf.getList(PropertyKey.UNDERFS_WEB_PARENT_NAMES, ",");
    int flagIndex = -1;
    for (int i = 0; flagIndex == -1 && i < listElements.size(); i++) {
        for (final String flag : parentNames) {
            if (listElements.get(i).text().equalsIgnoreCase(flag)) {
                flagIndex = i;
                break;
            }
        }
    }
    List<UfsStatus> statusList = new ArrayList<>();
    for (int i = (flagIndex == -1 ? 0 : flagIndex); i < listElements.size(); i++) {
        Element listElement = listElements.get(i);
        String href = listElement.attr("href");
        String fileName = listElement.text();
        if (!new WebUnderFileSystemFactory().supportsPath(href)) {
            href = path + "/" + href;
        }
        try {
            UfsStatus ufsStatus = getStatus(href, fileName);
            statusList.add(ufsStatus);
        } catch (IOException e) {
            LOG.error("Failed to get status for url: {}", href, e);
        }
    }
    UfsStatus[] rtn = new UfsStatus[statusList.size()];
    return statusList.toArray(rtn);
}
Also used : UfsStatus(alluxio.underfs.UfsStatus) Element(org.jsoup.nodes.Element) ArrayList(java.util.ArrayList) IOException(java.io.IOException) Document(org.jsoup.nodes.Document) Elements(org.jsoup.select.Elements) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

Example 20 with UfsStatus

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

the class FileSystemAclIntegrationTest method s3GetPermission.

@Test
public void s3GetPermission() throws Exception {
    Assume.assumeTrue(UnderFileSystemUtils.isS3(sUfs));
    ServerConfiguration.unset(PropertyKey.UNDERFS_S3_OWNER_ID_TO_USERNAME_MAPPING);
    Path fileA = new Path("/s3GetPermissionFile");
    create(sTFS, fileA);
    Assert.assertTrue(sUfs.isFile(PathUtils.concatPath(sUfsRoot, fileA)));
    // Without providing "alluxio.underfs.s3.canonical.owner.id.to.username.mapping", the default
    // display name of the S3 owner account is NOT empty.
    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