Search in sources :

Example 1 with DeleteObjectResponse

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);
    }
}
Also used : DeleteObjectRequest(software.amazon.awssdk.services.s3.model.DeleteObjectRequest) NoSuchKeyException(software.amazon.awssdk.services.s3.model.NoSuchKeyException) ListObjectsV2Request(software.amazon.awssdk.services.s3.model.ListObjectsV2Request) S3Exception(software.amazon.awssdk.services.s3.model.S3Exception) DeleteObjectResponse(software.amazon.awssdk.services.s3.model.DeleteObjectResponse) S3Object(software.amazon.awssdk.services.s3.model.S3Object) IOException(java.io.IOException) ListObjectsV2Response(software.amazon.awssdk.services.s3.model.ListObjectsV2Response) NoSuchKeyException(software.amazon.awssdk.services.s3.model.NoSuchKeyException) URISyntaxException(java.net.URISyntaxException) S3Exception(software.amazon.awssdk.services.s3.model.S3Exception) IOException(java.io.IOException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 2 with DeleteObjectResponse

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"));
}
Also used : DeleteObjectResponse(software.amazon.awssdk.services.s3.model.DeleteObjectResponse) Segment(com.newrelic.api.agent.Segment)

Example 3 with DeleteObjectResponse

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;
    }
}
Also used : DeleteObjectResponse(software.amazon.awssdk.services.s3.model.DeleteObjectResponse) NoSuchKeyException(software.amazon.awssdk.services.s3.model.NoSuchKeyException) S3Exception(software.amazon.awssdk.services.s3.model.S3Exception) AwsServiceException(software.amazon.awssdk.awscore.exception.AwsServiceException) SdkClientException(software.amazon.awssdk.core.exception.SdkClientException) Trace(com.newrelic.api.agent.Trace)

Aggregations

DeleteObjectResponse (software.amazon.awssdk.services.s3.model.DeleteObjectResponse)3 NoSuchKeyException (software.amazon.awssdk.services.s3.model.NoSuchKeyException)2 S3Exception (software.amazon.awssdk.services.s3.model.S3Exception)2 Segment (com.newrelic.api.agent.Segment)1 Trace (com.newrelic.api.agent.Trace)1 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 URISyntaxException (java.net.URISyntaxException)1 AwsServiceException (software.amazon.awssdk.awscore.exception.AwsServiceException)1 SdkClientException (software.amazon.awssdk.core.exception.SdkClientException)1 DeleteObjectRequest (software.amazon.awssdk.services.s3.model.DeleteObjectRequest)1 ListObjectsV2Request (software.amazon.awssdk.services.s3.model.ListObjectsV2Request)1 ListObjectsV2Response (software.amazon.awssdk.services.s3.model.ListObjectsV2Response)1 S3Object (software.amazon.awssdk.services.s3.model.S3Object)1