From 63375af8c1d95064bc813efd8df27902e4de6aee Mon Sep 17 00:00:00 2001 From: Anu Engineer Date: Fri, 19 Oct 2018 08:48:11 -0700 Subject: [PATCH] HDDS-680. Provide web based bucket browser. Contributed by Elek, Marton. (cherry picked from commit b22651e94939132c0ec9b241691e82935035a760) --- NOTICE.txt | 8 + .../ozone/s3/endpoint/BucketEndpoint.java | 16 +- .../s3gateway/src/main/resources/browser.html | 617 ++++++++++++++++++ .../ozone/s3/endpoint/TestBucketGet.java | 10 +- 4 files changed, 646 insertions(+), 5 deletions(-) create mode 100644 hadoop-ozone/s3gateway/src/main/resources/browser.html diff --git a/NOTICE.txt b/NOTICE.txt index a53f13c7002..00fa3758eef 100644 --- a/NOTICE.txt +++ b/NOTICE.txt @@ -613,3 +613,11 @@ which has the following notices: Written by Doug Lea with assistance from members of JCP JSR-166 Expert Group and released to the public domain, as explained at http://creativecommons.org/publicdomain/zero/1.0/ + + +The source and binary distribution of this product bundles modified version of + github.com/awslabs/aws-js-s3-explorer licensed under Apache 2.0 license + with the following notice: + +AWS JavaScript S3 Explorer +Copyright 2014-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. \ No newline at end of file diff --git a/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/endpoint/BucketEndpoint.java b/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/endpoint/BucketEndpoint.java index 7a7c92d2618..1fa19c422ff 100644 --- a/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/endpoint/BucketEndpoint.java +++ b/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/endpoint/BucketEndpoint.java @@ -27,9 +27,11 @@ import javax.ws.rs.PathParam; import javax.ws.rs.QueryParam; import javax.ws.rs.core.Context; import javax.ws.rs.core.HttpHeaders; +import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import javax.ws.rs.core.Response.Status; import java.io.IOException; +import java.io.InputStream; import java.time.Instant; import java.util.Iterator; @@ -60,15 +62,25 @@ public class BucketEndpoint extends EndpointBase { * for more details. */ @GET - public ListObjectResponse list( + public Response list( @PathParam("bucket") String bucketName, @QueryParam("delimiter") String delimiter, @QueryParam("encoding-type") String encodingType, @QueryParam("marker") String marker, @DefaultValue("1000") @QueryParam("max-keys") int maxKeys, @QueryParam("prefix") String prefix, + @QueryParam("browser") String browser, @Context HttpHeaders hh) throws OS3Exception, IOException { + if (browser != null) { + try (InputStream browserPage = getClass() + .getResourceAsStream("/browser.html")) { + return Response.ok(browserPage, + MediaType.TEXT_HTML_TYPE) + .build(); + } + } + if (delimiter == null) { delimiter = "/"; } @@ -125,7 +137,7 @@ public class BucketEndpoint extends EndpointBase { } response.setKeyCount( response.getCommonPrefixes().size() + response.getContents().size()); - return response; + return Response.ok(response).build(); } @PUT diff --git a/hadoop-ozone/s3gateway/src/main/resources/browser.html b/hadoop-ozone/s3gateway/src/main/resources/browser.html new file mode 100644 index 00000000000..dc05a001775 --- /dev/null +++ b/hadoop-ozone/s3gateway/src/main/resources/browser.html @@ -0,0 +1,617 @@ + + + + + + + + AWS S3 Explorer + + + + + + + + + + + + + +
+
+
+
+ + +
+ +
+
+ Ozone S3 Explorer  +
+ +
+ +
+
+ +
+
+ + +
+ + +
+
+ +
+ + 42 +
+
+
+ + +
+ + + + + + + + + + + +
ObjectFolderLast ModifiedTimestampSize
+
+
+
+
+
+ + + + + + + + + + + + + diff --git a/hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/s3/endpoint/TestBucketGet.java b/hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/s3/endpoint/TestBucketGet.java index 41778b2a2a9..54534edc939 100644 --- a/hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/s3/endpoint/TestBucketGet.java +++ b/hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/s3/endpoint/TestBucketGet.java @@ -44,7 +44,9 @@ public class TestBucketGet { getBucket.setClient(client); ListObjectResponse getBucketResponse = - getBucket.list("b1", "/", null, null, 100, "", null); + (ListObjectResponse) getBucket + .list("b1", "/", null, null, 100, "", null, null) + .getEntity(); Assert.assertEquals(1, getBucketResponse.getCommonPrefixes().size()); Assert.assertEquals("dir1/", @@ -66,7 +68,8 @@ public class TestBucketGet { getBucket.setClient(client); ListObjectResponse getBucketResponse = - getBucket.list("b1", "/", null, null, 100, "dir1", null); + (ListObjectResponse) getBucket + .list("b1", "/", null, null, 100, "dir1", null, null).getEntity(); Assert.assertEquals(1, getBucketResponse.getCommonPrefixes().size()); Assert.assertEquals("dir1/", @@ -87,7 +90,8 @@ public class TestBucketGet { getBucket.setClient(ozoneClient); ListObjectResponse getBucketResponse = - getBucket.list("b1", "/", null, null, 100, "dir1/", null); + (ListObjectResponse) getBucket + .list("b1", "/", null, null, 100, "dir1/", null, null).getEntity(); Assert.assertEquals(1, getBucketResponse.getCommonPrefixes().size()); Assert.assertEquals("dir1/dir2/",