Search in sources :

Example 1 with DeleteObject

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());
}
Also used : OzoneBucket(org.apache.hadoop.ozone.client.OzoneBucket) DeleteObject(org.apache.hadoop.ozone.s3.endpoint.MultiDeleteRequest.DeleteObject) OzoneClientStub(org.apache.hadoop.ozone.client.OzoneClientStub) OzoneClient(org.apache.hadoop.ozone.client.OzoneClient) Test(org.junit.Test)

Example 2 with DeleteObject

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());
}
Also used : OzoneBucket(org.apache.hadoop.ozone.client.OzoneBucket) DeleteObject(org.apache.hadoop.ozone.s3.endpoint.MultiDeleteRequest.DeleteObject) OzoneClientStub(org.apache.hadoop.ozone.client.OzoneClientStub) OzoneClient(org.apache.hadoop.ozone.client.OzoneClient) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 3 with DeleteObject

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;
}
Also used : OzoneBucket(org.apache.hadoop.ozone.client.OzoneBucket) DeleteObject(org.apache.hadoop.ozone.s3.endpoint.MultiDeleteRequest.DeleteObject) S3GAction(org.apache.hadoop.ozone.audit.S3GAction) S3ErrorTable.newError(org.apache.hadoop.ozone.s3.exception.S3ErrorTable.newError) Error(org.apache.hadoop.ozone.s3.endpoint.MultiDeleteResponse.Error) OMException(org.apache.hadoop.ozone.om.exceptions.OMException) DeletedObject(org.apache.hadoop.ozone.s3.endpoint.MultiDeleteResponse.DeletedObject) OS3Exception(org.apache.hadoop.ozone.s3.exception.OS3Exception) OMException(org.apache.hadoop.ozone.om.exceptions.OMException) IOException(java.io.IOException) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces)

Aggregations

OzoneBucket (org.apache.hadoop.ozone.client.OzoneBucket)3 DeleteObject (org.apache.hadoop.ozone.s3.endpoint.MultiDeleteRequest.DeleteObject)3 OzoneClient (org.apache.hadoop.ozone.client.OzoneClient)2 OzoneClientStub (org.apache.hadoop.ozone.client.OzoneClientStub)2 Test (org.junit.Test)2 IOException (java.io.IOException)1 HashSet (java.util.HashSet)1 POST (javax.ws.rs.POST)1 Produces (javax.ws.rs.Produces)1 S3GAction (org.apache.hadoop.ozone.audit.S3GAction)1 OMException (org.apache.hadoop.ozone.om.exceptions.OMException)1 DeletedObject (org.apache.hadoop.ozone.s3.endpoint.MultiDeleteResponse.DeletedObject)1 Error (org.apache.hadoop.ozone.s3.endpoint.MultiDeleteResponse.Error)1 OS3Exception (org.apache.hadoop.ozone.s3.exception.OS3Exception)1 S3ErrorTable.newError (org.apache.hadoop.ozone.s3.exception.S3ErrorTable.newError)1