Fix HDFS-2235 FI test failure.

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1156972 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Eli Collins 2011-08-12 05:51:50 +00:00
parent 4673ab17b0
commit 8061bb59c0
3 changed files with 14 additions and 21 deletions

View File

@ -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());
} }

View File

@ -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, response.sendRedirect(createRedirectURL(path, encodedPath,
info, ugi, nn, request, delegationToken).toString()); info, ugi, nn, request, delegationToken).toString());
} catch (URISyntaxException e) {
response.getWriter().println(e.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 {

View File

@ -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.URL;
import java.net.URISyntaxException; 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( pointcut callCreateUrl() : call (URL FileDataServlet.createRedirectURL(
String, HdfsFileStatus, UserGroupInformation, ClientProtocol, 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() { URL around () throws IOException : callCreateUrl() {
final URI original = proceed(); final URL original = proceed();
LOG.info("FI: original uri = " + original); LOG.info("FI: original url = " + original);
final URI replaced = new URI(original.getScheme(), original.getUserInfo(), final URL replaced = new URL("http", "localhost", original.getPort(),
"localhost", original.getPort(), original.getPath(), original.getPath() + '?' + original.getQuery());
original.getQuery(), original.getFragment()) ; LOG.info("FI: replaced url = " + replaced);
LOG.info("FI: replaced uri = " + replaced);
return replaced; return replaced;
} }
} }