public Builder newBuilderForType() { return newBuilder(); } public static Builder newBuilder() {
private void writeFile(FileSystem fs) throws IOException, AlluxioException { for (int i = 0; i < mNumFiles; i++) { ByteBuffer buf = ByteBuffer.allocate(80); buf.order(ByteOrder.nativeOrder()); for (int k = 0; k < mNumFiles; k++) { buf.putInt(k); } buf.flip(); AlluxioURI filePath = new AlluxioURI(mFileFolder + "/part-" + i); LOG.debug("Writing data to {}", filePath); OutputStream os = fs.createFile(filePath, CreateFilePOptions.newBuilder().setRecursive(true).build()); os.write(buf.array()); os.close(); } }
/** * Creates a file at the given path. * * @param fs a filesystem client * @param path the file path */ public static void createFile(FileSystem fs, AlluxioURI path) throws Exception { try (FileOutStream out = fs.createFile(path, CreateFilePOptions.newBuilder() .setBlockSizeBytes(Constants.KB).setRecursive(true).build())) { out.write("test".getBytes()); } }
@Override public void apply(FileSystem fs) throws Exception { Utils.createFile(fs, PATH); Utils.createFile(fs, NESTED); Utils.createFile(fs, MODE, CreateFilePOptions.newBuilder().setBlockSizeBytes(Constants.KB) .setRecursive(true).setMode(TEST_MODE.toProto()).build()); Utils.createFile(fs, THROUGH, CreateFilePOptions.newBuilder().setBlockSizeBytes(Constants.KB) .setRecursive(true).setWriteType(WritePType.THROUGH).build()); Utils.createFile(fs, TTL, CreateFilePOptions.newBuilder().setBlockSizeBytes(Constants.KB).setRecursive(true) .setCommonOptions(FileSystemMasterCommonPOptions.newBuilder().setTtl(TEST_TTL) .setTtlAction(alluxio.grpc.TtlAction.FREE)) .build()); }
/** * Tests that the worker writes with the specified write type. */ @Test @Ignore // TODO(ggezer) Fix. public void writeTypeTest() throws Exception { runTask(TEST_SOURCE, TEST_SOURCE, TEST_DESTINATION, WriteType.CACHE_THROUGH); verify(mMockFileSystem).createFile(eq(new AlluxioURI(TEST_DESTINATION)), Matchers .eq(CreateFilePOptions.newBuilder().setWriteType(WritePType.CACHE_THROUGH)).build()); runTask(TEST_SOURCE, TEST_SOURCE, TEST_DESTINATION, WriteType.MUST_CACHE); verify(mMockFileSystem).createFile(eq(new AlluxioURI(TEST_DESTINATION)), Matchers .eq(CreateFilePOptions.newBuilder().setWriteType(WritePType.MUST_CACHE)).build()); }
/** * @param filePath the path for the files * @param readType the {@link ReadPType} * @param writeType the {@link WritePType} * @param fsContext the {@link FileSystemContext } to use for client operations */ public BasicOperations(AlluxioURI filePath, ReadType readType, WriteType writeType, FileSystemContext fsContext) { mFilePath = filePath; mReadOptions = OpenFilePOptions.newBuilder().setReadType(readType.toProto()).build(); mWriteOptions = CreateFilePOptions.newBuilder().setWriteType(writeType.toProto()) .setRecursive(true).build(); mFsContext = fsContext; }
/** * 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); }
private FileOutStream createFile(FileSystem fileSystem, AlluxioURI filePath, boolean deleteIfExists) throws IOException, AlluxioException { CreateFilePOptions options = CreateFilePOptions.newBuilder().setWriteType(mWriteType.toProto()) .setRecursive(true).build(); if (!fileSystem.exists(filePath)) { // file doesn't exist yet, so create it return fileSystem.createFile(filePath, options); } else if (deleteIfExists) { // file exists, so delete it and recreate fileSystem.delete(filePath); return fileSystem.createFile(filePath, options); } // file exists and deleteIfExists is false throw new FileAlreadyExistsException("File exists and deleteIfExists is false"); }
/** * Tests that an exception is thrown when trying to create a file with invalid block size. */ @Test public void createFileWithInvalidBlockSize() throws Exception { mThrown.expect(BlockInfoException.class); mThrown.expectMessage("Invalid block size 0"); CreateFileContext context = CreateFileContext.defaults(CreateFilePOptions.newBuilder().setBlockSizeBytes(0)); createPath(mTree, TEST_URI, context); }
public static Inode createFileWithIdAndTtl(long id, long ttl) { return Inode.wrap(MutableInodeFile.create(id, 0, "ignored", 0, CreateFileContext.defaults(CreateFilePOptions.newBuilder() .setCommonOptions(FileSystemMasterCommonPOptions.newBuilder().setTtl(ttl))))); }
/** * Tests that an exception is thrown when trying to create a file with a negative block size. */ @Test public void createFileWithNegativeBlockSize() throws Exception { mThrown.expect(BlockInfoException.class); mThrown.expectMessage("Invalid block size -1"); CreateFileContext context = CreateFileContext.defaults(CreateFilePOptions.newBuilder().setBlockSizeBytes(-1)); createPath(mTree, TEST_URI, context); }
public static Inode createDirectoryWithIdAndTtl(long id, long ttl) { return Inode.wrap(MutableInodeFile.create(id, 0, "ignored", 0, CreateFileContext.defaults(CreateFilePOptions.newBuilder() .setCommonOptions(FileSystemMasterCommonPOptions.newBuilder().setTtl(ttl))))); } }
/** * Creates a simple file with {@code len} bytes. * * @param fs a {@link FileSystem} handler * @param fileName the name of the file to be created * @param writeType {@link WritePType} used to create the file * @param len file size * @param blockCapacityByte block size of the file */ public static void createByteFile(FileSystem fs, String fileName, WritePType writeType, int len, long blockCapacityByte) { CreateFilePOptions options = CreateFilePOptions.newBuilder().setWriteType(writeType) .setBlockSizeBytes(blockCapacityByte).setRecursive(true).build(); createByteFile(fs, new AlluxioURI(fileName), options, len); }
/** * @param id block container id of this inode * @return the inode file representation */ protected MutableInodeFile createInodeFile(long id) { return MutableInodeFile.create(id, 1, "testFile" + id, 0, CreateFileContext .defaults(CreateFilePOptions.newBuilder().setBlockSizeBytes(Constants.KB) .setMode(TEST_FILE_MODE.toProto())) .setOwner(TEST_OWNER).setGroup(TEST_GROUP)); } }
/** * Sets up the dependencies before a test runs. */ @Before public void before() throws Exception { GroupMappingServiceTestUtils.resetCache(); MetricsSystem.clearAllMetrics(); // This makes sure that the mount point of the UFS corresponding to the Alluxio root ("/") // doesn't exist by default (helps loadRootTest). mUnderFS = ServerConfiguration.get(PropertyKey.MASTER_MOUNT_TABLE_ROOT_UFS); mNestedFileContext = CreateFileContext.defaults( CreateFilePOptions.newBuilder().setBlockSizeBytes(Constants.KB).setRecursive(true)); mJournalFolder = mTestFolder.newFolder().getAbsolutePath(); startServices(); }
@Test public void renameToNonExistentParent() throws Exception { CreateFileContext context = CreateFileContext.defaults( CreateFilePOptions.newBuilder().setBlockSizeBytes(Constants.KB).setRecursive(true)); mFileSystemMaster.createFile(NESTED_URI, context); try { mFileSystemMaster.rename(NESTED_URI, new AlluxioURI("/testDNE/b"), RenameContext.defaults()); fail("Rename to a non-existent parent path should not succeed."); } catch (FileDoesNotExistException e) { // Expected case. } }
/** * Tests that an exception is thrown when trying to create a file in a non-existing directory * without setting the {@code recursive} flag. */ @Test public void renameUnderNonexistingDir() throws Exception { mThrown.expect(FileDoesNotExistException.class); mThrown.expectMessage(ExceptionMessage.PATH_DOES_NOT_EXIST.getMessage("/nested/test")); CreateFileContext context = CreateFileContext .defaults(CreateFilePOptions.newBuilder().setBlockSizeBytes(Constants.KB)); mFileSystemMaster.createFile(TEST_URI, context); // nested dir mFileSystemMaster.rename(TEST_URI, NESTED_FILE_URI, RenameContext.defaults()); }
private AlluxioURI createTestFile() throws Exception { AlluxioURI path = new AlluxioURI("/" + CommonUtils.randomAlphaNumString(10)); String owner = SecurityUtils.getOwnerFromGrpcClient(ServerConfiguration.global()); String group = SecurityUtils.getGroupFromGrpcClient(ServerConfiguration.global()); mFileSystemMaster.createFile(path, CreateFileContext .defaults( CreateFilePOptions.newBuilder().setMode(Mode.createFullAccess().toProto())) .setOwner(owner).setGroup(group)); mFileSystemMaster.completeFile(path, CompleteFileContext.defaults()); return path; }
private void verifyCreateFile(TestUser user, String path, boolean recursive) throws Exception { try (Closeable r = new AuthenticatedUserRule(user.getUser(), ServerConfiguration.global()).toResource()) { CreateFileContext context = CreateFileContext .defaults( CreateFilePOptions.newBuilder().setRecursive(recursive)) .setOwner(SecurityUtils.getOwnerFromGrpcClient(ServerConfiguration.global())) .setGroup(SecurityUtils.getGroupFromGrpcClient(ServerConfiguration.global())) .setPersisted(true); long fileId = mFileSystemMaster.createFile(new AlluxioURI(path), context); FileInfo fileInfo = mFileSystemMaster.getFileInfo(fileId); String[] pathComponents = path.split("/"); assertEquals(pathComponents[pathComponents.length - 1], fileInfo.getName()); assertEquals(user.getUser(), fileInfo.getOwner()); } }
/** * Tests that an exception is thrown when trying to get information about a file after it * has been deleted because of a TTL of 0. */ @Test public void setTtlForFileWithNoTtl() throws Exception { CreateFileContext context = CreateFileContext.defaults( CreateFilePOptions.newBuilder().setBlockSizeBytes(Constants.KB).setRecursive(true)); long fileId = mFileSystemMaster.createFile(NESTED_FILE_URI, context); HeartbeatScheduler.execute(HeartbeatContext.MASTER_TTL_CHECK); // Since no TTL is set, the file should not be deleted. assertEquals(fileId, mFileSystemMaster.getFileInfo(NESTED_FILE_URI, GET_STATUS_CONTEXT).getFileId()); mFileSystemMaster.setAttribute(NESTED_FILE_URI, SetAttributeContext.defaults(SetAttributePOptions.newBuilder().setTtl(0))); HeartbeatScheduler.execute(HeartbeatContext.MASTER_TTL_CHECK); // TTL is set to 0, the file should have been deleted during last TTL check. mThrown.expect(FileDoesNotExistException.class); mFileSystemMaster.getFileInfo(fileId); }