|
@@ -51,6 +51,7 @@ import org.apache.hadoop.fs.MD5MD5CRC32FileChecksum;
|
|
import org.apache.hadoop.fs.permission.FsPermission;
|
|
import org.apache.hadoop.fs.permission.FsPermission;
|
|
import org.apache.hadoop.hdfs.DFSClient;
|
|
import org.apache.hadoop.hdfs.DFSClient;
|
|
import org.apache.hadoop.hdfs.DFSClient.DFSDataInputStream;
|
|
import org.apache.hadoop.hdfs.DFSClient.DFSDataInputStream;
|
|
|
|
+import org.apache.hadoop.hdfs.security.token.delegation.DelegationTokenIdentifier;
|
|
import org.apache.hadoop.hdfs.server.datanode.DataNode;
|
|
import org.apache.hadoop.hdfs.server.datanode.DataNode;
|
|
import org.apache.hadoop.hdfs.server.namenode.NameNode;
|
|
import org.apache.hadoop.hdfs.server.namenode.NameNode;
|
|
import org.apache.hadoop.hdfs.web.JsonUtil;
|
|
import org.apache.hadoop.hdfs.web.JsonUtil;
|
|
@@ -58,7 +59,9 @@ import org.apache.hadoop.hdfs.web.ParamFilter;
|
|
import org.apache.hadoop.hdfs.web.WebHdfsFileSystem;
|
|
import org.apache.hadoop.hdfs.web.WebHdfsFileSystem;
|
|
import org.apache.hadoop.hdfs.web.resources.BlockSizeParam;
|
|
import org.apache.hadoop.hdfs.web.resources.BlockSizeParam;
|
|
import org.apache.hadoop.hdfs.web.resources.BufferSizeParam;
|
|
import org.apache.hadoop.hdfs.web.resources.BufferSizeParam;
|
|
|
|
+import org.apache.hadoop.hdfs.web.resources.DelegationParam;
|
|
import org.apache.hadoop.hdfs.web.resources.GetOpParam;
|
|
import org.apache.hadoop.hdfs.web.resources.GetOpParam;
|
|
|
|
+import org.apache.hadoop.hdfs.web.resources.HttpOpParam;
|
|
import org.apache.hadoop.hdfs.web.resources.LengthParam;
|
|
import org.apache.hadoop.hdfs.web.resources.LengthParam;
|
|
import org.apache.hadoop.hdfs.web.resources.OffsetParam;
|
|
import org.apache.hadoop.hdfs.web.resources.OffsetParam;
|
|
import org.apache.hadoop.hdfs.web.resources.OverwriteParam;
|
|
import org.apache.hadoop.hdfs.web.resources.OverwriteParam;
|
|
@@ -69,7 +72,9 @@ import org.apache.hadoop.hdfs.web.resources.PutOpParam;
|
|
import org.apache.hadoop.hdfs.web.resources.ReplicationParam;
|
|
import org.apache.hadoop.hdfs.web.resources.ReplicationParam;
|
|
import org.apache.hadoop.hdfs.web.resources.UriFsPathParam;
|
|
import org.apache.hadoop.hdfs.web.resources.UriFsPathParam;
|
|
import org.apache.hadoop.io.IOUtils;
|
|
import org.apache.hadoop.io.IOUtils;
|
|
|
|
+import org.apache.hadoop.security.SecurityUtil;
|
|
import org.apache.hadoop.security.UserGroupInformation;
|
|
import org.apache.hadoop.security.UserGroupInformation;
|
|
|
|
+import org.apache.hadoop.security.token.Token;
|
|
|
|
|
|
import com.sun.jersey.spi.container.ResourceFilters;
|
|
import com.sun.jersey.spi.container.ResourceFilters;
|
|
|
|
|
|
@@ -84,6 +89,29 @@ public class DatanodeWebHdfsMethods {
|
|
private @Context ServletContext context;
|
|
private @Context ServletContext context;
|
|
private @Context HttpServletResponse response;
|
|
private @Context HttpServletResponse response;
|
|
|
|
|
|
|
|
+ private void init(final UserGroupInformation ugi, final DelegationParam delegation,
|
|
|
|
+ final UriFsPathParam path, final HttpOpParam<?> op,
|
|
|
|
+ final Param<?, ?>... parameters) throws IOException {
|
|
|
|
+ if (LOG.isTraceEnabled()) {
|
|
|
|
+ LOG.trace("HTTP " + op.getValue().getType() + ": " + op + ", " + path
|
|
|
|
+ + ", ugi=" + ugi + Param.toSortedString(", ", parameters));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //clear content type
|
|
|
|
+ response.setContentType(null);
|
|
|
|
+
|
|
|
|
+ if (UserGroupInformation.isSecurityEnabled()) {
|
|
|
|
+ //add a token for RPC.
|
|
|
|
+ final DataNode datanode = (DataNode)context.getAttribute("datanode");
|
|
|
|
+ final InetSocketAddress nnRpcAddr = NameNode.getAddress(datanode.getConf());
|
|
|
|
+ final Token<DelegationTokenIdentifier> token = new Token<DelegationTokenIdentifier>();
|
|
|
|
+ token.decodeFromUrlString(delegation.getValue());
|
|
|
|
+ SecurityUtil.setTokenService(token, nnRpcAddr);
|
|
|
|
+ token.setKind(DelegationTokenIdentifier.HDFS_DELEGATION_KIND);
|
|
|
|
+ ugi.addToken(token);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
/** Handle HTTP PUT request for the root. */
|
|
/** Handle HTTP PUT request for the root. */
|
|
@PUT
|
|
@PUT
|
|
@Path("/")
|
|
@Path("/")
|
|
@@ -92,6 +120,8 @@ public class DatanodeWebHdfsMethods {
|
|
public Response putRoot(
|
|
public Response putRoot(
|
|
final InputStream in,
|
|
final InputStream in,
|
|
@Context final UserGroupInformation ugi,
|
|
@Context final UserGroupInformation ugi,
|
|
|
|
+ @QueryParam(DelegationParam.NAME) @DefaultValue(DelegationParam.DEFAULT)
|
|
|
|
+ final DelegationParam delegation,
|
|
@QueryParam(PutOpParam.NAME) @DefaultValue(PutOpParam.DEFAULT)
|
|
@QueryParam(PutOpParam.NAME) @DefaultValue(PutOpParam.DEFAULT)
|
|
final PutOpParam op,
|
|
final PutOpParam op,
|
|
@QueryParam(PermissionParam.NAME) @DefaultValue(PermissionParam.DEFAULT)
|
|
@QueryParam(PermissionParam.NAME) @DefaultValue(PermissionParam.DEFAULT)
|
|
@@ -105,7 +135,7 @@ public class DatanodeWebHdfsMethods {
|
|
@QueryParam(BlockSizeParam.NAME) @DefaultValue(BlockSizeParam.DEFAULT)
|
|
@QueryParam(BlockSizeParam.NAME) @DefaultValue(BlockSizeParam.DEFAULT)
|
|
final BlockSizeParam blockSize
|
|
final BlockSizeParam blockSize
|
|
) throws IOException, InterruptedException {
|
|
) throws IOException, InterruptedException {
|
|
- return put(in, ugi, ROOT, op, permission, overwrite, bufferSize,
|
|
|
|
|
|
+ return put(in, ugi, delegation, ROOT, op, permission, overwrite, bufferSize,
|
|
replication, blockSize);
|
|
replication, blockSize);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -117,6 +147,8 @@ public class DatanodeWebHdfsMethods {
|
|
public Response put(
|
|
public Response put(
|
|
final InputStream in,
|
|
final InputStream in,
|
|
@Context final UserGroupInformation ugi,
|
|
@Context final UserGroupInformation ugi,
|
|
|
|
+ @QueryParam(DelegationParam.NAME) @DefaultValue(DelegationParam.DEFAULT)
|
|
|
|
+ final DelegationParam delegation,
|
|
@PathParam(UriFsPathParam.NAME) final UriFsPathParam path,
|
|
@PathParam(UriFsPathParam.NAME) final UriFsPathParam path,
|
|
@QueryParam(PutOpParam.NAME) @DefaultValue(PutOpParam.DEFAULT)
|
|
@QueryParam(PutOpParam.NAME) @DefaultValue(PutOpParam.DEFAULT)
|
|
final PutOpParam op,
|
|
final PutOpParam op,
|
|
@@ -132,14 +164,8 @@ public class DatanodeWebHdfsMethods {
|
|
final BlockSizeParam blockSize
|
|
final BlockSizeParam blockSize
|
|
) throws IOException, InterruptedException {
|
|
) throws IOException, InterruptedException {
|
|
|
|
|
|
- if (LOG.isTraceEnabled()) {
|
|
|
|
- LOG.trace(op + ": " + path + ", ugi=" + ugi
|
|
|
|
- + Param.toSortedString(", ", permission, overwrite, bufferSize,
|
|
|
|
- replication, blockSize));
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- //clear content type
|
|
|
|
- response.setContentType(null);
|
|
|
|
|
|
+ init(ugi, delegation, path, op, permission, overwrite, bufferSize,
|
|
|
|
+ replication, blockSize);
|
|
|
|
|
|
return ugi.doAs(new PrivilegedExceptionAction<Response>() {
|
|
return ugi.doAs(new PrivilegedExceptionAction<Response>() {
|
|
@Override
|
|
@Override
|
|
@@ -193,12 +219,14 @@ public class DatanodeWebHdfsMethods {
|
|
public Response postRoot(
|
|
public Response postRoot(
|
|
final InputStream in,
|
|
final InputStream in,
|
|
@Context final UserGroupInformation ugi,
|
|
@Context final UserGroupInformation ugi,
|
|
|
|
+ @QueryParam(DelegationParam.NAME) @DefaultValue(DelegationParam.DEFAULT)
|
|
|
|
+ final DelegationParam delegation,
|
|
@QueryParam(PostOpParam.NAME) @DefaultValue(PostOpParam.DEFAULT)
|
|
@QueryParam(PostOpParam.NAME) @DefaultValue(PostOpParam.DEFAULT)
|
|
final PostOpParam op,
|
|
final PostOpParam op,
|
|
@QueryParam(BufferSizeParam.NAME) @DefaultValue(BufferSizeParam.DEFAULT)
|
|
@QueryParam(BufferSizeParam.NAME) @DefaultValue(BufferSizeParam.DEFAULT)
|
|
final BufferSizeParam bufferSize
|
|
final BufferSizeParam bufferSize
|
|
) throws IOException, InterruptedException {
|
|
) throws IOException, InterruptedException {
|
|
- return post(in, ugi, ROOT, op, bufferSize);
|
|
|
|
|
|
+ return post(in, ugi, delegation, ROOT, op, bufferSize);
|
|
}
|
|
}
|
|
|
|
|
|
/** Handle HTTP POST request. */
|
|
/** Handle HTTP POST request. */
|
|
@@ -209,6 +237,8 @@ public class DatanodeWebHdfsMethods {
|
|
public Response post(
|
|
public Response post(
|
|
final InputStream in,
|
|
final InputStream in,
|
|
@Context final UserGroupInformation ugi,
|
|
@Context final UserGroupInformation ugi,
|
|
|
|
+ @QueryParam(DelegationParam.NAME) @DefaultValue(DelegationParam.DEFAULT)
|
|
|
|
+ final DelegationParam delegation,
|
|
@PathParam(UriFsPathParam.NAME) final UriFsPathParam path,
|
|
@PathParam(UriFsPathParam.NAME) final UriFsPathParam path,
|
|
@QueryParam(PostOpParam.NAME) @DefaultValue(PostOpParam.DEFAULT)
|
|
@QueryParam(PostOpParam.NAME) @DefaultValue(PostOpParam.DEFAULT)
|
|
final PostOpParam op,
|
|
final PostOpParam op,
|
|
@@ -216,13 +246,7 @@ public class DatanodeWebHdfsMethods {
|
|
final BufferSizeParam bufferSize
|
|
final BufferSizeParam bufferSize
|
|
) throws IOException, InterruptedException {
|
|
) throws IOException, InterruptedException {
|
|
|
|
|
|
- if (LOG.isTraceEnabled()) {
|
|
|
|
- LOG.trace(op + ": " + path + ", ugi=" + ugi
|
|
|
|
- + Param.toSortedString(", ", bufferSize));
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- //clear content type
|
|
|
|
- response.setContentType(null);
|
|
|
|
|
|
+ init(ugi, delegation, path, op, bufferSize);
|
|
|
|
|
|
return ugi.doAs(new PrivilegedExceptionAction<Response>() {
|
|
return ugi.doAs(new PrivilegedExceptionAction<Response>() {
|
|
@Override
|
|
@Override
|
|
@@ -265,6 +289,8 @@ public class DatanodeWebHdfsMethods {
|
|
@Produces({MediaType.APPLICATION_OCTET_STREAM, MediaType.APPLICATION_JSON})
|
|
@Produces({MediaType.APPLICATION_OCTET_STREAM, MediaType.APPLICATION_JSON})
|
|
public Response getRoot(
|
|
public Response getRoot(
|
|
@Context final UserGroupInformation ugi,
|
|
@Context final UserGroupInformation ugi,
|
|
|
|
+ @QueryParam(DelegationParam.NAME) @DefaultValue(DelegationParam.DEFAULT)
|
|
|
|
+ final DelegationParam delegation,
|
|
@QueryParam(GetOpParam.NAME) @DefaultValue(GetOpParam.DEFAULT)
|
|
@QueryParam(GetOpParam.NAME) @DefaultValue(GetOpParam.DEFAULT)
|
|
final GetOpParam op,
|
|
final GetOpParam op,
|
|
@QueryParam(OffsetParam.NAME) @DefaultValue(OffsetParam.DEFAULT)
|
|
@QueryParam(OffsetParam.NAME) @DefaultValue(OffsetParam.DEFAULT)
|
|
@@ -274,7 +300,7 @@ public class DatanodeWebHdfsMethods {
|
|
@QueryParam(BufferSizeParam.NAME) @DefaultValue(BufferSizeParam.DEFAULT)
|
|
@QueryParam(BufferSizeParam.NAME) @DefaultValue(BufferSizeParam.DEFAULT)
|
|
final BufferSizeParam bufferSize
|
|
final BufferSizeParam bufferSize
|
|
) throws IOException, InterruptedException {
|
|
) throws IOException, InterruptedException {
|
|
- return get(ugi, ROOT, op, offset, length, bufferSize);
|
|
|
|
|
|
+ return get(ugi, delegation, ROOT, op, offset, length, bufferSize);
|
|
}
|
|
}
|
|
|
|
|
|
/** Handle HTTP GET request. */
|
|
/** Handle HTTP GET request. */
|
|
@@ -283,6 +309,8 @@ public class DatanodeWebHdfsMethods {
|
|
@Produces({MediaType.APPLICATION_OCTET_STREAM, MediaType.APPLICATION_JSON})
|
|
@Produces({MediaType.APPLICATION_OCTET_STREAM, MediaType.APPLICATION_JSON})
|
|
public Response get(
|
|
public Response get(
|
|
@Context final UserGroupInformation ugi,
|
|
@Context final UserGroupInformation ugi,
|
|
|
|
+ @QueryParam(DelegationParam.NAME) @DefaultValue(DelegationParam.DEFAULT)
|
|
|
|
+ final DelegationParam delegation,
|
|
@PathParam(UriFsPathParam.NAME) final UriFsPathParam path,
|
|
@PathParam(UriFsPathParam.NAME) final UriFsPathParam path,
|
|
@QueryParam(GetOpParam.NAME) @DefaultValue(GetOpParam.DEFAULT)
|
|
@QueryParam(GetOpParam.NAME) @DefaultValue(GetOpParam.DEFAULT)
|
|
final GetOpParam op,
|
|
final GetOpParam op,
|
|
@@ -294,13 +322,7 @@ public class DatanodeWebHdfsMethods {
|
|
final BufferSizeParam bufferSize
|
|
final BufferSizeParam bufferSize
|
|
) throws IOException, InterruptedException {
|
|
) throws IOException, InterruptedException {
|
|
|
|
|
|
- if (LOG.isTraceEnabled()) {
|
|
|
|
- LOG.trace(op + ": " + path + ", ugi=" + ugi
|
|
|
|
- + Param.toSortedString(", ", offset, length, bufferSize));
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- //clear content type
|
|
|
|
- response.setContentType(null);
|
|
|
|
|
|
+ init(ugi, delegation, path, op, offset, length, bufferSize);
|
|
|
|
|
|
return ugi.doAs(new PrivilegedExceptionAction<Response>() {
|
|
return ugi.doAs(new PrivilegedExceptionAction<Response>() {
|
|
@Override
|
|
@Override
|