Search in sources :

Example 6 with FileSystem

use of alluxio.client.file.FileSystem in project alluxio by Alluxio.

the class UnderStorageSystemInterfaceIntegrationTest method loadMetadata.

/**
   * Tests load metadata on list.
   */
@Test
public void loadMetadata() throws Exception {
    String dirName = "loadMetaDataRoot";
    String rootDir = PathUtils.concatPath(mUnderfsAddress, dirName);
    mUfs.mkdirs(rootDir);
    String rootFile1 = PathUtils.concatPath(rootDir, "file1");
    createEmptyFile(rootFile1);
    String rootFile2 = PathUtils.concatPath(rootDir, "file2");
    createEmptyFile(rootFile2);
    AlluxioURI rootAlluxioURI = new AlluxioURI("/" + dirName);
    FileSystem client = mLocalAlluxioClusterResource.get().getClient();
    client.listStatus(rootAlluxioURI, ListStatusOptions.defaults().setLoadMetadataType(LoadMetadataType.Always));
    try {
        client.createDirectory(rootAlluxioURI, CreateDirectoryOptions.defaults());
        Assert.fail("create is expected to fail with FileAlreadyExistsException");
    } catch (FileAlreadyExistsException e) {
        Assert.assertEquals(ExceptionMessage.FILE_ALREADY_EXISTS.getMessage(rootAlluxioURI), e.getMessage());
    }
    AlluxioURI file1URI = rootAlluxioURI.join("file1");
    try {
        client.createFile(file1URI, CreateFileOptions.defaults()).close();
        Assert.fail("create is expected to fail with FileAlreadyExistsException");
    } catch (FileAlreadyExistsException e) {
        Assert.assertEquals(ExceptionMessage.FILE_ALREADY_EXISTS.getMessage(file1URI), e.getMessage());
    }
    AlluxioURI file2URI = rootAlluxioURI.join("file2");
    try {
        client.createFile(file2URI, CreateFileOptions.defaults()).close();
        Assert.fail("create is expected to fail with FileAlreadyExistsException");
    } catch (FileAlreadyExistsException e) {
        Assert.assertEquals(ExceptionMessage.FILE_ALREADY_EXISTS.getMessage(file2URI), e.getMessage());
    }
}
Also used : FileAlreadyExistsException(alluxio.exception.FileAlreadyExistsException) FileSystem(alluxio.client.file.FileSystem) AlluxioURI(alluxio.AlluxioURI) Test(org.junit.Test)

Example 7 with FileSystem

use of alluxio.client.file.FileSystem in project alluxio by Alluxio.

the class TestRunner method main.

/**
   * Console program that validates the configuration.
   *
   * @param args there are no arguments needed
   * @throws Exception if error occurs during tests
   */
public static void main(String[] args) throws Exception {
    TestRunner runner = new TestRunner();
    JCommander jCommander = new JCommander(runner, args);
    jCommander.setProgramName("TestRunner");
    if (runner.mHelp) {
        jCommander.usage();
        return;
    }
    AlluxioURI testDir = new AlluxioURI(TEST_PATH);
    FileSystem fs = FileSystem.Factory.get();
    if (fs.exists(testDir)) {
        fs.delete(testDir, DeleteOptions.defaults().setRecursive(true));
    }
    int ret = runner.runTests();
    System.exit(ret);
}
Also used : JCommander(com.beust.jcommander.JCommander) FileSystem(alluxio.client.file.FileSystem) AlluxioURI(alluxio.AlluxioURI)

Example 8 with FileSystem

use of alluxio.client.file.FileSystem in project alluxio by Alluxio.

the class BasicNonByteBufferOperations method call.

@Override
public Boolean call() throws Exception {
    FileSystem alluxioClient = FileSystem.Factory.get();
    write(alluxioClient);
    return read(alluxioClient);
}
Also used : FileSystem(alluxio.client.file.FileSystem)

Example 9 with FileSystem

use of alluxio.client.file.FileSystem in project alluxio by Alluxio.

the class BasicOperations method call.

@Override
public Boolean call() throws Exception {
    FileSystem fs = FileSystem.Factory.get();
    writeFile(fs);
    return readFile(fs);
}
Also used : FileSystem(alluxio.client.file.FileSystem)

Example 10 with FileSystem

use of alluxio.client.file.FileSystem in project alluxio by Alluxio.

the class MultiMount method main.

/**
   * Entry point for the {@link MultiMount} program.
   *
   * @param args command-line arguments
   */
public static void main(String[] args) {
    if (args.length != 1) {
        System.err.println("Usage: ./bin/alluxio runClass alluxio.examples.MultiMount <HDFS_URL>");
        System.exit(-1);
    }
    AlluxioURI mntPath = new AlluxioURI("/mnt");
    AlluxioURI s3Mount = new AlluxioURI("/mnt/s3");
    AlluxioURI inputPath = new AlluxioURI("/mnt/s3/hello.txt");
    AlluxioURI s3Path = new AlluxioURI("s3n://alluxio-demo/");
    AlluxioURI hdfsMount = new AlluxioURI("/mnt/hdfs");
    AlluxioURI outputPath = new AlluxioURI("/mnt/hdfs/hello.txt");
    AlluxioURI hdfsPath = new AlluxioURI(args[0]);
    FileSystem fileSystem = FileSystem.Factory.get();
    try {
        // Make sure mount directory exists.
        if (!fileSystem.exists(mntPath)) {
            System.out.print("creating " + mntPath + " ... ");
            fileSystem.createDirectory(mntPath);
            System.out.println("done");
        }
        // Make sure the S3 mount point does not exist.
        if (fileSystem.exists(s3Mount)) {
            System.out.print("unmounting " + s3Mount + " ... ");
            fileSystem.unmount(s3Mount);
            System.out.println("done");
        }
        // Make sure the HDFS mount point does not exist.
        if (fileSystem.exists(hdfsMount)) {
            System.out.print("unmounting " + hdfsMount + " ... ");
            fileSystem.unmount(hdfsMount);
            System.out.println("done");
        }
        // Mount S3.
        System.out.print("mounting " + s3Path + " to " + s3Mount + " ... ");
        fileSystem.mount(s3Mount, s3Path);
        System.out.println("done");
        // Mount HDFS.
        System.out.print("mounting " + hdfsPath + " to " + hdfsMount + " ... ");
        fileSystem.mount(hdfsMount, hdfsPath);
        System.out.println("done");
        // Make sure output file does not exist.
        if (fileSystem.exists(outputPath)) {
            System.out.print("deleting " + outputPath + " ... ");
            fileSystem.delete(outputPath);
            System.out.println("done");
        }
        // Open the input stream.
        System.out.print("opening " + inputPath + " ... ");
        FileInStream is = fileSystem.openFile(inputPath);
        System.out.println("done");
        // Open the output stream, setting the write type to make sure result is persisted.
        System.out.print("opening " + outputPath + " ... ");
        CreateFileOptions options = CreateFileOptions.defaults().setWriteType(WriteType.CACHE_THROUGH);
        FileOutStream os = fileSystem.createFile(outputPath, options);
        System.out.println("done");
        // Copy the data
        System.out.print("transferring data from " + inputPath + " to " + outputPath + " ... ");
        IOUtils.copy(is, os);
        System.out.println("done");
        // Close the input stream.
        System.out.print("closing " + inputPath + " ... ");
        is.close();
        System.out.println("done");
        // Close the output stream.
        System.out.print("closing " + outputPath + " ... ");
        os.close();
        System.out.println("done");
    } catch (Exception e) {
        System.out.println("fail");
        e.printStackTrace();
    } finally {
        // Make sure the S3 mount point is removed.
        try {
            if (fileSystem.exists(s3Mount)) {
                System.out.print("unmounting " + s3Mount + " ... ");
                fileSystem.unmount(s3Mount);
                System.out.println("done");
            }
        } catch (Exception e) {
            System.out.println("fail");
            e.printStackTrace();
        }
        // Make sure the HDFS mount point is removed.
        try {
            if (fileSystem.exists(hdfsMount)) {
                System.out.print("unmounting " + hdfsMount + " ... ");
                fileSystem.unmount(hdfsMount);
                System.out.println("done");
            }
        } catch (Exception e) {
            System.out.println("fail");
            e.printStackTrace();
        }
    }
}
Also used : CreateFileOptions(alluxio.client.file.options.CreateFileOptions) FileSystem(alluxio.client.file.FileSystem) FileInStream(alluxio.client.file.FileInStream) FileOutStream(alluxio.client.file.FileOutStream) AlluxioURI(alluxio.AlluxioURI)

Aggregations

FileSystem (alluxio.client.file.FileSystem)23 AlluxioURI (alluxio.AlluxioURI)16 Test (org.junit.Test)10 URIStatus (alluxio.client.file.URIStatus)7 FileInStream (alluxio.client.file.FileInStream)6 FileOutStream (alluxio.client.file.FileOutStream)4 OpenFileOptions (alluxio.client.file.options.OpenFileOptions)2 LineageFileSystem (alluxio.client.lineage.LineageFileSystem)2 CommandLineJob (alluxio.job.CommandLineJob)2 JobConf (alluxio.job.JobConf)2 ArrayList (java.util.ArrayList)2 CreateFileOptions (alluxio.client.file.options.CreateFileOptions)1 RoundRobinPolicy (alluxio.client.file.policy.RoundRobinPolicy)1 AlluxioLineage (alluxio.client.lineage.AlluxioLineage)1 LineageMasterClient (alluxio.client.lineage.LineageMasterClient)1 DeleteLineageOptions (alluxio.client.lineage.options.DeleteLineageOptions)1 FileAlreadyExistsException (alluxio.exception.FileAlreadyExistsException)1 FileSystemMaster (alluxio.master.file.FileSystemMaster)1 UnderFileSystem (alluxio.underfs.UnderFileSystem)1 FileBlockInfo (alluxio.wire.FileBlockInfo)1