/** * Tests getting and setting fields. */ @Test public void fields() { Random random = new Random(); boolean createParent = random.nextBoolean(); String owner = CommonUtils.randomAlphaNumString(10); String group = CommonUtils.randomAlphaNumString(10); Mode mode = new Mode((short) random.nextInt()); MkdirsOptions options = MkdirsOptions.defaults(mConfiguration); options.setCreateParent(createParent); options.setOwner(owner); options.setGroup(group); options.setMode(mode); assertEquals(createParent, options.getCreateParent()); assertEquals(owner, options.getOwner()); assertEquals(group, options.getGroup()); assertEquals(mode, options.getMode()); }
path = stripPath(path); File file = new File(path); if (!options.getCreateParent()) { if (file.mkdir()) { setMode(file.getPath(), options.getMode().toShort()); FileUtils.setLocalDirStickyBit(file.getPath()); try { setOwner(file.getPath(), options.getOwner(), options.getGroup()); } catch (IOException e) { LOG.warn("Failed to update the ufs dir ownership, default values will be used: {}", File dirToMake = dirsToMake.pop(); if (dirToMake.mkdir()) { setMode(dirToMake.getAbsolutePath(), options.getMode().toShort()); FileUtils.setLocalDirStickyBit(file.getPath()); setOwner(dirToMake.getAbsolutePath(), options.getOwner(), options.getGroup()); } catch (IOException e) { LOG.warn("Failed to update the ufs dir ownership, default values will be used: {}",
Path dirToMake = dirsToMake.pop(); if (!FileSystem.mkdirs(hdfs, dirToMake, new FsPermission(options.getMode().toShort()))) { return false; setOwner(dirToMake.toString(), options.getOwner(), options.getGroup()); } catch (IOException e) { LOG.warn("Failed to update the ufs dir ownership, default values will be used. " + e);
/** * Prepares journal writer to upgrade journals from v0 to v1. */ private void prepare() throws IOException { alluxio.master.journalv0.JournalWriter journalWriterV0 = mJournalV0.getWriter(); journalWriterV0.recover(); journalWriterV0.completeLogs(); journalWriterV0.close(); if (!mJournalV1.isFormatted()) { LOG.info("Starting to format journal {}.", mJournalV1.getLocation()); mJournalV1.format(); LOG.info("Finished formatting journal {}.", mJournalV1.getLocation()); } if (!mUfs.exists(mCheckpointsV1.toString())) { mUfs.mkdirs(mCheckpointsV1.toString(), MkdirsOptions.defaults(mAlluxioConf) .setCreateParent(true)); } if (!mUfs.exists(mLogsV1.toString())) { mUfs.mkdirs(mLogsV1.toString(), MkdirsOptions.defaults(mAlluxioConf).setCreateParent(true)); } }
UnderFileSystem ufs = ufsResource.get(); MkdirsOptions mkdirsOptions = MkdirsOptions.defaults(ServerConfiguration.global()).setCreateParent(false) .setOwner(dir.getOwner()).setGroup(dir.getGroup()).setMode(new Mode(dir.getMode())); if (!ufs.mkdirs(ufsUri, mkdirsOptions)) {
@Override public boolean mkdirs(String path) throws IOException { return mkdirs(path, MkdirsOptions.defaults(mUfsConf)); }
return false; if (!options.getCreateParent()) { if (parentExists(path)) {
MkdirsOptions.defaults(ServerConfiguration.global()).setCreateParent(false) .setOwner(curDirStatus.getOwner()) .setGroup(curDirStatus.getGroup()) .setMode(new Mode((short) curDirStatus.getMode())))); curAlluxioPath = curAlluxioPath.getParent(); curUfsPath = curUfsPath.getParent();
private LargeDirectoryConfig prepareLargeDirectoryTest() throws IOException { final String filePrefix = "a_"; final String folderPrefix = "b_"; String topLevelDirectory = PathUtils.concatPath(mUnderfsAddress, "topLevelDir"); final int numFiles = 100; String[] children = new String[numFiles + numFiles]; // Make top level directory mUfs.mkdirs(topLevelDirectory, MkdirsOptions.defaults(mConfiguration).setCreateParent(false)); // Make the children files for (int i = 0; i < numFiles; ++i) { children[i] = PathUtils.concatPath(topLevelDirectory, filePrefix + String.format("%04d", i)); createEmptyFile(children[i]); } // Make the children folders for (int i = 0; i < numFiles; ++i) { children[numFiles + i] = PathUtils.concatPath(topLevelDirectory, folderPrefix + String.format("%04d", i)); mUfs.mkdirs(children[numFiles + i], MkdirsOptions.defaults(mConfiguration) .setCreateParent(false)); } return new LargeDirectoryConfig(topLevelDirectory, children); }
/** * Tests for default {@link MkdirsOptions}. */ @Test public void defaults() throws IOException { MkdirsOptions options = MkdirsOptions.defaults(mConfiguration); // Verify the default createParent is true. assertTrue(options.getCreateParent()); // Verify that the owner and group are not set. assertNull(options.getOwner()); assertNull(options.getGroup()); String umask = mConfiguration.get(PropertyKey.SECURITY_AUTHORIZATION_PERMISSION_UMASK); assertEquals(ModeUtils.applyDirectoryUMask(Mode.defaults(), umask), options.getMode()); }
Path dirToMake = dirsToMake.pop(); if (!FileSystem.mkdirs(mFileSystem, dirToMake, new FsPermission(options.getMode().toShort()))) { return false; setOwner(dirToMake.toString(), options.getOwner(), options.getGroup()); } catch (IOException e) { LOG.warn("Failed to update the ufs dir ownership, default values will be used. " + e);
return false; if (!options.getCreateParent()) { if (parentExists(path)) {
URIStatus curDirStatus = mFileSystem.getStatus(curAlluxioPath); ufsDirsToMakeWithOptions.push(new Pair<>(curUfsPath.toString(), MkdirsOptions.defaults(ServerConfiguration.global()).setCreateParent(false) .setOwner(curDirStatus.getOwner()) .setGroup(curDirStatus.getGroup()) .setMode(new Mode((short) curDirStatus.getMode())))); curAlluxioPath = curAlluxioPath.getParent(); curUfsPath = curUfsPath.getParent(); throw new IOException( "Failed to create " + ufsDirAndPerm.getFirst() + " with permission " + ufsDirAndPerm .getSecond().toString());
@Before public final void before() throws Exception { mUnderfsAddress = PathUtils.concatPath(getUfsBaseDir(), UUID.randomUUID()); mUfs = createUfs(mUnderfsAddress, UnderFileSystemConfiguration.defaults()); mUfs.mkdirs(mUnderfsAddress, MkdirsOptions.defaults(mConfiguration).setCreateParent(true)); }
/** * Tests for building an {@link MkdirsOptions} with a security enabled * configuration. */ @Test public void securityEnabled() throws IOException { InstancedConfiguration conf = new InstancedConfiguration(ConfigurationUtils.defaults()); conf.set(PropertyKey.SECURITY_AUTHENTICATION_TYPE, AuthType.SIMPLE.getAuthName()); conf.set(PropertyKey.SECURITY_LOGIN_USERNAME, "foo"); // Use IdentityUserGroupMapping to map user "foo" to group "foo". conf.set(PropertyKey.SECURITY_GROUP_MAPPING_CLASS, IdentityUserGroupsMapping.class.getName()); MkdirsOptions options = MkdirsOptions.defaults(mConfiguration); // Verify the default createParent is true. assertTrue(options.getCreateParent()); // Verify that the owner and group are not set. assertNull(options.getOwner()); assertNull(options.getGroup()); String umask = mConfiguration.get(PropertyKey.SECURITY_AUTHORIZATION_PERMISSION_UMASK); assertEquals(ModeUtils.applyDirectoryUMask(Mode.defaults(), umask), options.getMode()); }
@Override public boolean mkdirs(String path) throws IOException { return mkdirs(path, MkdirsOptions.defaults()); }
try (CloseableResource<UnderFileSystem> ufsResource = resolution.acquireUfsResource()) { UnderFileSystem ufs = ufsResource.get(); MkdirsOptions mkdirsOptions = MkdirsOptions.defaults().setCreateParent(false) .setOwner(dir.getOwner()).setGroup(dir.getGroup()).setMode(new Mode(dir.getMode())); if (!ufs.mkdirs(ufsUri, mkdirsOptions)) {
if (!ufs.mkdirs(dir, MkdirsOptions.defaults(ServerConfiguration.global()) .setCreateParent(true))) { throw new IOException(String.format("Failed to create directory %s", dir));
String testDirNonEmptyChildDirFile = PathUtils.concatPath(testDirNonEmptyChildDir, "testDirNonEmptyChildDirF"); mUfs.mkdirs(testDirNonEmpty, MkdirsOptions.defaults(mConfiguration).setCreateParent(false)); mUfs.mkdirs(testDirNonEmptyChildDir, MkdirsOptions.defaults(mConfiguration) .setCreateParent(false)); createEmptyFile(testDirNonEmptyChildFile); createEmptyFile(testDirNonEmptyChildDirFile);