Search in sources :

Example 21 with UfsStatus

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

the class FileSystemAclIntegrationTest method changeNonexistentGroupForHdfs.

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

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

the class FileSystemAclIntegrationTest method objectStoreSetOwner.

@Test
public void objectStoreSetOwner() throws Exception {
    Assume.assumeTrue(sUfs.isObjectStorage());
    Path fileA = new Path("/objectfileA");
    final String newOwner = "new-user1";
    final String newGroup = "new-group1";
    create(sTFS, fileA);
    // Set owner to Alluxio files that are persisted in UFS will NOT propagate to underlying object.
    sTFS.setOwner(fileA, newOwner, newGroup);
    UfsStatus ufsStatus = sUfs.getFileStatus(PathUtils.concatPath(sUfsRoot, fileA));
    Assert.assertNotEquals("", ufsStatus.getOwner());
    Assert.assertNotEquals("", ufsStatus.getGroup());
}
Also used : Path(org.apache.hadoop.fs.Path) UfsStatus(alluxio.underfs.UfsStatus) BaseIntegrationTest(alluxio.testutils.BaseIntegrationTest) Test(org.junit.Test)

Example 23 with UfsStatus

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

the class UfsJournal method isFormatted.

@Override
public boolean isFormatted() throws IOException {
    UfsStatus[] files;
    try (UnderFileSystem ufs = UnderFileSystem.Factory.create(mLocation.toString(), UnderFileSystemConfiguration.defaults(ServerConfiguration.global()))) {
        files = ufs.listStatus(mLocation.toString());
    }
    if (files == null) {
        return false;
    }
    // Search for the format file.
    String formatFilePrefix = ServerConfiguration.getString(PropertyKey.MASTER_FORMAT_FILE_PREFIX);
    for (UfsStatus file : files) {
        if (file.getName().startsWith(formatFilePrefix)) {
            return true;
        }
    }
    return false;
}
Also used : UfsStatus(alluxio.underfs.UfsStatus) UnderFileSystem(alluxio.underfs.UnderFileSystem)

Example 24 with UfsStatus

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

the class UfsMutableJournal method format.

@Override
public void format() throws IOException {
    LOG.info("Formatting {}", mLocation);
    try (UnderFileSystem ufs = UnderFileSystem.Factory.create(mLocation.toString(), UnderFileSystemConfiguration.defaults(ServerConfiguration.global()))) {
        if (ufs.isDirectory(mLocation.toString())) {
            for (UfsStatus p : ufs.listStatus(mLocation.toString())) {
                URI childPath;
                try {
                    childPath = URIUtils.appendPath(mLocation, p.getName());
                } catch (URISyntaxException e) {
                    throw new RuntimeException(e.getMessage());
                }
                boolean failedToDelete;
                if (p.isDirectory()) {
                    failedToDelete = !ufs.deleteDirectory(childPath.toString(), DeleteOptions.defaults().setRecursive(true));
                } else {
                    failedToDelete = !ufs.deleteFile(childPath.toString());
                }
                if (failedToDelete) {
                    throw new IOException(String.format("Failed to delete %s", childPath));
                }
            }
        } else if (!ufs.mkdirs(mLocation.toString())) {
            throw new IOException(String.format("Failed to create %s", mLocation));
        }
        // Create a breadcrumb that indicates that the journal folder has been formatted.
        try {
            UnderFileSystemUtils.touch(ufs, URIUtils.appendPath(mLocation, ServerConfiguration.getString(PropertyKey.MASTER_FORMAT_FILE_PREFIX) + System.currentTimeMillis()).toString());
        } catch (URISyntaxException e) {
            throw new RuntimeException(e.getMessage());
        }
    }
}
Also used : UfsStatus(alluxio.underfs.UfsStatus) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) UnderFileSystem(alluxio.underfs.UnderFileSystem) URI(java.net.URI)

Example 25 with UfsStatus

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

the class UfsJournalSnapshot method getCurrentLog.

/**
 * Gets the current log (the incomplete log) that is being written to.
 *
 * @param journal the journal
 * @return the current log
 */
@VisibleForTesting
public static UfsJournalFile getCurrentLog(UfsJournal journal) throws IOException {
    List<UfsJournalFile> logs = new ArrayList<>();
    UfsStatus[] statuses = journal.getUfs().listStatus(journal.getLogDir().toString());
    if (statuses != null) {
        for (UfsStatus status : statuses) {
            UfsJournalFile file = UfsJournalFile.decodeLogFile(journal, status.getName());
            if (file != null) {
                logs.add(file);
            }
        }
        if (!logs.isEmpty()) {
            UfsJournalFile file = Collections.max(logs);
            if (file.isIncompleteLog()) {
                return file;
            }
        }
    }
    return null;
}
Also used : UfsStatus(alluxio.underfs.UfsStatus) ArrayList(java.util.ArrayList) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

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