Преглед на файлове

AMBARI-8536: Views: Files, UI and trash

sposetti преди 10 години
родител
ревизия
7b77f4dc64

+ 122 - 0
contrib/views/files/readme.md

@@ -0,0 +1,122 @@
+<!---
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements.  See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License.  You may obtain a copy of the License at [http://www.apache.org/licenses/LICENSE-2.0](http://www.apache.org/licenses/LICENSE-2.0)
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+-->
+
+Files View
+============
+
+Description
+-----
+This View provides a UI to browse HDFS, create directories and upload + download files.
+
+Requirements
+-----
+
+- Ambari 1.7.0
+- HDFS with WebHDFS configured
+
+Build
+-----
+
+The view can be built as a maven project.
+
+    mvn clean install
+
+The build will produce the view archive.
+
+    target/files-0.1.0-SNAPSHOT.jar
+
+Place the view archive on the Ambari Server and restart to deploy.    
+
+    cp files-0.1.0-SNAPSHOT.jar /var/lib/ambari-server/resources/views/
+    ambari-server restart
+
+View Definition
+-----
+
+    <parameter>
+        <name>webhdfs.url</name>
+        <description>WebHDFS FileSystem URI (example: webhdfs://namenode:50070)</description>
+        <required>true</required>
+    </parameter>
+    <parameter>
+        <name>webhdfs.username</name>
+        <description>User and doAs for proxy user for HDFS</description>
+        <required>false</required>
+    </parameter>
+
+Cluster Configuration
+-----
+
+Configure HDFS for a proxy user. In core-site.xml, add the following properties:
+
+    hadoop.proxyuser.root.hosts=*
+    hadoop.proxyuser.root.groups=*
+
+Create Hadoop users and make members of the hdfs, hadoop and users groups. For example, to create a user "admin": 
+
+    useradd -G hdfs admin
+    usermod -a -G users admin
+    usermod -a -G hadoop admin
+
+Check the "admin" user has the correct group membership.
+
+    id admin
+    uid=1002(admin) gid=1002(admin) groups=1002(admin),100(users),503(hadoop),498(hdfs)
+
+
+Deploying the View
+-----
+
+Use the [Ambari Vagrant](https://cwiki.apache.org/confluence/display/AMBARI/Quick+Start+Guide) setup to create a cluster:
+
+Deploy the Files view into Ambari.
+
+    cp files-0.1.0-SNAPSHOT.jar /var/lib/ambari-server/resources/views/
+    ambari-server restart
+
+From the Ambari Administration interface, create a Files view instance.
+
+|Property|Value|
+|---|---|
+| Details: Instance Name | FILES_1 |
+| Details: Display Name | Files |
+| Details: Description | Browse HDFS files and directories |
+| Properties: webhdfs.url | webhdfs://c6401.ambari.apache.org:50070 |
+
+Login to Ambari as "admin" and browse to the view instance.
+
+    http://c6401.ambari.apache.org:8080/#/main/views/FILES/0.1.0/FILES_1
+
+Optional: Development with Local Vagrant VM
+-----
+
+After deploying the view into a Vagrant VM, if you want to perform view development from your local build, perform the following:
+
+Browse to the work directory.
+
+    cd /var/lib/ambari-server/resources/views/work
+
+Remove the FILES{0.1.0} directory.
+
+    rm FILES\{0.1.0\}
+    
+Create a link to your local build.
+
+    ln -s /vagrant/ambari/contrib/views/files/target/classes/ FILES\{0.1.0\}
+
+Restart Ambari Server.
+
+    ambari-server restart
+

+ 6 - 2
contrib/views/files/src/main/java/org/apache/ambari/view/filebrowser/FileOperationService.java

@@ -206,9 +206,13 @@ public class FileOperationService extends HdfsService {
   public Response moveToTrash(RemoveRequest request) {
     try {
       HdfsApi api = getApi(context);
+      
+      String trashDir = api.getTrashDirPath(request.path);
+      
       ResponseBuilder result;
-      if (api.moveToTrash(request.path)){
-        result = Response.ok(new BoolResult(true)).status(204);
+      if (api.rename(request.path, trashDir)) {
+        result = Response.ok(getApi(context).fileStatusToJSON(api
+            .getFileStatus(trashDir)));
       } else {
         result = Response.ok(new BoolResult(false)).status(422);
       }

+ 28 - 0
contrib/views/files/src/main/java/org/apache/ambari/view/filebrowser/HdfsApi.java

@@ -171,7 +171,35 @@ public class HdfsApi {
       }
     });
   }
+ 
+   /**
+    * Trash directory path.
+    *
+    * @return trash directory path
+    * @throws Exception
+    */
+  public String getTrashDirPath() throws Exception {
+    Path trashDir = getTrashDir();
+    
+    return  trashDir.toUri().getRawPath();
+  }
+
+   /**
+    * Trash directory path.
+    *
+    * @param    filePath        the path to the file
+    * @return trash directory path for the file
+    * @throws Exception
+    */
+  public String getTrashDirPath(String filePath) throws Exception {
+      String trashDirPath = getTrashDirPath();
 
+      Path path = new Path(filePath);
+      trashDirPath = trashDirPath+"/"+path.getName();
+      
+    return  trashDirPath;
+  }
+      
   /**
    * Empty trash
    * @return

+ 8 - 2
contrib/views/files/src/main/resources/ui/app/templates/util/fileRow.hbs

@@ -28,11 +28,17 @@
     {{#rename-input fileBinding='content' confirm='rename' isRenaming=isRenaming}}
       <div class="file-name allow-open">
         <span>
+        {{#if content.readAccess}}
           <a {{action 'open'}}>
             <strong>
               {{content.name}}
             </strong>
           </a>
+          {{else}}
+            <strong>
+              {{content.name}}
+            </strong>
+          {{/if}}
         </span>
         <span class="help-block mod-time allow-open">
           <small class='allow-open'>
@@ -57,9 +63,9 @@
         <li>
         {{#if content.readAccess}}
           {{#if content.isDirectory}}
-            <a href="#" {{action 'download' 'zip'}} data-toggle="tooltip" data-placement="bottom" title="Download zip"><i class="fa fa-archive fa-fw fa-lg"></i></a>
+            <a href="#" {{action 'download' 'zip'}} data-toggle="tooltip" data-placement="bottom" title="Download ZIP"><i class="fa fa-archive fa-fw fa-lg"></i></a>
           {{else}}
-            <a href="#" {{action 'download' 'browse'}} data-toggle="tooltip" data-placement="bottom" title="Download"><i class="fa fa-download fa-fw fa-lg"></i></a>
+            <a href="#" {{action 'download' 'browse'}} data-toggle="tooltip" data-placement="bottom" title="Download File"><i class="fa fa-download fa-fw fa-lg"></i></a>
           {{/if}}
         {{/if}}
         </li>