Skip to content

Commit

Permalink
HDDS-4022. Ozone s3 API return 400 Bad Request for head-bucket for no…
Browse files Browse the repository at this point in the history
…n existing bucket. (#1251)
  • Loading branch information
bharatviswa504 committed Jul 27, 2020
1 parent 18552c1 commit a123b4e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
5 changes: 3 additions & 2 deletions hadoop-ozone/dist/src/main/smoketest/s3/buckethead.robot
Original file line number Diff line number Diff line change
Expand Up @@ -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

Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
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;
Expand Down Expand Up @@ -253,12 +252,7 @@ public Response head(@PathParam("bucket") String bucketName)
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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@
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;
Expand Down Expand Up @@ -60,7 +63,11 @@ public void testHeadBucket() throws Exception {

@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());
}
}
}

0 comments on commit a123b4e

Please sign in to comment.