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());
}
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());
}
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;
}
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());
}
}
}
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;
}
Aggregations