You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by yu...@apache.org on 2015/08/31 21:32:56 UTC

ambari git commit: AMBARI-12877. Ambari File Browser view - Downloading a directory always creates a zip with name hdfs.zip. (Nitiraj Singh Rathore via yusaku)

Repository: ambari
Updated Branches:
  refs/heads/trunk 59bc26139 -> fc64eae4f


AMBARI-12877. Ambari File Browser view - Downloading a directory always creates a zip with name hdfs.zip. (Nitiraj Singh Rathore via yusaku)


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

Branch: refs/heads/trunk
Commit: fc64eae4f59786cb190c61a5a5156d42f90fa203
Parents: 59bc261
Author: Yusaku Sako <yu...@hortonworks.com>
Authored: Mon Aug 31 12:32:24 2015 -0700
Committer: Yusaku Sako <yu...@hortonworks.com>
Committed: Mon Aug 31 12:32:24 2015 -0700

----------------------------------------------------------------------
 .../view/filebrowser/DownloadService.java       |  8 +++-
 .../view/filebrowser/FilebrowserTest.java       | 50 ++++++++++++++++++--
 2 files changed, 52 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/fc64eae4/contrib/views/files/src/main/java/org/apache/ambari/view/filebrowser/DownloadService.java
----------------------------------------------------------------------
diff --git a/contrib/views/files/src/main/java/org/apache/ambari/view/filebrowser/DownloadService.java b/contrib/views/files/src/main/java/org/apache/ambari/view/filebrowser/DownloadService.java
index 4d45a76..274d0d9 100644
--- a/contrib/views/files/src/main/java/org/apache/ambari/view/filebrowser/DownloadService.java
+++ b/contrib/views/files/src/main/java/org/apache/ambari/view/filebrowser/DownloadService.java
@@ -18,6 +18,7 @@
 
 package org.apache.ambari.view.filebrowser;
 
+import java.io.File;
 import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.io.OutputStream;
@@ -156,6 +157,11 @@ public class DownloadService extends HdfsService {
   @Produces(MediaType.APPLICATION_OCTET_STREAM)
   public Response downloadGZip(final DownloadRequest request) {
     try {
+      String name = "hdfs.zip";
+      if(request.entries.length == 1 ){
+        name = new File(request.entries[0]).getName() + ".zip";
+      }
+
       StreamingOutput result = new StreamingOutput() {
         public void write(OutputStream output) throws IOException,
             ServiceFormattedException {
@@ -197,7 +203,7 @@ public class DownloadService extends HdfsService {
         }
       };
       return Response.ok(result)
-          .header("Content-Disposition", "inline; filename=\"hdfs.zip\"").build();
+          .header("Content-Disposition", "inline; filename=\"" + name +"\"").build();
     } catch (WebApplicationException ex) {
       throw ex;
     } catch (Exception ex) {

http://git-wip-us.apache.org/repos/asf/ambari/blob/fc64eae4/contrib/views/files/src/test/java/org/apache/ambari/view/filebrowser/FilebrowserTest.java
----------------------------------------------------------------------
diff --git a/contrib/views/files/src/test/java/org/apache/ambari/view/filebrowser/FilebrowserTest.java b/contrib/views/files/src/test/java/org/apache/ambari/view/filebrowser/FilebrowserTest.java
index d481323..00cd368 100644
--- a/contrib/views/files/src/test/java/org/apache/ambari/view/filebrowser/FilebrowserTest.java
+++ b/contrib/views/files/src/test/java/org/apache/ambari/view/filebrowser/FilebrowserTest.java
@@ -28,6 +28,7 @@ import java.io.FileInputStream;
 import java.io.FileWriter;
 import java.io.InputStream;
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 
 import javax.ws.rs.core.HttpHeaders;
@@ -146,15 +147,21 @@ public class FilebrowserTest{
     Assert.assertEquals(200, response2.getStatus());
   }
 
-  @Test
-  public void testStreamingGzip() throws Exception {
-    String gzipDir = "/tmp/testGzip";
+  private void createDirectoryWithFiles(String dirPath) throws Exception {
     FileOperationService.MkdirRequest request = new FileOperationService.MkdirRequest();
-    request.path = gzipDir;
+    request.path = dirPath;
+    File file = new File(dirPath);
+    String fileName = file.getName();
     fileBrowserService.fileOps().mkdir(request);
     for (int i = 0; i < 10; i++) {
-      uploadFile(gzipDir, "testGzip" + i, ".txt", "Hello world" + i);
+      uploadFile(dirPath, fileName + i, ".txt", "Hello world" + i);
     }
+  }
+
+  @Test
+  public void testStreamingGzip() throws Exception {
+    String gzipDir = "/tmp/testGzip";
+    createDirectoryWithFiles(gzipDir);
     DownloadService.DownloadRequest dr = new DownloadService.DownloadRequest();
     dr.entries = new String[] { gzipDir };
 
@@ -162,6 +169,39 @@ public class FilebrowserTest{
   }
 
   @Test
+  public void testStreamingDownloadGzipName() throws Exception {
+    String gzipDir = "/tmp/testGzip1";
+    createDirectoryWithFiles(gzipDir);
+
+    // test download 1 folder
+    validateDownloadZipName(new String[]{gzipDir}, "testGzip1.zip" );
+
+    // test download 1 folder
+    validateDownloadZipName(new String[]{gzipDir + "/testGzip11.txt"}, "testGzip11.txt.zip" );
+
+    String gzipDir2 = "/tmp/testGzip2";
+    createDirectoryWithFiles(gzipDir2);
+
+    // test download 2 folders
+    validateDownloadZipName(new String[] { gzipDir, gzipDir2 }, "hdfs.zip" );
+
+    // test download 2 files of same folder
+    validateDownloadZipName(new String[] { gzipDir + "/testGzip11", gzipDir + "/testGzip12" }, "hdfs.zip" );
+
+    // test download 2 files of different folder -- although I think UI does not allow it
+    validateDownloadZipName(new String[] { gzipDir + "/testGzip11", gzipDir2 + "/testGzip21" }, "hdfs.zip" );
+  }
+
+  private void validateDownloadZipName(String[] entries, String downloadedFileName) {
+    DownloadService.DownloadRequest dr = new DownloadService.DownloadRequest();
+    dr.entries = entries;
+
+    Response result = fileBrowserService.download().downloadGZip(dr);
+    List<Object> contentDisposition = result.getMetadata().get("Content-Disposition");
+    Assert.assertEquals("inline; filename=\"" + downloadedFileName +"\"",contentDisposition.get(0));
+  }
+
+  @Test
   public void testUsername() throws Exception {
     Assert.assertEquals(System.getProperty("user.name"), fileBrowserService.upload().getDoAsUsername(context));
     properties.put("webhdfs.username", "test-user");