use of software.amazon.awssdk.services.s3.model.DeleteObjectResponse in project kaldb by slackhq.
the class S3BlobFs method delete.
@Override
public boolean delete(URI segmentUri, boolean forceDelete) throws IOException {
LOG.info("Deleting uri {} force {}", segmentUri, forceDelete);
try {
if (isDirectory(segmentUri)) {
if (!forceDelete) {
Preconditions.checkState(isEmptyDirectory(segmentUri), "ForceDelete flag is not set and directory '%s' is not empty", segmentUri);
}
String prefix = normalizeToDirectoryPrefix(segmentUri);
ListObjectsV2Response listObjectsV2Response;
ListObjectsV2Request.Builder listObjectsV2RequestBuilder = ListObjectsV2Request.builder().bucket(segmentUri.getHost());
if (prefix.equals(DELIMITER)) {
ListObjectsV2Request listObjectsV2Request = listObjectsV2RequestBuilder.build();
listObjectsV2Response = s3Client.listObjectsV2(listObjectsV2Request);
} else {
ListObjectsV2Request listObjectsV2Request = listObjectsV2RequestBuilder.prefix(prefix).build();
listObjectsV2Response = s3Client.listObjectsV2(listObjectsV2Request);
}
boolean deleteSucceeded = true;
for (S3Object s3Object : listObjectsV2Response.contents()) {
DeleteObjectRequest deleteObjectRequest = DeleteObjectRequest.builder().bucket(segmentUri.getHost()).key(s3Object.key()).build();
DeleteObjectResponse deleteObjectResponse = s3Client.deleteObject(deleteObjectRequest);
deleteSucceeded &= deleteObjectResponse.sdkHttpResponse().isSuccessful();
}
return deleteSucceeded;
} else {
String prefix = DELIMITER + sanitizePath(segmentUri.getPath());
DeleteObjectRequest deleteObjectRequest = DeleteObjectRequest.builder().bucket(segmentUri.getHost()).key(prefix).build();
DeleteObjectResponse deleteObjectResponse = s3Client.deleteObject(deleteObjectRequest);
return deleteObjectResponse.sdkHttpResponse().isSuccessful();
}
} catch (NoSuchKeyException e) {
return false;
} catch (S3Exception e) {
throw e;
} catch (Exception e) {
throw new IOException(e);
}
}
use of software.amazon.awssdk.services.s3.model.DeleteObjectResponse in project newrelic-java-agent by newrelic.
the class S3AsyncClient_Instrumentation method deleteObject.
public CompletableFuture<DeleteObjectResponse> deleteObject(DeleteObjectRequest deleteObjectRequest) {
String uri = "s3://" + deleteObjectRequest.bucket() + "/" + deleteObjectRequest.key();
Segment segment = NewRelic.getAgent().getTransaction().startSegment("S3", "deleteObject");
AgentBridge.getAgent().getTracedMethod().setTrackChildThreads(false);
CompletableFuture<DeleteObjectResponse> result = Weaver.callOriginal();
return result.whenComplete(new S3ResponseResultWrapper<>(segment, uri, "deleteObject"));
}
use of software.amazon.awssdk.services.s3.model.DeleteObjectResponse in project newrelic-java-agent by newrelic.
the class S3Client_Instrumentation method deleteObject.
@Trace
public DeleteObjectResponse deleteObject(DeleteObjectRequest deleteObjectRequest) {
String uri = "s3://" + deleteObjectRequest.bucket() + "/" + deleteObjectRequest.key();
try {
DeleteObjectResponse deleteObjectResponse = Weaver.callOriginal();
S3MetricUtil.reportExternalMetrics(NewRelic.getAgent().getTracedMethod(), uri, deleteObjectResponse, "deleteObject");
return deleteObjectResponse;
} catch (Exception e) {
S3MetricUtil.reportExternalMetrics(NewRelic.getAgent().getTracedMethod(), uri, "deleteObject");
throw e;
}
}
Aggregations