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 00000000000..56f8a83c8c5 --- /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 b78796f7c6e..a1feb8dbb2e 100644 --- a/hadoop-ozone/s3gateway/pom.xml +++ b/hadoop-ozone/s3gateway/pom.xml @@ -30,12 +30,6 @@ true - - - - - - javax.xml.bind @@ -185,4 +179,42 @@ provided + + + + + org.apache.maven.plugins + maven-dependency-plugin + + + copy-common-html + prepare-package + + unpack + + + + + org.apache.hadoop + hadoop-hdds-server-framework + ${project.build.outputDirectory} + + webapps/static/**/*.* + + + org.apache.hadoop + hadoop-hdds-docs + + ${project.build.outputDirectory}/webapps/static + + docs/**/*.* + + + true + + + + + + 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 7ad374d875a..bb918408da3 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 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 1ca50cba25e..7f17c9d3dc9 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 36aad1c9ad4..a3552f07006 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 @@ javax.ws.rs.Application org.apache.hadoop.ozone.s3.GatewayApplication - - jersey.config.servlet.filter.staticContentRegex - /static/images/*.ico - 1 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 00000000000..9b335d01a79 --- /dev/null +++ b/hadoop-ozone/s3gateway/src/main/resources/webapps/static/index.html @@ -0,0 +1,79 @@ + + + + + + + + + + + S3 gateway -- Apache Hadoop Ozone + + + + + + + + + + + + +
+ +

S3 gateway

+ +

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

+ +

For example with aws-cli:

+ +
aws s3api --endpoint  create-bucket --bucket=wordcount
+ +

For more information, please check the documentation. +

+
+ + + + 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 8759fff0d00..2e5944c6244 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()); }