|
@@ -14,12 +14,156 @@
|
|
|
<%!
|
|
|
static JspHelper jspHelper = new JspHelper();
|
|
|
|
|
|
+ public void generateFileDetails(JspWriter out, HttpServletRequest req)
|
|
|
+ throws IOException {
|
|
|
+
|
|
|
+ int chunkSizeToView = 0;
|
|
|
+ long startOffset = 0;
|
|
|
+ int datanodePort;
|
|
|
+
|
|
|
+ String blockIdStr = null;
|
|
|
+ long currBlockId = 0;
|
|
|
+ blockIdStr = req.getParameter("blockId");
|
|
|
+ if (blockIdStr == null) {
|
|
|
+ out.print("Invalid input (blockId absent)");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ currBlockId = Long.parseLong(blockIdStr);
|
|
|
+
|
|
|
+ String datanodePortStr = req.getParameter("datanodePort");
|
|
|
+ if (datanodePortStr == null) {
|
|
|
+ out.print("Invalid input (datanodePort absent)");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ datanodePort = Integer.parseInt(datanodePortStr);
|
|
|
+
|
|
|
+ String namenodeInfoPortStr = req.getParameter("namenodeInfoPort");
|
|
|
+ int namenodeInfoPort = -1;
|
|
|
+ if (namenodeInfoPortStr != null)
|
|
|
+ namenodeInfoPort = Integer.parseInt(namenodeInfoPortStr);
|
|
|
+
|
|
|
+ String chunkSizeToViewStr = req.getParameter("chunkSizeToView");
|
|
|
+ if (chunkSizeToViewStr != null && Integer.parseInt(chunkSizeToViewStr) > 0)
|
|
|
+ chunkSizeToView = Integer.parseInt(chunkSizeToViewStr);
|
|
|
+ else chunkSizeToView = jspHelper.defaultChunkSizeToView;
|
|
|
+
|
|
|
+ String startOffsetStr = req.getParameter("startOffset");
|
|
|
+ if (startOffsetStr == null || Long.parseLong(startOffsetStr) < 0)
|
|
|
+ startOffset = 0;
|
|
|
+ else startOffset = Long.parseLong(startOffsetStr);
|
|
|
+
|
|
|
+ String filename = req.getParameter("filename");
|
|
|
+ if (filename == null || filename.length() == 0) {
|
|
|
+ out.print("Invalid input");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ String blockSizeStr = req.getParameter("blockSize");
|
|
|
+ long blockSize = 0;
|
|
|
+ if (blockSizeStr == null && blockSizeStr.length() == 0) {
|
|
|
+ out.print("Invalid input");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ blockSize = Long.parseLong(blockSizeStr);
|
|
|
+
|
|
|
+ DFSClient dfs = new DFSClient(jspHelper.nameNodeAddr, jspHelper.conf);
|
|
|
+ LocatedBlock[] blocks = dfs.namenode.open(filename);
|
|
|
+ //Add the various links for looking at the file contents
|
|
|
+ //URL for downloading the full file
|
|
|
+ String downloadUrl = "http://" + req.getServerName() + ":" +
|
|
|
+ + req.getServerPort() + "/streamFile?" + "filename=" +
|
|
|
+ URLEncoder.encode(filename, "UTF-8");
|
|
|
+ out.print("<a name=\"viewOptions\"></a>");
|
|
|
+ out.print("<a href=\"" + downloadUrl + "\">Download this file</a><br>");
|
|
|
+
|
|
|
+ DatanodeInfo chosenNode;
|
|
|
+ //URL for TAIL
|
|
|
+ LocatedBlock lastBlk = blocks[blocks.length - 1];
|
|
|
+ long blockId = lastBlk.getBlock().getBlockId();
|
|
|
+ try {
|
|
|
+ chosenNode = jspHelper.bestNode(lastBlk);
|
|
|
+ } catch (IOException e) {
|
|
|
+ out.print(e.toString());
|
|
|
+ dfs.close();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ String fqdn =
|
|
|
+ InetAddress.getByName(chosenNode.getHost()).getCanonicalHostName();
|
|
|
+ String tailUrl = "http://" + fqdn + ":" +
|
|
|
+ chosenNode.getInfoPort() +
|
|
|
+ "/tail.jsp?filename=" + URLEncoder.encode(filename, "UTF-8") +
|
|
|
+ "&chunkSizeToView=" + chunkSizeToView +
|
|
|
+ "&referrer=" +
|
|
|
+ URLEncoder.encode(req.getRequestURL() + "?" + req.getQueryString(),
|
|
|
+ "UTF-8");
|
|
|
+ out.print("<a href=\"" + tailUrl + "\">TAIL this file</a><br>");
|
|
|
+
|
|
|
+ out.print("<form action=\"/browseBlock.jsp\" method=GET>");
|
|
|
+ out.print("<b>Chunk Size to view (in bytes, upto file's DFS blocksize): </b>");
|
|
|
+ out.print("<input type=\"hidden\" name=\"blockId\" value=\"" + currBlockId +
|
|
|
+ "\">");
|
|
|
+ out.print("<input type=\"hidden\" name=\"blockSize\" value=\"" +
|
|
|
+ blockSize + "\">");
|
|
|
+ out.print("<input type=\"hidden\" name=\"startOffset\" value=\"" +
|
|
|
+ startOffset + "\">");
|
|
|
+ out.print("<input type=\"hidden\" name=\"filename\" value=\"" + filename +
|
|
|
+ "\">");
|
|
|
+ out.print("<input type=\"hidden\" name=\"datanodePort\" value=\"" +
|
|
|
+ datanodePort+ "\">");
|
|
|
+ out.print("<input type=\"hidden\" name=\"namenodeInfoPort\" value=\"" +
|
|
|
+ namenodeInfoPort + "\">");
|
|
|
+ out.print("<input type=\"text\" name=\"chunkSizeToView\" value=" +
|
|
|
+ chunkSizeToView + " size=10 maxlength=10>");
|
|
|
+ out.print(" <input type=\"submit\" name=\"submit\" value=\"Refresh\">");
|
|
|
+ out.print("</form>");
|
|
|
+ out.print("<hr>");
|
|
|
+ out.print("<a name=\"blockDetails\"></a>");
|
|
|
+ out.print("<B>Total number of blocks: "+blocks.length+"</B><br>");
|
|
|
+ //generate a table and dump the info
|
|
|
+ for (int i = 0; i < blocks.length; i++) {
|
|
|
+ blockId = blocks[i].getBlock().getBlockId();
|
|
|
+ blockSize = blocks[i].getBlock().getNumBytes();
|
|
|
+ String blk = "blk_" + Long.toString(blockId);
|
|
|
+ DatanodeInfo[] locs = blocks[i].getLocations();
|
|
|
+ int r = jspHelper.rand.nextInt(locs.length);
|
|
|
+ String datanodeAddr = locs[r].getName();
|
|
|
+ datanodePort = Integer.parseInt(datanodeAddr.substring(
|
|
|
+ datanodeAddr.indexOf(':') + 1,
|
|
|
+ datanodeAddr.length()));
|
|
|
+ fqdn = InetAddress.getByName(locs[r].getHost()).getCanonicalHostName();
|
|
|
+ String blockUrl = "http://"+ fqdn + ":" +
|
|
|
+ locs[r].getInfoPort() +
|
|
|
+ "/browseBlock.jsp?blockId=" + Long.toString(blockId) +
|
|
|
+ "&blockSize=" + blockSize +
|
|
|
+ "&filename=" + URLEncoder.encode(filename, "UTF-8")+
|
|
|
+ "&datanodePort=" + datanodePort +
|
|
|
+ "&namenodeInfoPort=" + namenodeInfoPort +
|
|
|
+ "&chunkSizeToView=" + chunkSizeToView;
|
|
|
+ out.print("<a href=\"" + blockUrl + "\">" + "blk_" + blockId +
|
|
|
+ "</a>");
|
|
|
+ if (i < blocks.length - 1)
|
|
|
+ out.print(" ");
|
|
|
+ if (i % 3 == 0) out.print("<br>");
|
|
|
+ }
|
|
|
+ out.print("<hr>");
|
|
|
+ String namenodeHost = jspHelper.nameNodeAddr.getHostName();
|
|
|
+ out.print("<br><a href=\"http://" +
|
|
|
+ InetAddress.getByName(namenodeHost).getCanonicalHostName() + ":" +
|
|
|
+ namenodeInfoPort + "/dfshealth.jsp\">Go back to DFS home</a>");
|
|
|
+ dfs.close();
|
|
|
+ }
|
|
|
+
|
|
|
public void generateFileChunks(JspWriter out, HttpServletRequest req)
|
|
|
throws IOException {
|
|
|
long startOffset = 0;
|
|
|
int datanodePort = 0;
|
|
|
int chunkSizeToView = 0;
|
|
|
|
|
|
+ String namenodeInfoPortStr = req.getParameter("namenodeInfoPort");
|
|
|
+ int namenodeInfoPort = -1;
|
|
|
+ if (namenodeInfoPortStr != null)
|
|
|
+ namenodeInfoPort = Integer.parseInt(namenodeInfoPortStr);
|
|
|
+
|
|
|
String filename = req.getParameter("filename");
|
|
|
if (filename == null) {
|
|
|
out.print("Invalid input (filename absent)");
|
|
@@ -63,23 +207,13 @@
|
|
|
|
|
|
out.print("<h2>File: " + filename + "</h2>");
|
|
|
out.print("<a href=\"http://" + req.getServerName() + ":" +
|
|
|
- req.getServerPort() + "/browseData.jsp?filename=" + filename +
|
|
|
- "\">Go back to File details</a><br>");
|
|
|
- out.print("<b>Chunk Size to view (in bytes, upto file's DFS blocksize): </b>");
|
|
|
- out.print("<input type=\"hidden\" name=\"blockId\" value=\"" + blockId +
|
|
|
- "\">");
|
|
|
- out.print("<input type=\"hidden\" name=\"blockSize\" value=\"" +
|
|
|
- blockSize + "\">");
|
|
|
- out.print("<input type=\"hidden\" name=\"startOffset\" value=\"" +
|
|
|
- startOffset + "\">");
|
|
|
- out.print("<input type=\"hidden\" name=\"filename\" value=\"" + filename +
|
|
|
- "\">");
|
|
|
- out.print("<input type=\"hidden\" name=\"datanodePort\" value=\"" +
|
|
|
- datanodePort+ "\">");
|
|
|
- out.print("<input type=\"text\" name=\"chunkSizeToView\" value=" +
|
|
|
- chunkSizeToView + " size=10 maxlength=10>");
|
|
|
- out.print(" <input type=\"submit\" name=\"submit\" value=\"Refresh\"><hr>");
|
|
|
- out.print("</form>");
|
|
|
+ req.getServerPort() +
|
|
|
+ "/browseDirectory.jsp?dir=" +
|
|
|
+ URLEncoder.encode(new File(filename).getParent(), "UTF-8") +
|
|
|
+ "&namenodeInfoPort=" + namenodeInfoPort +
|
|
|
+ "\"><i>Go back to dir listing</i></a><br>");
|
|
|
+ out.print("<a href=\"#viewOptions\">Advanced view/download options</a><br>");
|
|
|
+ out.print("<hr>");
|
|
|
|
|
|
//Determine the prev & next blocks
|
|
|
DFSClient dfs = new DFSClient(jspHelper.nameNodeAddr, jspHelper.conf);
|
|
@@ -124,10 +258,12 @@
|
|
|
nextPort +
|
|
|
"/browseBlock.jsp?blockId=" + nextBlockIdStr +
|
|
|
"&blockSize=" + nextBlockSize + "&startOffset=" +
|
|
|
- nextStartOffset + "&filename=" + filename +
|
|
|
+ nextStartOffset +
|
|
|
+ "&filename=" + URLEncoder.encode(filename, "UTF-8") +
|
|
|
"&chunkSizeToView=" + chunkSizeToView +
|
|
|
- "&datanodePort=" + nextDatanodePort;
|
|
|
- out.print("<a href=\"" + nextUrl + "\">Next</a> ");
|
|
|
+ "&datanodePort=" + nextDatanodePort +
|
|
|
+ "&namenodeInfoPort=" + namenodeInfoPort;
|
|
|
+ out.print("<a href=\"" + nextUrl + "\">View Next chunk</a> ");
|
|
|
}
|
|
|
//determine data for the prev link
|
|
|
String prevBlockIdStr = null;
|
|
@@ -173,12 +309,15 @@
|
|
|
prevPort +
|
|
|
"/browseBlock.jsp?blockId=" + prevBlockIdStr +
|
|
|
"&blockSize=" + prevBlockSize + "&startOffset=" +
|
|
|
- prevStartOffset + "&filename=" + filename +
|
|
|
+ prevStartOffset +
|
|
|
+ "&filename=" + URLEncoder.encode(filename, "UTF-8") +
|
|
|
"&chunkSizeToView=" + chunkSizeToView +
|
|
|
- "&datanodePort=" + prevDatanodePort;
|
|
|
- out.print("<a href=\"" + prevUrl + "\">Prev</a> ");
|
|
|
+ "&datanodePort=" + prevDatanodePort +
|
|
|
+ "&namenodeInfoPort=" + namenodeInfoPort;
|
|
|
+ out.print("<a href=\"" + prevUrl + "\">View Prev chunk</a> ");
|
|
|
}
|
|
|
out.print("<hr>");
|
|
|
+ out.print("<textarea cols=\"100\" rows=\"25\" wrap=\"virtual\" READONLY>");
|
|
|
try {
|
|
|
jspHelper.streamBlockInAscii(
|
|
|
new InetSocketAddress(req.getServerName(), datanodePort), blockId,
|
|
@@ -186,6 +325,7 @@
|
|
|
} catch (Exception e){
|
|
|
out.print(e);
|
|
|
}
|
|
|
+ out.print("</textarea>");
|
|
|
dfs.close();
|
|
|
}
|
|
|
|
|
@@ -195,11 +335,13 @@
|
|
|
<title>Hadoop DFS File Viewer</title>
|
|
|
|
|
|
<body>
|
|
|
-<form action="/browseBlock.jsp" method=GET>
|
|
|
<%
|
|
|
generateFileChunks(out,request);
|
|
|
%>
|
|
|
<hr>
|
|
|
+<%
|
|
|
+ generateFileDetails(out,request);
|
|
|
+%>
|
|
|
|
|
|
<h2>Local logs</h2>
|
|
|
<a href="/logs/">Log</a> directory
|