Search in sources :

Example 1 with CreateFilePOptions

use of alluxio.grpc.CreateFilePOptions in project alluxio by Alluxio.

the class BaseFileSystem method createFile.

@Override
public FileOutStream createFile(AlluxioURI path, CreateFilePOptions options) throws FileAlreadyExistsException, InvalidPathException, IOException, AlluxioException {
    checkUri(path);
    return rpc(client -> {
        CreateFilePOptions mergedOptions = FileSystemOptions.createFileDefaults(mFsContext.getPathConf(path)).toBuilder().mergeFrom(options).build();
        URIStatus status = client.createFile(path, mergedOptions);
        LOG.debug("Created file {}, options: {}", path.getPath(), mergedOptions);
        OutStreamOptions outStreamOptions = new OutStreamOptions(mergedOptions, mFsContext.getClientContext(), mFsContext.getPathConf(path));
        outStreamOptions.setUfsPath(status.getUfsPath());
        outStreamOptions.setMountId(status.getMountId());
        outStreamOptions.setAcl(status.getAcl());
        try {
            return new AlluxioFileOutStream(path, outStreamOptions, mFsContext);
        } catch (Exception e) {
            delete(path);
            throw e;
        }
    });
}
Also used : OutStreamOptions(alluxio.client.file.options.OutStreamOptions) CreateFilePOptions(alluxio.grpc.CreateFilePOptions) FailedPreconditionException(alluxio.exception.status.FailedPreconditionException) InvalidPathException(alluxio.exception.InvalidPathException) InvalidArgumentException(alluxio.exception.status.InvalidArgumentException) UnauthenticatedException(alluxio.exception.status.UnauthenticatedException) AlluxioException(alluxio.exception.AlluxioException) FileDoesNotExistException(alluxio.exception.FileDoesNotExistException) UnavailableException(alluxio.exception.status.UnavailableException) AlreadyExistsException(alluxio.exception.status.AlreadyExistsException) DirectoryNotEmptyException(alluxio.exception.DirectoryNotEmptyException) AlluxioStatusException(alluxio.exception.status.AlluxioStatusException) FileAlreadyExistsException(alluxio.exception.FileAlreadyExistsException) IOException(java.io.IOException) NotFoundException(alluxio.exception.status.NotFoundException) FileIncompleteException(alluxio.exception.FileIncompleteException) OpenDirectoryException(alluxio.exception.OpenDirectoryException)

Example 2 with CreateFilePOptions

use of alluxio.grpc.CreateFilePOptions in project alluxio by Alluxio.

the class FileSystemTestUtils method createByteFile.

/**
 * Creates a simple file with {@code len} bytes.
 *
 * @param fs a {@link FileSystem} handler
 * @param fileURI URI of the file
 * @param writeType {@link WritePType} used to create the file
 * @param len file size
 */
public static void createByteFile(FileSystem fs, AlluxioURI fileURI, WritePType writeType, int len) {
    CreateFilePOptions options = CreateFilePOptions.newBuilder().setRecursive(true).setWriteType(writeType).build();
    createByteFile(fs, fileURI, options, len);
}
Also used : CreateFilePOptions(alluxio.grpc.CreateFilePOptions)

Example 3 with CreateFilePOptions

use of alluxio.grpc.CreateFilePOptions in project alluxio by Alluxio.

the class AlluxioJniFuseFileSystemTest method write.

@Test
public void write() throws Exception {
    FileOutStream fos = mock(FileOutStream.class);
    AlluxioURI anyURI = any();
    CreateFilePOptions options = any();
    when(mFileSystem.createFile(anyURI, options)).thenReturn(fos);
    // open a file
    mFileInfo.flags.set(O_WRONLY.intValue());
    mFuseFs.create("/foo/bar", 0, mFileInfo);
    // prepare something to write into it
    ByteBuffer ptr = ByteBuffer.allocateDirect(4);
    byte[] expected = { 42, -128, 1, 3 };
    ptr.put(expected, 0, 4);
    ptr.flip();
    mFuseFs.write("/foo/bar", ptr, 4, 0, mFileInfo);
    verify(fos).write(expected);
    // the second write is no-op because the writes must be sequential and overwriting is supported
    mFuseFs.write("/foo/bar", ptr, 4, 0, mFileInfo);
    verify(fos, times(1)).write(expected);
}
Also used : FileOutStream(alluxio.client.file.FileOutStream) CreateFilePOptions(alluxio.grpc.CreateFilePOptions) ByteBuffer(java.nio.ByteBuffer) AlluxioURI(alluxio.AlluxioURI) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 4 with CreateFilePOptions

use of alluxio.grpc.CreateFilePOptions in project alluxio by Alluxio.

the class AlluxioFuseFileSystemTest method flush.

@Test
public void flush() throws Exception {
    FileOutStream fos = mock(FileOutStream.class);
    AlluxioURI anyURI = any();
    CreateFilePOptions options = any();
    when(mFileSystem.createFile(anyURI, options)).thenReturn(fos);
    // open a file
    mFileInfo.flags.set(O_WRONLY.intValue());
    mFuseFs.create("/foo/bar", 0, mFileInfo);
    // then call flush into it
    mFuseFs.flush("/foo/bar", mFileInfo);
    verify(fos).flush();
}
Also used : FileOutStream(alluxio.client.file.FileOutStream) CreateFilePOptions(alluxio.grpc.CreateFilePOptions) AlluxioURI(alluxio.AlluxioURI) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 5 with CreateFilePOptions

use of alluxio.grpc.CreateFilePOptions in project alluxio by Alluxio.

the class StressJobServiceBench method createFiles.

private void createFiles(FileSystem fs, int numFiles, String dirPath, int fileSize) throws IOException, AlluxioException {
    CreateFilePOptions options = CreateFilePOptions.newBuilder().setRecursive(true).setWriteType(WritePType.THROUGH).build();
    for (int fileId = 0; fileId < numFiles; fileId++) {
        String filePath = String.format("%s/%d", dirPath, fileId);
        createByteFile(fs, new AlluxioURI(filePath), options, fileSize);
    }
}
Also used : CreateFilePOptions(alluxio.grpc.CreateFilePOptions) AlluxioURI(alluxio.AlluxioURI)

Aggregations

CreateFilePOptions (alluxio.grpc.CreateFilePOptions)68 AlluxioURI (alluxio.AlluxioURI)61 Test (org.junit.Test)49 BaseIntegrationTest (alluxio.testutils.BaseIntegrationTest)36 FileInStream (alluxio.client.file.FileInStream)27 FileOutStream (alluxio.client.file.FileOutStream)16 URIStatus (alluxio.client.file.URIStatus)9 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)5 FileSystem (alluxio.client.file.FileSystem)4 AlluxioException (alluxio.exception.AlluxioException)4 FileAlreadyExistsException (alluxio.exception.FileAlreadyExistsException)4 CreateDirectoryPOptions (alluxio.grpc.CreateDirectoryPOptions)4 IOException (java.io.IOException)4 DirectoryNotEmptyException (alluxio.exception.DirectoryNotEmptyException)3 FileDoesNotExistException (alluxio.exception.FileDoesNotExistException)3 ArrayList (java.util.ArrayList)3 ConfigurationRule (alluxio.ConfigurationRule)2 BlockMaster (alluxio.master.block.BlockMaster)2 Mode (alluxio.security.authorization.Mode)2 UnderFileSystem (alluxio.underfs.UnderFileSystem)2