Search in sources :

Example 41 with FileSystem

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

the class MiniBenchmark method writeFile.

/**
 * Writes a file.
 *
 * @param count the count to determine the filename
 * @throws Exception if it fails to write
 */
private static void writeFile(CyclicBarrier barrier, AtomicLong runtime, int count, AlluxioConfiguration alluxioConf) throws Exception {
    FileSystem fileSystem = FileSystem.Factory.create(alluxioConf);
    byte[] buffer = new byte[(int) Math.min(sFileSize, 4 * Constants.MB)];
    Arrays.fill(buffer, (byte) 'a');
    AlluxioURI path = filename(count);
    if (fileSystem.exists(path)) {
        fileSystem.delete(path);
    }
    barrier.await();
    long startTime = System.nanoTime();
    long bytesWritten = 0;
    try (FileOutStream outStream = fileSystem.createFile(path)) {
        while (bytesWritten < sFileSize) {
            outStream.write(buffer, 0, (int) Math.min(buffer.length, sFileSize - bytesWritten));
            bytesWritten += buffer.length;
        }
    }
    runtime.addAndGet(System.nanoTime() - startTime);
}
Also used : FileSystem(alluxio.client.file.FileSystem) FileOutStream(alluxio.client.file.FileOutStream) AlluxioURI(alluxio.AlluxioURI)

Example 42 with FileSystem

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

the class ManagerProcessContextTest method testApplyExistingMount.

@Test
public void testApplyExistingMount() throws Exception {
    FileSystem mockFs = mock(FileSystem.class);
    Map<String, MountPointInfo> mpi = new HashMap<>();
    mpi.put("/", new MountPointInfo().setUfsUri("hdfs://localhost:9000/").setReadOnly(true).setUfsType("hdfs").setUfsCapacityBytes(9001));
    doReturn(mockFs).when(mContext).getFileSystem();
    doReturn(mpi).when(mockFs).getMountTable();
    ApplyMountPointRequest vr = ApplyMountPointRequest.newBuilder().setPayload(ApplyMountPointRequest.Payload.newBuilder().setNew(mContext.getMountPointList().getMountPointList().get(0)).setBefore(mContext.getMountPointList().getMountPointList().get(0))).build();
    mContext.applyMount(vr);
}
Also used : MountPointInfo(alluxio.wire.MountPointInfo) HashMap(java.util.HashMap) FileSystem(alluxio.client.file.FileSystem) ApplyMountPointRequest(alluxio.hub.proto.ApplyMountPointRequest) BaseHubTest(alluxio.hub.test.BaseHubTest) Test(org.junit.Test)

Example 43 with FileSystem

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

the class ManagerProcessContextTest method testApplyRootMountToOtherPath.

@Test
public void testApplyRootMountToOtherPath() throws Exception {
    FileSystem mockFs = mock(FileSystem.class);
    Map<String, MountPointInfo> mpi = new HashMap<>();
    mpi.put("/", new MountPointInfo().setUfsUri("hdfs://localhost:9000/").setReadOnly(true).setUfsType("hdfs").setUfsCapacityBytes(9001));
    doReturn(mockFs).when(mContext).getFileSystem();
    doReturn(mpi).when(mockFs).getMountTable();
    ApplyMountPointRequest vr = ApplyMountPointRequest.newBuilder().setPayload(ApplyMountPointRequest.Payload.newBuilder().setNew(mContext.getMountPointList().getMountPointList().get(0).toBuilder().setAlluxioPath("/mnt/new")).setBefore(mContext.getMountPointList().getMountPointList().get(0))).build();
    ApplyMountPointResponse.Payload resp = mContext.applyMount(vr);
    assertFalse(resp.getSuccess());
    assertTrue(resp.getErrorCount() > 0);
}
Also used : ApplyMountPointResponse(alluxio.hub.proto.ApplyMountPointResponse) MountPointInfo(alluxio.wire.MountPointInfo) HashMap(java.util.HashMap) FileSystem(alluxio.client.file.FileSystem) ApplyMountPointRequest(alluxio.hub.proto.ApplyMountPointRequest) BaseHubTest(alluxio.hub.test.BaseHubTest) Test(org.junit.Test)

Example 44 with FileSystem

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

the class ManagerProcessContextTest method testListMountPoints.

@Test
public void testListMountPoints() throws Exception {
    FileSystem mockFs = mock(FileSystem.class);
    Map<String, MountPointInfo> mpi = new HashMap<>();
    mpi.put("/", new MountPointInfo().setUfsUri("hdfs://localhost:9000/").setReadOnly(true).setUfsType("hdfs").setUfsCapacityBytes(9001));
    doReturn(mockFs).when(mContext).getFileSystem();
    doReturn(mpi).when(mockFs).getMountTable();
    ListMountPointResponse.Payload mpl = mContext.getMountPointList();
    assertEquals(1, mpl.getMountPointList().size());
    alluxio.hub.proto.MountPointInfo i = mpl.getMountPointList().get(0);
    assertEquals("hdfs://localhost:9000/", i.getUfsUri());
    assertTrue(i.getReadOnly());
    assertEquals("/", i.getAlluxioPath());
    assertEquals(0, i.getPropertiesCount());
}
Also used : MountPointInfo(alluxio.wire.MountPointInfo) HashMap(java.util.HashMap) FileSystem(alluxio.client.file.FileSystem) ListMountPointResponse(alluxio.hub.proto.ListMountPointResponse) BaseHubTest(alluxio.hub.test.BaseHubTest) Test(org.junit.Test)

Example 45 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);
    }
    AlluxioConfiguration alluxioConf = new InstancedConfiguration(ConfigurationUtils.defaults());
    AlluxioURI mntPath = new AlluxioURI("/mnt");
    AlluxioURI s3Mount = new AlluxioURI("/mnt/s3");
    AlluxioURI inputPath = new AlluxioURI("/mnt/s3/hello.txt");
    AlluxioURI s3Path = new AlluxioURI("s3a://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.create(alluxioConf);
    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 + " ... ");
        CreateFilePOptions options = CreateFilePOptions.newBuilder().setWriteType(WritePType.CACHE_THROUGH).setRecursive(true).build();
        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 : InstancedConfiguration(alluxio.conf.InstancedConfiguration) FileSystem(alluxio.client.file.FileSystem) FileInStream(alluxio.client.file.FileInStream) FileOutStream(alluxio.client.file.FileOutStream) CreateFilePOptions(alluxio.grpc.CreateFilePOptions) AlluxioConfiguration(alluxio.conf.AlluxioConfiguration) 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