ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From yus...@apache.org
Subject 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)
Date Mon, 31 Aug 2015 19:33:22 GMT
Repository: ambari
Updated Branches:
  refs/heads/branch-2.1 bcd8df155 -> 8959cd5b5


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/8959cd5b
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/8959cd5b
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/8959cd5b

Branch: refs/heads/branch-2.1
Commit: 8959cd5b5d4ed21cfeaeb1b0fdf3d780d4ff0072
Parents: bcd8df1
Author: Yusaku Sako <yusaku@hortonworks.com>
Authored: Mon Aug 31 12:32:24 2015 -0700
Committer: Yusaku Sako <yusaku@hortonworks.com>
Committed: Mon Aug 31 12:33:17 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/8959cd5b/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/8959cd5b/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");


Mime
View raw message