public virtual void TestGetAclStatus() { InitCluster(true, false); fs.Mkdirs(Path); ExpectException(); fs.GetAclStatus(Path); }
/// <exception cref="System.IO.IOException"/> private void DoTestDefaultAclNewChildren(bool persistNamespace) { Path dirPath = new Path("/dir"); Path filePath = new Path(dirPath, "file1"); Path subdirPath = new Path(dirPath, "subdir1"); DistributedFileSystem fs = cluster.GetFileSystem(); fs.Mkdirs(dirPath); IList <AclEntry> aclSpec = Lists.NewArrayList(AclTestHelpers.AclEntry(AclEntryScope .Default, AclEntryType.User, "foo", FsAction.All)); fs.SetAcl(dirPath, aclSpec); fs.Create(filePath).Close(); fs.Mkdirs(subdirPath); AclEntry[] fileExpected = new AclEntry[] { AclTestHelpers.AclEntry(AclEntryScope. Access, AclEntryType.User, "foo", FsAction.All), AclTestHelpers.AclEntry(AclEntryScope .Access, AclEntryType.Group, FsAction.ReadExecute) }; AclEntry[] subdirExpected = new AclEntry[] { AclTestHelpers.AclEntry(AclEntryScope .Access, AclEntryType.User, "foo", FsAction.All), AclTestHelpers.AclEntry(AclEntryScope .Access, AclEntryType.Group, FsAction.ReadExecute), AclTestHelpers.AclEntry(AclEntryScope .Default, AclEntryType.User, FsAction.All), AclTestHelpers.AclEntry(AclEntryScope .Default, AclEntryType.User, "foo", FsAction.All), AclTestHelpers.AclEntry(AclEntryScope .Default, AclEntryType.Group, FsAction.ReadExecute), AclTestHelpers.AclEntry(AclEntryScope .Default, AclEntryType.Mask, FsAction.All), AclTestHelpers.AclEntry(AclEntryScope .Default, AclEntryType.Other, FsAction.ReadExecute) }; AclEntry[] fileReturned = Sharpen.Collections.ToArray(fs.GetAclStatus(filePath).GetEntries (), new AclEntry[0]); Assert.AssertArrayEquals(fileExpected, fileReturned); AclEntry[] subdirReturned = Sharpen.Collections.ToArray(fs.GetAclStatus(subdirPath ).GetEntries(), new AclEntry[0]); Assert.AssertArrayEquals(subdirExpected, subdirReturned); AclTestHelpers.AssertPermission(fs, subdirPath, (short)0x11ed); Restart(fs, persistNamespace); fileReturned = Sharpen.Collections.ToArray(fs.GetAclStatus(filePath).GetEntries() , new AclEntry[0]); Assert.AssertArrayEquals(fileExpected, fileReturned); subdirReturned = Sharpen.Collections.ToArray(fs.GetAclStatus(subdirPath).GetEntries (), new AclEntry[0]); Assert.AssertArrayEquals(subdirExpected, subdirReturned); AclTestHelpers.AssertPermission(fs, subdirPath, (short)0x11ed); aclSpec = Lists.NewArrayList(AclTestHelpers.AclEntry(AclEntryScope.Default, AclEntryType .User, "foo", FsAction.ReadWrite)); fs.ModifyAclEntries(dirPath, aclSpec); fileReturned = Sharpen.Collections.ToArray(fs.GetAclStatus(filePath).GetEntries() , new AclEntry[0]); Assert.AssertArrayEquals(fileExpected, fileReturned); subdirReturned = Sharpen.Collections.ToArray(fs.GetAclStatus(subdirPath).GetEntries (), new AclEntry[0]); Assert.AssertArrayEquals(subdirExpected, subdirReturned); AclTestHelpers.AssertPermission(fs, subdirPath, (short)0x11ed); Restart(fs, persistNamespace); fileReturned = Sharpen.Collections.ToArray(fs.GetAclStatus(filePath).GetEntries() , new AclEntry[0]); Assert.AssertArrayEquals(fileExpected, fileReturned); subdirReturned = Sharpen.Collections.ToArray(fs.GetAclStatus(subdirPath).GetEntries (), new AclEntry[0]); Assert.AssertArrayEquals(subdirExpected, subdirReturned); AclTestHelpers.AssertPermission(fs, subdirPath, (short)0x11ed); fs.RemoveAcl(dirPath); fileReturned = Sharpen.Collections.ToArray(fs.GetAclStatus(filePath).GetEntries() , new AclEntry[0]); Assert.AssertArrayEquals(fileExpected, fileReturned); subdirReturned = Sharpen.Collections.ToArray(fs.GetAclStatus(subdirPath).GetEntries (), new AclEntry[0]); Assert.AssertArrayEquals(subdirExpected, subdirReturned); AclTestHelpers.AssertPermission(fs, subdirPath, (short)0x11ed); Restart(fs, persistNamespace); fileReturned = Sharpen.Collections.ToArray(fs.GetAclStatus(filePath).GetEntries() , new AclEntry[0]); Assert.AssertArrayEquals(fileExpected, fileReturned); subdirReturned = Sharpen.Collections.ToArray(fs.GetAclStatus(subdirPath).GetEntries (), new AclEntry[0]); Assert.AssertArrayEquals(subdirExpected, subdirReturned); AclTestHelpers.AssertPermission(fs, subdirPath, (short)0x11ed); }
public static void CreateOriginalFSImage() { MiniDFSCluster cluster = null; try { Configuration conf = new Configuration(); conf.SetBoolean(DFSConfigKeys.DfsNamenodeAclsEnabledKey, true); cluster = new MiniDFSCluster.Builder(conf).Build(); cluster.WaitActive(); DistributedFileSystem hdfs = cluster.GetFileSystem(); // Create a reasonable namespace with ACLs Path dir = new Path("/dirWithNoAcl"); hdfs.Mkdirs(dir); writtenAcls[dir.ToString()] = hdfs.GetAclStatus(dir); dir = new Path("/dirWithDefaultAcl"); hdfs.Mkdirs(dir); hdfs.SetAcl(dir, Lists.NewArrayList(AclTestHelpers.AclEntry(AclEntryScope.Default , AclEntryType.User, FsAction.All), AclTestHelpers.AclEntry(AclEntryScope.Default , AclEntryType.User, "foo", FsAction.All), AclTestHelpers.AclEntry(AclEntryScope .Default, AclEntryType.Group, FsAction.ReadExecute), AclTestHelpers.AclEntry(AclEntryScope .Default, AclEntryType.Other, FsAction.None))); writtenAcls[dir.ToString()] = hdfs.GetAclStatus(dir); Path file = new Path("/noAcl"); FSDataOutputStream o = hdfs.Create(file); o.Write(23); o.Close(); writtenAcls[file.ToString()] = hdfs.GetAclStatus(file); file = new Path("/withAcl"); o = hdfs.Create(file); o.Write(23); o.Close(); hdfs.SetAcl(file, Lists.NewArrayList(AclTestHelpers.AclEntry(AclEntryScope.Access , AclEntryType.User, FsAction.ReadWrite), AclTestHelpers.AclEntry(AclEntryScope. Access, AclEntryType.User, "foo", FsAction.Read), AclTestHelpers.AclEntry(AclEntryScope .Access, AclEntryType.Group, FsAction.Read), AclTestHelpers.AclEntry(AclEntryScope .Access, AclEntryType.Other, FsAction.None))); writtenAcls[file.ToString()] = hdfs.GetAclStatus(file); file = new Path("/withSeveralAcls"); o = hdfs.Create(file); o.Write(23); o.Close(); hdfs.SetAcl(file, Lists.NewArrayList(AclTestHelpers.AclEntry(AclEntryScope.Access , AclEntryType.User, FsAction.ReadWrite), AclTestHelpers.AclEntry(AclEntryScope. Access, AclEntryType.User, "foo", FsAction.ReadWrite), AclTestHelpers.AclEntry(AclEntryScope .Access, AclEntryType.User, "bar", FsAction.Read), AclTestHelpers.AclEntry(AclEntryScope .Access, AclEntryType.Group, FsAction.Read), AclTestHelpers.AclEntry(AclEntryScope .Access, AclEntryType.Group, "group", FsAction.Read), AclTestHelpers.AclEntry(AclEntryScope .Access, AclEntryType.Other, FsAction.None))); writtenAcls[file.ToString()] = hdfs.GetAclStatus(file); // Write results to the fsimage file hdfs.SetSafeMode(HdfsConstants.SafeModeAction.SafemodeEnter, false); hdfs.SaveNamespace(); // Determine the location of the fsimage file originalFsimage = FSImageTestUtil.FindLatestImageFile(FSImageTestUtil.GetFSImage( cluster.GetNameNode()).GetStorage().GetStorageDir(0)); if (originalFsimage == null) { throw new RuntimeException("Didn't generate or can't find fsimage"); } Log.Debug("original FS image file is " + originalFsimage); } finally { if (cluster != null) { cluster.Shutdown(); } } }