use of alluxio.client.file.FileSystem in project alluxio by Alluxio.
the class FileDataManager method prepareUfsFilePath.
/**
* Prepares the destination file path of the given file id. Also creates the parent folder if it
* does not exist.
*
* @param fileId the file id
* @return the path for persistence
* @throws AlluxioException if an unexpected Alluxio exception is thrown
* @throws IOException if the folder creation fails
*/
private String prepareUfsFilePath(long fileId) throws AlluxioException, IOException {
FileInfo fileInfo = mBlockWorker.getFileInfo(fileId);
AlluxioURI alluxioPath = new AlluxioURI(fileInfo.getPath());
FileSystem fs = FileSystem.Factory.get();
URIStatus status = fs.getStatus(alluxioPath);
String ufsPath = status.getUfsPath();
UnderFileSystem ufs = UnderFileSystem.Factory.get(ufsPath);
UnderFileSystemUtils.prepareFilePath(alluxioPath, ufsPath, fs, ufs);
return ufsPath;
}
use of alluxio.client.file.FileSystem in project alluxio by Alluxio.
the class LineageMasterIntegrationTest method lineageRecovery.
/**
* Tests that a lineage job is executed when the output file for the lineage is reported as lost.
*
* The checkpoint interval is set high so that we are guaranteed to call reportLostFile
* before persistence is complete.
*/
@Test(timeout = 100000)
@LocalAlluxioClusterResource.Config(confParams = { PropertyKey.Name.MASTER_LINEAGE_CHECKPOINT_INTERVAL_MS, "100000" })
public void lineageRecovery() throws Exception {
final File logFile = mFolder.newFile();
// Delete the log file so that when it starts to exist we know that it was created by the
// lineage recompute job
logFile.delete();
FileSystem fs = FileSystem.Factory.get();
try (LineageMasterClient lineageClient = getLineageMasterClient()) {
lineageClient.createLineage(ImmutableList.<String>of(), ImmutableList.of("/testFile"), new CommandLineJob("echo hello world", new JobConf(logFile.getAbsolutePath())));
FileOutStream out = fs.createFile(new AlluxioURI("/testFile"));
out.write("foo".getBytes());
out.close();
lineageClient.reportLostFile("/testFile");
}
// Wait for the log file to be created by the recompute job
CommonUtils.waitFor("the log file to be written", new Function<Void, Boolean>() {
@Override
public Boolean apply(Void input) {
if (!logFile.exists()) {
return false;
}
try (BufferedReader reader = new BufferedReader(new FileReader(logFile))) {
String line = reader.readLine();
return line != null && line.equals("hello world");
} catch (Exception e) {
throw Throwables.propagate(e);
}
}
}, WaitForOptions.defaults().setTimeout(100 * Constants.SECOND_MS));
}
use of alluxio.client.file.FileSystem in project alluxio by Alluxio.
the class ClusterInitializationTest method recoverClusterSuccess.
/**
* When a user starts a cluster with journal logs, which are generated by previous running
* cluster owned by the same user, it should succeed.
*/
@Test
@LocalAlluxioClusterResource.Config(confParams = { PropertyKey.Name.SECURITY_LOGIN_USERNAME, SUPER_USER })
public void recoverClusterSuccess() throws Exception {
FileSystem fs = mLocalAlluxioClusterResource.get().getClient();
fs.createFile(new AlluxioURI("/testFile")).close();
mLocalAlluxioClusterResource.get().stopFS();
LoginUserTestUtils.resetLoginUser(SUPER_USER);
// user alluxio can recover master from journal
FileSystemMaster fileSystemMaster = MasterTestUtils.createLeaderFileSystemMasterFromJournal();
AuthenticatedClientUser.set(SUPER_USER);
Assert.assertEquals(SUPER_USER, fileSystemMaster.getFileInfo(new AlluxioURI("/testFile")).getOwner());
}
use of alluxio.client.file.FileSystem in project alluxio by Alluxio.
the class ClusterInitializationTest method recoverClusterFail.
/**
* When a user starts a cluster with journal logs, which are generated by previous running
* cluster owned by a different user, it should fail and throw an exception.
*/
@Test
@LocalAlluxioClusterResource.Config(confParams = { PropertyKey.Name.SECURITY_LOGIN_USERNAME, SUPER_USER })
public void recoverClusterFail() throws Exception {
mThrown.expect(RuntimeException.class);
mThrown.expectMessage(ExceptionMessage.PERMISSION_DENIED.getMessage("Unauthorized user on root"));
FileSystem fs = mLocalAlluxioClusterResource.get().getClient();
fs.createFile(new AlluxioURI("/testFile")).close();
mLocalAlluxioClusterResource.get().stopFS();
LoginUserTestUtils.resetLoginUser(USER);
// user jack cannot recover master from journal, in which the root is owned by alluxio.
MasterTestUtils.createLeaderFileSystemMasterFromJournal();
}
use of alluxio.client.file.FileSystem in project alluxio by Alluxio.
the class AlluxioFrameworkIntegrationTest method basicAlluxioTests.
private static void basicAlluxioTests() throws Exception {
LOG.info("Running tests");
FileSystem fs = FileSystem.Factory.get();
int listSize = fs.listStatus(new AlluxioURI("/")).size();
if (listSize != 1) {
throw new RuntimeException("Expected 1 path to exist at the root, but found " + listSize);
}
FileOutStream outStream = fs.createFile(new AlluxioURI("/test"));
outStream.write("abc".getBytes());
outStream.close();
FileInStream inStream = fs.openFile(new AlluxioURI("/test"));
String result = IOUtils.toString(inStream);
if (!result.equals("abc")) {
throw new RuntimeException("Expected abc but got " + result);
}
LOG.info("Tests passed");
}
Aggregations