@Override public void abortMultipartUpload(AbortMultipartUploadRequest abortMultipartUploadRequest) throws SdkClientException, AmazonServiceException { abortMultipartUploadRequest = beforeClientExecution(abortMultipartUploadRequest); rejectNull(abortMultipartUploadRequest, "The request parameter must be specified when aborting a multipart upload"); rejectNull(abortMultipartUploadRequest.getBucketName(), "The bucket name parameter must be specified when aborting a multipart upload"); rejectNull(abortMultipartUploadRequest.getKey(), "The key parameter must be specified when aborting a multipart upload"); rejectNull(abortMultipartUploadRequest.getUploadId(), "The upload ID parameter must be specified when aborting a multipart upload"); String bucketName = abortMultipartUploadRequest.getBucketName(); String key = abortMultipartUploadRequest.getKey(); Request<AbortMultipartUploadRequest> request = createRequest(bucketName, key, abortMultipartUploadRequest, HttpMethodName.DELETE); request.addParameter("uploadId", abortMultipartUploadRequest.getUploadId()); populateRequesterPaysHeader(request, abortMultipartUploadRequest.isRequesterPays()); invoke(request, voidResponseHandler, bucketName, key); }
/** * <p> * Aborts any multipart uploads that were initiated before the specified date. * </p> * <p> * This method is useful for cleaning up any interrupted multipart uploads. * <code>TransferManager</code> attempts to abort any failed uploads, * but in some cases this may not be possible, such as if network connectivity * is completely lost. * </p> * * @param bucketName * The name of the bucket containing the multipart uploads to * abort. * @param date * The date indicating which multipart uploads should be aborted. */ public void abortMultipartUploads(String bucketName, Date date) throws AmazonServiceException, AmazonClientException { MultipartUploadListing uploadListing = s3.listMultipartUploads(appendSingleObjectUserAgent( new ListMultipartUploadsRequest(bucketName))); do { for (MultipartUpload upload : uploadListing.getMultipartUploads()) { if (upload.getInitiated().compareTo(date) < 0) { s3.abortMultipartUpload(appendSingleObjectUserAgent(new AbortMultipartUploadRequest( bucketName, upload.getKey(), upload.getUploadId()))); } } ListMultipartUploadsRequest request = new ListMultipartUploadsRequest(bucketName) .withUploadIdMarker(uploadListing.getNextUploadIdMarker()) .withKeyMarker(uploadListing.getNextKeyMarker()); uploadListing = s3.listMultipartUploads(appendSingleObjectUserAgent(request)); } while (uploadListing.isTruncated()); }
/** * Performs an * {@link AmazonS3#abortMultipartUpload(AbortMultipartUploadRequest)} * operation for the given multi-part upload. */ void performAbortMultipartUpload() { if (multipartUploadId == null) { return; } try { AbortMultipartUploadRequest abortRequest = new AbortMultipartUploadRequest(origReq.getBucketName(), origReq.getKey(), multipartUploadId) .withRequesterPays(origReq.isRequesterPays()); s3.abortMultipartUpload(abortRequest); } catch (Exception e2) { log.info( "Unable to abort multipart upload, you may need to manually remove uploaded parts: " + e2.getMessage(), e2); } }
/** * Deletes all existing buckets */ @After public void cleanupFilestore() { for (final Bucket bucket : s3Client.listBuckets()) { if (!INITIAL_BUCKET_NAMES.contains(bucket.getName())) { s3Client.listMultipartUploads(new ListMultipartUploadsRequest(bucket.getName())) .getMultipartUploads() .forEach(upload -> s3Client.abortMultipartUpload( new AbortMultipartUploadRequest(bucket.getName(), upload.getKey(), upload.getUploadId())) ); s3Client.deleteBucket(bucket.getName()); } } }
/** * Tests if a multipart upload can be aborted. * * @throws Exception not expected */ @Test public void shouldAbortMultipartUpload() throws Exception { s3Client.createBucket(BUCKET_NAME); assertThat(s3Client.listMultipartUploads(new ListMultipartUploadsRequest(BUCKET_NAME)) .getMultipartUploads(), is(empty())); final InitiateMultipartUploadResult initiateMultipartUploadResult = s3Client .initiateMultipartUpload(new InitiateMultipartUploadRequest(BUCKET_NAME, UPLOAD_FILE_NAME)); final String uploadId = initiateMultipartUploadResult.getUploadId(); assertThat(s3Client.listMultipartUploads(new ListMultipartUploadsRequest(BUCKET_NAME)) .getMultipartUploads(), is(not(empty()))); s3Client.abortMultipartUpload( new AbortMultipartUploadRequest(BUCKET_NAME, UPLOAD_FILE_NAME, uploadId)); assertThat(s3Client.listMultipartUploads(new ListMultipartUploadsRequest(BUCKET_NAME)) .getMultipartUploads(), is(empty())); }
@Test public void testAtomicMpuAbort() throws Exception { String key = "testAtomicMpuAbort"; ObjectMetadata metadata = new ObjectMetadata(); metadata.setContentLength(BYTE_SOURCE.size()); client.putObject(containerName, key, BYTE_SOURCE.openStream(), metadata); InitiateMultipartUploadRequest initRequest = new InitiateMultipartUploadRequest(containerName, key); InitiateMultipartUploadResult initResponse = client.initiateMultipartUpload(initRequest); String uploadId = initResponse.getUploadId(); client.abortMultipartUpload(new AbortMultipartUploadRequest( containerName, key, uploadId)); S3Object object = client.getObject(containerName, key); assertThat(object.getObjectMetadata().getContentLength()).isEqualTo( BYTE_SOURCE.size()); try (InputStream actual = object.getObjectContent(); InputStream expected = BYTE_SOURCE.openStream()) { assertThat(actual).hasContentEqualTo(expected); } }
@Override public CompletableFuture<Void> cancel() { if (cancellation == null) { cancellation = CompletableFuture.runAsync(() -> s3.abortMultipartUpload(new AbortMultipartUploadRequest(bucket, key, uploadId))); } return cancellation; }
public void abort() { LOG.warn("Aborting multi-part upload with id '{}'", uploadId); try { client.abortMultipartUpload(new AbortMultipartUploadRequest(bucket, key, uploadId)); } catch (Exception e2) { LOG.warn("Unable to abort multipart upload, you may need to purge " + "uploaded parts: " + e2, e2); } }
private void abortMultipartCopy() { try { AbortMultipartUploadRequest abortRequest = new AbortMultipartUploadRequest( copyObjectRequest.getDestinationBucketName(), copyObjectRequest.getDestinationKey(), multipartUploadId) .withRequesterPays(copyObjectRequest.isRequesterPays()); s3.abortMultipartUpload(abortRequest); } catch (Exception e) { log.info( "Unable to abort multipart upload, you may need to manually remove uploaded parts: " + e.getMessage(), e); } }
@Override public void abortMultipartUploadSecurely(AbortMultipartUploadRequest req) { if (defaultCryptoMode == EncryptionOnly) eo.abortMultipartUploadSecurely(req); else ae.abortMultipartUploadSecurely(req); }
/** * Notified from * {@link AmazonS3EncryptionClient#uploadObject(UploadObjectRequest)} when * failed to upload any part. This method is responsible for cancelling * ongoing uploads and aborting the multi-part upload request. */ public void onAbort() { for (Future<?> future : getFutures()) { future.cancel(true); } if (uploadId != null) { try { s3.abortMultipartUpload(new AbortMultipartUploadRequest( req.getBucketName(), req.getKey(), uploadId)); } catch (Exception e) { LogFactory.getLog(getClass()) .debug("Failed to abort multi-part upload: " + uploadId, e); } } }
private void abortAllMultipartUploads() { ListMultipartUploadsRequest multipartUploadsRequest = new ListMultipartUploadsRequest(bucketName); amazonS3.listMultipartUploads(multipartUploadsRequest) .getMultipartUploads() .forEach(upload -> { AbortMultipartUploadRequest request = new AbortMultipartUploadRequest(bucketName, upload.getKey(), upload.getUploadId()); amazonS3.abortMultipartUpload(request); }); }
public void abort() { log.warn("Aborting multi-part upload with id '{}'", uploadId); try { s3.abortMultipartUpload(new AbortMultipartUploadRequest(bucket, key, uploadId)); } catch (Exception e) { // ignoring failure on abort. log.warn("Unable to abort multipart upload, you may need to purge uploaded parts: ", e); } }
public void abortMultipartUpload(S3Upload upload) { try { runtimeCredentialsProvider.setAwsCredentials(upload.getAwsCredentials()); amazonS3.setRegion(Region.getRegion(Regions.fromName(upload.getRegion()))); amazonS3.abortMultipartUpload(new AbortMultipartUploadRequest(upload.getBucket(), upload.getKey(), upload.getUploadId())); } catch (AmazonClientException e) { throw new OmakaseRuntimeException(e); } }
/** * {@inheritDoc} * <p/> * This implementation simulates abort multipart upload operation. */ @Override public void abortMultipartUpload(AbortMultipartUploadRequest abortMultipartUploadRequest, AmazonS3 s3Client) { // This method does nothing. }
private void abortUpload() { if (this.uploadId == null) { // This is not a multipart upload, nothing to do here return; } try { final AbortMultipartUploadRequest request = new AbortMultipartUploadRequest(this.bucket, this.object, this.uploadId); this.s3Client.abortMultipartUpload(request); } catch (AmazonServiceException e) { // Ignore exception } }
private void multipartUpload(String key, File file, ObjectMetadata objectMetadata, Optional<StorageClass> maybeStorageClass) throws Exception { List<PartETag> partETags = new ArrayList<>(); InitiateMultipartUploadRequest initRequest = new InitiateMultipartUploadRequest(bucketName, key, objectMetadata); if (maybeStorageClass.isPresent()) { initRequest.setStorageClass(maybeStorageClass.get()); } InitiateMultipartUploadResult initResponse = s3Client.initiateMultipartUpload(initRequest); long contentLength = file.length(); long partSize = configuration.getUploadPartSize(); try { long filePosition = 0; for (int i = 1; filePosition < contentLength; i++) { partSize = Math.min(partSize, (contentLength - filePosition)); UploadPartRequest uploadRequest = new UploadPartRequest() .withBucketName(bucketName) .withKey(key) .withUploadId(initResponse.getUploadId()) .withPartNumber(i) .withFileOffset(filePosition) .withFile(file) .withPartSize(partSize); partETags.add(s3Client.uploadPart(uploadRequest).getPartETag()); filePosition += partSize; } CompleteMultipartUploadRequest completeRequest = new CompleteMultipartUploadRequest(bucketName, key, initResponse.getUploadId(), partETags); s3Client.completeMultipartUpload(completeRequest); } catch (Exception e) { s3Client.abortMultipartUpload(new AbortMultipartUploadRequest(bucketName, key, initResponse.getUploadId())); Throwables.propagate(e); } }
public void abort() /* */ { /* 175 */ for (Future future : this.futures) { /* 176 */ future.cancel(true); /* */ } /* 178 */ this.s3.abortMultipartUpload(new AbortMultipartUploadRequest(this.bucketName, this.key, this.uploadId)); /* */ }
protected void doAbortMultipart(S3BlobStore blobStore, String bucketName, String blobName, String uploadId) throws AmazonS3Exception { blobStore.client().abortMultipartUpload(new AbortMultipartUploadRequest(bucketName, blobName, uploadId)); }
@Override public void abortMultipartUpload(AbortMultipartUploadRequest request) throws AmazonClientException, AmazonServiceException { delegate.abortMultipartUpload(request); }
@Override public void abortMultipartUpload(AbortMultipartUploadRequest abortMultipartUploadRequest) throws AmazonClientException, AmazonServiceException { throw new UnsupportedOperationException(); }
@Override public final void abortMultipartUploadSecurely(AbortMultipartUploadRequest req) { s3.abortMultipartUpload(req); multipartUploadContexts.remove(req.getUploadId()); }
@Override public void abortMultipartUpload(AbortMultipartUploadRequest req) { crypto.abortMultipartUploadSecurely(req); }
@Override public void abortMultipartUpload(AbortMultipartUploadRequest req) { AmazonS3EncryptionClient.super.abortMultipartUpload(req); }
@Override public void abortMultipartUpload(AbortMultipartUploadRequest request) { run(() -> getDelegate().abortMultipartUpload(request)); }
/** * Abort a multipart upload operation * @param uploadId multipart operation Id * @throws AmazonClientException on problems */ void abortMultipartUpload(String uploadId) throws AmazonClientException { LOG.debug("Aborting multipart upload {}", uploadId); mClient.abortMultipartUpload( new AbortMultipartUploadRequest(mBucket, key, uploadId)); }
public AbortMultipartUploadRequest getAbortMultipartUploadRequest() { return new AbortMultipartUploadRequest(this.bucketName, this.key, this.uploadId); }
@Override public CompletableFuture<Void> abortMultipartUpload(String bucketName, String key, String uploadId) { AbortMultipartUploadRequest request = new AbortMultipartUploadRequest(bucketName, key, uploadId); return CompletableFuture.runAsync(() -> s3Client.abortMultipartUpload(request), executorService); }
@Override public void abortMultipartUpload(AbortMultipartUploadRequest abortMultipartUploadRequest, AmazonS3 s3Client) { s3Client.abortMultipartUpload(abortMultipartUploadRequest); }
@Override public int abortMultipartUploads(S3FileTransferRequestParamsDto params, Date thresholdDate) { // Create an Amazon S3 client. AmazonS3Client s3Client = getAmazonS3(params); int abortedMultipartUploadsCount = 0; try { // List upload markers. Null implies initial list request. String uploadIdMarker = null; String keyMarker = null; boolean truncated; do { // Create the list multipart request, optionally using the last markers. ListMultipartUploadsRequest request = new ListMultipartUploadsRequest(params.getS3BucketName()); request.setUploadIdMarker(uploadIdMarker); request.setKeyMarker(keyMarker); // Request the multipart upload listing. MultipartUploadListing uploadListing = s3Operations.listMultipartUploads(TransferManager.appendSingleObjectUserAgent(request), s3Client); for (MultipartUpload upload : uploadListing.getMultipartUploads()) { if (upload.getInitiated().compareTo(thresholdDate) < 0) { // Abort the upload. s3Operations.abortMultipartUpload(TransferManager .appendSingleObjectUserAgent(new AbortMultipartUploadRequest(params.getS3BucketName(), upload.getKey(), upload.getUploadId())), s3Client); // Log the information about the aborted multipart upload. LOGGER.info("Aborted S3 multipart upload. s3Key=\"{}\" s3BucketName=\"{}\" s3MultipartUploadInitiatedDate=\"{}\"", upload.getKey(), params.getS3BucketName(), upload.getInitiated()); // Increment the counter. abortedMultipartUploadsCount++; } } // Determine whether there are more uploads to list. truncated = uploadListing.isTruncated(); if (truncated) { // Record the list markers. uploadIdMarker = uploadListing.getNextUploadIdMarker(); keyMarker = uploadListing.getNextKeyMarker(); } } while (truncated); } finally { // Shutdown the Amazon S3 client instance to release resources. s3Client.shutdown(); } return abortedMultipartUploadsCount; }