Skip to content

Commit

Permalink
Rename createMultipartUpload functions
Browse files Browse the repository at this point in the history
  • Loading branch information
afranken committed May 15, 2024
1 parent 474bef7 commit c9eb9a7
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 98 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
import java.io.InputStream;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import org.apache.commons.io.FileUtils;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpRange;
Expand Down Expand Up @@ -330,25 +329,20 @@ public ResponseEntity<InitiateMultipartUploadResult> createMultipartUpload(
@RequestHeader HttpHeaders httpHeaders) {
bucketService.verifyBucketExists(bucketName);

var checksum = checksumFrom(httpHeaders);
var checksumAlgorithm = checksumAlgorithmFromHeader(httpHeaders);

//bucket -> key -> uploadId[] -> metadata, part[]

var uploadId = UUID.randomUUID().toString();
var result =
multipartService.prepareMultipartUpload(bucketName,
multipartService.createMultipartUpload(bucketName,
key.key(),
contentType,
storeHeadersFrom(httpHeaders),
uploadId,
DEFAULT_OWNER,
DEFAULT_OWNER,
userMetadataFrom(httpHeaders),
encryptionHeadersFrom(httpHeaders),
storageClass,
checksum,
checksumAlgorithm);
checksumFrom(httpHeaders),
checksumAlgorithmFromHeader(httpHeaders));

//return encryption headers
//return checksum algorithm headers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,50 +203,47 @@ public Pair<CompleteMultipartUploadResult, MultipartUploadInfo> completeMultipar
* @param key object to upload
* @param contentType the content type
* @param storeHeaders various headers to store
* @param uploadId id of the upload
* @param owner owner of the upload
* @param initiator initiator of the upload
* @param userMetadata custom metadata
*
* @return upload result
*/
public InitiateMultipartUploadResult prepareMultipartUpload(String bucketName,
String key,
String contentType,
Map<String, String> storeHeaders,
String uploadId,
Owner owner,
Owner initiator,
Map<String, String> userMetadata,
Map<String, String> encryptionHeaders,
StorageClass storageClass,
String checksum,
ChecksumAlgorithm checksumAlgorithm) {
public InitiateMultipartUploadResult createMultipartUpload(String bucketName,
String key,
String contentType,
Map<String, String> storeHeaders,
Owner owner,
Owner initiator,
Map<String, String> userMetadata,
Map<String, String> encryptionHeaders,
StorageClass storageClass,
String checksum,
ChecksumAlgorithm checksumAlgorithm) {
var bucketMetadata = bucketStore.getBucketMetadata(bucketName);
//TODO: add upload to bucket
var id = bucketStore.addKeyToBucket(key, bucketName);

try {
multipartStore.prepareMultipartUpload(bucketMetadata,
var multipartUpload = multipartStore.createMultipartUpload(bucketMetadata,
key,
id,
contentType,
storeHeaders,
uploadId,
owner,
initiator,
userMetadata,
encryptionHeaders,
storageClass,
checksum,
checksumAlgorithm);
return new InitiateMultipartUploadResult(bucketName, key, uploadId);
return new InitiateMultipartUploadResult(bucketName, key, multipartUpload.uploadId());
} catch (Exception e) {
//something went wrong with writing the destination file, clean up ID from BucketStore.
bucketStore.removeFromBucket(key, bucketName);
throw new IllegalStateException(String.format(
"Could prepare Multipart Upload. bucket=%s, key=%s, id=%s, uploadId=%s",
bucketMetadata, key, id, uploadId
"Could prepare Multipart Upload. bucket=%s, key=%s, id=%s",
bucketMetadata, key, id
), e);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,26 +92,25 @@ public MultipartStore(boolean retainFilesOnExit,
* @param id ID of the object
* @param contentType the content type
* @param storeHeaders various headers to store
* @param uploadId id of the upload
* @param owner owner of the upload
* @param initiator initiator of the upload
* @param userMetadata custom metadata
*
* @return upload result
*/
public MultipartUpload prepareMultipartUpload(BucketMetadata bucket,
String key,
UUID id,
String contentType,
Map<String, String> storeHeaders,
String uploadId,
Owner owner,
Owner initiator,
Map<String, String> userMetadata,
Map<String, String> encryptionHeaders,
StorageClass storageClass,
String checksum,
ChecksumAlgorithm checksumAlgorithm) {
public MultipartUpload createMultipartUpload(BucketMetadata bucket,
String key,
UUID id,
String contentType,
Map<String, String> storeHeaders,
Owner owner,
Owner initiator,
Map<String, String> userMetadata,
Map<String, String> encryptionHeaders,
StorageClass storageClass,
String checksum,
ChecksumAlgorithm checksumAlgorithm) {
var uploadId = UUID.randomUUID().toString();
if (!createPartsFolder(bucket, id, uploadId)) {
LOG.error("Directories for storing multipart uploads couldn't be created. bucket={}, key={}, "
+ "id={}, uploadId={}", bucket, key, id, uploadId);
Expand All @@ -120,16 +119,18 @@ public MultipartUpload prepareMultipartUpload(BucketMetadata bucket,
}
var upload = new MultipartUpload(key, uploadId, owner, initiator, storageClass, new Date());
//TODO: store on disk, not in memory
uploadIdToInfo.put(uploadId, new MultipartUploadInfo(upload,
var multipartUploadInfo = new MultipartUploadInfo(upload,
contentType,
userMetadata,
storeHeaders,
encryptionHeaders,
bucket.name(),
storageClass,
checksum,
checksumAlgorithm)
);
checksumAlgorithm);
uploadIdToInfo.put(uploadId, multipartUploadInfo);

writeMetafile(bucket, id, multipartUploadInfo);

return upload;
}
Expand Down
Loading

0 comments on commit c9eb9a7

Please sign in to comment.