/** * Creates a new dir. * * @param path the path on the FS of the new dir * @param mode Dir creation flags (IGNORED) * @return 0 on success, a negative value on error */ @Override public int mkdir(String path, @mode_t long mode) { final AlluxioURI turi = mPathResolverCache.getUnchecked(path); LOG.trace("mkdir({}) [Alluxio: {}]", path, turi); try { mFileSystem.createDirectory(turi); } catch (Throwable t) { LOG.error("Failed to create directory {}", path, t); return AlluxioFuseUtils.getErrorCode(t); } return 0; }
@Override public void apply(FileSystem fs) throws Exception { fs.createDirectory(DIR_SET); fs.setAcl(DIR_SET, SetAclAction.MODIFY, Arrays.asList(AclEntry.fromCliString(ACL_STRING))); fs.createDirectory(DIR_ADD_REMOVE); fs.setAcl(DIR_ADD_REMOVE, SetAclAction.MODIFY, Arrays.asList(AclEntry.fromCliString(ACL_STRING))); fs.setAcl(DIR_ADD_REMOVE, SetAclAction.REMOVE, Arrays.asList(AclEntry.fromCliString(ACL_STRING))); }
@Override public int run(CommandLine cl) throws AlluxioException, IOException { String[] args = cl.getArgs(); for (String path : args) { AlluxioURI inputPath = new AlluxioURI(path); CreateDirectoryPOptions options = CreateDirectoryPOptions.newBuilder().setRecursive(true).build(); mFileSystem.createDirectory(inputPath, options); System.out.println("Successfully created directory " + inputPath); } return 0; }
/** * @param path the path of the directory to move; it must be a subpath of source * @param source the base source path being moved * @param destination the destination path */ private void moveDirectory(String path, String source, String destination) throws Exception { String newDir = computeTargetPath(path, source, destination); mFileSystem.createDirectory(new AlluxioURI(newDir), CreateDirectoryPOptions.getDefaultInstance()); }
private void useUriWithAuthority(String authority) throws Exception { mFileSystem.createDirectory(new AlluxioURI(String.format("alluxio://%s/dir", authority))); }
/** * Creates a directory in the Alluxio filesystem space. It will not throw any exception if the * destination directory already exists. * * @param dstPath the {@link AlluxioURI} of the destination directory which will be created */ private void createDstDir(AlluxioURI dstPath) throws AlluxioException, IOException { try { mFileSystem.createDirectory(dstPath); } catch (FileAlreadyExistsException e) { // it's fine if the directory already exists } URIStatus dstStatus = mFileSystem.getStatus(dstPath); if (!dstStatus.isFolder()) { throw new InvalidPathException(ExceptionMessage.DESTINATION_CANNOT_BE_FILE.getMessage()); } }
@Override public void apply(FileSystem fs) throws Exception { fs.createDirectory(DIR); Utils.createFile(fs, INNER_FILE); fs.setAttribute(INNER_FILE, SetAttributePOptions.newBuilder().setPersisted(true).build()); }
mFileSystem.createDirectory(dstPath); System.out.println("Created directory: " + dstPath);
fileSystem.createDirectory(mntPath); System.out.println("done");
@Override public void apply(FileSystem fs) throws Exception { fs.createDirectory(DIR); fs.createDirectory(NESTED_DIR); fs.createDirectory(NESTED_NESTED_DIR); fs.createDirectory(RECURSIVE, CreateDirectoryPOptions.newBuilder().setRecursive(true).build()); fs.createDirectory(RECURSIVE, CreateDirectoryPOptions.newBuilder().setAllowExists(true).build()); fs.createDirectory(MODE_DIR, CreateDirectoryPOptions.newBuilder().setMode(TEST_MODE.toProto()) .setRecursive(true).build()); // Set TTL via common options instead (should have the same effect). fs.createDirectory(COMMON_TTL_DIR, CreateDirectoryPOptions.newBuilder().setRecursive(true).setCommonOptions( FileSystemMasterCommonPOptions.newBuilder().setTtl(TTL).setTtlAction(TtlAction.DELETE)) .build()); fs.createDirectory(TTL_DIR, CreateDirectoryPOptions.newBuilder().setCommonOptions( FileSystemMasterCommonPOptions.newBuilder().setTtl(TTL).setTtlAction(TtlAction.DELETE)) .setRecursive(true).build()); fs.createDirectory(THROUGH_DIR, CreateDirectoryPOptions.newBuilder() .setWriteType(WritePType.THROUGH).setRecursive(true).build()); fs.createDirectory(ALL_OPTS_DIR, CreateDirectoryPOptions.newBuilder().setRecursive(true) .setMode(TEST_MODE.toProto()).setAllowExists(true).setWriteType(WritePType.THROUGH) .setCommonOptions( FileSystemMasterCommonPOptions.newBuilder().setTtl(TTL).setTtlAction(TtlAction.DELETE)) .build()); }
} else { try { mFileSystem.createDirectory(dstPath); } catch (Exception e) { pool.fail(srcPath, dstPath, e);
@Test public void moveEmptyDirectory() throws Exception { createDirectory("/src"); createDirectory("/dst"); setPathToNotExist("/dst/src"); assignMoves("/src", "/dst/src"); verify(mMockFileSystem).createDirectory(eq(new AlluxioURI("/dst/src")), any(CreateDirectoryPOptions.class)); }
/** * Tests for the {@link BaseFileSystem#createDirectory(AlluxioURI, CreateDirectoryPOptions)} * method. */ @Test public void createDirectory() throws Exception { AlluxioURI dir = new AlluxioURI("/dir"); CreateDirectoryPOptions createDirectoryOptions = CreateDirectoryPOptions.getDefaultInstance(); doNothing().when(mFileSystemMasterClient).createDirectory(dir, createDirectoryOptions); mFileSystem.createDirectory(dir, createDirectoryOptions); verify(mFileSystemMasterClient).createDirectory(dir, createDirectoryOptions); verifyFilesystemContextAcquiredAndReleased(); }
/** * Attempts to create a folder with the specified path. Parent directories will be created. * * @param path path to create * @param permission permissions to grant the created folder * @return true if the indicated folder is created successfully or already exists */ @Override public boolean mkdirs(Path path, FsPermission permission) throws IOException { LOG.debug("mkdirs({}, {})", path, permission); if (mStatistics != null) { mStatistics.incrementWriteOps(1); } AlluxioURI uri = new AlluxioURI(HadoopUtils.getPathWithoutScheme(path)); CreateDirectoryPOptions options = CreateDirectoryPOptions.newBuilder().setRecursive(true) .setAllowExists(true).setMode(new Mode(permission.toShort()).toProto()).build(); try { mFileSystem.createDirectory(uri, options); return true; } catch (AlluxioException e) { throw new IOException(e); } }
@Override public void apply(FileSystem fs) throws Exception { Utils.createFile(fs, SRC); fs.rename(SRC, DST); fs.createDirectory(new AlluxioURI("/renameDir/a/b"), CreateDirectoryPOptions.newBuilder().setRecursive(true).build()); fs.rename(new AlluxioURI("/renameDir/a"), new AlluxioURI("/renameDir/c")); }
/** * Ensures an exception is thrown when an invalid scheme is passed. */ @Test public void uriCheckBadScheme() throws Exception { mConf.set(PropertyKey.MASTER_HOSTNAME, "localhost"); mConf.set(PropertyKey.MASTER_RPC_PORT, "19998"); AlluxioURI uri = new AlluxioURI("hdfs://localhost:19998/root"); try { mFileSystem.createDirectory(uri); fail("Should have failed on bad host and port"); } catch (IllegalArgumentException e) { assertThat(e.getMessage(), containsString("Scheme hdfs:// in AlluxioURI is invalid")); } }
mFileSystem.createDirectory(dstPath); System.out.println("Created directory: " + dstPath); mFileSystem.createDirectory(dstPath); System.out.println("Created directory: " + dstPath);
@Test public void moveNestedEmptyDirectory() throws Exception { createDirectory("/src"); FileInfo nested = createDirectory("/src/nested"); setChildren("/src", nested); createDirectory("/dst"); setPathToNotExist("/dst/src"); assignMoves("/src", "/dst/src"); verify(mMockFileSystem).createDirectory(eq(new AlluxioURI("/dst/src/nested")), Matchers.eq(CreateDirectoryPOptions.getDefaultInstance())); }
/** * Ensures that an exception is propagated correctly when creating a directory. */ @Test public void createDirectoryException() throws Exception { AlluxioURI dir = new AlluxioURI("/dir"); CreateDirectoryPOptions createDirectoryOptions = CreateDirectoryPOptions.getDefaultInstance(); doThrow(EXCEPTION).when(mFileSystemMasterClient) .createDirectory(dir, createDirectoryOptions); try { mFileSystem.createDirectory(dir, createDirectoryOptions); fail(SHOULD_HAVE_PROPAGATED_MESSAGE); } catch (Exception e) { assertSame(EXCEPTION, e); } verifyFilesystemContextAcquiredAndReleased(); }
/** * Ensures there is no warnings or errors when an {@link AlluxioURI} without a scheme and * authority is passed. */ @Test public void uriCheckNoSchemeAuthority() throws Exception { mConf.set(PropertyKey.MASTER_HOSTNAME, "localhost"); mConf.set(PropertyKey.MASTER_RPC_PORT, "19998"); AlluxioURI uri = new AlluxioURI("/root"); mFileSystem.createDirectory(uri); assertFalse(loggedAuthorityWarning()); assertFalse(loggedSchemeWarning()); }