hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cutt...@apache.org
Subject svn commit: r474949 - in /lucene/hadoop/trunk: CHANGES.txt conf/hadoop-default.xml src/java/org/apache/hadoop/dfs/JspHelper.java src/webapps/dfs/browseDirectory.jsp
Date Tue, 14 Nov 2006 20:30:49 GMT
Author: cutting
Date: Tue Nov 14 12:30:48 2006
New Revision: 474949

URL: http://svn.apache.org/viewvc?view=rev&rev=474949
Log:
HADOOP-668.  Improvements to the web-based DFS browser.  Contributed by Hairong.

Modified:
    lucene/hadoop/trunk/CHANGES.txt
    lucene/hadoop/trunk/conf/hadoop-default.xml
    lucene/hadoop/trunk/src/java/org/apache/hadoop/dfs/JspHelper.java
    lucene/hadoop/trunk/src/webapps/dfs/browseDirectory.jsp

Modified: lucene/hadoop/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/hadoop/trunk/CHANGES.txt?view=diff&rev=474949&r1=474948&r2=474949
==============================================================================
--- lucene/hadoop/trunk/CHANGES.txt (original)
+++ lucene/hadoop/trunk/CHANGES.txt Tue Nov 14 12:30:48 2006
@@ -70,6 +70,9 @@
 21. HADOOP-712.  Fix record io's xml serialization to correctly handle
     control-characters.  (Milind Bhandarkar via cutting)
 
+22. HADOOP-668.  Improvements to the web-based DFS browser.
+    (Hairong Kuang via cutting)
+
 
 Release 0.8.0 - 2006-11-03
 

Modified: lucene/hadoop/trunk/conf/hadoop-default.xml
URL: http://svn.apache.org/viewvc/lucene/hadoop/trunk/conf/hadoop-default.xml?view=diff&rev=474949&r1=474948&r2=474949
==============================================================================
--- lucene/hadoop/trunk/conf/hadoop-default.xml (original)
+++ lucene/hadoop/trunk/conf/hadoop-default.xml Tue Nov 14 12:30:48 2006
@@ -153,7 +153,7 @@
  
 <property>
   <name>dfs.default.chunk.view.size</name>
-  <value>2048</value>
+  <value>32768</value>
   <description>The number of bytes to view for a file on the browser.
   </description>
 </property>

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=474949&r1=474948&r2=474949
==============================================================================
--- lucene/hadoop/trunk/src/java/org/apache/hadoop/dfs/JspHelper.java (original)
+++ lucene/hadoop/trunk/src/java/org/apache/hadoop/dfs/JspHelper.java Tue Nov 14 12:30:48
2006
@@ -34,7 +34,7 @@
     static Configuration conf = new Configuration();
 
     static int defaultChunkSizeToView = 
-                        conf.getInt("dfs.default.chunk.view.size",2 * 1024);
+                        conf.getInt("dfs.default.chunk.view.size",32 * 1024);
     static Random rand = new Random();
 
     public JspHelper() {
@@ -160,6 +160,19 @@
       out.print("<tr>");
       for (int i = 0; i < columns.length; i++) {
         out.print("<td style=\"vertical-align: top;\"><B>"+columns[i]+"</B><br></td>");
+      }
+      out.print("</tr>");
+    }
+    public void addTableRow(JspWriter out, String[] columns, int row) throws IOException
{
+      out.print("<tr>");
+      
+      for (int i = 0; i < columns.length; i++) {
+        if( row/2*2 == row ) {//even
+          out.print("<td style=\"vertical-align: top;background-color:LightGrey;\"><B>"+columns[i]+"</B><br></td>");
+        } else {
+          out.print("<td style=\"vertical-align: top;background-color:LightBlue;\"><B>"+columns[i]+"</B><br></td>");
+          
+        }
       }
       out.print("</tr>");
     }

Modified: lucene/hadoop/trunk/src/webapps/dfs/browseDirectory.jsp
URL: http://svn.apache.org/viewvc/lucene/hadoop/trunk/src/webapps/dfs/browseDirectory.jsp?view=diff&rev=474949&r1=474948&r2=474949
==============================================================================
--- lucene/hadoop/trunk/src/webapps/dfs/browseDirectory.jsp (original)
+++ lucene/hadoop/trunk/src/webapps/dfs/browseDirectory.jsp Tue Nov 14 12:30:48 2006
@@ -13,21 +13,51 @@
 <%!
   static JspHelper jspHelper = new JspHelper();
   
-  public void generateDirectoryStructure(JspWriter out, HttpServletRequest req) 
+  public void generateDirectoryStructure( JspWriter out, 
+                                          HttpServletRequest req,
+                                          HttpServletResponse resp) 
     throws IOException {
     String dir = req.getParameter("dir");
     if (dir == null || dir.length() == 0) {
       out.print("Invalid input");
       return;
     }
-
+    
     String namenodeInfoPortStr = req.getParameter("namenodeInfoPort");
     int namenodeInfoPort = -1;
     if (namenodeInfoPortStr != null)
       namenodeInfoPort = Integer.parseInt(namenodeInfoPortStr);
     
     DFSClient dfs = new DFSClient(jspHelper.nameNodeAddr, jspHelper.conf);
-    DFSFileInfo[] files = dfs.listPaths(new UTF8(dir));
+    UTF8 target = new UTF8(dir);
+    if( !dfs.isDirectory(target) ) { // a file
+      LocatedBlock[] blocks = dfs.namenode.open(dir);
+      DatanodeInfo [] locations = blocks[0].getLocations();
+      if (locations.length == 0) {
+        out.print("Empty file");
+      } else {
+        DatanodeInfo chosenNode = jspHelper.bestNode(blocks[0]);
+        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=" +
+                             blocks[0].getBlock().getBlockId() +
+                             "&blockSize=" + blocks[0].getBlock().getNumBytes() +
+                             "&filename=" + URLEncoder.encode(dir, "UTF-8") + 
+                             "&datanodePort=" + datanodePort + 
+                             "&namenodeInfoPort=" + namenodeInfoPort;
+        resp.sendRedirect(redirectLocation);
+      }
+      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";
@@ -48,7 +78,8 @@
     }
 
     jspHelper.addTableHeader(out);
-    jspHelper.addTableRow(out, headings);
+    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
@@ -57,47 +88,30 @@
         LocatedBlock[] blocks = dfs.namenode.open(files[i].getPath());
         DatanodeInfo [] locations = blocks[0].getLocations();
         if (locations.length == 0) {
-          cols[0] = files[i].getPath();
-          cols[1] = "file";
-          cols[2] = Long.toString(files[i].getLen());
-          cols[3] = Short.toString(files[i].getReplication());
-          cols[4] = Long.toString(files[i].getBlockSize());
-          jspHelper.addTableRow(out, cols);
-          continue;
+          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>";
         }
-        DatanodeInfo chosenNode = jspHelper.bestNode(blocks[0]);
-        String fqdn = InetAddress.getByName(chosenNode.getHost()).getCanonicalHostName();
-        String datanodeAddr = chosenNode.getName();
-        int datanodePort = Integer.parseInt(
-                                  datanodeAddr.substring(
-                                        datanodeAddr.indexOf(':') + 1, 
-                                  datanodeAddr.length())); 
-        String datanodeUrl = "http://"+fqdn+":" +
-                             chosenNode.getInfoPort() + 
-                             "/browseBlock.jsp?blockId=" +
-                             blocks[0].getBlock().getBlockId() +
-                             "&blockSize=" + files[i].getBlockSize() +
-               "&filename=" + URLEncoder.encode(files[i].getPath(), "UTF-8") + 
-                             "&datanodePort=" + datanodePort + 
-                             "&namenodeInfoPort=" + namenodeInfoPort;
-        cols[0] = "<a href=\""+datanodeUrl+"\">"+files[i].getPath()+"</a>";
         cols[1] = "file";
-        cols[2] = Long.toString(files[i].getLen());
+        cols[2] = DFSShell.byteDesc(files[i].getLen());
         cols[3] = Short.toString(files[i].getReplication());
-        cols[4] = Long.toString(files[i].getBlockSize());
-        jspHelper.addTableRow(out, cols);
+        cols[4] = DFSShell.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].getPath()+"</a>";
+        cols[0] = "<a href=\""+datanodeUrl+"\">"+files[i].getName()+"</a>";
         cols[1] = "dir";
-        cols[2] = "0";
-        cols[3] = Short.toString(files[i].getReplication());
-        cols[4] = Long.toString(files[i].getBlockSize());
-        jspHelper.addTableRow(out, cols);
+        cols[2] = "";
+        cols[3] = "";
+        cols[4] = "";
       }
+      jspHelper.addTableRow(out, cols, row++);
     }
     jspHelper.addTableFooter(out);
     String namenodeHost = jspHelper.nameNodeAddr.getHostName();
@@ -110,13 +124,21 @@
 %>
 
 <html>
-
+<HEAD>
+<STYLE TYPE=text/css>
+<!--
+BODY 
+  {
+  font-face:sanserif;
+  }
+-->
+</STYLE>
 <title>Hadoop DFS Directory Browsing</title>
+</HEAD>
 
 <body>
-
 <% 
-   generateDirectoryStructure(out,request);
+   generateDirectoryStructure(out,request,response);
 %>
 <hr>
 



Mime
View raw message