forked from opensearch-project/data-prepper
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Asif Sohail Mohammed <[email protected]>
- Loading branch information
1 parent
90ee648
commit 2dd22f3
Showing
24 changed files
with
583 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
...-source/src/main/java/org/opensearch/dataprepper/plugins/source/S3ObjectDeleteWorker.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package org.opensearch.dataprepper.plugins.source; | ||
|
||
import io.micrometer.core.instrument.Counter; | ||
import org.opensearch.dataprepper.metrics.PluginMetrics; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import software.amazon.awssdk.core.exception.SdkException; | ||
import software.amazon.awssdk.services.s3.S3Client; | ||
import software.amazon.awssdk.services.s3.model.DeleteObjectRequest; | ||
import software.amazon.awssdk.services.s3.model.DeleteObjectResponse; | ||
|
||
public class S3ObjectDeleteWorker { | ||
private static final Logger LOG = LoggerFactory.getLogger(S3ObjectDeleteWorker.class); | ||
static final String S3_OBJECTS_DELETED_METRIC_NAME = "s3ObjectsDeleted"; | ||
static final String S3_OBJECTS_DELETE_FAILED_METRIC_NAME = "s3ObjectsDeleteFailed"; | ||
private final S3Client s3Client; | ||
private final Counter s3ObjectsDeletedCounter; | ||
private final Counter s3ObjectsDeleteFailedCounter; | ||
|
||
public S3ObjectDeleteWorker(final S3Client s3Client, final PluginMetrics pluginMetrics) { | ||
this.s3Client = s3Client; | ||
|
||
s3ObjectsDeletedCounter = pluginMetrics.counter(S3_OBJECTS_DELETED_METRIC_NAME); | ||
s3ObjectsDeleteFailedCounter = pluginMetrics.counter(S3_OBJECTS_DELETE_FAILED_METRIC_NAME); | ||
} | ||
|
||
public void deleteS3Object(final DeleteObjectRequest deleteObjectRequest) { | ||
try { | ||
final DeleteObjectResponse deleteObjectResponse = s3Client.deleteObject(deleteObjectRequest); | ||
if (deleteObjectResponse.sdkHttpResponse().isSuccessful()) { | ||
LOG.info("Deleted object: {} in S3 bucket: {}. ", deleteObjectRequest.key(), deleteObjectRequest.bucket()); | ||
s3ObjectsDeletedCounter.increment(); | ||
} else { | ||
s3ObjectsDeleteFailedCounter.increment(); | ||
} | ||
} catch (final SdkException e) { | ||
LOG.error("Failed to delete object: {} from S3 bucket: {}. ", deleteObjectRequest.key(), deleteObjectRequest.bucket(), e); | ||
s3ObjectsDeleteFailedCounter.increment(); | ||
} | ||
} | ||
|
||
public DeleteObjectRequest buildDeleteObjectRequest(final String bucketName, final String key) { | ||
return DeleteObjectRequest.builder() | ||
.bucket(bucketName) | ||
.key(key) | ||
.build(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.