HDFS-6438. DeleteSnapshot should be a DELETE request in WebHdfs. Contributed by Jing Zhao.

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1596772 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Jing Zhao 2014-05-22 07:30:18 +00:00
parent 619ec833fc
commit 752a9d84bb
6 changed files with 144 additions and 16 deletions

View File

@ -578,6 +578,8 @@ Release 2.5.0 - UNRELEASED
HDFS-6433. Replace BytesMoved class with AtomicLong.
(Benoy Antony via cnauroth)
HDFS-6438. DeleteSnapshot should be a DELETE request in WebHdfs. (jing9)
Release 2.4.1 - UNRELEASED
INCOMPATIBLE CHANGES

View File

@ -590,10 +590,6 @@ private Response put(
org.apache.hadoop.fs.Path.class.getSimpleName(), snapshotPath);
return Response.ok(js).type(MediaType.APPLICATION_JSON).build();
}
case DELETESNAPSHOT: {
np.deleteSnapshot(fullpath, snapshotName.getValue());
return Response.ok().type(MediaType.APPLICATION_OCTET_STREAM).build();
}
case RENAMESNAPSHOT: {
np.renameSnapshot(fullpath, oldSnapshotName.getValue(),
snapshotName.getValue());
@ -953,9 +949,12 @@ public Response deleteRoot(
@QueryParam(DeleteOpParam.NAME) @DefaultValue(DeleteOpParam.DEFAULT)
final DeleteOpParam op,
@QueryParam(RecursiveParam.NAME) @DefaultValue(RecursiveParam.DEFAULT)
final RecursiveParam recursive
final RecursiveParam recursive,
@QueryParam(SnapshotNameParam.NAME) @DefaultValue(SnapshotNameParam.DEFAULT)
final SnapshotNameParam snapshotName
) throws IOException, InterruptedException {
return delete(ugi, delegation, username, doAsUser, ROOT, op, recursive);
return delete(ugi, delegation, username, doAsUser, ROOT, op, recursive,
snapshotName);
}
/** Handle HTTP DELETE request. */
@ -974,17 +973,19 @@ public Response delete(
@QueryParam(DeleteOpParam.NAME) @DefaultValue(DeleteOpParam.DEFAULT)
final DeleteOpParam op,
@QueryParam(RecursiveParam.NAME) @DefaultValue(RecursiveParam.DEFAULT)
final RecursiveParam recursive
final RecursiveParam recursive,
@QueryParam(SnapshotNameParam.NAME) @DefaultValue(SnapshotNameParam.DEFAULT)
final SnapshotNameParam snapshotName
) throws IOException, InterruptedException {
init(ugi, delegation, username, doAsUser, path, op, recursive);
init(ugi, delegation, username, doAsUser, path, op, recursive, snapshotName);
return ugi.doAs(new PrivilegedExceptionAction<Response>() {
@Override
public Response run() throws IOException {
try {
return delete(ugi, delegation, username, doAsUser,
path.getAbsolutePath(), op, recursive);
path.getAbsolutePath(), op, recursive, snapshotName);
} finally {
reset();
}
@ -999,17 +1000,22 @@ private Response delete(
final DoAsParam doAsUser,
final String fullpath,
final DeleteOpParam op,
final RecursiveParam recursive
final RecursiveParam recursive,
final SnapshotNameParam snapshotName
) throws IOException {
final NameNode namenode = (NameNode)context.getAttribute("name.node");
final NamenodeProtocols np = getRPCServer(namenode);
switch(op.getValue()) {
case DELETE:
{
final boolean b = getRPCServer(namenode).delete(fullpath, recursive.getValue());
case DELETE: {
final boolean b = np.delete(fullpath, recursive.getValue());
final String js = JsonUtil.toJsonString("boolean", b);
return Response.ok(js).type(MediaType.APPLICATION_JSON).build();
}
case DELETESNAPSHOT: {
np.deleteSnapshot(fullpath, snapshotName.getValue());
return Response.ok().type(MediaType.APPLICATION_OCTET_STREAM).build();
}
default:
throw new UnsupportedOperationException(op + " is not supported");
}

View File

@ -957,7 +957,7 @@ Path decodeResponse(Map<?,?> json) {
public void deleteSnapshot(final Path path, final String snapshotName)
throws IOException {
statistics.incrementWriteOps(1);
final HttpOpParam.Op op = PutOpParam.Op.DELETESNAPSHOT;
final HttpOpParam.Op op = DeleteOpParam.Op.DELETESNAPSHOT;
new FsPathRunner(op, path, new SnapshotNameParam(snapshotName)).run();
}

View File

@ -24,6 +24,7 @@ public class DeleteOpParam extends HttpOpParam<DeleteOpParam.Op> {
/** Delete operations. */
public static enum Op implements HttpOpParam.Op {
DELETE(HttpURLConnection.HTTP_OK),
DELETESNAPSHOT(HttpURLConnection.HTTP_OK),
NULL(HttpURLConnection.HTTP_NOT_IMPLEMENTED);

View File

@ -47,7 +47,6 @@ public static enum Op implements HttpOpParam.Op {
REMOVEXATTR(false, HttpURLConnection.HTTP_OK),
CREATESNAPSHOT(false, HttpURLConnection.HTTP_OK),
DELETESNAPSHOT(false, HttpURLConnection.HTTP_OK),
RENAMESNAPSHOT(false, HttpURLConnection.HTTP_OK),
NULL(false, HttpURLConnection.HTTP_NOT_IMPLEMENTED);

View File

@ -102,6 +102,12 @@ WebHDFS REST API
* {{{Cancel Delegation Token}<<<CANCELDELEGATIONTOKEN>>>}}
(see {{{../../api/org/apache/hadoop/fs/FileSystem.html}FileSystem}}.cancelDelegationToken)
* {{{Create Snapshot}<<<CREATESNAPSHOT>>>}}
(see {{{../../api/org/apache/hadoop/fs/FileSystem.html}FileSystem}}.createSnapshot)
* {{{Rename Snapshot}<<<RENAMESNAPSHOT>>>}}
(see {{{../../api/org/apache/hadoop/fs/FileSystem.html}FileSystem}}.renameSnapshot)
* HTTP POST
* {{{Append to a File}<<<APPEND>>>}}
@ -114,6 +120,9 @@ WebHDFS REST API
* {{{Delete a File/Directory}<<<DELETE>>>}}
(see {{{../../api/org/apache/hadoop/fs/FileSystem.html}FileSystem}}.delete)
* {{{Delete Snapshot}<<<DELETESNAPSHOT>>>}}
(see {{{../../api/org/apache/hadoop/fs/FileSystem.html}FileSystem}}.deleteSnapshot)
** {FileSystem URIs vs HTTP URLs}
@ -900,6 +909,75 @@ Transfer-Encoding: chunked
{{{../../api/org/apache/hadoop/fs/FileSystem.html}FileSystem}}.getAclStatus
* {Snapshot Operations}
** {Create Snapshot}
* Submit a HTTP PUT request.
+---------------------------------
curl -i -X PUT "http://<HOST>:<PORT>/webhdfs/v1/<PATH>?op=CREATESNAPSHOT[&snapshotname=<SNAPSHOTNAME>]"
+---------------------------------
The client receives a response with a {{{Path JSON Schema}<<<Path>>> JSON object}}:
+---------------------------------
HTTP/1.1 200 OK
Content-Type: application/json
Transfer-Encoding: chunked
{"Path": "/user/szetszwo/.snapshot/s1"}
+---------------------------------
[]
See also:
{{{../../api/org/apache/hadoop/fs/FileSystem.html}FileSystem}}.createSnapshot
** {Delete Snapshot}
* Submit a HTTP DELETE request.
+---------------------------------
curl -i -X DELETE "http://<HOST>:<PORT>/webhdfs/v1/<PATH>?op=DELETESNAPSHOT&snapshotname=<SNAPSHOTNAME>"
+---------------------------------
The client receives a response with zero content length:
+---------------------------------
HTTP/1.1 200 OK
Content-Length: 0
+---------------------------------
[]
See also:
{{{../../api/org/apache/hadoop/fs/FileSystem.html}FileSystem}}.deleteSnapshot
** {Rename Snapshot}
* Submit a HTTP PUT request.
+---------------------------------
curl -i -X PUT "http://<HOST>:<PORT>/webhdfs/v1/<PATH>?op=RENAMESNAPSHOT
&oldsnapshotname=<SNAPSHOTNAME>&snapshotname=<SNAPSHOTNAME>"
+---------------------------------
The client receives a response with zero content length:
+---------------------------------
HTTP/1.1 200 OK
Content-Length: 0
+---------------------------------
[]
See also:
{{{../../api/org/apache/hadoop/fs/FileSystem.html}FileSystem}}.renameSnapshot
* {Delegation Token Operations}
** {Get Delegation Token}
@ -1839,6 +1917,26 @@ var tokenProperties =
{{{Open and Read a File}<<<OPEN>>>}}
** {Old Snapshot Name}
*----------------+-------------------------------------------------------------------+
|| Name | <<<oldsnapshotname>>> |
*----------------+-------------------------------------------------------------------+
|| Description | The old name of the snapshot to be renamed. |
*----------------+-------------------------------------------------------------------+
|| Type | String |
*----------------+-------------------------------------------------------------------+
|| Default Value | null |
*----------------+-------------------------------------------------------------------+
|| Valid Values | An existing snapshot name. |
*----------------+-------------------------------------------------------------------+
|| Syntax | Any string. |
*----------------+-------------------------------------------------------------------+
See also:
{{{Rename Snapshot}<<<RENAMESNAPSHOT>>>}}
** {Op}
*----------------+-------------------------------------------------------------------+
@ -1983,6 +2081,29 @@ var tokenProperties =
{{{Set Replication Factor}<<<SETREPLICATION>>>}}
** {Snapshot Name}
*----------------+-------------------------------------------------------------------+
|| Name | <<<snapshotname>>> |
*----------------+-------------------------------------------------------------------+
|| Description | The name of the snapshot to be created/deleted. |
|| | Or the new name for snapshot rename. |
*----------------+-------------------------------------------------------------------+
|| Type | String |
*----------------+-------------------------------------------------------------------+
|| Default Value | null |
*----------------+-------------------------------------------------------------------+
|| Valid Values | Any valid snapshot name. |
*----------------+-------------------------------------------------------------------+
|| Syntax | Any string. |
*----------------+-------------------------------------------------------------------+
See also:
{{{Create Snapshot}<<<CREATESNAPSHOT>>>}},
{{{Delete Snapshot}<<<DELETESNAPSHOT>>>}},
{{{Rename Snapshot}<<<RENAMESNAPSHOT>>>}}
** {Sources}
*----------------+-------------------------------------------------------------------+
@ -2042,4 +2163,3 @@ var tokenProperties =
See also:
{{Authentication}}