Пример #1
0
            /// <exception cref="System.Exception"/>
            public Void Run()
            {
                string       path = ServletUtil.GetDecodedPath(request, "/contentSummary");
                PrintWriter  @out = response.GetWriter();
                XMLOutputter xml  = new XMLOutputter(@out, "UTF-8");

                xml.Declaration();
                try
                {
                    ClientProtocol nnproxy = this._enclosing.CreateNameNodeProxy();
                    ContentSummary cs      = nnproxy.GetContentSummary(path);
                    xml.StartTag(typeof(ContentSummary).FullName);
                    if (cs != null)
                    {
                        xml.Attribute("length", string.Empty + cs.GetLength());
                        xml.Attribute("fileCount", string.Empty + cs.GetFileCount());
                        xml.Attribute("directoryCount", string.Empty + cs.GetDirectoryCount());
                        xml.Attribute("quota", string.Empty + cs.GetQuota());
                        xml.Attribute("spaceConsumed", string.Empty + cs.GetSpaceConsumed());
                        xml.Attribute("spaceQuota", string.Empty + cs.GetSpaceQuota());
                    }
                    xml.EndTag();
                }
                catch (IOException ioe)
                {
                    this._enclosing.WriteXml(ioe, path, xml);
                }
                xml.EndDocument();
                return(null);
            }
Пример #2
0
        /// <exception cref="System.Exception"/>
        private void TestContentSummary()
        {
            FileSystem   fs   = FileSystem.Get(GetProxiedFSConf());
            Path         path = new Path(GetProxiedFSTestDir(), "foo.txt");
            OutputStream os   = fs.Create(path);

            os.Write(1);
            os.Close();
            ContentSummary hdfsContentSummary = fs.GetContentSummary(path);

            fs.Close();
            fs = GetHttpFSFileSystem();
            ContentSummary httpContentSummary = fs.GetContentSummary(path);

            fs.Close();
            NUnit.Framework.Assert.AreEqual(httpContentSummary.GetDirectoryCount(), hdfsContentSummary
                                            .GetDirectoryCount());
            NUnit.Framework.Assert.AreEqual(httpContentSummary.GetFileCount(), hdfsContentSummary
                                            .GetFileCount());
            NUnit.Framework.Assert.AreEqual(httpContentSummary.GetLength(), hdfsContentSummary
                                            .GetLength());
            NUnit.Framework.Assert.AreEqual(httpContentSummary.GetQuota(), hdfsContentSummary
                                            .GetQuota());
            NUnit.Framework.Assert.AreEqual(httpContentSummary.GetSpaceConsumed(), hdfsContentSummary
                                            .GetSpaceConsumed());
            NUnit.Framework.Assert.AreEqual(httpContentSummary.GetSpaceQuota(), hdfsContentSummary
                                            .GetSpaceQuota());
        }
Пример #3
0
        /// <summary>Convert a ContentSummary to a Json string.</summary>
        public static string ToJsonString(ContentSummary contentsummary)
        {
            if (contentsummary == null)
            {
                return(null);
            }
            IDictionary <string, object> m = new SortedDictionary <string, object>();

            m["length"]         = contentsummary.GetLength();
            m["fileCount"]      = contentsummary.GetFileCount();
            m["directoryCount"] = contentsummary.GetDirectoryCount();
            m["quota"]          = contentsummary.GetQuota();
            m["spaceConsumed"]  = contentsummary.GetSpaceConsumed();
            m["spaceQuota"]     = contentsummary.GetSpaceQuota();
            return(ToJsonString(typeof(ContentSummary), m));
        }
Пример #4
0
        /// <summary>
        /// Converts a <code>ContentSummary</code> object into a JSON array
        /// object.
        /// </summary>
        /// <param name="contentSummary">the content summary</param>
        /// <returns>The JSON representation of the content summary.</returns>
        private static IDictionary ContentSummaryToJSON(ContentSummary contentSummary)
        {
            IDictionary json = new LinkedHashMap();

            json[HttpFSFileSystem.ContentSummaryDirectoryCountJson] = contentSummary.GetDirectoryCount
                                                                          ();
            json[HttpFSFileSystem.ContentSummaryFileCountJson] = contentSummary.GetFileCount(
                );
            json[HttpFSFileSystem.ContentSummaryLengthJson]        = contentSummary.GetLength();
            json[HttpFSFileSystem.ContentSummaryQuotaJson]         = contentSummary.GetQuota();
            json[HttpFSFileSystem.ContentSummarySpaceConsumedJson] = contentSummary.GetSpaceConsumed
                                                                         ();
            json[HttpFSFileSystem.ContentSummarySpaceQuotaJson] = contentSummary.GetSpaceQuota
                                                                      ();
            IDictionary response = new LinkedHashMap();

            response[HttpFSFileSystem.ContentSummaryJson] = json;
            return(response);
        }