Search in sources :

Example 66 with FileSystem

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;
}
Also used : FileInfo(alluxio.wire.FileInfo) FileSystem(alluxio.client.file.FileSystem) UnderFileSystem(alluxio.underfs.UnderFileSystem) URIStatus(alluxio.client.file.URIStatus) UnderFileSystem(alluxio.underfs.UnderFileSystem) AlluxioURI(alluxio.AlluxioURI)

Example 67 with FileSystem

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));
}
Also used : FileOutStream(alluxio.client.file.FileOutStream) LineageMasterClient(alluxio.client.lineage.LineageMasterClient) CommandLineJob(alluxio.job.CommandLineJob) FileSystem(alluxio.client.file.FileSystem) LineageFileSystem(alluxio.client.lineage.LineageFileSystem) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) File(java.io.File) JobConf(alluxio.job.JobConf) AlluxioURI(alluxio.AlluxioURI) Test(org.junit.Test)

Example 68 with FileSystem

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());
}
Also used : FileSystem(alluxio.client.file.FileSystem) FileSystemMaster(alluxio.master.file.FileSystemMaster) AlluxioURI(alluxio.AlluxioURI) Test(org.junit.Test)

Example 69 with FileSystem

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();
}
Also used : FileSystem(alluxio.client.file.FileSystem) AlluxioURI(alluxio.AlluxioURI) Test(org.junit.Test)

Example 70 with FileSystem

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");
}
Also used : FileSystem(alluxio.client.file.FileSystem) FileOutStream(alluxio.client.file.FileOutStream) FileInStream(alluxio.client.file.FileInStream) AlluxioURI(alluxio.AlluxioURI)

Aggregations

FileSystem (alluxio.client.file.FileSystem)122 AlluxioURI (alluxio.AlluxioURI)90 Test (org.junit.Test)75 URIStatus (alluxio.client.file.URIStatus)42 BaseIntegrationTest (alluxio.testutils.BaseIntegrationTest)22 FileInStream (alluxio.client.file.FileInStream)13 IOException (java.io.IOException)12 AbstractFileSystemShellTest (alluxio.client.cli.fs.AbstractFileSystemShellTest)11 ArrayList (java.util.ArrayList)11 FileOutStream (alluxio.client.file.FileOutStream)10 AlluxioException (alluxio.exception.AlluxioException)9 File (java.io.File)9 Path (javax.ws.rs.Path)9 FileDoesNotExistException (alluxio.exception.FileDoesNotExistException)8 HashMap (java.util.HashMap)8 FileSystemContext (alluxio.client.file.FileSystemContext)7 FileAlreadyExistsException (alluxio.exception.FileAlreadyExistsException)6 CreateFilePOptions (alluxio.grpc.CreateFilePOptions)6 TestUserState (alluxio.security.user.TestUserState)6 InstancedConfiguration (alluxio.conf.InstancedConfiguration)5