|
@@ -54,6 +54,7 @@ import org.apache.hadoop.hdfs.protocol.HdfsFileStatus;
|
|
|
import org.apache.hadoop.hdfs.protocol.LocatedBlocks;
|
|
|
import org.apache.hadoop.hdfs.security.token.delegation.DelegationTokenIdentifier;
|
|
|
import org.apache.hadoop.hdfs.security.token.delegation.DelegationTokenSecretManager;
|
|
|
+import org.apache.hadoop.hdfs.server.namenode.FSNamesystem;
|
|
|
import org.apache.hadoop.hdfs.server.namenode.JspHelper;
|
|
|
import org.apache.hadoop.hdfs.server.namenode.NameNode;
|
|
|
import org.apache.hadoop.hdfs.web.JsonUtil;
|
|
@@ -107,6 +108,11 @@ public class NamenodeWebHdfsMethods {
|
|
|
return REMOTE_ADDRESS.get();
|
|
|
}
|
|
|
|
|
|
+ /** Set the remote client address. */
|
|
|
+ static void setRemoteAddress(String remoteAddress) {
|
|
|
+ REMOTE_ADDRESS.set(remoteAddress);
|
|
|
+ }
|
|
|
+
|
|
|
private @Context ServletContext context;
|
|
|
private @Context HttpServletRequest request;
|
|
|
private @Context HttpServletResponse response;
|
|
@@ -126,12 +132,21 @@ public class NamenodeWebHdfsMethods {
|
|
|
response.setContentType(null);
|
|
|
}
|
|
|
|
|
|
- private static DatanodeInfo chooseDatanode(final NameNode namenode,
|
|
|
- final String path, final HttpOpParam.Op op, final long openOffset
|
|
|
- ) throws IOException {
|
|
|
- if (op == GetOpParam.Op.OPEN
|
|
|
+ static DatanodeInfo chooseDatanode(final NameNode namenode,
|
|
|
+ final String path, final HttpOpParam.Op op, final long openOffset,
|
|
|
+ final long blocksize) throws IOException {
|
|
|
+ final FSNamesystem ns = namenode.getNamesystem();
|
|
|
+
|
|
|
+ if (op == PutOpParam.Op.CREATE) {
|
|
|
+ //choose a datanode near to client
|
|
|
+ final DatanodeInfo dn = ns.chooseDatanode(getRemoteAddress(), blocksize);
|
|
|
+ if (dn != null) {
|
|
|
+ return dn;
|
|
|
+ }
|
|
|
+ } else if (op == GetOpParam.Op.OPEN
|
|
|
|| op == GetOpParam.Op.GETFILECHECKSUM
|
|
|
|| op == PostOpParam.Op.APPEND) {
|
|
|
+ //choose a datanode containing a replica
|
|
|
final HdfsFileStatus status = namenode.getFileInfo(path);
|
|
|
if (status == null) {
|
|
|
throw new FileNotFoundException("File " + path + " not found.");
|
|
@@ -155,7 +170,7 @@ public class NamenodeWebHdfsMethods {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- return namenode.getNamesystem().getRandomDatanode();
|
|
|
+ return ns.getRandomDatanode();
|
|
|
}
|
|
|
|
|
|
private Token<? extends TokenIdentifier> generateDelegationToken(
|
|
@@ -173,8 +188,10 @@ public class NamenodeWebHdfsMethods {
|
|
|
final UserGroupInformation ugi, final DelegationParam delegation,
|
|
|
final UserParam username, final DoAsParam doAsUser,
|
|
|
final String path, final HttpOpParam.Op op, final long openOffset,
|
|
|
+ final long blocksize,
|
|
|
final Param<?, ?>... parameters) throws URISyntaxException, IOException {
|
|
|
- final DatanodeInfo dn = chooseDatanode(namenode, path, op, openOffset);
|
|
|
+ final DatanodeInfo dn = chooseDatanode(namenode, path, op, openOffset,
|
|
|
+ blocksize);
|
|
|
|
|
|
final String delegationQuery;
|
|
|
if (!UserGroupInformation.isSecurityEnabled()) {
|
|
@@ -302,7 +319,7 @@ public class NamenodeWebHdfsMethods {
|
|
|
case CREATE:
|
|
|
{
|
|
|
final URI uri = redirectURI(namenode, ugi, delegation, username, doAsUser,
|
|
|
- fullpath, op.getValue(), -1L,
|
|
|
+ fullpath, op.getValue(), -1L, blockSize.getValue(conf),
|
|
|
permission, overwrite, bufferSize, replication, blockSize);
|
|
|
return Response.temporaryRedirect(uri).type(MediaType.APPLICATION_OCTET_STREAM).build();
|
|
|
}
|
|
@@ -425,7 +442,7 @@ public class NamenodeWebHdfsMethods {
|
|
|
case APPEND:
|
|
|
{
|
|
|
final URI uri = redirectURI(namenode, ugi, delegation, username, doAsUser,
|
|
|
- fullpath, op.getValue(), -1L, bufferSize);
|
|
|
+ fullpath, op.getValue(), -1L, -1L, bufferSize);
|
|
|
return Response.temporaryRedirect(uri).type(MediaType.APPLICATION_OCTET_STREAM).build();
|
|
|
}
|
|
|
default:
|
|
@@ -507,7 +524,7 @@ public class NamenodeWebHdfsMethods {
|
|
|
case OPEN:
|
|
|
{
|
|
|
final URI uri = redirectURI(namenode, ugi, delegation, username, doAsUser,
|
|
|
- fullpath, op.getValue(), offset.getValue(), offset, length, bufferSize);
|
|
|
+ fullpath, op.getValue(), offset.getValue(), -1L, offset, length, bufferSize);
|
|
|
return Response.temporaryRedirect(uri).type(MediaType.APPLICATION_OCTET_STREAM).build();
|
|
|
}
|
|
|
case GET_BLOCK_LOCATIONS:
|
|
@@ -543,7 +560,7 @@ public class NamenodeWebHdfsMethods {
|
|
|
case GETFILECHECKSUM:
|
|
|
{
|
|
|
final URI uri = redirectURI(namenode, ugi, delegation, username, doAsUser,
|
|
|
- fullpath, op.getValue(), -1L);
|
|
|
+ fullpath, op.getValue(), -1L, -1L);
|
|
|
return Response.temporaryRedirect(uri).type(MediaType.APPLICATION_OCTET_STREAM).build();
|
|
|
}
|
|
|
case GETDELEGATIONTOKEN:
|