use of software.amazon.awssdk.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 software.amazon.awssdk.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 software.amazon.awssdk.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 software.amazon.awssdk.services.s3.model.DeleteObjectRequest in project FP-PSP-SERVER by FundacionParaguaya.
the class ImageUploadServiceImpl method deleteImage.
@Override
public void deleteImage(String logoUrl, String imageDirectory) {
if (logoUrl == null) {
return;
}
try {
String strRegion = applicationProperties.getAws().getStrRegion();
Regions region = Regions.valueOf(strRegion);
AmazonS3 s3Client = AmazonS3ClientBuilder.standard().withRegion(region).build();
String bucketName = applicationProperties.getAws().getBucketName();
String fileName = logoUrl.substring(logoUrl.lastIndexOf('/') + 1);
String keyName = imageDirectory + fileName;
s3Client.deleteObject(new DeleteObjectRequest(bucketName, keyName));
} catch (SdkClientException sdkClientExc) {
LOG.error(sdkClientExc.getMessage(), sdkClientExc);
throw new AWSS3RuntimeException(sdkClientExc);
}
}
use of software.amazon.awssdk.services.s3.model.DeleteObjectRequest in project dataverse by IQSS.
the class S3AccessIO method deleteAuxObject.
@Override
public void deleteAuxObject(String auxItemTag) throws IOException {
if (!this.canWrite()) {
open(DataAccessOption.WRITE_ACCESS);
}
String destinationKey = getDestinationKey(auxItemTag);
try {
DeleteObjectRequest dor = new DeleteObjectRequest(bucketName, destinationKey);
s3.deleteObject(dor);
} catch (AmazonClientException ase) {
logger.warning("S3AccessIO: Unable to delete object " + ase.getMessage());
}
}
Aggregations