HDFS-3404. Make putImage in GetImageServlet infer remote address to fetch from request. Contributed by Aaron T. Myers.

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/branch-2@1337756 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Aaron Myers 2012-05-13 02:57:41 +00:00
parent a5da2f6d68
commit 8cb6cc9d91
3 changed files with 11 additions and 6 deletions

View File

@ -320,6 +320,9 @@ Release 2.0.0 - UNRELEASED
HADOOP-8285 HDFS changes for Use ProtoBuf for RpcPayLoadHeader (sanjay radia) HADOOP-8285 HDFS changes for Use ProtoBuf for RpcPayLoadHeader (sanjay radia)
HDFS-3404. Make putImage in GetImageServlet infer remote address to fetch
from request. (atm)
OPTIMIZATIONS OPTIMIZATIONS
HDFS-2477. Optimize computing the diff between a block report and the HDFS-2477. Optimize computing the diff between a block report and the

View File

@ -29,6 +29,7 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import org.apache.hadoop.hdfs.DFSConfigKeys; import org.apache.hadoop.hdfs.DFSConfigKeys;
import org.apache.hadoop.net.NetUtils;
import org.apache.hadoop.security.SecurityUtil; import org.apache.hadoop.security.SecurityUtil;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
@ -49,6 +50,7 @@ import org.apache.hadoop.util.StringUtils;
import com.google.common.annotations.VisibleForTesting; import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
import com.google.common.net.InetAddresses;
/** /**
* This class is used in Namesystem's jetty to retrieve a file. * This class is used in Namesystem's jetty to retrieve a file.
@ -282,8 +284,7 @@ public class GetImageServlet extends HttpServlet {
return "putimage=1" + return "putimage=1" +
"&" + TXID_PARAM + "=" + txid + "&" + TXID_PARAM + "=" + txid +
"&port=" + imageListenAddress.getPort() + "&port=" + imageListenAddress.getPort() +
"&machine=" + imageListenAddress.getHostName() "&" + STORAGEINFO_PARAM + "=" +
+ "&" + STORAGEINFO_PARAM + "=" +
storage.toColonSeparatedString(); storage.toColonSeparatedString();
} }
@ -310,7 +311,10 @@ public class GetImageServlet extends HttpServlet {
Map<String, String[]> pmap = request.getParameterMap(); Map<String, String[]> pmap = request.getParameterMap();
isGetImage = isGetEdit = isPutImage = fetchLatest = false; isGetImage = isGetEdit = isPutImage = fetchLatest = false;
remoteport = 0; remoteport = 0;
machineName = null; machineName = request.getRemoteHost();
if (InetAddresses.isInetAddress(machineName)) {
machineName = NetUtils.getHostNameOfIP(machineName);
}
for (Map.Entry<String, String[]> entry : pmap.entrySet()) { for (Map.Entry<String, String[]> entry : pmap.entrySet()) {
String key = entry.getKey(); String key = entry.getKey();
@ -335,8 +339,6 @@ public class GetImageServlet extends HttpServlet {
txId = parseLongParam(request, TXID_PARAM); txId = parseLongParam(request, TXID_PARAM);
} else if (key.equals("port")) { } else if (key.equals("port")) {
remoteport = new Integer(val[0]).intValue(); remoteport = new Integer(val[0]).intValue();
} else if (key.equals("machine")) {
machineName = val[0];
} else if (key.equals(STORAGEINFO_PARAM)) { } else if (key.equals(STORAGEINFO_PARAM)) {
storageInfoString = val[0]; storageInfoString = val[0];
} }

View File

@ -112,7 +112,7 @@ public class StandbyCheckpointer {
*/ */
private boolean checkAddress(String addrStr) { private boolean checkAddress(String addrStr) {
InetSocketAddress addr = NetUtils.createSocketAddr(addrStr); InetSocketAddress addr = NetUtils.createSocketAddr(addrStr);
return addr.getPort() != 0 && !addr.getAddress().isAnyLocalAddress(); return addr.getPort() != 0;
} }
public void start() { public void start() {