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;
}
});
}
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);
}
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);
}
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();
}
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);
}
}
Aggregations