use of com.amazonaws.services.s3.model.DeleteObjectRequest in project stocator by CODAIT.
the class COSAPIClient method delete.
@Override
public boolean delete(String hostName, Path path, boolean recursive) throws IOException {
String key = pathToKey(path);
LOG.debug("Object name to delete {}. Path {}", key, path.toString());
try {
mClient.deleteObject(new DeleteObjectRequest(mBucket, key));
memoryCache.removeFileStatus(path.toString());
return true;
} catch (AmazonServiceException e) {
if (e.getStatusCode() != 404) {
throw new IOException(e);
}
}
LOG.warn("Delete on {} not found. Nothing to delete");
return false;
}
use of com.amazonaws.services.s3.model.DeleteObjectRequest in project nifi by apache.
the class TestDeleteS3Object method testDeleteObjectSimple.
@Test
public void testDeleteObjectSimple() throws IOException {
runner.setProperty(DeleteS3Object.REGION, "us-west-2");
runner.setProperty(DeleteS3Object.BUCKET, "test-bucket");
final Map<String, String> attrs = new HashMap<>();
attrs.put("filename", "delete-key");
runner.enqueue(new byte[0], attrs);
runner.run(1);
runner.assertAllFlowFilesTransferred(DeleteS3Object.REL_SUCCESS, 1);
ArgumentCaptor<DeleteObjectRequest> captureRequest = ArgumentCaptor.forClass(DeleteObjectRequest.class);
Mockito.verify(mockS3Client, Mockito.times(1)).deleteObject(captureRequest.capture());
DeleteObjectRequest request = captureRequest.getValue();
assertEquals("test-bucket", request.getBucketName());
assertEquals("delete-key", request.getKey());
Mockito.verify(mockS3Client, Mockito.never()).deleteVersion(Mockito.any(DeleteVersionRequest.class));
}
use of com.amazonaws.services.s3.model.DeleteObjectRequest in project nifi by apache.
the class TestDeleteS3Object method testDeleteObjectS3Exception.
@Test
public void testDeleteObjectS3Exception() {
runner.setProperty(DeleteS3Object.REGION, "us-west-2");
runner.setProperty(DeleteS3Object.BUCKET, "test-bucket");
final Map<String, String> attrs = new HashMap<>();
attrs.put("filename", "delete-key");
runner.enqueue(new byte[0], attrs);
Mockito.doThrow(new AmazonS3Exception("NoSuchBucket")).when(mockS3Client).deleteObject(Mockito.any());
runner.run(1);
runner.assertAllFlowFilesTransferred(DeleteS3Object.REL_FAILURE, 1);
ArgumentCaptor<DeleteObjectRequest> captureRequest = ArgumentCaptor.forClass(DeleteObjectRequest.class);
Mockito.verify(mockS3Client, Mockito.never()).deleteVersion(Mockito.any(DeleteVersionRequest.class));
}
use of com.amazonaws.services.s3.model.DeleteObjectRequest in project nifi by apache.
the class DeleteS3Object method onTrigger.
@Override
public void onTrigger(final ProcessContext context, final ProcessSession session) {
FlowFile flowFile = session.get();
if (flowFile == null) {
return;
}
final long startNanos = System.nanoTime();
final String bucket = context.getProperty(BUCKET).evaluateAttributeExpressions(flowFile).getValue();
final String key = context.getProperty(KEY).evaluateAttributeExpressions(flowFile).getValue();
final String versionId = context.getProperty(VERSION_ID).evaluateAttributeExpressions(flowFile).getValue();
final AmazonS3 s3 = getClient();
// Deletes a key on Amazon S3
try {
if (versionId == null) {
final DeleteObjectRequest r = new DeleteObjectRequest(bucket, key);
// This call returns success if object doesn't exist
s3.deleteObject(r);
} else {
final DeleteVersionRequest r = new DeleteVersionRequest(bucket, key, versionId);
s3.deleteVersion(r);
}
} catch (final AmazonServiceException ase) {
getLogger().error("Failed to delete S3 Object for {}; routing to failure", new Object[] { flowFile, ase });
flowFile = session.penalize(flowFile);
session.transfer(flowFile, REL_FAILURE);
return;
}
session.transfer(flowFile, REL_SUCCESS);
final long transferMillis = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startNanos);
getLogger().info("Successfully delete S3 Object for {} in {} millis; routing to success", new Object[] { flowFile, transferMillis });
}
use of com.amazonaws.services.s3.model.DeleteObjectRequest in project stocator by SparkTC.
the class COSAPIClient method delete.
@Override
public boolean delete(String hostName, Path path, boolean recursive) throws IOException {
String key = pathToKey(path);
LOG.debug("Object name to delete {}. Path {}", key, path.toString());
try {
mClient.deleteObject(new DeleteObjectRequest(mBucket, key));
memoryCache.removeFileStatus(path.toString());
return true;
} catch (AmazonServiceException e) {
if (e.getStatusCode() != 404) {
throw new IOException(e);
}
}
LOG.warn("Delete on {} not found. Nothing to delete");
return false;
}
Aggregations