예제 #1
0
 /// <summary>Generate a XML block as such, <item label=key value=value/></summary>
 /// <exception cref="System.IO.IOException"/>
 private static void ToXmlItemBlock(XMLOutputter doc, string key, string value)
 {
     doc.StartTag("item");
     doc.Attribute("label", key);
     doc.Attribute("value", value);
     doc.EndTag();
 }
예제 #2
0
 /// <summary>
 /// Generate a XML block as such, &lt;item label="Node" value="hostname"
 /// link="http://hostname:50070" /&gt;
 /// </summary>
 /// <exception cref="System.IO.IOException"/>
 private static void ToXmlItemBlockWithLink(XMLOutputter doc, string value, Uri url
                                            , string label)
 {
     doc.StartTag("item");
     doc.Attribute("label", label);
     doc.Attribute("value", value);
     doc.Attribute("link", url.ToString());
     doc.EndTag();
 }
예제 #3
0
 /// <summary>Write that object to xml output.</summary>
 /// <exception cref="System.IO.IOException"/>
 public static void Write(XMLOutputter xml, Org.Apache.Hadoop.FS.MD5MD5CRC32FileChecksum
                          that)
 {
     xml.StartTag(typeof(Org.Apache.Hadoop.FS.MD5MD5CRC32FileChecksum).FullName);
     if (that != null)
     {
         xml.Attribute("bytesPerCRC", string.Empty + that.bytesPerCRC);
         xml.Attribute("crcPerBlock", string.Empty + that.crcPerBlock);
         xml.Attribute("crcType", string.Empty + that.GetCrcType().ToString());
         xml.Attribute("md5", string.Empty + that.md5);
     }
     xml.EndTag();
 }
예제 #4
0
 // unreportedNamnodes
 /// <summary>create XML block from general exception.</summary>
 /// <exception cref="System.IO.IOException"/>
 private static void CreateGeneralException(XMLOutputter doc, string clusterid, string
                                            eMsg)
 {
     doc.StartTag("cluster");
     doc.Attribute("clusterId", clusterid);
     doc.StartTag("message");
     doc.StartTag("item");
     doc.Attribute("msg", eMsg);
     doc.EndTag();
     // item
     doc.EndTag();
     // message
     doc.EndTag();
 }
예제 #5
0
 // item
 /// <summary>
 /// create the XML for exceptions that we encountered when connecting to
 /// namenode.
 /// </summary>
 /// <exception cref="System.IO.IOException"/>
 private static void CreateNamenodeExceptionMsg(XMLOutputter doc, IDictionary <string
                                                                               , Exception> exceptionMsg)
 {
     if (exceptionMsg.Count > 0)
     {
         doc.StartTag("unreportedNamenodes");
         foreach (KeyValuePair <string, Exception> m in exceptionMsg)
         {
             doc.StartTag("node");
             doc.Attribute("name", m.Key);
             doc.Attribute("exception", StringUtils.StringifyException(m.Value));
             doc.EndTag();
         }
         // node
         doc.EndTag();
     }
 }
예제 #6
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);
            }
예제 #7
0
        /// <summary>Write the object to XML format</summary>
        /// <exception cref="System.IO.IOException"/>
        protected internal virtual void WriteXml(Exception except, string path, XMLOutputter
                                                 doc)
        {
            doc.StartTag(typeof(RemoteException).Name);
            doc.Attribute("path", path);
            if (except is RemoteException)
            {
                doc.Attribute("class", ((RemoteException)except).GetClassName());
            }
            else
            {
                doc.Attribute("class", except.GetType().FullName);
            }
            string msg = except.GetLocalizedMessage();
            int    i   = msg.IndexOf("\n");

            if (i >= 0)
            {
                msg = Sharpen.Runtime.Substring(msg, 0, i);
            }
            doc.Attribute("message", Sharpen.Runtime.Substring(msg, msg.IndexOf(":") + 1).Trim
                              ());
            doc.EndTag();
        }
예제 #8
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();
        }
예제 #9
0
            /// <summary>Generate decommissioning datanode report in XML format</summary>
            /// <param name="doc">, xmloutputter</param>
            /// <exception cref="System.IO.IOException"/>
            public virtual void ToXML(XMLOutputter doc)
            {
                if (error != null)
                {
                    CreateGeneralException(doc, clusterid, StringUtils.StringifyException(error));
                    doc.GetWriter().Flush();
                    return;
                }
                if (statusMap == null || statusMap.IsEmpty())
                {
                    // none of the namenodes has reported, print exceptions from each nn.
                    doc.StartTag("cluster");
                    CreateNamenodeExceptionMsg(doc, exceptions);
                    doc.EndTag();
                    doc.GetWriter().Flush();
                    return;
                }
                doc.StartTag("cluster");
                doc.Attribute("clusterId", clusterid);
                doc.StartTag("decommissioningReport");
                CountDecommissionDatanodes();
                ToXmlItemBlock(doc, ClusterJspHelper.DecommissionStates.Decommissioned.ToString()
                               , Sharpen.Extensions.ToString(decommissioned));
                ToXmlItemBlock(doc, ClusterJspHelper.DecommissionStates.DecommissionInprogress.ToString
                                   (), Sharpen.Extensions.ToString(decommissioning));
                ToXmlItemBlock(doc, ClusterJspHelper.DecommissionStates.PartiallyDecommissioned.ToString
                                   (), Sharpen.Extensions.ToString(partial));
                doc.EndTag();
                // decommissioningReport
                doc.StartTag("datanodes");
                ICollection <string> dnSet = statusMap.Keys;

                foreach (string dnhost in dnSet)
                {
                    IDictionary <string, string> nnStatus = statusMap[dnhost];
                    if (nnStatus == null || nnStatus.IsEmpty())
                    {
                        continue;
                    }
                    string overallStatus = nnStatus[OverallStatus];
                    // check if datanode is in decommission states
                    if (overallStatus != null && (overallStatus.Equals(DatanodeInfo.AdminStates.DecommissionInprogress
                                                                       .ToString()) || overallStatus.Equals(DatanodeInfo.AdminStates.Decommissioned.ToString
                                                                                                                ()) || overallStatus.Equals(ClusterJspHelper.DecommissionStates.PartiallyDecommissioned
                                                                                                                                            .ToString()) || overallStatus.Equals(ClusterJspHelper.DecommissionStates.Unknown
                                                                                                                                                                                 .ToString())))
                    {
                        doc.StartTag("node");
                        // dn
                        ToXmlItemBlockWithLink(doc, dnhost, new Uri("http", dnhost, httpPort, string.Empty
                                                                    ), "DataNode");
                        // overall status first
                        ToXmlItemBlock(doc, OverallStatus, overallStatus);
                        foreach (KeyValuePair <string, string> m in nnStatus)
                        {
                            string nn = m.Key;
                            if (nn.Equals(OverallStatus))
                            {
                                continue;
                            }
                            // xml
                            ToXmlItemBlock(doc, nn, nnStatus[nn]);
                        }
                        doc.EndTag();
                    }
                }
                // node
                doc.EndTag();
                // datanodes
                CreateNamenodeExceptionMsg(doc, exceptions);
                doc.EndTag();
            }
예제 #10
0
            /// <exception cref="System.IO.IOException"/>
            public virtual void ToXML(XMLOutputter doc)
            {
                if (error != null)
                {
                    // general exception, only print exception message onto web page.
                    CreateGeneralException(doc, clusterid, StringUtils.StringifyException(error));
                    doc.GetWriter().Flush();
                    return;
                }
                int   size                = nnList.Count;
                long  total               = 0L;
                long  free                = 0L;
                long  nonDfsUsed          = 0l;
                float dfsUsedPercent      = 0.0f;
                float dfsRemainingPercent = 0.0f;

                if (size > 0)
                {
                    total               = total_sum / size;
                    free                = free_sum / size;
                    nonDfsUsed          = nonDfsUsed_sum / size;
                    dfsUsedPercent      = DFSUtil.GetPercentUsed(clusterDfsUsed, total);
                    dfsRemainingPercent = DFSUtil.GetPercentRemaining(free, total);
                }
                doc.StartTag("cluster");
                doc.Attribute("clusterId", clusterid);
                doc.StartTag("storage");
                ToXmlItemBlock(doc, "Total Files And Directories", System.Convert.ToString(totalFilesAndDirectories
                                                                                           ));
                ToXmlItemBlock(doc, "Configured Capacity", StringUtils.ByteDesc(total));
                ToXmlItemBlock(doc, "DFS Used", StringUtils.ByteDesc(clusterDfsUsed));
                ToXmlItemBlock(doc, "Non DFS Used", StringUtils.ByteDesc(nonDfsUsed));
                ToXmlItemBlock(doc, "DFS Remaining", StringUtils.ByteDesc(free));
                // dfsUsedPercent
                ToXmlItemBlock(doc, "DFS Used%", DFSUtil.Percent2String(dfsUsedPercent));
                // dfsRemainingPercent
                ToXmlItemBlock(doc, "DFS Remaining%", DFSUtil.Percent2String(dfsRemainingPercent)
                               );
                doc.EndTag();
                // storage
                doc.StartTag("namenodes");
                // number of namenodes
                ToXmlItemBlock(doc, "NamenodesCount", Sharpen.Extensions.ToString(size));
                foreach (ClusterJspHelper.NamenodeStatus nn in nnList)
                {
                    doc.StartTag("node");
                    ToXmlItemBlockWithLink(doc, nn.host, nn.httpAddress, "NameNode");
                    ToXmlItemBlock(doc, "Blockpool Used", StringUtils.ByteDesc(nn.bpUsed));
                    ToXmlItemBlock(doc, "Blockpool Used%", DFSUtil.Percent2String(DFSUtil.GetPercentUsed
                                                                                      (nn.bpUsed, total)));
                    ToXmlItemBlock(doc, "Files And Directories", System.Convert.ToString(nn.filesAndDirectories
                                                                                         ));
                    ToXmlItemBlock(doc, "Blocks", System.Convert.ToString(nn.blocksCount));
                    ToXmlItemBlock(doc, "Missing Blocks", System.Convert.ToString(nn.missingBlocksCount
                                                                                  ));
                    ToXmlItemBlockWithLink(doc, nn.liveDatanodeCount + " (" + nn.liveDecomCount + ")"
                                           , new Uri(nn.httpAddress, "/dfsnodelist.jsp?whatNodes=LIVE"), "Live Datanode (Decommissioned)"
                                           );
                    ToXmlItemBlockWithLink(doc, nn.deadDatanodeCount + " (" + nn.deadDecomCount + ")"
                                           , new Uri(nn.httpAddress, "/dfsnodelist.jsp?whatNodes=DEAD"), "Dead Datanode (Decommissioned)"
                                           );
                    ToXmlItemBlock(doc, "Software Version", nn.softwareVersion);
                    doc.EndTag();
                }
                // node
                doc.EndTag();
                // namenodes
                CreateNamenodeExceptionMsg(doc, nnExceptions);
                doc.EndTag();
                // cluster
                doc.GetWriter().Flush();
            }