From 3655e573e28eea79e46936d348a852158b2fc48a Mon Sep 17 00:00:00 2001 From: Bharat Viswanadham Date: Mon, 29 Oct 2018 12:59:41 -0700 Subject: [PATCH] HDDS-743. S3 multi delete request should return XML header in quiet mode. Contributed by Elek Marton. --- .../ozone/s3/endpoint/BucketEndpoint.java | 9 +-- .../s3/endpoint/TestObjectMultiDelete.java | 61 ++++++++++++++----- 2 files changed, 48 insertions(+), 22 deletions(-) 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 fca251d9bbd..8f554ed1e56 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 @@ -223,7 +223,7 @@ public class BucketEndpoint extends EndpointBase { */ @POST @Produces(MediaType.APPLICATION_XML) - public Response multiDelete(@PathParam("bucket") String bucketName, + public MultiDeleteResponse multiDelete(@PathParam("bucket") String bucketName, @QueryParam("delete") String delete, MultiDeleteRequest request) throws OS3Exception, IOException { OzoneBucket bucket = getBucket(bucketName); @@ -251,11 +251,6 @@ public class BucketEndpoint extends EndpointBase { } } } - ResponseBuilder response = Response.ok(); - if (!request.isQuiet() || result.getErrors().size() > 0) { - response = response.entity(result); - } - return response.build(); - + return result; } } diff --git a/hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/s3/endpoint/TestObjectMultiDelete.java b/hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/s3/endpoint/TestObjectMultiDelete.java index 12a14a0989c..dabbd2291b4 100644 --- a/hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/s3/endpoint/TestObjectMultiDelete.java +++ b/hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/s3/endpoint/TestObjectMultiDelete.java @@ -46,16 +46,7 @@ public class TestObjectMultiDelete { public void delete() throws IOException, OS3Exception, JAXBException { //GIVEN OzoneClient client = new OzoneClientStub(); - client.getObjectStore().createS3Bucket("bilbo", "b1"); - - String volumeName = client.getObjectStore().getOzoneVolumeName("b1"); - - OzoneBucket bucket = - client.getObjectStore().getVolume(volumeName).getBucket("b1"); - - bucket.createKey("key1", 0).close(); - bucket.createKey("key2", 0).close(); - bucket.createKey("key3", 0).close(); + OzoneBucket bucket = initTestData(client); BucketEndpoint rest = new BucketEndpoint(); rest.setClient(client); @@ -66,11 +57,9 @@ public class TestObjectMultiDelete { mdr.getObjects().add(new DeleteObject("key4")); //WHEN - Response response = rest.multiDelete("b1", "", mdr); + MultiDeleteResponse response = rest.multiDelete("b1", "", mdr); //THEN - MultiDeleteResponse mdresponse = (MultiDeleteResponse) response.getEntity(); - Set keysAtTheEnd = Sets.newHashSet(bucket.listKeys("")).stream() .map(OzoneKey::getName) .collect(Collectors.toSet()); @@ -80,7 +69,49 @@ public class TestObjectMultiDelete { //THEN Assert.assertEquals(expectedResult, keysAtTheEnd); - Assert.assertEquals(3, mdresponse.getDeletedObjects().size()); - Assert.assertEquals(0, mdresponse.getErrors().size()); + Assert.assertEquals(3, response.getDeletedObjects().size()); + Assert.assertEquals(0, response.getErrors().size()); + } + + @Test + public void deleteQuiet() throws IOException, OS3Exception, JAXBException { + //GIVEN + OzoneClient client = new OzoneClientStub(); + OzoneBucket bucket = initTestData(client); + + BucketEndpoint rest = new BucketEndpoint(); + rest.setClient(client); + + MultiDeleteRequest mdr = new MultiDeleteRequest(); + mdr.setQuiet(true); + mdr.getObjects().add(new DeleteObject("key1")); + mdr.getObjects().add(new DeleteObject("key2")); + mdr.getObjects().add(new DeleteObject("key4")); + + //WHEN + MultiDeleteResponse response = rest.multiDelete("b1", "", mdr); + + //THEN + Set keysAtTheEnd = Sets.newHashSet(bucket.listKeys("")).stream() + .map(OzoneKey::getName) + .collect(Collectors.toSet()); + + //THEN + Assert.assertEquals(0, response.getDeletedObjects().size()); + Assert.assertEquals(0, response.getErrors().size()); + } + + private OzoneBucket initTestData(OzoneClient client) throws IOException { + client.getObjectStore().createS3Bucket("bilbo", "b1"); + + String volumeName = client.getObjectStore().getOzoneVolumeName("b1"); + + OzoneBucket bucket = + client.getObjectStore().getVolume(volumeName).getBucket("b1"); + + bucket.createKey("key1", 0).close(); + bucket.createKey("key2", 0).close(); + bucket.createKey("key3", 0).close(); + return bucket; } } \ No newline at end of file