You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by rl...@apache.org on 2015/06/07 12:57:29 UTC

ambari git commit: AMBARI-11735. Automatically creates user's trash directory on hdfs if does not exist (Erik Bergenholtz via rlevas)

Repository: ambari
Updated Branches:
  refs/heads/trunk 9127e1987 -> 219e2f953


AMBARI-11735. Automatically creates user's trash directory on hdfs if does not exist (Erik Bergenholtz via rlevas)


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/219e2f95
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/219e2f95
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/219e2f95

Branch: refs/heads/trunk
Commit: 219e2f95368abc8cfee3849e90031c5243719983
Parents: 9127e19
Author: Erik Bergenholtz <eb...@hortonworks.com>
Authored: Sun Jun 7 06:57:27 2015 -0400
Committer: Robert Levas <rl...@hortonworks.com>
Committed: Sun Jun 7 06:57:27 2015 -0400

----------------------------------------------------------------------
 contrib/views/files/pom.xml                     |  2 +-
 .../view/filebrowser/FileOperationService.java  | 34 +++++++++++++-------
 .../ambari/view/filebrowser/HdfsService.java    |  6 ++++
 contrib/views/files/src/main/resources/view.xml |  2 +-
 4 files changed, 30 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/219e2f95/contrib/views/files/pom.xml
----------------------------------------------------------------------
diff --git a/contrib/views/files/pom.xml b/contrib/views/files/pom.xml
index 5026ee6..c3bfd18 100644
--- a/contrib/views/files/pom.xml
+++ b/contrib/views/files/pom.xml
@@ -19,7 +19,7 @@
   <modelVersion>4.0.0</modelVersion>
   <groupId>org.apache.ambari.contrib.views</groupId>
   <artifactId>files</artifactId>
-  <version>0.2.0-SNAPSHOT</version>
+  <version>1.0.0-SNAPSHOT</version>
   <name>Files</name>
 
   <parent>

http://git-wip-us.apache.org/repos/asf/ambari/blob/219e2f95/contrib/views/files/src/main/java/org/apache/ambari/view/filebrowser/FileOperationService.java
----------------------------------------------------------------------
diff --git a/contrib/views/files/src/main/java/org/apache/ambari/view/filebrowser/FileOperationService.java b/contrib/views/files/src/main/java/org/apache/ambari/view/filebrowser/FileOperationService.java
index fd07da6..973fb8f 100644
--- a/contrib/views/files/src/main/java/org/apache/ambari/view/filebrowser/FileOperationService.java
+++ b/contrib/views/files/src/main/java/org/apache/ambari/view/filebrowser/FileOperationService.java
@@ -90,7 +90,7 @@ public class FileOperationService extends HdfsService {
         result = Response.ok(getApi(context).fileStatusToJSON(api
             .getFileStatus(request.dst)));
       } else {
-        result = Response.ok(new BoolResult(false)).status(422);
+        result = Response.ok(new BoolResult(false, "Can't move '" + request.src + "' to '" + request.dst + "'")).status(422);
       }
       return result.build();
     } catch (WebApplicationException ex) {
@@ -117,7 +117,7 @@ public class FileOperationService extends HdfsService {
         result = Response.ok(getApi(context).fileStatusToJSON(api
             .getFileStatus(request.path)));
       } else {
-        result = Response.ok(new BoolResult(false)).status(422);
+        result = Response.ok(new BoolResult(false, "Can't chmod '" + request.path + "'")).status(422);
       }
       return result.build();
     } catch (WebApplicationException ex) {
@@ -147,7 +147,8 @@ public class FileOperationService extends HdfsService {
         result = Response.ok(getApi(context).fileStatusToJSON(api
             .getFileStatus(request.dst)));
       } catch (HdfsApiException e) {
-        result = Response.ok(new BoolResult(false)).status(422);
+        result = Response.ok(new BoolResult(false, "Can't copy '" + request.src + "' to '" + request.dst + "'")).
+            status(422);
       }
       return result.build();
     } catch (WebApplicationException ex) {
@@ -172,7 +173,7 @@ public class FileOperationService extends HdfsService {
       if (api.mkdir(request.path)) {
         result = Response.ok(getApi(context).fileStatusToJSON(api.getFileStatus(request.path)));
       } else {
-        result = Response.ok(new BoolResult(false)).status(422);
+        result = Response.ok(new BoolResult(false, "Can't create dir '" + request.path + "'")).status(422);
       }
       return result.build();
     } catch (WebApplicationException ex) {
@@ -212,16 +213,25 @@ public class FileOperationService extends HdfsService {
   @Produces(MediaType.APPLICATION_JSON)
   public Response moveToTrash(RemoveRequest request) {
     try {
-      HdfsApi api = getApi(context);
-      
-      String trashDir = api.getTrashDirPath(request.path);
-      
       ResponseBuilder result;
-      if (api.rename(request.path, trashDir)) {
+
+      HdfsApi api = getApi(context);
+      String trash = api.getTrashDirPath();
+
+      if (!api.exists(trash)) {
+        if (!api.mkdir(trash)) {
+          result = Response.ok(new BoolResult(false, "Trash dir does not exists. Can't create dir for trash '" + trash + "'")).status(422);
+          return result.build();
+        }
+      }
+
+      String trashFilePath = api.getTrashDirPath(request.path);
+
+      if (api.rename(request.path, trashFilePath)) {
         result = Response.ok(getApi(context).fileStatusToJSON(api
-            .getFileStatus(trashDir)));
+            .getFileStatus(trashFilePath)));
       } else {
-        result = Response.ok(new BoolResult(false)).status(422);
+        result = Response.ok(new BoolResult(false, "Can't move file to '" + trashFilePath + "'")).status(422);
       }
       return result.build();
     } catch (WebApplicationException ex) {
@@ -248,7 +258,7 @@ public class FileOperationService extends HdfsService {
       if (api.delete(request.path, request.recursive)) {
         result = Response.ok(new BoolResult(true)).status(204);
       } else {
-        result = Response.ok(new BoolResult(false)).status(422);
+        result = Response.ok(new BoolResult(false, "Can't remove '" + request.path + "'")).status(422);
       }
       return result.build();
     } catch (WebApplicationException ex) {

http://git-wip-us.apache.org/repos/asf/ambari/blob/219e2f95/contrib/views/files/src/main/java/org/apache/ambari/view/filebrowser/HdfsService.java
----------------------------------------------------------------------
diff --git a/contrib/views/files/src/main/java/org/apache/ambari/view/filebrowser/HdfsService.java b/contrib/views/files/src/main/java/org/apache/ambari/view/filebrowser/HdfsService.java
index 073f13a..d47304f 100644
--- a/contrib/views/files/src/main/java/org/apache/ambari/view/filebrowser/HdfsService.java
+++ b/contrib/views/files/src/main/java/org/apache/ambari/view/filebrowser/HdfsService.java
@@ -55,9 +55,15 @@ public abstract class HdfsService {
   @XmlRootElement
   public static class BoolResult{
     public boolean success;
+    public String message;
     public BoolResult(boolean success){
       this.success = success;
     }
+
+    public BoolResult(boolean success, String message){
+      this.success = success;
+      this.message = message;
+    }
   }
 
   private HdfsApi _api = null;

http://git-wip-us.apache.org/repos/asf/ambari/blob/219e2f95/contrib/views/files/src/main/resources/view.xml
----------------------------------------------------------------------
diff --git a/contrib/views/files/src/main/resources/view.xml b/contrib/views/files/src/main/resources/view.xml
index 1c8991e..b91a52c 100644
--- a/contrib/views/files/src/main/resources/view.xml
+++ b/contrib/views/files/src/main/resources/view.xml
@@ -17,7 +17,7 @@
 <view>
     <name>FILES</name>
     <label>Files</label>
-    <version>0.2.0</version>
+    <version>1.0.0</version>
 
     <min-ambari-version>2.0.*</min-ambari-version>