Пример #1
0
        /// <exception cref="System.IO.IOException"/>
        private void OnGetFileChecksum(ChannelHandlerContext ctx)
        {
            MD5MD5CRC32FileChecksum checksum = null;
            string    nnId      = @params.NamenodeId();
            DFSClient dfsclient = NewDfsClient(nnId, conf);

            try
            {
                checksum = dfsclient.GetFileChecksum(path, long.MaxValue);
                dfsclient.Close();
                dfsclient = null;
            }
            finally
            {
                IOUtils.Cleanup(Log, dfsclient);
            }
            byte[] js = Sharpen.Runtime.GetBytesForString(JsonUtil.ToJsonString(checksum), Charsets
                                                          .Utf8);
            DefaultFullHttpResponse resp = new DefaultFullHttpResponse(HttpVersion.Http11, HttpResponseStatus
                                                                       .Ok, Unpooled.WrappedBuffer(js));

            resp.Headers().Set(HttpHeaders.Names.ContentType, ApplicationJsonUtf8);
            resp.Headers().Set(HttpHeaders.Names.ContentLength, js.Length);
            resp.Headers().Set(HttpHeaders.Names.Connection, HttpHeaders.Values.Close);
            ctx.WriteAndFlush(resp).AddListener(ChannelFutureListener.Close);
        }
Пример #2
0
            /// <exception cref="Javax.Servlet.ServletException"/>
            /// <exception cref="System.IO.IOException"/>
            protected override void DoGet(HttpServletRequest request, HttpServletResponse response
                                          )
            {
                PrintWriter  @out = response.GetWriter();
                string       path = ServletUtil.GetDecodedPath(request, "/getFileChecksum");
                XMLOutputter xml  = new XMLOutputter(@out, "UTF-8");

                xml.Declaration();
                ServletContext context  = GetServletContext();
                DataNode       datanode = (DataNode)context.GetAttribute("datanode");
                Configuration  conf     = new HdfsConfiguration(datanode.GetConf());

                try
                {
                    DFSClient dfs = DatanodeJspHelper.GetDFSClient(request, datanode, conf, GetUGI(request
                                                                                                   , conf));
                    MD5MD5CRC32FileChecksum checksum = dfs.GetFileChecksum(path, long.MaxValue);
                    MD5MD5CRC32FileChecksum.Write(xml, checksum);
                }
                catch (IOException ioe)
                {
                    WriteXml(ioe, path, xml);
                }
                catch (Exception e)
                {
                    WriteXml(e, path, xml);
                }
                xml.EndDocument();
            }
Пример #3
0
        /// <summary>Convert a Json map to a MD5MD5CRC32FileChecksum.</summary>
        /// <exception cref="System.IO.IOException"/>
        public static MD5MD5CRC32FileChecksum ToMD5MD5CRC32FileChecksum <_T0>(IDictionary <
                                                                                  _T0> json)
        {
            if (json == null)
            {
                return(null);
            }
            IDictionary <object, object> m = (IDictionary <object, object>)json[typeof(FileChecksum
                                                                                       ).Name];
            string algorithm = (string)m["algorithm"];
            int    length    = ((Number)m["length"]);

            byte[]          bytes = StringUtils.HexStringToByte((string)m["bytes"]);
            DataInputStream @in   = new DataInputStream(new ByteArrayInputStream(bytes));

            DataChecksum.Type crcType = MD5MD5CRC32FileChecksum.GetCrcTypeFromAlgorithmName(algorithm
                                                                                            );
            MD5MD5CRC32FileChecksum checksum;

            switch (crcType)
            {
            case DataChecksum.Type.Crc32:
            {
                // Recreate what DFSClient would have returned.
                checksum = new MD5MD5CRC32GzipFileChecksum();
                break;
            }

            case DataChecksum.Type.Crc32c:
            {
                checksum = new MD5MD5CRC32CastagnoliFileChecksum();
                break;
            }

            default:
            {
                throw new IOException("Unknown algorithm: " + algorithm);
            }
            }
            checksum.ReadFields(@in);
            //check algorithm name
            if (!checksum.GetAlgorithmName().Equals(algorithm))
            {
                throw new IOException("Algorithm not matched. Expected " + algorithm + ", Received "
                                      + checksum.GetAlgorithmName());
            }
            //check length
            if (length != checksum.GetLength())
            {
                throw new IOException("Length not matched: length=" + length + ", checksum.getLength()="
                                      + checksum.GetLength());
            }
            return(checksum);
        }
Пример #4
0
 /// <exception cref="Org.Xml.Sax.SAXException"/>
 public override void StartElement(string ns, string localname, string qname, Attributes
                                   attrs)
 {
     if (!typeof(MD5MD5CRC32FileChecksum).FullName.Equals(qname))
     {
         if (typeof(RemoteException).Name.Equals(qname))
         {
             throw new SAXException(RemoteException.ValueOf(attrs));
         }
         throw new SAXException("Unrecognized entry: " + qname);
     }
     this.filechecksum = MD5MD5CRC32FileChecksum.ValueOf(attrs);
 }
Пример #5
0
        /// <summary>Convert a MD5MD5CRC32FileChecksum to a Json string.</summary>
        public static string ToJsonString(MD5MD5CRC32FileChecksum checksum)
        {
            if (checksum == null)
            {
                return(null);
            }
            IDictionary <string, object> m = new SortedDictionary <string, object>();

            m["algorithm"] = checksum.GetAlgorithmName();
            m["length"]    = checksum.GetLength();
            m["bytes"]     = StringUtils.ByteToHexString(checksum.GetBytes());
            return(ToJsonString(typeof(FileChecksum), m));
        }