/// <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); }
/// <exception cref="System.IO.IOException"/> public Void Run() { ClientProtocol nn = this._enclosing.CreateNameNodeProxy(); string path = ServletUtil.GetDecodedPath(request, "/data"); string encodedPath = ServletUtil.GetRawPath(request, "/data"); string delegationToken = request.GetParameter(JspHelper.DelegationParameterName); HdfsFileStatus info = nn.GetFileInfo(path); if (info != null && !info.IsDir()) { response.SendRedirect(this._enclosing.CreateRedirectURL(path, encodedPath, info, ugi, nn, request, delegationToken).ToString()); } else { if (info == null) { response.SendError(400, "File not found " + path); } else { response.SendError(400, path + ": is a directory"); } } return(null); }
/// <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(); }
/// <summary>Service a GET request as described below.</summary> /// <remarks> /// Service a GET request as described below. /// Request: /// <c>GET http://<nn>:<port>/listPaths[/<path>][<?option>[&option]*] HTTP/1.1 /// </c> /// Where <i>option</i> (default) in: /// recursive ("no") /// filter (".*") /// exclude ("\..*\.crc") /// Response: A flat list of files/directories in the following format: /// <c> /// <listing path="..." recursive="(yes|no)" filter="..." /// time="yyyy-MM-dd hh:mm:ss UTC" version="..."> /// <directory path="..." modified="yyyy-MM-dd hh:mm:ss"/> /// <file path="..." modified="yyyy-MM-dd'T'hh:mm:ssZ" accesstime="yyyy-MM-dd'T'hh:mm:ssZ" /// blocksize="..." /// replication="..." size="..."/> /// </listing> /// </c> /// </remarks> /// <exception cref="Javax.Servlet.ServletException"/> /// <exception cref="System.IO.IOException"/> protected override void DoGet(HttpServletRequest request, HttpServletResponse response ) { PrintWriter @out = response.GetWriter(); XMLOutputter doc = new XMLOutputter(@out, "UTF-8"); IDictionary <string, string> root = BuildRoot(request, doc); string path = root["path"]; string filePath = ServletUtil.GetDecodedPath(request, "/listPaths"); try { bool recur = "yes".Equals(root["recursive"]); Sharpen.Pattern filter = Sharpen.Pattern.Compile(root["filter"]); Sharpen.Pattern exclude = Sharpen.Pattern.Compile(root["exclude"]); Configuration conf = (Configuration)GetServletContext().GetAttribute(JspHelper.CurrentConf ); GetUGI(request, conf).DoAs(new _PrivilegedExceptionAction_149(this, doc, root, filePath , path, exclude, filter, recur)); } catch (IOException ioe) { WriteXml(ioe, path, doc); } catch (Exception e) { Log.Warn("ListPathServlet encountered InterruptedException", e); response.SendError(400, e.Message); } finally { if (doc != null) { doc.EndDocument(); } if (@out != null) { @out.Close(); } } }
/// <summary>Build a map from the query string, setting values and defaults.</summary> protected internal virtual IDictionary <string, string> BuildRoot(HttpServletRequest request, XMLOutputter doc) { string path = ServletUtil.GetDecodedPath(request, "/listPaths"); string exclude = request.GetParameter("exclude") != null?request.GetParameter("exclude" ) : string.Empty; string filter = request.GetParameter("filter") != null?request.GetParameter("filter" ) : ".*"; bool recur = request.GetParameter("recursive") != null && "yes".Equals(request.GetParameter ("recursive")); IDictionary <string, string> root = new Dictionary <string, string>(); root["path"] = path; root["recursive"] = recur ? "yes" : "no"; root["filter"] = filter; root["exclude"] = exclude; root["time"] = df.Get().Format(new DateTime()); root["version"] = VersionInfo.GetVersion(); return(root); }
/// <exception cref="Javax.Servlet.ServletException"/> /// <exception cref="System.IO.IOException"/> protected override void DoGet(HttpServletRequest request, HttpServletResponse response ) { string path = ServletUtil.GetDecodedPath(request, "/streamFile"); string rawPath = ServletUtil.GetRawPath(request, "/streamFile"); string filename = JspHelper.ValidatePath(path); string rawFilename = JspHelper.ValidatePath(rawPath); if (filename == null) { response.SetContentType("text/plain"); PrintWriter @out = response.GetWriter(); @out.Write("Invalid input"); return; } Enumeration <string> reqRanges = request.GetHeaders("Range"); if (reqRanges != null && !reqRanges.MoveNext()) { reqRanges = null; } DFSClient dfs; try { dfs = GetDFSClient(request); } catch (Exception e) { response.SendError(400, e.Message); return; } HdfsDataInputStream @in = null; OutputStream out_1 = null; try { @in = dfs.CreateWrappedInputStream(dfs.Open(filename)); out_1 = response.GetOutputStream(); long fileLen = @in.GetVisibleLength(); if (reqRanges != null) { IList <InclusiveByteRange> ranges = InclusiveByteRange.SatisfiableRanges(reqRanges , fileLen); StreamFile.SendPartialData(@in, out_1, response, fileLen, ranges); } else { // No ranges, so send entire file response.SetHeader("Content-Disposition", "attachment; filename=\"" + rawFilename + "\""); response.SetContentType("application/octet-stream"); response.SetHeader(ContentLength, string.Empty + fileLen); StreamFile.CopyFromOffset(@in, out_1, 0L, fileLen); } @in.Close(); @in = null; out_1.Close(); out_1 = null; dfs.Close(); dfs = null; } catch (IOException ioe) { if (Log.IsDebugEnabled()) { Log.Debug("response.isCommitted()=" + response.IsCommitted(), ioe); } throw; } finally { IOUtils.Cleanup(Log, @in); IOUtils.Cleanup(Log, out_1); IOUtils.Cleanup(Log, dfs); } }