Пример #1
0
        public static Nfs3FileAttributes GetNfs3FileAttrFromFileStatus(HdfsFileStatus fs,
                                                                       IdMappingServiceProvider iug)
        {
            NfsFileType fileType = fs.IsDir() ? NfsFileType.Nfsdir : NfsFileType.Nfsreg;

            fileType = fs.IsSymlink() ? NfsFileType.Nfslnk : fileType;
            int  nlink = (fileType == NfsFileType.Nfsdir) ? fs.GetChildrenNum() + 2 : 1;
            long size  = (fileType == NfsFileType.Nfsdir) ? GetDirSize(fs.GetChildrenNum()) :
                         fs.GetLen();

            return(new Nfs3FileAttributes(fileType, nlink, fs.GetPermission().ToShort(), iug.
                                          GetUidAllowingUnknown(fs.GetOwner()), iug.GetGidAllowingUnknown(fs.GetGroup()),
                                          size, 0, fs.GetFileId(), fs.GetModificationTime(), fs.GetAccessTime(), new Nfs3FileAttributes.Specdata3
                                              ()));
        }
Пример #2
0
        /// <exception cref="System.IO.IOException"/>
        public static WccAttr GetWccAttr(DFSClient client, string fileIdPath)
        {
            HdfsFileStatus fstat = GetFileStatus(client, fileIdPath);

            if (fstat == null)
            {
                return(null);
            }
            long size = fstat.IsDir() ? GetDirSize(fstat.GetChildrenNum()) : fstat.GetLen();

            return(new WccAttr(size, new NfsTime(fstat.GetModificationTime()), new NfsTime(fstat
                                                                                           .GetModificationTime())));
        }
Пример #3
0
        public virtual void TestGetFileInfo()
        {
            // Check that / exists
            Path path = new Path("/");

            NUnit.Framework.Assert.IsTrue("/ should be a directory", fs.GetFileStatus(path).IsDirectory
                                              ());
            // Make sure getFileInfo returns null for files which do not exist
            HdfsFileStatus fileInfo = dfsClient.GetFileInfo("/noSuchFile");

            NUnit.Framework.Assert.AreEqual("Non-existant file should result in null", null,
                                            fileInfo);
            Path path1 = new Path("/name1");
            Path path2 = new Path("/name1/name2");

            NUnit.Framework.Assert.IsTrue(fs.Mkdirs(path1));
            FSDataOutputStream @out = fs.Create(path2, false);

            @out.Close();
            fileInfo = dfsClient.GetFileInfo(path1.ToString());
            NUnit.Framework.Assert.AreEqual(1, fileInfo.GetChildrenNum());
            fileInfo = dfsClient.GetFileInfo(path2.ToString());
            NUnit.Framework.Assert.AreEqual(0, fileInfo.GetChildrenNum());
            // Test getFileInfo throws the right exception given a non-absolute path.
            try
            {
                dfsClient.GetFileInfo("non-absolute");
                NUnit.Framework.Assert.Fail("getFileInfo for a non-absolute path did not throw IOException"
                                            );
            }
            catch (RemoteException re)
            {
                NUnit.Framework.Assert.IsTrue("Wrong exception for invalid file name", re.ToString
                                                  ().Contains("Invalid file name"));
            }
        }
Пример #4
0
        /// <summary>Convert a HdfsFileStatus object to a Json string.</summary>
        public static string ToJsonString(HdfsFileStatus status, bool includeType)
        {
            if (status == null)
            {
                return(null);
            }
            IDictionary <string, object> m = new SortedDictionary <string, object>();

            m["pathSuffix"] = status.GetLocalName();
            m["type"]       = JsonUtil.PathType.ValueOf(status);
            if (status.IsSymlink())
            {
                m["symlink"] = status.GetSymlink();
            }
            m["length"] = status.GetLen();
            m["owner"]  = status.GetOwner();
            m["group"]  = status.GetGroup();
            FsPermission perm = status.GetPermission();

            m["permission"] = ToString(perm);
            if (perm.GetAclBit())
            {
                m["aclBit"] = true;
            }
            if (perm.GetEncryptedBit())
            {
                m["encBit"] = true;
            }
            m["accessTime"]       = status.GetAccessTime();
            m["modificationTime"] = status.GetModificationTime();
            m["blockSize"]        = status.GetBlockSize();
            m["replication"]      = status.GetReplication();
            m["fileId"]           = status.GetFileId();
            m["childrenNum"]      = status.GetChildrenNum();
            m["storagePolicy"]    = status.GetStoragePolicy();
            ObjectMapper mapper = new ObjectMapper();

            try
            {
                return(includeType ? ToJsonString(typeof(FileStatus), m) : mapper.WriteValueAsString
                           (m));
            }
            catch (IOException)
            {
            }
            return(null);
        }