[ 
https://issues.apache.org/jira/browse/HDFS-15982?focusedWorklogId=590970&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-590970
 ]

ASF GitHub Bot logged work on HDFS-15982:
-----------------------------------------

                Author: ASF GitHub Bot
            Created on: 29/Apr/21 13:04
            Start Date: 29/Apr/21 13:04
    Worklog Time Spent: 10m 
      Work Description: smengcl commented on a change in pull request #2927:
URL: https://github.com/apache/hadoop/pull/2927#discussion_r623031345



##########
File path: 
hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/web/resources/NamenodeWebHdfsMethods.java
##########
@@ -1527,34 +1535,49 @@ public Response delete(
       @QueryParam(RecursiveParam.NAME) @DefaultValue(RecursiveParam.DEFAULT)
           final RecursiveParam recursive,
       @QueryParam(SnapshotNameParam.NAME) 
@DefaultValue(SnapshotNameParam.DEFAULT)
-          final SnapshotNameParam snapshotName
+          final SnapshotNameParam snapshotName,
+      @QueryParam(DeleteSkipTrashParam.NAME)
+      @DefaultValue(DeleteSkipTrashParam.DEFAULT)
+          final DeleteSkipTrashParam skiptrash
       ) throws IOException, InterruptedException {
 
-    init(ugi, delegation, username, doAsUser, path, op, recursive, 
snapshotName);
+    init(ugi, delegation, username, doAsUser, path, op, recursive,
+        snapshotName, skiptrash);
 
-    return doAs(ugi, new PrivilegedExceptionAction<Response>() {
-      @Override
-      public Response run() throws IOException {
-          return delete(ugi, delegation, username, doAsUser,
-              path.getAbsolutePath(), op, recursive, snapshotName);
-      }
-    });
+    return doAs(ugi, () -> delete(
+        path.getAbsolutePath(), op, recursive, snapshotName, skiptrash));
   }
 
   protected Response delete(
-      final UserGroupInformation ugi,
-      final DelegationParam delegation,
-      final UserParam username,
-      final DoAsParam doAsUser,
       final String fullpath,
       final DeleteOpParam op,
       final RecursiveParam recursive,
-      final SnapshotNameParam snapshotName
-      ) throws IOException {
+      final SnapshotNameParam snapshotName,
+      final DeleteSkipTrashParam skipTrash) throws IOException {
     final ClientProtocol cp = getRpcClientProtocol();
 
     switch(op.getValue()) {
     case DELETE: {
+      Configuration conf =
+          (Configuration) context.getAttribute(JspHelper.CURRENT_CONF);
+      long trashInterval =
+          conf.getLong(FS_TRASH_INTERVAL_KEY, FS_TRASH_INTERVAL_DEFAULT);
+      if (trashInterval > 0 && !skipTrash.getValue()) {
+        LOG.info("{} is {} , trying to archive {} instead of removing",
+            FS_TRASH_INTERVAL_KEY, trashInterval, fullpath);
+        org.apache.hadoop.fs.Path path =
+            new org.apache.hadoop.fs.Path(fullpath);
+        boolean movedToTrash = Trash.moveToAppropriateTrash(
+            FileSystem.get(conf), path, conf);
+        if (movedToTrash) {
+          final String js = JsonUtil.toJsonString("boolean", true);
+          return Response.ok(js).type(MediaType.APPLICATION_JSON).build();
+        }
+        // Same is the behavior with Delete shell command.
+        // If moveToAppropriateTrash() returns false, file deletion
+        // is attempted rather than throwing Error.
+        LOG.error("Could not move {} to Trash, attempting removal", fullpath);

Review comment:
       Same as above




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Issue Time Tracking
-------------------

    Worklog Id:     (was: 590970)
    Time Spent: 6h  (was: 5h 50m)

> Deleted data using HTTP API should be saved to the trash
> --------------------------------------------------------
>
>                 Key: HDFS-15982
>                 URL: https://issues.apache.org/jira/browse/HDFS-15982
>             Project: Hadoop HDFS
>          Issue Type: New Feature
>          Components: hdfs, httpfs, webhdfs
>            Reporter: Bhavik Patel
>            Assignee: Viraj Jasani
>            Priority: Major
>              Labels: pull-request-available
>         Attachments: Screenshot 2021-04-23 at 4.19.42 PM.png, Screenshot 
> 2021-04-23 at 4.36.57 PM.png
>
>          Time Spent: 6h
>  Remaining Estimate: 0h
>
> If we delete the data from the Web UI then it should be first moved to 
> configured/default Trash directory and after the trash interval time, it 
> should be removed. currently, data directly removed from the system[This 
> behavior should be the same as CLI cmd]
> This can be helpful when the user accidentally deletes data from the Web UI.
> Similarly we should provide "Skip Trash" option in HTTP API as well which 
> should be accessible through Web UI.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

---------------------------------------------------------------------
To unsubscribe, e-mail: hdfs-issues-unsubscr...@hadoop.apache.org
For additional commands, e-mail: hdfs-issues-h...@hadoop.apache.org

Reply via email to