예제 #1
0
        public virtual void TestCustomProvider()
        {
            FileSystem fs = FileSystem.Get(miniDFS.GetConfiguration(0));

            fs.Mkdirs(new Path("/user/xxx"));
            FileStatus status = fs.GetFileStatus(new Path("/user/xxx"));

            NUnit.Framework.Assert.AreEqual(Runtime.GetProperty("user.name"), status.GetOwner
                                                ());
            NUnit.Framework.Assert.AreEqual("supergroup", status.GetGroup());
            NUnit.Framework.Assert.AreEqual(new FsPermission((short)0x1ed), status.GetPermission
                                                ());
            fs.Mkdirs(new Path("/user/authz"));
            Path p = new Path("/user/authz");

            status = fs.GetFileStatus(p);
            NUnit.Framework.Assert.AreEqual("foo", status.GetOwner());
            NUnit.Framework.Assert.AreEqual("bar", status.GetGroup());
            NUnit.Framework.Assert.AreEqual(new FsPermission((short)0x1f8), status.GetPermission
                                                ());
            AclStatus aclStatus = fs.GetAclStatus(p);

            NUnit.Framework.Assert.AreEqual(1, aclStatus.GetEntries().Count);
            NUnit.Framework.Assert.AreEqual(AclEntryType.Group, aclStatus.GetEntries()[0].GetType
                                                ());
            NUnit.Framework.Assert.AreEqual("xxx", aclStatus.GetEntries()[0].GetName());
            NUnit.Framework.Assert.AreEqual(FsAction.All, aclStatus.GetEntries()[0].GetPermission
                                                ());
            IDictionary <string, byte[]> xAttrs = fs.GetXAttrs(p);

            NUnit.Framework.Assert.IsTrue(xAttrs.Contains("user.test"));
            NUnit.Framework.Assert.AreEqual(2, xAttrs["user.test"].Length);
        }
예제 #2
0
        public virtual void TestRootACLAfterLoadingFsImage()
        {
            DistributedFileSystem fs = cluster.GetFileSystem();
            Path     rootdir         = new Path("/");
            AclEntry e1 = new AclEntry.Builder().SetName("foo").SetPermission(FsAction.All).SetScope
                              (AclEntryScope.Access).SetType(AclEntryType.Group).Build();
            AclEntry e2 = new AclEntry.Builder().SetName("bar").SetPermission(FsAction.Read).
                          SetScope(AclEntryScope.Access).SetType(AclEntryType.Group).Build();

            fs.ModifyAclEntries(rootdir, Lists.NewArrayList(e1, e2));
            AclStatus s = cluster.GetNamesystem().GetAclStatus(rootdir.ToString());

            AclEntry[] returned = Sharpen.Collections.ToArray(Lists.NewArrayList(s.GetEntries
                                                                                     ()), new AclEntry[0]);
            Assert.AssertArrayEquals(new AclEntry[] { AclTestHelpers.AclEntry(AclEntryScope.Access
                                                                              , AclEntryType.Group, FsAction.ReadExecute), AclTestHelpers.AclEntry(AclEntryScope
                                                                                                                                                   .Access, AclEntryType.Group, "bar", FsAction.Read), AclTestHelpers.AclEntry(AclEntryScope
                                                                                                                                                                                                                               .Access, AclEntryType.Group, "foo", FsAction.All) }, returned);
            // restart - hence save and load from fsimage
            Restart(fs, true);
            s        = cluster.GetNamesystem().GetAclStatus(rootdir.ToString());
            returned = Sharpen.Collections.ToArray(Lists.NewArrayList(s.GetEntries()), new AclEntry
                                                   [0]);
            Assert.AssertArrayEquals(new AclEntry[] { AclTestHelpers.AclEntry(AclEntryScope.Access
                                                                              , AclEntryType.Group, FsAction.ReadExecute), AclTestHelpers.AclEntry(AclEntryScope
                                                                                                                                                   .Access, AclEntryType.Group, "bar", FsAction.Read), AclTestHelpers.AclEntry(AclEntryScope
                                                                                                                                                                                                                               .Access, AclEntryType.Group, "foo", FsAction.All) }, returned);
        }
예제 #3
0
 /// <summary>Runs assertions testing that two AclStatus objects contain the same info
 ///     </summary>
 /// <param name="a">First AclStatus</param>
 /// <param name="b">Second AclStatus</param>
 /// <exception cref="System.Exception"/>
 private void AssertSameAcls(AclStatus a, AclStatus b)
 {
     NUnit.Framework.Assert.IsTrue(a.GetOwner().Equals(b.GetOwner()));
     NUnit.Framework.Assert.IsTrue(a.GetGroup().Equals(b.GetGroup()));
     NUnit.Framework.Assert.IsTrue(a.IsStickyBit() == b.IsStickyBit());
     NUnit.Framework.Assert.IsTrue(a.GetEntries().Count == b.GetEntries().Count);
     foreach (AclEntry e in a.GetEntries())
     {
         NUnit.Framework.Assert.IsTrue(b.GetEntries().Contains(e));
     }
     foreach (AclEntry e_1 in b.GetEntries())
     {
         NUnit.Framework.Assert.IsTrue(a.GetEntries().Contains(e_1));
     }
 }
예제 #4
0
        public virtual void TestInternalGetAclStatus()
        {
            UserGroupInformation currentUser = UserGroupInformation.GetCurrentUser();
            AclStatus            aclStatus   = fsView.GetAclStatus(new Path("/internalDir"));

            Assert.Equal(aclStatus.GetOwner(), currentUser.GetUserName());
            Assert.Equal(aclStatus.GetGroup(), currentUser.GetGroupNames()
                         [0]);
            Assert.Equal(aclStatus.GetEntries(), AclUtil.GetMinimalAcl(Constants
                                                                       .Permission555));
            NUnit.Framework.Assert.IsFalse(aclStatus.IsStickyBit());
        }
예제 #5
0
        /// <exception cref="System.IO.IOException"/>
        private void TestAcl(bool persistNamespace)
        {
            Path p = new Path("/p");
            DistributedFileSystem fs = cluster.GetFileSystem();

            fs.Create(p).Close();
            fs.Mkdirs(new Path("/23"));
            AclEntry e = new AclEntry.Builder().SetName("foo").SetPermission(FsAction.ReadExecute
                                                                             ).SetScope(AclEntryScope.Access).SetType(AclEntryType.User).Build();

            fs.ModifyAclEntries(p, Lists.NewArrayList(e));
            Restart(fs, persistNamespace);
            AclStatus s = cluster.GetNamesystem().GetAclStatus(p.ToString());

            AclEntry[] returned = Sharpen.Collections.ToArray(Lists.NewArrayList(s.GetEntries
                                                                                     ()), new AclEntry[0]);
            Assert.AssertArrayEquals(new AclEntry[] { AclTestHelpers.AclEntry(AclEntryScope.Access
                                                                              , AclEntryType.User, "foo", FsAction.ReadExecute), AclTestHelpers.AclEntry(AclEntryScope
                                                                                                                                                         .Access, AclEntryType.Group, FsAction.Read) }, returned);
            fs.RemoveAcl(p);
            if (persistNamespace)
            {
                fs.SetSafeMode(HdfsConstants.SafeModeAction.SafemodeEnter);
                fs.SaveNamespace();
                fs.SetSafeMode(HdfsConstants.SafeModeAction.SafemodeLeave);
            }
            cluster.RestartNameNode();
            cluster.WaitActive();
            s        = cluster.GetNamesystem().GetAclStatus(p.ToString());
            returned = Sharpen.Collections.ToArray(Lists.NewArrayList(s.GetEntries()), new AclEntry
                                                   [0]);
            Assert.AssertArrayEquals(new AclEntry[] {  }, returned);
            fs.ModifyAclEntries(p, Lists.NewArrayList(e));
            s        = cluster.GetNamesystem().GetAclStatus(p.ToString());
            returned = Sharpen.Collections.ToArray(Lists.NewArrayList(s.GetEntries()), new AclEntry
                                                   [0]);
            Assert.AssertArrayEquals(new AclEntry[] { AclTestHelpers.AclEntry(AclEntryScope.Access
                                                                              , AclEntryType.User, "foo", FsAction.ReadExecute), AclTestHelpers.AclEntry(AclEntryScope
                                                                                                                                                         .Access, AclEntryType.Group, FsAction.Read) }, returned);
        }
예제 #6
0
        /// <summary>Convert a AclStatus object to a Json string.</summary>
        public static string ToJsonString(AclStatus status)
        {
            if (status == null)
            {
                return(null);
            }
            IDictionary <string, object> m = new SortedDictionary <string, object>();

            m["owner"]     = status.GetOwner();
            m["group"]     = status.GetGroup();
            m["stickyBit"] = status.IsStickyBit();
            IList <string> stringEntries = new AList <string>();

            foreach (AclEntry entry in status.GetEntries())
            {
                stringEntries.AddItem(entry.ToString());
            }
            m["entries"] = stringEntries;
            FsPermission perm = status.GetPermission();

            if (perm != null)
            {
                m["permission"] = ToString(perm);
                if (perm.GetAclBit())
                {
                    m["aclBit"] = true;
                }
                if (perm.GetEncryptedBit())
                {
                    m["encBit"] = true;
                }
            }
            IDictionary <string, IDictionary <string, object> > finalMap = new SortedDictionary <
                string, IDictionary <string, object> >();

            finalMap[typeof(AclStatus).Name] = m;
            ObjectMapper mapper = new ObjectMapper();

            try
            {
                return(mapper.WriteValueAsString(finalMap));
            }
            catch (IOException)
            {
            }
            return(null);
        }
예제 #7
0
        /// <summary>Converts an <code>AclStatus</code> object into a JSON object.</summary>
        /// <param name="aclStatus">AclStatus object</param>
        /// <returns>The JSON representation of the ACLs for the file</returns>
        private static IDictionary <string, object> AclStatusToJSON(AclStatus aclStatus)
        {
            IDictionary <string, object> json  = new LinkedHashMap <string, object>();
            IDictionary <string, object> inner = new LinkedHashMap <string, object>();
            JSONArray entriesArray             = new JSONArray();

            inner[HttpFSFileSystem.OwnerJson]        = aclStatus.GetOwner();
            inner[HttpFSFileSystem.GroupJson]        = aclStatus.GetGroup();
            inner[HttpFSFileSystem.AclStickyBitJson] = aclStatus.IsStickyBit();
            foreach (AclEntry e in aclStatus.GetEntries())
            {
                entriesArray.AddItem(e.ToString());
            }
            inner[HttpFSFileSystem.AclEntriesJson] = entriesArray;
            json[HttpFSFileSystem.AclStatusJson]   = inner;
            return(json);
        }
예제 #8
0
            /// <exception cref="System.IO.IOException"/>
            protected internal override void ProcessPath(PathData item)
            {
                @out.WriteLine("# file: " + item);
                @out.WriteLine("# owner: " + item.stat.GetOwner());
                @out.WriteLine("# group: " + item.stat.GetGroup());
                FsPermission perm = item.stat.GetPermission();

                if (perm.GetStickyBit())
                {
                    @out.WriteLine("# flags: --" + (perm.GetOtherAction().Implies(FsAction.Execute) ?
                                                    "t" : "T"));
                }
                AclStatus        aclStatus = item.fs.GetAclStatus(item.path);
                IList <AclEntry> entries   = perm.GetAclBit() ? aclStatus.GetEntries() : Collections
                                             .EmptyList <AclEntry>();
                ScopedAclEntries scopedEntries = new ScopedAclEntries(AclUtil.GetAclFromPermAndEntries
                                                                          (perm, entries));

                PrintAclEntriesForSingleScope(aclStatus, perm, scopedEntries.GetAccessEntries());
                PrintAclEntriesForSingleScope(aclStatus, perm, scopedEntries.GetDefaultEntries());
                @out.WriteLine();
            }
예제 #9
0
            /// <summary>
            /// Return in inner part of the JSON for the status - used by both the
            /// GETFILESTATUS and LISTSTATUS calls.
            /// </summary>
            /// <param name="emptyPathSuffix">Whether or not to include PATH_SUFFIX_JSON</param>
            /// <returns>The JSONish Map</returns>
            public virtual IDictionary <string, object> ToJsonInner(bool emptyPathSuffix)
            {
                IDictionary <string, object> json = new LinkedHashMap <string, object>();

                json[HttpFSFileSystem.PathSuffixJson] = (emptyPathSuffix) ? string.Empty : fileStatus
                                                        .GetPath().GetName();
                json[HttpFSFileSystem.TypeJson] = HttpFSFileSystem.FILE_TYPE.GetType(fileStatus).
                                                  ToString();
                json[HttpFSFileSystem.LengthJson]     = fileStatus.GetLen();
                json[HttpFSFileSystem.OwnerJson]      = fileStatus.GetOwner();
                json[HttpFSFileSystem.GroupJson]      = fileStatus.GetGroup();
                json[HttpFSFileSystem.PermissionJson] = HttpFSFileSystem.PermissionToString(fileStatus
                                                                                            .GetPermission());
                json[HttpFSFileSystem.AccessTimeJson]       = fileStatus.GetAccessTime();
                json[HttpFSFileSystem.ModificationTimeJson] = fileStatus.GetModificationTime();
                json[HttpFSFileSystem.BlockSizeJson]        = fileStatus.GetBlockSize();
                json[HttpFSFileSystem.ReplicationJson]      = fileStatus.GetReplication();
                if ((aclStatus != null) && !(aclStatus.GetEntries().IsEmpty()))
                {
                    json[HttpFSFileSystem.AclBitJson] = true;
                }
                return(json);
            }
예제 #10
0
 private AclEntry[] AclEntryArray(AclStatus aclStatus)
 {
     return(Sharpen.Collections.ToArray(aclStatus.GetEntries(), new AclEntry[0]));
 }