You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ozone.apache.org by el...@apache.org on 2020/07/27 11:23:42 UTC

[hadoop-ozone] branch master updated: HDDS-4022. Ozone s3 API return 400 Bad Request for head-bucket for non existing bucket. (#1251)

This is an automated email from the ASF dual-hosted git repository.

elek pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/hadoop-ozone.git


The following commit(s) were added to refs/heads/master by this push:
     new a123b4e  HDDS-4022. Ozone s3 API return 400 Bad Request for head-bucket for non existing bucket. (#1251)
a123b4e is described below

commit a123b4ef6d4e9804d298390ca1a8aeb8e64e62a5
Author: Bharat Viswanadham <bh...@apache.org>
AuthorDate: Mon Jul 27 04:23:25 2020 -0700

    HDDS-4022. Ozone s3 API return 400 Bad Request for head-bucket for non existing bucket. (#1251)
---
 hadoop-ozone/dist/src/main/smoketest/s3/buckethead.robot      |  5 +++--
 .../org/apache/hadoop/ozone/s3/endpoint/BucketEndpoint.java   |  8 +-------
 .../org/apache/hadoop/ozone/s3/endpoint/TestBucketHead.java   | 11 +++++++++--
 3 files changed, 13 insertions(+), 11 deletions(-)

diff --git a/hadoop-ozone/dist/src/main/smoketest/s3/buckethead.robot b/hadoop-ozone/dist/src/main/smoketest/s3/buckethead.robot
index 7666871..f3ecd01 100644
--- a/hadoop-ozone/dist/src/main/smoketest/s3/buckethead.robot
+++ b/hadoop-ozone/dist/src/main/smoketest/s3/buckethead.robot
@@ -31,5 +31,6 @@ ${BUCKET}             generated
 Head Bucket not existent
     ${result} =         Execute AWSS3APICli     head-bucket --bucket ${BUCKET}
     ${result} =         Execute AWSS3APICli and checkrc      head-bucket --bucket ozonenosuchbucketqqweqwe  255
-                        Should contain          ${result}    Bad Request
-                        Should contain          ${result}    400
+                        Should contain          ${result}    404
+                        Should contain          ${result}    Not Found
+
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 ef02510..067d6a4 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
@@ -31,7 +31,6 @@ 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.util.Iterator;
@@ -253,12 +252,7 @@ public class BucketEndpoint extends EndpointBase {
       getBucket(bucketName);
     } catch (OS3Exception ex) {
       LOG.error("Exception occurred in headBucket", ex);
-      //TODO: use a subclass fo OS3Exception and catch it here.
-      if (ex.getCode().contains("NoSuchBucket")) {
-        return Response.status(Status.BAD_REQUEST).build();
-      } else {
-        throw ex;
-      }
+      throw ex;
     }
     return Response.ok().build();
   }
diff --git a/hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/s3/endpoint/TestBucketHead.java b/hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/s3/endpoint/TestBucketHead.java
index 6f991e6..18b4b2c 100644
--- a/hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/s3/endpoint/TestBucketHead.java
+++ b/hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/s3/endpoint/TestBucketHead.java
@@ -26,7 +26,10 @@ import org.apache.hadoop.ozone.OzoneConsts;
 import org.apache.hadoop.ozone.client.OzoneClient;
 import org.apache.hadoop.ozone.client.OzoneClientStub;
 
+import org.apache.hadoop.ozone.s3.exception.OS3Exception;
 import org.junit.Assert;
+
+import static java.net.HttpURLConnection.HTTP_NOT_FOUND;
 import static org.junit.Assert.assertEquals;
 import org.junit.Before;
 import org.junit.Test;
@@ -60,7 +63,11 @@ public class TestBucketHead {
 
   @Test
   public void testHeadFail() throws Exception {
-    Response response = bucketEndpoint.head("unknownbucket");
-    Assert.assertEquals(400, response.getStatus());
+    try {
+      bucketEndpoint.head("unknownbucket");
+    } catch (OS3Exception ex) {
+      Assert.assertEquals(HTTP_NOT_FOUND, ex.getHttpCode());
+      Assert.assertEquals("NoSuchBucket", ex.getCode());
+    }
   }
 }


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