/** * 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); } }
.setRecursive(context.getOptions().getCreateAncestors()).setAllowExists(false) .setCommonOptions(FileSystemMasterCommonPOptions.newBuilder() .setTtl(context.getOptions().getCommonOptions().getTtl())
@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()); }
public Builder mergeFrom(alluxio.grpc.CreateDirectoryPOptions other) { if (other == alluxio.grpc.CreateDirectoryPOptions.getDefaultInstance()) return this; if (other.hasRecursive()) { setRecursive(other.getRecursive()); } if (other.hasAllowExists()) { setAllowExists(other.getAllowExists()); } if (other.hasMode()) { mergeMode(other.getMode()); } if (other.hasWriteType()) { setWriteType(other.getWriteType()); } if (other.hasCommonOptions()) { mergeCommonOptions(other.getCommonOptions()); } this.mergeUnknownFields(other.unknownFields); onChanged(); return this; }
/** * Tests that an exception is thrown when trying to create an already existing directory with the * {@code allowExists} flag set to {@code false}. */ @Test public void createExistingDirectory() throws Exception { // create directory createPath(mTree, TEST_URI, sDirectoryContext); // create again with allowExists true createPath(mTree, TEST_URI, CreateDirectoryContext .defaults(CreateDirectoryPOptions.newBuilder().setAllowExists(true))); // create again with allowExists false mThrown.expect(FileAlreadyExistsException.class); mThrown.expectMessage(ExceptionMessage.FILE_ALREADY_EXISTS.getMessage(TEST_URI)); createPath(mTree, TEST_URI, CreateDirectoryContext .defaults(CreateDirectoryPOptions.newBuilder().setAllowExists(false))); }
/** * @return Master side defaults for {@link CreateDirectoryPOptions} */ public static CreateDirectoryPOptions createDirectoryDefaults() { return CreateDirectoryPOptions.newBuilder() .setCommonOptions(commonDefaults()) .setMode(ModeUtils.applyDirectoryUMask(Mode.defaults(), ServerConfiguration.get(PropertyKey.SECURITY_AUTHORIZATION_PERMISSION_UMASK)).toProto()) .setRecursive(false) .setWriteType(ServerConfiguration .getEnum(PropertyKey.USER_FILE_WRITE_TYPE_DEFAULT, WriteType.class).toProto()) .setAllowExists(false).build(); }