Пример #1
0
 internal static FileStatus ToFileStatus(HdfsFileStatus f, string parent)
 {
     return(new FileStatus(f.GetLen(), f.IsDir(), f.GetReplication(), f.GetBlockSize()
                           , f.GetModificationTime(), f.GetAccessTime(), f.GetPermission(), f.GetOwner(), f
                           .GetGroup(), f.IsSymlink() ? new Path(f.GetSymlink()) : null, new Path(f.GetFullName
                                                                                                      (parent))));
 }
Пример #2
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);
        }
Пример #3
0
        /// <summary>Write a node to output.</summary>
        /// <remarks>
        /// Write a node to output.
        /// Node information includes path, modification, permission, owner and group.
        /// For files, it also includes size, replication and block-size.
        /// </remarks>
        /// <exception cref="System.IO.IOException"/>
        internal static void WriteInfo(Path fullpath, HdfsFileStatus i, XMLOutputter doc)
        {
            SimpleDateFormat ldf = df.Get();

            doc.StartTag(i.IsDir() ? "directory" : "file");
            doc.Attribute("path", fullpath.ToUri().GetPath());
            doc.Attribute("modified", ldf.Format(Sharpen.Extensions.CreateDate(i.GetModificationTime
                                                                                   ())));
            doc.Attribute("accesstime", ldf.Format(Sharpen.Extensions.CreateDate(i.GetAccessTime
                                                                                     ())));
            if (!i.IsDir())
            {
                doc.Attribute("size", i.GetLen().ToString());
                doc.Attribute("replication", i.GetReplication().ToString());
                doc.Attribute("blocksize", i.GetBlockSize().ToString());
            }
            doc.Attribute("permission", (i.IsDir() ? "d" : "-") + i.GetPermission());
            doc.Attribute("owner", i.GetOwner());
            doc.Attribute("group", i.GetGroup());
            doc.EndTag();
        }
Пример #4
0
            /// <exception cref="System.Exception"/>
            private void VerifyFile(Path parent, HdfsFileStatus status, byte expectedPolicyId
                                    )
            {
                HdfsLocatedFileStatus fileStatus = (HdfsLocatedFileStatus)status;
                byte policyId             = fileStatus.GetStoragePolicy();
                BlockStoragePolicy policy = this.policies.GetPolicy(policyId);

                if (expectedPolicyId != null)
                {
                    NUnit.Framework.Assert.AreEqual(unchecked ((byte)expectedPolicyId), policy.GetId()
                                                    );
                }
                IList <StorageType> types = policy.ChooseStorageTypes(status.GetReplication());

                foreach (LocatedBlock lb in fileStatus.GetBlockLocations().GetLocatedBlocks())
                {
                    Mover.StorageTypeDiff diff = new Mover.StorageTypeDiff(types, lb.GetStorageTypes(
                                                                               ));
                    NUnit.Framework.Assert.IsTrue(fileStatus.GetFullName(parent.ToString()) + " with policy "
                                                  + policy + " has non-empty overlap: " + diff + ", the corresponding block is "
                                                  + lb.GetBlock().GetLocalBlock(), diff.RemoveOverlap(true));
                }
            }