下面列出了怎么用com.amazonaws.services.s3.model.CompleteMultipartUploadResult的API类实例代码及写法,或者点击链接到github查看源代码。
/**
* This completes a multipart upload. Sometimes it fails; here retries are
* handled to avoid losing all data on a transient failure.
*
* @param partETags list of partial uploads
* @throws IOException on any problem
*/
private CompleteMultipartUploadResult complete(List<PartETag> partETags) throws IOException {
int retryCount = 0;
AmazonClientException lastException;
String operation = String.format("Completing multi-part upload for key '%s',"
+ " id '%s' with %s partitions ",
key, uploadId, partETags.size());
do {
try {
LOG.debug(operation);
return writeOperationHelper.completeMultipartUpload(uploadId, partETags);
} catch (AmazonClientException e) {
lastException = e;
}
}
while (shouldRetry(operation, lastException, retryCount++));
// this point is only reached if the operation failed more than
// the allowed retry count
throw translateException(operation, key, lastException);
}
@Override
public void commitMultipart(String s3Key, String uploadId, List<PartETag> partETags)
throws ModelDBException {
// Validate bucket
Boolean exist = doesBucketExist(bucketName);
if (!exist) {
throw new ModelDBException("Bucket does not exists", io.grpc.Status.Code.INTERNAL);
}
CompleteMultipartUploadRequest completeMultipartUploadRequest =
new CompleteMultipartUploadRequest(bucketName, s3Key, uploadId, partETags);
try {
CompleteMultipartUploadResult result =
s3Client.completeMultipartUpload(completeMultipartUploadRequest);
LOGGER.info("upload result: {}", result);
} catch (AmazonS3Exception e) {
if (e.getStatusCode() == HttpStatusCodes.STATUS_CODE_BAD_REQUEST) {
LOGGER.info("message: {} additional details: {}", e.getMessage(), e.getAdditionalDetails());
throw new ModelDBException(e.getErrorMessage(), io.grpc.Status.Code.FAILED_PRECONDITION);
}
throw e;
}
}
@Override
public CompleteMultipartUploadResult commitMultiPartUpload(
String key,
String uploadId,
List<PartETag> partETags,
long length,
AtomicInteger errorCount) throws IOException {
return null;
}
@Override
public CompleteMultipartUploadResult commitMultiPartUpload(
String key,
String uploadId,
List<PartETag> partETags,
long length,
AtomicInteger errorCount) throws IOException {
return null;
}
/**
* Complete a multipart upload operation.
* @param uploadId multipart operation Id
* @param partETags list of partial uploads
* @return the result
* @throws AmazonClientException on problems
*/
CompleteMultipartUploadResult completeMultipartUpload(String uploadId,
List<PartETag> partETags) throws AmazonClientException {
LOG.debug("Completing multipart upload {} with {} parts",
uploadId, partETags.size());
return mClient.completeMultipartUpload(
new CompleteMultipartUploadRequest(mBucket,
key,
uploadId,
partETags));
}
/**
* Send the CompleteMultipartUploadRequest to S3 if all the blocks of a file are uploaded into S3.
* @param keyName file to upload into S3
*/
private void verifyAndEmitFileMerge(String keyName)
{
if (currentWindowId <= windowDataManager.getLargestCompletedWindow()) {
return;
}
S3InitiateFileUploadOperator.UploadFileMetadata uploadFileMetadata = fileMetadatas.get(keyName);
List<PartETag> partETags = uploadParts.get(keyName);
if (partETags == null || uploadFileMetadata == null ||
uploadFileMetadata.getFileMetadata().getNumberOfBlocks() != partETags.size()) {
return;
}
if (partETags.size() <= 1) {
uploadedFiles.add(keyName);
LOG.debug("Uploaded file {} successfully", keyName);
return;
}
CompleteMultipartUploadRequest compRequest = new CompleteMultipartUploadRequest(bucketName,
keyName, uploadFileMetadata.getUploadId(), partETags);
CompleteMultipartUploadResult result = s3Client.completeMultipartUpload(compRequest);
if (result.getETag() != null) {
uploadedFiles.add(keyName);
LOG.debug("Uploaded file {} successfully", keyName);
}
}
private CompleteMultipartUploadResult completeMultiPart() throws IOException
{
FileUtils.copyFile(inputFile, new File(outputDir + File.separator + FILE));
CompleteMultipartUploadResult result = new CompleteMultipartUploadResult();
result.setETag(outputDir);
return result;
}
@Override
public CompleteMultipartUploadResult commitMultiPartUpload(
String key,
String uploadId,
List<PartETag> partETags,
long length,
AtomicInteger errorCount) throws IOException {
return null;
}
@Override
public CompleteMultipartUploadResult commitMultiPartUpload(String destKey, String uploadId, List<PartETag> partETags, long length, AtomicInteger errorCount) throws IOException {
return s3accessHelper.completeMPUwithRetries(destKey, uploadId, partETags, length, errorCount);
}
@Override
public CompleteMultipartUploadResult commitMultiPartUpload(String destKey, String uploadId, List<PartETag> partETags, long length, AtomicInteger errorCount) throws IOException {
return s3accessHelper.completeMPUwithRetries(destKey, uploadId, partETags, length, errorCount);
}
private static CompleteMultipartUploadResult newResult(
CompleteMultipartUploadRequest req) {
return new CompleteMultipartUploadResult();
}
/** Unsupported Operation. */
@Override public CompleteMultipartUploadResult completeMultipartUpload(
CompleteMultipartUploadRequest req) throws SdkClientException {
throw new UnsupportedOperationException("Operation not supported");
}
@Override
public CompleteMultipartUploadResult commitMultiPartUpload(String destKey, String uploadId, List<PartETag> partETags, long length, AtomicInteger errorCount) throws IOException {
return s3accessHelper.completeMPUwithRetries(destKey, uploadId, partETags, length, errorCount);
}
@Override
public CompleteMultipartUploadResult completeMultipartUpload(CompleteMultipartUploadRequest request)
throws AmazonClientException, AmazonServiceException {
// TODO Auto-generated method stub
return null;
}
/**
* Finalizes a Multi-Part Upload.
*
* @param key the key identifying the object we finished uploading.
* @param uploadId the id of the MPU.
* @param partETags the list of {@link PartETag ETags} associated with this MPU.
* @param length the size of the uploaded object.
* @param errorCount a counter that will be used to count any failed attempts to commit the MPU.
* @return The {@link CompleteMultipartUploadResult result} of the attempt to finalize the MPU.
* @throws IOException
*/
CompleteMultipartUploadResult commitMultiPartUpload(String key, String uploadId, List<PartETag> partETags, long length, AtomicInteger errorCount) throws IOException;
/**
* Finalizes a Multi-Part Upload.
*
* @param key the key identifying the object we finished uploading.
* @param uploadId the id of the MPU.
* @param partETags the list of {@link PartETag ETags} associated with this MPU.
* @param length the size of the uploaded object.
* @param errorCount a counter that will be used to count any failed attempts to commit the MPU.
* @return The {@link CompleteMultipartUploadResult result} of the attempt to finalize the MPU.
* @throws IOException
*/
CompleteMultipartUploadResult commitMultiPartUpload(String key, String uploadId, List<PartETag> partETags, long length, AtomicInteger errorCount) throws IOException;
/**
* Finalizes a Multi-Part Upload.
*
* @param key the key identifying the object we finished uploading.
* @param uploadId the id of the MPU.
* @param partETags the list of {@link PartETag ETags} associated with this MPU.
* @param length the size of the uploaded object.
* @param errorCount a counter that will be used to count any failed attempts to commit the MPU.
* @return The {@link CompleteMultipartUploadResult result} of the attempt to finalize the MPU.
* @throws IOException
*/
CompleteMultipartUploadResult commitMultiPartUpload(String key, String uploadId, List<PartETag> partETags, long length, AtomicInteger errorCount) throws IOException;