use of org.apache.hadoop.ozone.s3.endpoint.MultiDeleteRequest.DeleteObject in project ozone by apache.
the class TestObjectMultiDelete method deleteQuiet.
@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<String> keysAtTheEnd = Sets.newHashSet(bucket.listKeys("")).stream().map(OzoneKey::getName).collect(Collectors.toSet());
// THEN
Assert.assertEquals(singleton("key3"), keysAtTheEnd);
Assert.assertEquals(0, response.getDeletedObjects().size());
Assert.assertEquals(0, response.getErrors().size());
}
use of org.apache.hadoop.ozone.s3.endpoint.MultiDeleteRequest.DeleteObject in project ozone by apache.
the class TestObjectMultiDelete method delete.
@Test
public void delete() 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.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<String> keysAtTheEnd = Sets.newHashSet(bucket.listKeys("")).stream().map(OzoneKey::getName).collect(Collectors.toSet());
Set<String> expectedResult = new HashSet<>();
expectedResult.add("key3");
// THEN
Assert.assertEquals(expectedResult, keysAtTheEnd);
Assert.assertEquals(3, response.getDeletedObjects().size());
Assert.assertEquals(0, response.getErrors().size());
}
use of org.apache.hadoop.ozone.s3.endpoint.MultiDeleteRequest.DeleteObject in project ozone by apache.
the class BucketEndpoint method multiDelete.
/**
* Implement multi delete.
* <p>
* see: https://docs.aws.amazon
* .com/AmazonS3/latest/API/multiobjectdeleteapi.html
*/
@POST
@Produces(MediaType.APPLICATION_XML)
public MultiDeleteResponse multiDelete(@PathParam("bucket") String bucketName, @QueryParam("delete") String delete, MultiDeleteRequest request) throws OS3Exception, IOException {
S3GAction s3GAction = S3GAction.MULTI_DELETE;
OzoneBucket bucket = getBucket(bucketName);
MultiDeleteResponse result = new MultiDeleteResponse();
if (request.getObjects() != null) {
for (DeleteObject keyToDelete : request.getObjects()) {
try {
bucket.deleteKey(keyToDelete.getKey());
if (!request.isQuiet()) {
result.addDeleted(new DeletedObject(keyToDelete.getKey()));
}
} catch (OMException ex) {
if (ex.getResult() == ResultCodes.PERMISSION_DENIED) {
result.addError(new Error(keyToDelete.getKey(), "PermissionDenied", ex.getMessage()));
} else if (ex.getResult() != ResultCodes.KEY_NOT_FOUND) {
result.addError(new Error(keyToDelete.getKey(), "InternalError", ex.getMessage()));
} else if (!request.isQuiet()) {
result.addDeleted(new DeletedObject(keyToDelete.getKey()));
}
} catch (Exception ex) {
result.addError(new Error(keyToDelete.getKey(), "InternalError", ex.getMessage()));
}
}
}
if (result.getErrors().size() != 0) {
AUDIT.logWriteFailure(buildAuditMessageForFailure(s3GAction, getAuditParameters(), new Exception("MultiDelete Exception")));
} else {
AUDIT.logWriteSuccess(buildAuditMessageForSuccess(s3GAction, getAuditParameters()));
}
return result;
}
Aggregations