hadoop-hdfs-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From t...@apache.org
Subject svn commit: r1125213 - in /hadoop/hdfs/branches/branch-0.22: ./ src/java/org/apache/hadoop/hdfs/server/common/ src/java/org/apache/hadoop/hdfs/server/datanode/ src/test/hdfs/org/apache/hadoop/hdfs/server/datanode/
Date Fri, 20 May 2011 03:14:36 GMT
Author: todd
Date: Fri May 20 03:14:35 2011
New Revision: 1125213

URL: http://svn.apache.org/viewvc?rev=1125213&view=rev
Log:
HDFS-1575. Viewing block from web UI is broken. Contributed by Aaron T. Myers.

Added:
    hadoop/hdfs/branches/branch-0.22/src/test/hdfs/org/apache/hadoop/hdfs/server/datanode/TestDatanodeJsp.java
Modified:
    hadoop/hdfs/branches/branch-0.22/CHANGES.txt
    hadoop/hdfs/branches/branch-0.22/src/java/org/apache/hadoop/hdfs/server/common/JspHelper.java
    hadoop/hdfs/branches/branch-0.22/src/java/org/apache/hadoop/hdfs/server/datanode/DataNode.java
    hadoop/hdfs/branches/branch-0.22/src/java/org/apache/hadoop/hdfs/server/datanode/DatanodeJspHelper.java

Modified: hadoop/hdfs/branches/branch-0.22/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/hdfs/branches/branch-0.22/CHANGES.txt?rev=1125213&r1=1125212&r2=1125213&view=diff
==============================================================================
--- hadoop/hdfs/branches/branch-0.22/CHANGES.txt (original)
+++ hadoop/hdfs/branches/branch-0.22/CHANGES.txt Fri May 20 03:14:35 2011
@@ -524,6 +524,8 @@ Release 0.22.0 - Unreleased
     HDFS-1925. SafeModeInfo should use the correct constant instead of a
     hard-coded value for its default. (Joey Echeverria via todd)
 
+    HDFS-1575. Viewing block from web UI is broken. (Aaron T. Myers via todd)
+
 Release 0.21.1 - Unreleased
 
   IMPROVEMENTS

Modified: hadoop/hdfs/branches/branch-0.22/src/java/org/apache/hadoop/hdfs/server/common/JspHelper.java
URL: http://svn.apache.org/viewvc/hadoop/hdfs/branches/branch-0.22/src/java/org/apache/hadoop/hdfs/server/common/JspHelper.java?rev=1125213&r1=1125212&r2=1125213&view=diff
==============================================================================
--- hadoop/hdfs/branches/branch-0.22/src/java/org/apache/hadoop/hdfs/server/common/JspHelper.java
(original)
+++ hadoop/hdfs/branches/branch-0.22/src/java/org/apache/hadoop/hdfs/server/common/JspHelper.java
Fri May 20 03:14:35 2011
@@ -535,5 +535,41 @@ public class JspHelper {
     }
   }
 
+  /**
+   * Returns the url parameter for the given string, prefixed with
+   * paramSeparator.
+   * 
+   * @param name parameter name
+   * @param val parameter value
+   * @param paramSeparator URL parameter prefix, i.e. either '?' or '&'
+   * @return url parameter
+   */
+  public static String getUrlParam(String name, String val, String paramSeparator) {
+    return val == null ? "" : paramSeparator + name + "=" + val;
+  }
+
+  /**
+   * Returns the url parameter for the given string, prefixed with '?' if
+   * firstParam is true, prefixed with '&' if firstParam is false.
+   * 
+   * @param name parameter name
+   * @param val parameter value
+   * @param firstParam true if this is the first parameter in the list, false otherwise
+   * @return url parameter
+   */
+  public static String getUrlParam(String name, String val, boolean firstParam) {
+    return getUrlParam(name, val, firstParam ? "?" : "&");
+  }
+        
+  /**
+   * Returns the url parameter for the given string, prefixed with '&'.
+   *
+   * @param name parameter name
+   * @param val parameter value
+   * @return url parameter
+   */
+  public static String getUrlParam(String name, String val) {
+    return getUrlParam(name, val, false);
+  }
 
 }

Modified: hadoop/hdfs/branches/branch-0.22/src/java/org/apache/hadoop/hdfs/server/datanode/DataNode.java
URL: http://svn.apache.org/viewvc/hadoop/hdfs/branches/branch-0.22/src/java/org/apache/hadoop/hdfs/server/datanode/DataNode.java?rev=1125213&r1=1125212&r2=1125213&view=diff
==============================================================================
--- hadoop/hdfs/branches/branch-0.22/src/java/org/apache/hadoop/hdfs/server/datanode/DataNode.java
(original)
+++ hadoop/hdfs/branches/branch-0.22/src/java/org/apache/hadoop/hdfs/server/datanode/DataNode.java
Fri May 20 03:14:35 2011
@@ -1971,6 +1971,10 @@ public class DataNode extends Configured
     return this.getConf().get("dfs.datanode.info.port");
   }
 
+  public int getInfoPort() {
+    return this.infoServer.getPort();
+  }
+
   @Override // DataNodeMXBean
   public String getNamenodeAddress(){
     return nameNodeAddr.getHostName();

Modified: hadoop/hdfs/branches/branch-0.22/src/java/org/apache/hadoop/hdfs/server/datanode/DatanodeJspHelper.java
URL: http://svn.apache.org/viewvc/hadoop/hdfs/branches/branch-0.22/src/java/org/apache/hadoop/hdfs/server/datanode/DatanodeJspHelper.java?rev=1125213&r1=1125212&r2=1125213&view=diff
==============================================================================
--- hadoop/hdfs/branches/branch-0.22/src/java/org/apache/hadoop/hdfs/server/datanode/DatanodeJspHelper.java
(original)
+++ hadoop/hdfs/branches/branch-0.22/src/java/org/apache/hadoop/hdfs/server/datanode/DatanodeJspHelper.java
Fri May 20 03:14:35 2011
@@ -30,6 +30,7 @@ import javax.servlet.http.HttpServletReq
 import javax.servlet.http.HttpServletResponse;
 import javax.servlet.jsp.JspWriter;
 
+import org.apache.commons.lang.StringEscapeUtils;
 import org.apache.hadoop.classification.InterfaceAudience;
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.fs.FsShell;
@@ -46,6 +47,7 @@ import org.apache.hadoop.net.NetUtils;
 import org.apache.hadoop.security.UserGroupInformation;
 import org.apache.hadoop.security.token.Token;
 import org.apache.hadoop.util.StringUtils;
+import org.mortbay.util.URIUtil;
 
 @InterfaceAudience.Private
 public class DatanodeJspHelper {
@@ -79,7 +81,8 @@ public class DatanodeJspHelper {
                                          Configuration conf
                                          ) throws IOException,
                                                   InterruptedException {
-    final String dir = JspHelper.validatePath(req.getParameter("dir"));
+    final String dir = StringEscapeUtils.unescapeHtml(
+        JspHelper.validatePath(req.getParameter("dir")));
     if (dir == null) {
       out.print("Invalid input");
       return;
@@ -238,9 +241,11 @@ public class DatanodeJspHelper {
     else
       startOffset = Long.parseLong(startOffsetStr);
 
-    final String filename=JspHelper.validatePath(
-                          req.getPathInfo() == null ? 
-                          "/" : req.getPathInfo());
+    String path = StringEscapeUtils.unescapeHtml(req.getParameter("filename"));
+    if (path == null) {
+      path = req.getPathInfo() == null ? "/" : req.getPathInfo();
+    }
+    final String filename = JspHelper.validatePath(path);
     if (filename == null) {
       out.print("Invalid input");
       return;
@@ -260,8 +265,7 @@ public class DatanodeJspHelper {
     // 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")
+        + req.getServerPort() + "/streamFile" + URIUtil.encodePath(filename)
         + JspHelper.getDelegationTokenUrlParam(tokenString);
     out.print("<a name=\"viewOptions\"></a>");
     out.print("<a href=\"" + downloadUrl + "\">Download this file</a><br>");
@@ -367,7 +371,7 @@ public class DatanodeJspHelper {
       namenodeInfoPort = Integer.parseInt(namenodeInfoPortStr);
 
     final String filename = JspHelper
-        .validatePath(req.getParameter("filename"));
+        .validatePath(StringEscapeUtils.unescapeHtml(req.getParameter("filename")));
     if (filename == null) {
       out.print("Invalid input (filename absent)");
       return;
@@ -382,16 +386,19 @@ public class DatanodeJspHelper {
     final DFSClient dfs = getDFSClient(ugi, datanode.getNameNodeAddrForClient(), conf);
 
     Token<BlockTokenIdentifier> blockToken = BlockTokenSecretManager.DUMMY_TOKEN;
-    if (conf.getBoolean(
-        DFSConfigKeys.DFS_BLOCK_ACCESS_TOKEN_ENABLE_KEY, 
-        DFSConfigKeys.DFS_BLOCK_ACCESS_TOKEN_ENABLE_DEFAULT)) {
-      List<LocatedBlock> blks = dfs.getNamenode().getBlockLocations(filename, 0,
+    List<LocatedBlock> blks = dfs.getNamenode().getBlockLocations(filename, 0,
           Long.MAX_VALUE).getLocatedBlocks();
-      if (blks == null || blks.size() == 0) {
-        out.print("Can't locate file blocks");
-        dfs.close();
-        return;
-      }
+    if (blks == null || blks.size() == 0) {
+      out.print("Can't locate file blocks");
+      dfs.close();
+      return;
+    }
+
+    boolean needBlockToken = conf.getBoolean(
+            DFSConfigKeys.DFS_BLOCK_ACCESS_TOKEN_ENABLE_KEY,
+            DFSConfigKeys.DFS_BLOCK_ACCESS_TOKEN_ENABLE_DEFAULT);
+
+    if (needBlockToken) {
       for (int i = 0; i < blks.size(); i++) {
         if (blks.get(i).getBlock().getBlockId() == blockId) {
           blockToken = blks.get(i).getBlockToken();
@@ -579,7 +586,7 @@ public class DatanodeJspHelper {
     }
 
     final String filename = JspHelper
-        .validatePath(req.getParameter("filename"));
+        .validatePath(req.getParameter(StringEscapeUtils.unescapeHtml("filename")));
     if (filename == null) {
       out.print("Invalid input (file name absent)");
       return;

Added: hadoop/hdfs/branches/branch-0.22/src/test/hdfs/org/apache/hadoop/hdfs/server/datanode/TestDatanodeJsp.java
URL: http://svn.apache.org/viewvc/hadoop/hdfs/branches/branch-0.22/src/test/hdfs/org/apache/hadoop/hdfs/server/datanode/TestDatanodeJsp.java?rev=1125213&view=auto
==============================================================================
--- hadoop/hdfs/branches/branch-0.22/src/test/hdfs/org/apache/hadoop/hdfs/server/datanode/TestDatanodeJsp.java
(added)
+++ hadoop/hdfs/branches/branch-0.22/src/test/hdfs/org/apache/hadoop/hdfs/server/datanode/TestDatanodeJsp.java
Fri May 20 03:14:35 2011
@@ -0,0 +1,80 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.hdfs.server.datanode;
+
+import static org.junit.Assert.assertTrue;
+
+import java.io.IOException;
+import java.net.InetSocketAddress;
+import java.net.URL;
+import java.net.URLEncoder;
+
+import org.apache.commons.httpclient.util.URIUtil;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.fs.FileSystem;
+import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.hdfs.DFSTestUtil;
+import org.apache.hadoop.hdfs.HdfsConfiguration;
+import org.apache.hadoop.hdfs.MiniDFSCluster;
+import org.apache.hadoop.hdfs.server.common.JspHelper;
+import org.junit.Test;
+
+public class TestDatanodeJsp {
+
+  private static final String FILE_DATA = "foo bar baz biz buz";
+
+  private static void testViewingFile(MiniDFSCluster cluster, String filePath) throws IOException
{
+    FileSystem fs = cluster.getFileSystem();
+
+    Path testPath = new Path(filePath);
+    DFSTestUtil.writeFile(fs, testPath, FILE_DATA);
+
+    InetSocketAddress nnHttpAddress = cluster.getNameNode().getHttpAddress();
+    int dnInfoPort = cluster.getDataNodes().get(0).getInfoPort();
+
+    URL url = new URL("http://localhost:" + dnInfoPort + "/browseDirectory.jsp" +
+        JspHelper.getUrlParam("dir", URLEncoder.encode(testPath.toString(), "UTF-8"), true)
+
+        JspHelper.getUrlParam("namenodeInfoPort", Integer.toString(nnHttpAddress.getPort())));
+
+    String viewFilePage = DFSTestUtil.urlGet(url);
+
+    assertTrue("page should show preview of file contents", viewFilePage.contains(FILE_DATA));
+    assertTrue("page should show link to download file", viewFilePage
+        .contains("/streamFile" + URIUtil.encodePath(testPath.toString())));
+  }
+
+  @Test
+  public void testViewFileJsp() throws IOException {
+    MiniDFSCluster cluster = null;
+    try {
+      Configuration conf = new HdfsConfiguration();
+      cluster = new MiniDFSCluster.Builder(conf).build();
+      cluster.waitActive();
+
+      testViewingFile(cluster, "/test-file");
+      testViewingFile(cluster, "/tmp/test-file");
+      testViewingFile(cluster, "/tmp/test-file%with goofy&characters");
+
+    } finally {
+      if (cluster != null) {
+        cluster.shutdown();
+      }
+    }
+  }
+
+}



Mime
View raw message