HDFS-2786. Fix host-based token incompatibilities in DFSUtil. Contributed by Kihwal Lee.
git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1241766 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
4018798d4b
commit
11db1b855f
@ -123,6 +123,9 @@ Trunk (unreleased changes)
|
|||||||
HDS-2895. Remove Writable wire protocol types and translators to
|
HDS-2895. Remove Writable wire protocol types and translators to
|
||||||
complete transition to protocol buffers. (suresh)
|
complete transition to protocol buffers. (suresh)
|
||||||
|
|
||||||
|
HDFS-2786. Fix host-based token incompatibilities in DFSUtil. (Kihwal Lee
|
||||||
|
via jitendra)
|
||||||
|
|
||||||
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
|
||||||
namenode state. (Tomasz Nykiel via hairong)
|
namenode state. (Tomasz Nykiel via hairong)
|
||||||
|
@ -599,19 +599,6 @@ public static float getPercentRemaining(long remaining, long capacity) {
|
|||||||
return capacity <= 0 ? 0 : (remaining * 100.0f)/capacity;
|
return capacity <= 0 ? 0 : (remaining * 100.0f)/capacity;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param address address of format host:port
|
|
||||||
* @return InetSocketAddress for the address
|
|
||||||
*/
|
|
||||||
public static InetSocketAddress getSocketAddress(String address) {
|
|
||||||
int colon = address.indexOf(":");
|
|
||||||
if (colon < 0) {
|
|
||||||
return new InetSocketAddress(address, 0);
|
|
||||||
}
|
|
||||||
return new InetSocketAddress(address.substring(0, colon),
|
|
||||||
Integer.parseInt(address.substring(colon + 1)));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Round bytes to GiB (gibibyte)
|
* Round bytes to GiB (gibibyte)
|
||||||
* @param bytes number of bytes
|
* @param bytes number of bytes
|
||||||
|
@ -498,7 +498,7 @@ private static InetSocketAddress getNNServiceAddress(ServletContext context,
|
|||||||
String namenodeAddressInUrl = request.getParameter(NAMENODE_ADDRESS);
|
String namenodeAddressInUrl = request.getParameter(NAMENODE_ADDRESS);
|
||||||
InetSocketAddress namenodeAddress = null;
|
InetSocketAddress namenodeAddress = null;
|
||||||
if (namenodeAddressInUrl != null) {
|
if (namenodeAddressInUrl != null) {
|
||||||
namenodeAddress = DFSUtil.getSocketAddress(namenodeAddressInUrl);
|
namenodeAddress = NetUtils.createSocketAddr(namenodeAddressInUrl);
|
||||||
} else if (context != null) {
|
} else if (context != null) {
|
||||||
namenodeAddress = NameNodeHttpServer.getNameNodeAddressFromContext(
|
namenodeAddress = NameNodeHttpServer.getNameNodeAddressFromContext(
|
||||||
context);
|
context);
|
||||||
|
@ -53,18 +53,30 @@
|
|||||||
@InterfaceAudience.Private
|
@InterfaceAudience.Private
|
||||||
public class DatanodeJspHelper {
|
public class DatanodeJspHelper {
|
||||||
private static DFSClient getDFSClient(final UserGroupInformation user,
|
private static DFSClient getDFSClient(final UserGroupInformation user,
|
||||||
final InetSocketAddress addr,
|
final String addr,
|
||||||
final Configuration conf
|
final Configuration conf
|
||||||
) throws IOException,
|
) throws IOException,
|
||||||
InterruptedException {
|
InterruptedException {
|
||||||
return
|
return
|
||||||
user.doAs(new PrivilegedExceptionAction<DFSClient>() {
|
user.doAs(new PrivilegedExceptionAction<DFSClient>() {
|
||||||
public DFSClient run() throws IOException {
|
public DFSClient run() throws IOException {
|
||||||
return new DFSClient(addr, conf);
|
return new DFSClient(NetUtils.createSocketAddr(addr), conf);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Internal convenience method for canonicalizing host name.
|
||||||
|
* @param addr name:port or name
|
||||||
|
* @return canonicalized host name
|
||||||
|
*/
|
||||||
|
private static String canonicalize(String addr) {
|
||||||
|
// default port 1 is supplied to allow addr without port.
|
||||||
|
// the port will be ignored.
|
||||||
|
return NetUtils.createSocketAddr(addr, 1).getAddress()
|
||||||
|
.getCanonicalHostName();
|
||||||
|
}
|
||||||
|
|
||||||
private static final SimpleDateFormat lsDateFormat =
|
private static final SimpleDateFormat lsDateFormat =
|
||||||
new SimpleDateFormat("yyyy-MM-dd HH:mm");
|
new SimpleDateFormat("yyyy-MM-dd HH:mm");
|
||||||
|
|
||||||
@ -102,8 +114,7 @@ static void generateDirectoryStructure(JspWriter out,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
InetSocketAddress namenodeAddress = DFSUtil.getSocketAddress(nnAddr);
|
DFSClient dfs = getDFSClient(ugi, nnAddr, conf);
|
||||||
DFSClient dfs = getDFSClient(ugi, namenodeAddress, conf);
|
|
||||||
String target = dir;
|
String target = dir;
|
||||||
final HdfsFileStatus targetStatus = dfs.getFileInfo(target);
|
final HdfsFileStatus targetStatus = dfs.getFileInfo(target);
|
||||||
if (targetStatus == null) { // not exists
|
if (targetStatus == null) { // not exists
|
||||||
@ -125,8 +136,7 @@ static void generateDirectoryStructure(JspWriter out,
|
|||||||
out.print("Empty file");
|
out.print("Empty file");
|
||||||
} else {
|
} else {
|
||||||
DatanodeInfo chosenNode = JspHelper.bestNode(firstBlock, conf);
|
DatanodeInfo chosenNode = JspHelper.bestNode(firstBlock, conf);
|
||||||
String fqdn = InetAddress.getByName(chosenNode.getHost())
|
String fqdn = canonicalize(chosenNode.getHost());
|
||||||
.getCanonicalHostName();
|
|
||||||
String datanodeAddr = chosenNode.getName();
|
String datanodeAddr = chosenNode.getName();
|
||||||
int datanodePort = Integer.parseInt(datanodeAddr.substring(
|
int datanodePort = Integer.parseInt(datanodeAddr.substring(
|
||||||
datanodeAddr.indexOf(':') + 1, datanodeAddr.length()));
|
datanodeAddr.indexOf(':') + 1, datanodeAddr.length()));
|
||||||
@ -210,9 +220,8 @@ static void generateDirectoryStructure(JspWriter out,
|
|||||||
JspHelper.addTableFooter(out);
|
JspHelper.addTableFooter(out);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
String namenodeHost = namenodeAddress.getHostName();
|
|
||||||
out.print("<br><a href=\"http://"
|
out.print("<br><a href=\"http://"
|
||||||
+ InetAddress.getByName(namenodeHost).getCanonicalHostName() + ":"
|
+ canonicalize(nnAddr) + ":"
|
||||||
+ namenodeInfoPort + "/dfshealth.jsp\">Go back to DFS home</a>");
|
+ namenodeInfoPort + "/dfshealth.jsp\">Go back to DFS home</a>");
|
||||||
dfs.close();
|
dfs.close();
|
||||||
}
|
}
|
||||||
@ -282,8 +291,7 @@ static void generateFileDetails(JspWriter out,
|
|||||||
}
|
}
|
||||||
long blockSize = Long.parseLong(blockSizeStr);
|
long blockSize = Long.parseLong(blockSizeStr);
|
||||||
|
|
||||||
final InetSocketAddress namenodeAddress = DFSUtil.getSocketAddress(nnAddr);
|
final DFSClient dfs = getDFSClient(ugi, nnAddr, conf);
|
||||||
final DFSClient dfs = getDFSClient(ugi, namenodeAddress, conf);
|
|
||||||
List<LocatedBlock> blocks = dfs.getNamenode().getBlockLocations(filename, 0,
|
List<LocatedBlock> blocks = dfs.getNamenode().getBlockLocations(filename, 0,
|
||||||
Long.MAX_VALUE).getLocatedBlocks();
|
Long.MAX_VALUE).getLocatedBlocks();
|
||||||
// Add the various links for looking at the file contents
|
// Add the various links for looking at the file contents
|
||||||
@ -305,8 +313,7 @@ static void generateFileDetails(JspWriter out,
|
|||||||
dfs.close();
|
dfs.close();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
String fqdn = InetAddress.getByName(chosenNode.getHost())
|
String fqdn = canonicalize(chosenNode.getHost());
|
||||||
.getCanonicalHostName();
|
|
||||||
String tailUrl = "http://" + fqdn + ":" + chosenNode.getInfoPort()
|
String tailUrl = "http://" + fqdn + ":" + chosenNode.getInfoPort()
|
||||||
+ "/tail.jsp?filename=" + URLEncoder.encode(filename, "UTF-8")
|
+ "/tail.jsp?filename=" + URLEncoder.encode(filename, "UTF-8")
|
||||||
+ "&namenodeInfoPort=" + namenodeInfoPort
|
+ "&namenodeInfoPort=" + namenodeInfoPort
|
||||||
@ -345,9 +352,7 @@ static void generateFileDetails(JspWriter out,
|
|||||||
// generate a table and dump the info
|
// generate a table and dump the info
|
||||||
out.println("\n<table>");
|
out.println("\n<table>");
|
||||||
|
|
||||||
String namenodeHost = namenodeAddress.getHostName();
|
String nnCanonicalName = canonicalize(nnAddr);
|
||||||
String namenodeHostName = InetAddress.getByName(namenodeHost).getCanonicalHostName();
|
|
||||||
|
|
||||||
for (LocatedBlock cur : blocks) {
|
for (LocatedBlock cur : blocks) {
|
||||||
out.print("<tr>");
|
out.print("<tr>");
|
||||||
final String blockidstring = Long.toString(cur.getBlock().getBlockId());
|
final String blockidstring = Long.toString(cur.getBlock().getBlockId());
|
||||||
@ -358,7 +363,7 @@ static void generateFileDetails(JspWriter out,
|
|||||||
String datanodeAddr = locs[j].getName();
|
String datanodeAddr = locs[j].getName();
|
||||||
datanodePort = Integer.parseInt(datanodeAddr.substring(datanodeAddr
|
datanodePort = Integer.parseInt(datanodeAddr.substring(datanodeAddr
|
||||||
.indexOf(':') + 1, datanodeAddr.length()));
|
.indexOf(':') + 1, datanodeAddr.length()));
|
||||||
fqdn = InetAddress.getByName(locs[j].getHost()).getCanonicalHostName();
|
fqdn = canonicalize(locs[j].getHost());
|
||||||
String blockUrl = "http://" + fqdn + ":" + locs[j].getInfoPort()
|
String blockUrl = "http://" + fqdn + ":" + locs[j].getInfoPort()
|
||||||
+ "/browseBlock.jsp?blockId=" + blockidstring
|
+ "/browseBlock.jsp?blockId=" + blockidstring
|
||||||
+ "&blockSize=" + blockSize
|
+ "&blockSize=" + blockSize
|
||||||
@ -370,7 +375,7 @@ static void generateFileDetails(JspWriter out,
|
|||||||
+ JspHelper.getDelegationTokenUrlParam(tokenString)
|
+ JspHelper.getDelegationTokenUrlParam(tokenString)
|
||||||
+ JspHelper.getUrlParam(JspHelper.NAMENODE_ADDRESS, nnAddr);
|
+ JspHelper.getUrlParam(JspHelper.NAMENODE_ADDRESS, nnAddr);
|
||||||
|
|
||||||
String blockInfoUrl = "http://" + namenodeHostName + ":"
|
String blockInfoUrl = "http://" + nnCanonicalName + ":"
|
||||||
+ namenodeInfoPort
|
+ namenodeInfoPort
|
||||||
+ "/block_info_xml.jsp?blockId=" + blockidstring;
|
+ "/block_info_xml.jsp?blockId=" + blockidstring;
|
||||||
out.print("<td> </td><td><a href=\"" + blockUrl + "\">"
|
out.print("<td> </td><td><a href=\"" + blockUrl + "\">"
|
||||||
@ -382,7 +387,7 @@ static void generateFileDetails(JspWriter out,
|
|||||||
out.println("</table>");
|
out.println("</table>");
|
||||||
out.print("<hr>");
|
out.print("<hr>");
|
||||||
out.print("<br><a href=\"http://"
|
out.print("<br><a href=\"http://"
|
||||||
+ InetAddress.getByName(namenodeHost).getCanonicalHostName() + ":"
|
+ nnCanonicalName + ":"
|
||||||
+ namenodeInfoPort + "/dfshealth.jsp\">Go back to DFS home</a>");
|
+ namenodeInfoPort + "/dfshealth.jsp\">Go back to DFS home</a>");
|
||||||
dfs.close();
|
dfs.close();
|
||||||
}
|
}
|
||||||
@ -419,8 +424,7 @@ static void generateFileChunks(JspWriter out, HttpServletRequest req,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
final DFSClient dfs = getDFSClient(ugi,
|
final DFSClient dfs = getDFSClient(ugi, nnAddr, conf);
|
||||||
DFSUtil.getSocketAddress(nnAddr), conf);
|
|
||||||
|
|
||||||
String bpid = null;
|
String bpid = null;
|
||||||
Token<BlockTokenIdentifier> blockToken = BlockTokenSecretManager.DUMMY_TOKEN;
|
Token<BlockTokenIdentifier> blockToken = BlockTokenSecretManager.DUMMY_TOKEN;
|
||||||
@ -518,8 +522,7 @@ static void generateFileChunks(JspWriter out, HttpServletRequest req,
|
|||||||
String datanodeAddr = d.getName();
|
String datanodeAddr = d.getName();
|
||||||
nextDatanodePort = Integer.parseInt(datanodeAddr.substring(
|
nextDatanodePort = Integer.parseInt(datanodeAddr.substring(
|
||||||
datanodeAddr.indexOf(':') + 1, datanodeAddr.length()));
|
datanodeAddr.indexOf(':') + 1, datanodeAddr.length()));
|
||||||
nextHost = InetAddress.getByName(d.getHost())
|
nextHost = d.getHost();
|
||||||
.getCanonicalHostName();
|
|
||||||
nextPort = d.getInfoPort();
|
nextPort = d.getInfoPort();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -533,7 +536,7 @@ static void generateFileChunks(JspWriter out, HttpServletRequest req,
|
|||||||
}
|
}
|
||||||
String nextUrl = null;
|
String nextUrl = null;
|
||||||
if (nextBlockIdStr != null) {
|
if (nextBlockIdStr != null) {
|
||||||
nextUrl = "http://" + nextHost + ":" + nextPort
|
nextUrl = "http://" + canonicalize(nextHost) + ":" + nextPort
|
||||||
+ "/browseBlock.jsp?blockId=" + nextBlockIdStr
|
+ "/browseBlock.jsp?blockId=" + nextBlockIdStr
|
||||||
+ "&blockSize=" + nextBlockSize
|
+ "&blockSize=" + nextBlockSize
|
||||||
+ "&startOffset=" + nextStartOffset
|
+ "&startOffset=" + nextStartOffset
|
||||||
@ -573,8 +576,7 @@ static void generateFileChunks(JspWriter out, HttpServletRequest req,
|
|||||||
String datanodeAddr = d.getName();
|
String datanodeAddr = d.getName();
|
||||||
prevDatanodePort = Integer.parseInt(datanodeAddr.substring(
|
prevDatanodePort = Integer.parseInt(datanodeAddr.substring(
|
||||||
datanodeAddr.indexOf(':') + 1, datanodeAddr.length()));
|
datanodeAddr.indexOf(':') + 1, datanodeAddr.length()));
|
||||||
prevHost = InetAddress.getByName(d.getHost())
|
prevHost = d.getHost();
|
||||||
.getCanonicalHostName();
|
|
||||||
prevPort = d.getInfoPort();
|
prevPort = d.getInfoPort();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -591,7 +593,7 @@ static void generateFileChunks(JspWriter out, HttpServletRequest req,
|
|||||||
|
|
||||||
String prevUrl = null;
|
String prevUrl = null;
|
||||||
if (prevBlockIdStr != null) {
|
if (prevBlockIdStr != null) {
|
||||||
prevUrl = "http://" + prevHost + ":" + prevPort
|
prevUrl = "http://" + canonicalize(prevHost) + ":" + prevPort
|
||||||
+ "/browseBlock.jsp?blockId=" + prevBlockIdStr
|
+ "/browseBlock.jsp?blockId=" + prevBlockIdStr
|
||||||
+ "&blockSize=" + prevBlockSize
|
+ "&blockSize=" + prevBlockSize
|
||||||
+ "&startOffset=" + prevStartOffset
|
+ "&startOffset=" + prevStartOffset
|
||||||
@ -669,8 +671,7 @@ static void generateFileChunksForTail(JspWriter out, HttpServletRequest req,
|
|||||||
+ "\">");
|
+ "\">");
|
||||||
|
|
||||||
// fetch the block from the datanode that has the last block for this file
|
// fetch the block from the datanode that has the last block for this file
|
||||||
final DFSClient dfs = getDFSClient(ugi, DFSUtil.getSocketAddress(nnAddr),
|
final DFSClient dfs = getDFSClient(ugi, nnAddr, conf);
|
||||||
conf);
|
|
||||||
List<LocatedBlock> blocks = dfs.getNamenode().getBlockLocations(filename, 0,
|
List<LocatedBlock> blocks = dfs.getNamenode().getBlockLocations(filename, 0,
|
||||||
Long.MAX_VALUE).getLocatedBlocks();
|
Long.MAX_VALUE).getLocatedBlocks();
|
||||||
if (blocks == null || blocks.size() == 0) {
|
if (blocks == null || blocks.size() == 0) {
|
||||||
@ -710,6 +711,6 @@ public static DFSClient getDFSClient(final HttpServletRequest request,
|
|||||||
final DataNode datanode, final Configuration conf,
|
final DataNode datanode, final Configuration conf,
|
||||||
final UserGroupInformation ugi) throws IOException, InterruptedException {
|
final UserGroupInformation ugi) throws IOException, InterruptedException {
|
||||||
final String nnAddr = request.getParameter(JspHelper.NAMENODE_ADDRESS);
|
final String nnAddr = request.getParameter(JspHelper.NAMENODE_ADDRESS);
|
||||||
return getDFSClient(ugi, DFSUtil.getSocketAddress(nnAddr), conf);
|
return getDFSClient(ugi, nnAddr, conf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1127,7 +1127,7 @@ public int run(String[] argv) throws Exception {
|
|||||||
|
|
||||||
private ClientDatanodeProtocol getDataNodeProxy(String datanode)
|
private ClientDatanodeProtocol getDataNodeProxy(String datanode)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
InetSocketAddress datanodeAddr = DFSUtil.getSocketAddress(datanode);
|
InetSocketAddress datanodeAddr = NetUtils.createSocketAddr(datanode);
|
||||||
// Get the current configuration
|
// Get the current configuration
|
||||||
Configuration conf = getConf();
|
Configuration conf = getConf();
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user