hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aengin...@apache.org
Subject [hadoop] branch trunk updated: HDDS-905. Create informative landing page for Ozone S3 gateway. Contributed by Elek, Marton.
Date Fri, 15 Feb 2019 07:22:01 GMT
This is an automated email from the ASF dual-hosted git repository.

aengineer pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/hadoop.git


The following commit(s) were added to refs/heads/trunk by this push:
     new 506bd02  HDDS-905. Create informative landing page for Ozone S3 gateway. Contributed
by Elek, Marton.
506bd02 is described below

commit 506bd02c638da06df77248f6831118505fe56a65
Author: Anu Engineer <aengineer@apache.org>
AuthorDate: Thu Feb 14 23:16:23 2019 -0800

    HDDS-905. Create informative landing page for Ozone S3 gateway.
    Contributed by Elek, Marton.
---
 .../dist/src/main/smoketest/s3/webui.robot         | 34 ++++++++++
 hadoop-ozone/s3gateway/pom.xml                     | 44 ++++++++++--
 .../hadoop/ozone/s3/endpoint/RootEndpoint.java     | 17 ++++-
 .../s3/header/AuthenticationHeaderParser.java      |  4 ++
 .../resources/webapps/s3gateway/WEB-INF/web.xml    |  4 --
 .../src/main/resources/webapps/static/index.html   | 79 ++++++++++++++++++++++
 .../hadoop/ozone/s3/endpoint/TestRootList.java     |  4 +-
 7 files changed, 171 insertions(+), 15 deletions(-)

diff --git a/hadoop-ozone/dist/src/main/smoketest/s3/webui.robot b/hadoop-ozone/dist/src/main/smoketest/s3/webui.robot
new file mode 100644
index 0000000..56f8a83
--- /dev/null
+++ b/hadoop-ozone/dist/src/main/smoketest/s3/webui.robot
@@ -0,0 +1,34 @@
+# 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
+#
+# 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.
+
+*** Settings ***
+Documentation       S3 gateway web ui test
+Library             OperatingSystem
+Library             String
+Resource            ../commonlib.robot
+Resource            ./commonawslib.robot
+Suite Setup         Setup s3 tests
+
+*** Variables ***
+${ENDPOINT_URL}       http://s3g:9878
+${BUCKET}             generated
+
+*** Test Cases ***
+
+File upload and directory list
+    ${result} =         Execute                             curl -v ${ENDPOINT_URL}
+                        Should contain      ${result}       HTTP/1.1 307 Temporary Redirect
+    ${result} =         Execute                             curl -v ${ENDPOINT_URL}/static/
+                        Should contain      ${result}       Apache Hadoop Ozone S3
diff --git a/hadoop-ozone/s3gateway/pom.xml b/hadoop-ozone/s3gateway/pom.xml
index b78796f..a1feb8d 100644
--- a/hadoop-ozone/s3gateway/pom.xml
+++ b/hadoop-ozone/s3gateway/pom.xml
@@ -30,12 +30,6 @@
     <downloadSources>true</downloadSources>
   </properties>
 
-  <build>
-    <plugins>
-
-    </plugins>
-  </build>
-
   <dependencies>
     <dependency>
       <groupId>javax.xml.bind</groupId>
@@ -185,4 +179,42 @@
       <scope>provided</scope>
     </dependency>
   </dependencies>
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-dependency-plugin</artifactId>
+        <executions>
+          <execution>
+            <id>copy-common-html</id>
+            <phase>prepare-package</phase>
+            <goals>
+              <goal>unpack</goal>
+            </goals>
+            <configuration>
+              <artifactItems>
+                <artifactItem>
+                  <groupId>org.apache.hadoop</groupId>
+                  <artifactId>hadoop-hdds-server-framework</artifactId>
+                  <outputDirectory>${project.build.outputDirectory}
+                  </outputDirectory>
+                  <includes>webapps/static/**/*.*</includes>
+                </artifactItem>
+                <artifactItem>
+                  <groupId>org.apache.hadoop</groupId>
+                  <artifactId>hadoop-hdds-docs</artifactId>
+                  <outputDirectory>
+                    ${project.build.outputDirectory}/webapps/static
+                  </outputDirectory>
+                  <includes>docs/**/*.*</includes>
+                </artifactItem>
+              </artifactItems>
+              <overWriteSnapshots>true</overWriteSnapshots>
+            </configuration>
+          </execution>
+        </executions>
+      </plugin>
+    </plugins>
+  </build>
 </project>
diff --git a/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/endpoint/RootEndpoint.java
b/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/endpoint/RootEndpoint.java
index 7ad374d..bb91840 100644
--- a/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/endpoint/RootEndpoint.java
+++ b/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/endpoint/RootEndpoint.java
@@ -19,6 +19,8 @@ package org.apache.hadoop.ozone.s3.endpoint;
 
 import javax.ws.rs.GET;
 import javax.ws.rs.Path;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.Response.Status;
 import java.io.IOException;
 import java.time.Instant;
 import java.util.Iterator;
@@ -27,6 +29,7 @@ import org.apache.hadoop.ozone.client.OzoneBucket;
 import org.apache.hadoop.ozone.client.OzoneVolume;
 import org.apache.hadoop.ozone.s3.commontypes.BucketMetadata;
 import org.apache.hadoop.ozone.s3.exception.OS3Exception;
+import org.apache.hadoop.ozone.s3.header.AuthenticationHeaderParser;
 
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -47,12 +50,20 @@ public class RootEndpoint extends EndpointBase {
    * for more details.
    */
   @GET
-  public ListBucketResponse get()
+  public Response get()
       throws OS3Exception, IOException {
     OzoneVolume volume;
     ListBucketResponse response = new ListBucketResponse();
 
-    String userName = getAuthenticationHeaderParser().getAccessKeyID();
+    AuthenticationHeaderParser authenticationHeaderParser =
+        getAuthenticationHeaderParser();
+
+    if (!authenticationHeaderParser.doesAuthenticationInfoExists()) {
+      return Response.status(Status.TEMPORARY_REDIRECT)
+          .header("Location", "/static/")
+          .build();
+    }
+    String userName = authenticationHeaderParser.getAccessKeyID();
     Iterator<? extends OzoneBucket> bucketIterator = listS3Buckets(userName,
         null);
 
@@ -65,6 +76,6 @@ public class RootEndpoint extends EndpointBase {
       response.addBucket(bucketMetadata);
     }
 
-    return response;
+    return Response.ok(response).build();
   }
 }
diff --git a/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/header/AuthenticationHeaderParser.java
b/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/header/AuthenticationHeaderParser.java
index 1ca50cb..7f17c9d 100644
--- a/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/header/AuthenticationHeaderParser.java
+++ b/hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/header/AuthenticationHeaderParser.java
@@ -50,6 +50,10 @@ public class AuthenticationHeaderParser {
     }
   }
 
+  public boolean doesAuthenticationInfoExists() {
+    return authHeader != null;
+  }
+
   public String getAccessKeyID() throws OS3Exception {
     parse();
     return accessKeyID;
diff --git a/hadoop-ozone/s3gateway/src/main/resources/webapps/s3gateway/WEB-INF/web.xml b/hadoop-ozone/s3gateway/src/main/resources/webapps/s3gateway/WEB-INF/web.xml
index 36aad1c..a3552f0 100644
--- a/hadoop-ozone/s3gateway/src/main/resources/webapps/s3gateway/WEB-INF/web.xml
+++ b/hadoop-ozone/s3gateway/src/main/resources/webapps/s3gateway/WEB-INF/web.xml
@@ -21,10 +21,6 @@
       <param-name>javax.ws.rs.Application</param-name>
       <param-value>org.apache.hadoop.ozone.s3.GatewayApplication</param-value>
     </init-param>
-    <init-param>
-      <param-name>jersey.config.servlet.filter.staticContentRegex</param-name>
-      <param-value>/static/images/*.ico</param-value>
-    </init-param>
     <load-on-startup>1</load-on-startup>
   </servlet>
   <servlet-mapping>
diff --git a/hadoop-ozone/s3gateway/src/main/resources/webapps/static/index.html b/hadoop-ozone/s3gateway/src/main/resources/webapps/static/index.html
new file mode 100644
index 0000000..9b335d0
--- /dev/null
+++ b/hadoop-ozone/s3gateway/src/main/resources/webapps/static/index.html
@@ -0,0 +1,79 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<!--
+   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
+
+   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.
+-->
+<html lang="en">
+<head>
+    <meta charset="utf-8">
+    <meta http-equiv="X-UA-Compatible" content="IE=edge">
+    <meta name="viewport" content="width=device-width, initial-scale=1">
+    <!-- The above 3 meta tags *must* come first in the head; any other head content must
come *after* these tags -->
+    <meta name="description" content="Apache Hadoop Ozone S3 gateway">
+
+    <title>S3 gateway -- Apache Hadoop Ozone</title>
+
+    <link href="bootstrap-3.3.7/css/bootstrap.min.css" rel="stylesheet">
+    <link href="hadoop.css" rel="stylesheet">
+    <link href="ozone.css" rel="stylesheet">
+
+</head>
+
+<body>
+
+<header class="navbar navbar-inverse navbar-fixed-top bs-docs-nav">
+    <div class="container-fluid">
+        <div class="navbar-header">
+            <button type="button" class="navbar-toggle collapsed"
+                    data-toggle="collapse" data-target="#navbar"
+                    aria-expanded="false" aria-controls="navbar">
+                <span class="sr-only">Toggle navigation</span>
+                <span class="icon-bar"></span>
+                <span class="icon-bar"></span>
+                <span class="icon-bar"></span>
+            </button>
+            <a class="navbar-brand" href="#">Ozone S3G</a>
+        </div>
+        <div id="navbar" class="collapse navbar-collapse">
+            <ul class="nav navbar-nav" id="ui-tabs">
+                <li><a href="docs">Documentation</a></li>
+
+            </ul>
+        </div><!--/.nav-collapse -->
+
+    </div>
+</header>
+
+
+<div class="container-fluid" style="margin: 12pt">
+
+    <h1>S3 gateway</h1>
+
+    <p>This is an endpoint of Apache Hadoop Ozone S3 gateway. Use it with any
+        AWS S3 compatible tool
+        with setting this url as an endpoint</p>
+
+    <p>For example with aws-cli:</p>
+
+    <pre>aws s3api --endpoint <script>document.write(window.location.href).replace("static/",
"")</script> create-bucket --bucket=wordcount</pre>
+
+    <p>For more information, please check the <a href="docs">documentation.</a>
+    </p>
+</div><!-- /.container -->
+
+<script src="static/bootstrap-3.3.7/js/bootstrap.min.js"></script>
+</body>
+</html>
diff --git a/hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/s3/endpoint/TestRootList.java
b/hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/s3/endpoint/TestRootList.java
index 8759fff..2e5944c 100644
--- a/hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/s3/endpoint/TestRootList.java
+++ b/hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/s3/endpoint/TestRootList.java
@@ -58,14 +58,14 @@ public class TestRootList {
   public void testListBucket() throws Exception {
 
     // List operation should succeed even there is no bucket.
-    ListBucketResponse response = rootEndpoint.get();
+    ListBucketResponse response = (ListBucketResponse) rootEndpoint.get().getEntity();
     assertEquals(0, response.getBucketsNum());
 
     String bucketBaseName = "bucket-" + getClass().getName();
     for(int i = 0; i < 10; i++) {
       objectStoreStub.createS3Bucket(userName, bucketBaseName + i);
     }
-    response = rootEndpoint.get();
+    response = (ListBucketResponse) rootEndpoint.get().getEntity();
     assertEquals(10, response.getBucketsNum());
   }
 


---------------------------------------------------------------------
To unsubscribe, e-mail: common-commits-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-commits-help@hadoop.apache.org


Mime
View raw message