浏览代码

Fix HDFS-2235 FI test failure.

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1156972 13f79535-47bb-0310-9956-ffa450edef68
Eli Collins 14 年之前
父节点
当前提交
8061bb59c0

+ 1 - 3
hdfs/src/java/org/apache/hadoop/hdfs/server/namenode/FileChecksumServlets.java

@@ -59,7 +59,7 @@ public class FileChecksumServlets {
     /** Create a redirection URL */
     /** Create a redirection URL */
     private URL createRedirectURL(UserGroupInformation ugi, DatanodeID host,
     private URL createRedirectURL(UserGroupInformation ugi, DatanodeID host,
         HttpServletRequest request, NameNode nn) 
         HttpServletRequest request, NameNode nn) 
-        throws IOException, URISyntaxException {
+        throws IOException {
       final String hostname = host instanceof DatanodeInfo 
       final String hostname = host instanceof DatanodeInfo 
           ? ((DatanodeInfo)host).getHostName() : host.getHost();
           ? ((DatanodeInfo)host).getHostName() : host.getHost();
       final String scheme = request.getScheme();
       final String scheme = request.getScheme();
@@ -94,8 +94,6 @@ public class FileChecksumServlets {
       try {
       try {
         response.sendRedirect(
         response.sendRedirect(
             createRedirectURL(ugi, datanode, request, namenode).toString());
             createRedirectURL(ugi, datanode, request, namenode).toString());
-      } catch(URISyntaxException e) {
-        throw new ServletException(e); 
       } catch (IOException e) {
       } catch (IOException e) {
         response.sendError(400, e.getMessage());
         response.sendError(400, e.getMessage());
       }
       }

+ 3 - 7
hdfs/src/java/org/apache/hadoop/hdfs/server/namenode/FileDataServlet.java

@@ -48,7 +48,7 @@ public class FileDataServlet extends DfsServlet {
   /** Create a redirection URL */
   /** Create a redirection URL */
   private URL createRedirectURL(String path, String encodedPath, HdfsFileStatus status, 
   private URL createRedirectURL(String path, String encodedPath, HdfsFileStatus status, 
       UserGroupInformation ugi, ClientProtocol nnproxy, HttpServletRequest request, String dt)
       UserGroupInformation ugi, ClientProtocol nnproxy, HttpServletRequest request, String dt)
-      throws IOException, URISyntaxException {
+      throws IOException {
     String scheme = request.getScheme();
     String scheme = request.getScheme();
     final LocatedBlocks blks = nnproxy.getBlockLocations(
     final LocatedBlocks blks = nnproxy.getBlockLocations(
         status.getFullPath(new Path(path)).toUri().getPath(), 0, 1);
         status.getFullPath(new Path(path)).toUri().getPath(), 0, 1);
@@ -121,12 +121,8 @@ public class FileDataServlet extends DfsServlet {
 
 
           HdfsFileStatus info = nn.getFileInfo(path);
           HdfsFileStatus info = nn.getFileInfo(path);
           if (info != null && !info.isDir()) {
           if (info != null && !info.isDir()) {
-            try {
-              response.sendRedirect(createRedirectURL(path, encodedPath, 
-                  info, ugi, nn, request, delegationToken).toString());
-            } catch (URISyntaxException e) {
-              response.getWriter().println(e.toString());
-            }
+            response.sendRedirect(createRedirectURL(path, encodedPath,
+                info, ugi, nn, request, delegationToken).toString());
           } else if (info == null) {
           } else if (info == null) {
             response.sendError(400, "File not found " + path);
             response.sendError(400, "File not found " + path);
           } else {
           } else {

+ 10 - 11
hdfs/src/test/aop/org/apache/hadoop/hdfs/server/namenode/FileDataServletAspects.aj

@@ -17,8 +17,8 @@
  */
  */
 package org.apache.hadoop.hdfs.server.namenode;
 package org.apache.hadoop.hdfs.server.namenode;
 
 
-import java.net.URI;
-import java.net.URISyntaxException;
+import java.net.URL;
+import java.io.IOException;
 
 
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletRequest;
 
 
@@ -30,18 +30,17 @@ import org.apache.hadoop.security.UserGroupInformation;
 public aspect FileDataServletAspects {
 public aspect FileDataServletAspects {
   static final Log LOG = FileDataServlet.LOG;
   static final Log LOG = FileDataServlet.LOG;
 
 
-  pointcut callCreateUri() : call (URI FileDataServlet.createUri(
-      String, HdfsFileStatus, UserGroupInformation, ClientProtocol,
+  pointcut callCreateUrl() : call (URL FileDataServlet.createRedirectURL(
+      String, String, HdfsFileStatus, UserGroupInformation, ClientProtocol,
       HttpServletRequest, String));
       HttpServletRequest, String));
 
 
   /** Replace host name with "localhost" for unit test environment. */
   /** Replace host name with "localhost" for unit test environment. */
-  URI around () throws URISyntaxException : callCreateUri() {
-    final URI original = proceed(); 
-    LOG.info("FI: original uri = " + original);
-    final URI replaced = new URI(original.getScheme(), original.getUserInfo(),
-        "localhost", original.getPort(), original.getPath(),
-        original.getQuery(), original.getFragment()) ; 
-    LOG.info("FI: replaced uri = " + replaced);
+  URL around () throws IOException : callCreateUrl() {
+    final URL original = proceed();
+    LOG.info("FI: original url = " + original);
+    final URL replaced = new URL("http", "localhost", original.getPort(),
+        original.getPath() + '?' + original.getQuery());
+    LOG.info("FI: replaced url = " + replaced);
     return replaced;
     return replaced;
   }
   }
 }
 }