hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cutt...@apache.org
Subject svn commit: r541082 - in /lucene/hadoop/trunk: CHANGES.txt src/java/org/apache/hadoop/dfs/JspHelper.java src/webapps/datanode/browseBlock.jsp src/webapps/datanode/browseDirectory.jsp src/webapps/datanode/tail.jsp
Date Wed, 23 May 2007 21:12:51 GMT
Author: cutting
Date: Wed May 23 14:12:50 2007
New Revision: 541082

URL: http://svn.apache.org/viewvc?view=rev&rev=541082
Log:
HADOOP-800.  Improvements to HDFS web-based file browser.  Contributed by Enis Soztutar.

Modified:
    lucene/hadoop/trunk/CHANGES.txt
    lucene/hadoop/trunk/src/java/org/apache/hadoop/dfs/JspHelper.java
    lucene/hadoop/trunk/src/webapps/datanode/browseBlock.jsp
    lucene/hadoop/trunk/src/webapps/datanode/browseDirectory.jsp
    lucene/hadoop/trunk/src/webapps/datanode/tail.jsp

Modified: lucene/hadoop/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/hadoop/trunk/CHANGES.txt?view=diff&rev=541082&r1=541081&r2=541082
==============================================================================
--- lucene/hadoop/trunk/CHANGES.txt (original)
+++ lucene/hadoop/trunk/CHANGES.txt Wed May 23 14:12:50 2007
@@ -63,6 +63,9 @@
  20. HADOOP-1226.  Change HDFS so that paths it returns are always
      fully qualified.  (Dhruba Borthakur via cutting)
 
+ 21. HADOOP-800.  Improvements to HDFS web-based file browser.
+     (Enis Soztutar via cutting)
+
 
 Branch 0.13 (unreleased changes)
 

Modified: lucene/hadoop/trunk/src/java/org/apache/hadoop/dfs/JspHelper.java
URL: http://svn.apache.org/viewvc/lucene/hadoop/trunk/src/java/org/apache/hadoop/dfs/JspHelper.java?view=diff&rev=541082&r1=541081&r2=541082
==============================================================================
--- lucene/hadoop/trunk/src/java/org/apache/hadoop/dfs/JspHelper.java (original)
+++ lucene/hadoop/trunk/src/java/org/apache/hadoop/dfs/JspHelper.java Wed May 23 14:12:50
2007
@@ -25,6 +25,7 @@
 import java.util.*;
 import java.net.*;
 import org.apache.hadoop.dfs.*;
+import org.apache.hadoop.fs.Path;
 import org.apache.hadoop.io.*;
 import org.apache.hadoop.conf.*;
 
@@ -245,4 +246,50 @@
         
     Collections.sort(nodes, new NodeComapare(field, order));
   }
+
+  public static void printPathWithLinks(String dir, JspWriter out, int namenodeInfoPort )
throws IOException {
+    try {
+      String[] parts = dir.split(Path.SEPARATOR);
+      StringBuilder tempPath = new StringBuilder(dir.length());
+      out.print("<a href=\"browseDirectory.jsp" + "?dir="+ Path.SEPARATOR
+          + "&namenodeInfoPort=" + namenodeInfoPort
+          + "\">" + Path.SEPARATOR + "</a>");
+      tempPath.append(Path.SEPARATOR);
+      for (int i = 0; i < parts.length-1; i++) {
+        if (!parts[i].equals("")) {
+          tempPath.append(parts[i]);
+          out.print("<a href=\"browseDirectory.jsp" + "?dir="
+              + tempPath.toString() + "&namenodeInfoPort=" + namenodeInfoPort);
+          out.print("\">" + parts[i] + "</a>" + Path.SEPARATOR);
+          tempPath.append(Path.SEPARATOR);
+        }
+      }
+      if(parts.length > 0) {
+        out.print(parts[parts.length-1]);
+      }
+    }
+    catch (UnsupportedEncodingException ex) {
+      ex.printStackTrace();
+    }
+  }
+
+  public static void printGotoForm(JspWriter out, int namenodeInfoPort, String file) throws
IOException {
+    out.print("<form action=\"browseDirectory.jsp\" method=\"get\" name=\"goto\">");
+    out.print("Goto : ");
+    out.print("<input name=\"dir\" type=\"text\" width=\"50\" id\"dir\" value=\""+ file+"\">");
+    out.print("<input name=\"go\" type=\"submit\" value=\"go\">");
+    out.print("<input name=\"namenodeInfoPort\" type=\"hidden\" "
+        + "value=\"" + namenodeInfoPort  + "\">");
+    out.print("</form>");
+  }
+  
+  public static void createTitle(JspWriter out, 
+      HttpServletRequest req, String  file) throws IOException{
+    if(file == null) file = "";
+    int start = Math.max(0,file.length() - 100);
+    if(start != 0)
+      file = "..." + file.substring(start, file.length());
+    out.print("<title>HDFS:" + file + "</title>");
+  }
+
 }

Modified: lucene/hadoop/trunk/src/webapps/datanode/browseBlock.jsp
URL: http://svn.apache.org/viewvc/lucene/hadoop/trunk/src/webapps/datanode/browseBlock.jsp?view=diff&rev=541082&r1=541081&r2=541082
==============================================================================
--- lucene/hadoop/trunk/src/webapps/datanode/browseBlock.jsp (original)
+++ lucene/hadoop/trunk/src/webapps/datanode/browseBlock.jsp Wed May 23 14:12:50 2007
@@ -94,6 +94,7 @@
     String tailUrl = "http://" + fqdn + ":" +
                      chosenNode.getInfoPort() + 
                  "/tail.jsp?filename=" + URLEncoder.encode(filename, "UTF-8") +
+                 "&namenodeInfoPort=" + namenodeInfoPort +
                  "&chunkSizeToView=" + chunkSizeToView +
                  "&referrer=" + 
           URLEncoder.encode(req.getRequestURL() + "?" + req.getQueryString(),
@@ -209,12 +210,16 @@
       return;
     }
     datanodePort = Integer.parseInt(datanodePortStr);
-
-    out.print("<h2>File: " + filename + "</h2>");
+    out.print("<h3>File: ");
+    JspHelper.printPathWithLinks(filename, out, namenodeInfoPort);
+    out.print("</h3><hr>");
+    String parent = new File(filename).getParent();
+    JspHelper.printGotoForm(out, namenodeInfoPort, parent);
+    out.print("<hr>");
     out.print("<a href=\"http://" + req.getServerName() + ":" + 
               req.getServerPort() + 
               "/browseDirectory.jsp?dir=" + 
-              URLEncoder.encode(new File(filename).getParent(), "UTF-8") +
+              URLEncoder.encode(parent, "UTF-8") +
               "&namenodeInfoPort=" + namenodeInfoPort + 
               "\"><i>Go back to dir listing</i></a><br>");
     out.print("<a href=\"#viewOptions\">Advanced view/download options</a><br>");
@@ -324,7 +329,7 @@
       out.print("<a href=\"" + prevUrl + "\">View Prev chunk</a>&nbsp;&nbsp;");
     }
     out.print("<hr>");
-    out.print("<textarea cols=\"100\" rows=\"25\" wrap=\"virtual\" READONLY>");
+    out.print("<textarea cols=\"100\" rows=\"25\" wrap=\"virtual\" style=\"width:100%\"
READONLY>");
     try {
     jspHelper.streamBlockInAscii(
             new InetSocketAddress(req.getServerName(), datanodePort), blockId, 
@@ -338,10 +343,10 @@
 
 %>
 <html>
-
-<title>Hadoop DFS File Viewer</title>
-
-<body>
+<head>
+<%JspHelper.createTitle(out, request, request.getParameter("filename")); %>
+</head>
+<body onload="document.goto.dir.focus()">
 <% 
    generateFileChunks(out,request);
 %>

Modified: lucene/hadoop/trunk/src/webapps/datanode/browseDirectory.jsp
URL: http://svn.apache.org/viewvc/lucene/hadoop/trunk/src/webapps/datanode/browseDirectory.jsp?view=diff&rev=541082&r1=541081&r2=541082
==============================================================================
--- lucene/hadoop/trunk/src/webapps/datanode/browseDirectory.jsp (original)
+++ lucene/hadoop/trunk/src/webapps/datanode/browseDirectory.jsp Wed May 23 14:12:50 2007
@@ -32,94 +32,103 @@
     
     DFSClient dfs = new DFSClient(jspHelper.nameNodeAddr, jspHelper.conf);
     UTF8 target = new UTF8(dir);
-    if( !dfs.isDirectory(target) ) { // a file
-      List<LocatedBlock> blocks = 
-        dfs.namenode.getBlockLocations(dir, 0, 1).getLocatedBlocks();
-      
-      LocatedBlock firstBlock = blocks.get(0);
-      DatanodeInfo [] locations = firstBlock.getLocations();
-      if (locations.length == 0) {
-        out.print("Empty file");
-      } else {
-        DatanodeInfo chosenNode = jspHelper.bestNode(firstBlock);
-        String fqdn = InetAddress.getByName(chosenNode.getHost()).
-                                  getCanonicalHostName();
-        String datanodeAddr = chosenNode.getName();
-        int datanodePort = Integer.parseInt(
-                                  datanodeAddr.substring(
-                                  datanodeAddr.indexOf(':') + 1, 
-                                  datanodeAddr.length())); 
-        String redirectLocation = "http://"+fqdn+":" +
-                             chosenNode.getInfoPort() + 
-                             "/browseBlock.jsp?blockId=" +
-                             firstBlock.getBlock().getBlockId() +
-                             "&blockSize=" + firstBlock.getBlock().getNumBytes() +
-                             "&filename=" + URLEncoder.encode(dir, "UTF-8") + 
-                             "&datanodePort=" + datanodePort + 
-                             "&namenodeInfoPort=" + namenodeInfoPort;
-        resp.sendRedirect(redirectLocation);
-      }
-      return;
+    if (!dfs.exists(target)) {
+      out.print("<h3>File or directory : " + target + " does not exists</h3>");
+      JspHelper.printGotoForm(out, namenodeInfoPort, target.toString());
     }
-    // directory
-    DFSFileInfo[] files = dfs.listPaths(target);
-    //generate a table and dump the info
-    String [] headings = new String[5];
-    headings[0] = "Name"; headings[1] = "Type"; headings[2] = "Size";
-    headings[3] = "Replication"; headings[4] = "BlockSize";
-    out.print("<h3>Contents of directory " + dir + "</h3><hr>");
-
-    File f = new File(dir);
-    String parent;
-    if ((parent = f.getParent()) != null)
-      out.print("<a href=\"" + req.getRequestURL() + "?dir=" + parent +
-                "&namenodeInfoPort=" + namenodeInfoPort +
-                "\">Go to parent directory</a><br>");
-
-    if (files == null || files.length == 0) {
-      out.print("Empty directory");
-      dfs.close();
-      return;
-    }
-
-    jspHelper.addTableHeader(out);
-    int row=0;
-    jspHelper.addTableRow(out, headings, row++);
-    String cols [] = new String[5];
-    for (int i = 0; i < files.length; i++) {
-      //Get the location of the first block of the file
-      if (files[i].getPath().endsWith(".crc")) continue;
-      if (!files[i].isDir()) {
+    else {
+      if( !dfs.isDirectory(target) ) { // a file
         List<LocatedBlock> blocks = 
-          dfs.namenode.getBlockLocations(files[i].getPath(), 0, 1).getLocatedBlocks();
-        DatanodeInfo [] locations = blocks.get(0).getLocations();
+          dfs.namenode.getBlockLocations(dir, 0, 1).getLocatedBlocks();
+	      
+        LocatedBlock firstBlock = blocks.get(0);
+        DatanodeInfo [] locations = firstBlock.getLocations();
         if (locations.length == 0) {
-          cols[0] = files[i].getName();
+          out.print("Empty file");
         } else {
-        String datanodeUrl = req.getRequestURL()+"?dir="+
-            URLEncoder.encode(files[i].getPath(), "UTF-8") + 
+          DatanodeInfo chosenNode = jspHelper.bestNode(firstBlock);
+          String fqdn = InetAddress.getByName(chosenNode.getHost()).
+            getCanonicalHostName();
+          String datanodeAddr = chosenNode.getName();
+          int datanodePort = Integer.parseInt(
+                                              datanodeAddr.substring(
+                                                                     datanodeAddr.indexOf(':')
+ 1, 
+                                                                     datanodeAddr.length()));

+          String redirectLocation = "http://"+fqdn+":" +
+            chosenNode.getInfoPort() + 
+            "/browseBlock.jsp?blockId=" +
+            firstBlock.getBlock().getBlockId() +
+            "&blockSize=" + firstBlock.getBlock().getNumBytes() +
+            "&filename=" + URLEncoder.encode(dir, "UTF-8") + 
+            "&datanodePort=" + datanodePort + 
             "&namenodeInfoPort=" + namenodeInfoPort;
-            
-        cols[0] = "<a href=\""+datanodeUrl+"\">"+files[i].getName()+"</a>";
+          resp.sendRedirect(redirectLocation);
         }
-        cols[1] = "file";
-        cols[2] = FsShell.byteDesc(files[i].getLen());
-        cols[3] = Short.toString(files[i].getReplication());
-        cols[4] = FsShell.byteDesc(files[i].getBlockSize());
+        return;
+      }
+      // directory
+      DFSFileInfo[] files = dfs.listPaths(target);
+      //generate a table and dump the info
+      String [] headings = new String[5];
+      headings[0] = "Name"; headings[1] = "Type"; headings[2] = "Size";
+      headings[3] = "Replication"; headings[4] = "BlockSize";
+      out.print("<h3>Contents of directory ");
+      JspHelper.printPathWithLinks(dir, out, namenodeInfoPort);
+      out.print("</h3><hr>");
+      JspHelper.printGotoForm(out, namenodeInfoPort, dir);
+      out.print("<hr>");
+	
+      File f = new File(dir);
+      String parent;
+      if ((parent = f.getParent()) != null)
+        out.print("<a href=\"" + req.getRequestURL() + "?dir=" + parent +
+                  "&namenodeInfoPort=" + namenodeInfoPort +
+                  "\">Go to parent directory</a><br>");
+	
+      if (files == null || files.length == 0) {
+        out.print("Empty directory");
       }
       else {
-        String datanodeUrl = req.getRequestURL()+"?dir="+
-            URLEncoder.encode(files[i].getPath(), "UTF-8") + 
-            "&namenodeInfoPort=" + namenodeInfoPort;
-        cols[0] = "<a href=\""+datanodeUrl+"\">"+files[i].getName()+"</a>";
-        cols[1] = "dir";
-        cols[2] = "";
-        cols[3] = "";
-        cols[4] = "";
+        jspHelper.addTableHeader(out);
+        int row=0;
+        jspHelper.addTableRow(out, headings, row++);
+        String cols [] = new String[5];
+        for (int i = 0; i < files.length; i++) {
+          //Get the location of the first block of the file
+          if (files[i].getPath().endsWith(".crc")) continue;
+          if (!files[i].isDir()) {
+            List<LocatedBlock> blocks = 
+              dfs.namenode.getBlockLocations(files[i].getPath(), 0, 1).getLocatedBlocks();
+            DatanodeInfo [] locations = blocks.get(0).getLocations();
+            if (locations.length == 0) {
+              cols[0] = files[i].getName();
+            } else {
+              String datanodeUrl = req.getRequestURL()+"?dir="+
+                URLEncoder.encode(files[i].getPath(), "UTF-8") + 
+                "&namenodeInfoPort=" + namenodeInfoPort;
+		            
+              cols[0] = "<a href=\""+datanodeUrl+"\">"+files[i].getName()+"</a>";
+            }
+            cols[1] = "file";
+            cols[2] = FsShell.byteDesc(files[i].getLen());
+            cols[3] = Short.toString(files[i].getReplication());
+            cols[4] = FsShell.byteDesc(files[i].getBlockSize());
+          }
+          else {
+            String datanodeUrl = req.getRequestURL()+"?dir="+
+              URLEncoder.encode(files[i].getPath(), "UTF-8") + 
+              "&namenodeInfoPort=" + namenodeInfoPort;
+            cols[0] = "<a href=\""+datanodeUrl+"\">"+files[i].getName()+"</a>";
+            cols[1] = "dir";
+            cols[2] = "";
+            cols[3] = "";
+            cols[4] = "";
+          }
+          jspHelper.addTableRow(out, cols, row++);
+        }
+        jspHelper.addTableFooter(out);
       }
-      jspHelper.addTableRow(out, cols, row++);
-    }
-    jspHelper.addTableFooter(out);
+    } 
     String namenodeHost = jspHelper.nameNodeAddr.getHostName();
     out.print("<br><a href=\"http://" + 
               InetAddress.getByName(namenodeHost).getCanonicalHostName() + ":" +
@@ -130,19 +139,19 @@
 %>
 
 <html>
-<HEAD>
-<STYLE TYPE=text/css>
+<head>
+<style type=text/css>
 <!--
-BODY 
+body 
   {
   font-face:sanserif;
   }
 -->
-</STYLE>
-<title>Hadoop DFS Directory Browsing</title>
-</HEAD>
+</style>
+<%JspHelper.createTitle(out, request, request.getParameter("dir")); %>
+</head>
 
-<body>
+<body onload="document.goto.dir.focus()">
 <% 
    generateDirectoryStructure(out,request,response);
 %>

Modified: lucene/hadoop/trunk/src/webapps/datanode/tail.jsp
URL: http://svn.apache.org/viewvc/lucene/hadoop/trunk/src/webapps/datanode/tail.jsp?view=diff&rev=541082&r1=541081&r2=541082
==============================================================================
--- lucene/hadoop/trunk/src/webapps/datanode/tail.jsp (original)
+++ lucene/hadoop/trunk/src/webapps/datanode/tail.jsp Wed May 23 14:12:50 2007
@@ -33,21 +33,33 @@
       return;
     }
 
+    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;
 
-    if (!noLink)
-      out.print("<h2><a href=\"" + referrer + "\">" + filename + "</a></h2>");
-    else
-      out.print("<h2>" + filename + "</h2>");
+    if (!noLink) {
+      out.print("<h3>Tail of File: ");
+      JspHelper.printPathWithLinks(filename, out, namenodeInfoPort);
+	    out.print("</h3><hr>");
+      out.print("<a href=\"" + referrer + "\">Go Back to File View</a><hr>");
+    }
+    else {
+      out.print("<h3>" + filename + "</h3>");
+    }
     out.print("<b>Chunk Size to view (in bytes, upto file's DFS blocksize): </b>");
     out.print("<input type=\"text\" name=\"chunkSizeToView\" value=" +
               chunkSizeToView + " size=10 maxlength=10>");
     out.print("&nbsp;&nbsp;<input type=\"submit\" name=\"submit\" value=\"Refresh\"><hr>");
     out.print("<input type=\"hidden\" name=\"filename\" value=\"" + filename +
               "\">");
+    out.print("<input type=\"hidden\" name=\"namenodeInfoPort\" value=\"" + namenodeInfoPort
+
+    "\">");
     if (!noLink)
       out.print("<input type=\"hidden\" name=\"referrer\" value=\"" + 
                 referrer+ "\">");
@@ -79,7 +91,7 @@
       startOffset = blockSize - chunkSizeToView;
     else startOffset = 0;
 
-    out.print("<textarea cols=\"100\" rows=\"25\" wrap=\"virtual\" READONLY>");
+    out.print("<textarea cols=\"100\" rows=\"25\" wrap=\"virtual\" style=\"width:100%\"
READONLY>");
     jspHelper.streamBlockInAscii(addr, blockId, blockSize, startOffset, chunkSizeToView,
out);
     out.print("</textarea>");
     dfs.close();
@@ -90,11 +102,11 @@
 
 
 <html>
-<meta http-equiv="refresh" content=60>
-<title>Hadoop DFS File Viewer</title>
-
+<head>
+<%JspHelper.createTitle(out, request, request.getParameter("filename")); %>
+</head>
 <body>
-<form action="/tail.jsp" method=GET>
+<form action="/tail.jsp" method="GET">
 <% 
    generateFileChunks(out,request);
 %>



Mime
View raw message