Search in sources :

Example 1 with ObjectMetadataProvider

use of com.amazonaws.services.s3.transfer.ObjectMetadataProvider in project herd by FINRAOS.

the class S3DaoImpl method uploadFileList.

@Override
public S3FileTransferResultsDto uploadFileList(final S3FileTransferRequestParamsDto params) throws InterruptedException {
    LOGGER.info("Uploading a list of files from the local directory to S3... localDirectory=\"{}\" s3KeyPrefix=\"{}\" s3BucketName=\"{}\" s3KeyCount={}", params.getLocalPath(), params.getS3KeyPrefix(), params.getS3BucketName(), params.getFiles().size());
    if (LOGGER.isInfoEnabled()) {
        for (File file : params.getFiles()) {
            LOGGER.info("s3Key=\"{}\"", file.getPath());
        }
    }
    // Perform the transfer.
    S3FileTransferResultsDto results = performTransfer(params, new Transferer() {

        @Override
        public Transfer performTransfer(TransferManager transferManager) {
            return s3Operations.uploadFileList(params.getS3BucketName(), params.getS3KeyPrefix(), new File(params.getLocalPath()), params.getFiles(), new ObjectMetadataProvider() {

                @Override
                public void provideObjectMetadata(File file, ObjectMetadata metadata) {
                    prepareMetadata(params, metadata);
                }
            }, transferManager);
        }
    });
    LOGGER.info("Uploaded list of files from the local directory to S3. " + "localDirectory=\"{}\" s3KeyPrefix=\"{}\" s3BucketName=\"{}\" s3KeyCount={} totalBytesTransferred={} transferDuration=\"{}\"", params.getLocalPath(), params.getS3KeyPrefix(), params.getS3BucketName(), results.getTotalFilesTransferred(), results.getTotalBytesTransferred(), HerdDateUtils.formatDuration(results.getDurationMillis()));
    logOverallTransferRate(results);
    return results;
}
Also used : TransferManager(com.amazonaws.services.s3.transfer.TransferManager) Transfer(com.amazonaws.services.s3.transfer.Transfer) ObjectMetadataProvider(com.amazonaws.services.s3.transfer.ObjectMetadataProvider) File(java.io.File) S3FileTransferResultsDto(org.finra.herd.model.dto.S3FileTransferResultsDto) ObjectMetadata(com.amazonaws.services.s3.model.ObjectMetadata)

Example 2 with ObjectMetadataProvider

use of com.amazonaws.services.s3.transfer.ObjectMetadataProvider in project herd by FINRAOS.

the class S3DaoImpl method uploadDirectory.

@Override
public S3FileTransferResultsDto uploadDirectory(final S3FileTransferRequestParamsDto params) throws InterruptedException {
    LOGGER.info("Uploading local directory to S3... localDirectory=\"{}\" s3KeyPrefix=\"{}\" s3BucketName=\"{}\"", params.getLocalPath(), params.getS3KeyPrefix(), params.getS3BucketName());
    // Perform the transfer.
    S3FileTransferResultsDto results = performTransfer(params, new Transferer() {

        @Override
        public Transfer performTransfer(TransferManager transferManager) {
            return s3Operations.uploadDirectory(params.getS3BucketName(), params.getS3KeyPrefix(), new File(params.getLocalPath()), params.isRecursive(), new ObjectMetadataProvider() {

                @Override
                public void provideObjectMetadata(File file, ObjectMetadata metadata) {
                    prepareMetadata(params, metadata);
                }
            }, transferManager);
        }
    });
    LOGGER.info("Uploaded local directory to S3. " + "localDirectory=\"{}\" s3KeyPrefix=\"{}\" s3BucketName=\"{}\" s3KeyCount={} totalBytesTransferred={} transferDuration=\"{}\"", params.getLocalPath(), params.getS3KeyPrefix(), params.getS3BucketName(), results.getTotalFilesTransferred(), results.getTotalBytesTransferred(), HerdDateUtils.formatDuration(results.getDurationMillis()));
    logOverallTransferRate(results);
    return results;
}
Also used : TransferManager(com.amazonaws.services.s3.transfer.TransferManager) Transfer(com.amazonaws.services.s3.transfer.Transfer) ObjectMetadataProvider(com.amazonaws.services.s3.transfer.ObjectMetadataProvider) S3FileTransferResultsDto(org.finra.herd.model.dto.S3FileTransferResultsDto) File(java.io.File) ObjectMetadata(com.amazonaws.services.s3.model.ObjectMetadata)

Example 3 with ObjectMetadataProvider

use of com.amazonaws.services.s3.transfer.ObjectMetadataProvider in project herd by FINRAOS.

the class MockS3OperationsImpl method uploadFileList.

@Override
public MultipleFileUpload uploadFileList(String bucketName, String virtualDirectoryKeyPrefix, File directory, List<File> files, ObjectMetadataProvider metadataProvider, TransferManager transferManager) {
    LOGGER.debug("uploadFileList(): bucketName = " + bucketName + ", virtualDirectoryKeyPrefix = " + virtualDirectoryKeyPrefix + ", directory = " + directory + ", files = " + files);
    String directoryPath = directory.getAbsolutePath();
    long totalFileLength = 0;
    List<Upload> subTransfers = new ArrayList<>();
    for (File file : files) {
        // Get path to file relative to the specified directory
        String relativeFilePath = file.getAbsolutePath().substring(directoryPath.length());
        // Replace any backslashes (i.e. Windows separator) with a forward slash.
        relativeFilePath = relativeFilePath.replace("\\", "/");
        // Remove any leading slashes
        relativeFilePath = relativeFilePath.replaceAll("^/+", "");
        long fileLength = file.length();
        // Remove any trailing slashes
        virtualDirectoryKeyPrefix = virtualDirectoryKeyPrefix.replaceAll("/+$", "");
        String s3ObjectKey = virtualDirectoryKeyPrefix + "/" + relativeFilePath;
        totalFileLength += fileLength;
        PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, s3ObjectKey, file);
        ObjectMetadata objectMetadata = new ObjectMetadata();
        metadataProvider.provideObjectMetadata(null, objectMetadata);
        putObjectRequest.setMetadata(objectMetadata);
        putObject(putObjectRequest, transferManager.getAmazonS3Client());
        subTransfers.add(new UploadImpl(null, null, null, null));
    }
    TransferProgress progress = new TransferProgress();
    progress.setTotalBytesToTransfer(totalFileLength);
    progress.updateProgress(totalFileLength);
    MultipleFileUploadImpl multipleFileUpload = new MultipleFileUploadImpl(null, progress, null, virtualDirectoryKeyPrefix, bucketName, subTransfers);
    multipleFileUpload.setState(TransferState.Completed);
    return multipleFileUpload;
}
Also used : MultipleFileUploadImpl(com.amazonaws.services.s3.transfer.internal.MultipleFileUploadImpl) ArrayList(java.util.ArrayList) Upload(com.amazonaws.services.s3.transfer.Upload) MultipartUpload(com.amazonaws.services.s3.model.MultipartUpload) MultipleFileUpload(com.amazonaws.services.s3.transfer.MultipleFileUpload) File(java.io.File) ObjectMetadata(com.amazonaws.services.s3.model.ObjectMetadata) PutObjectRequest(com.amazonaws.services.s3.model.PutObjectRequest) MultipleFileUploadImpl(com.amazonaws.services.s3.transfer.internal.MultipleFileUploadImpl) UploadImpl(com.amazonaws.services.s3.transfer.internal.UploadImpl) TransferProgress(com.amazonaws.services.s3.transfer.TransferProgress)

Aggregations

ObjectMetadata (com.amazonaws.services.s3.model.ObjectMetadata)3 File (java.io.File)3 ObjectMetadataProvider (com.amazonaws.services.s3.transfer.ObjectMetadataProvider)2 Transfer (com.amazonaws.services.s3.transfer.Transfer)2 TransferManager (com.amazonaws.services.s3.transfer.TransferManager)2 S3FileTransferResultsDto (org.finra.herd.model.dto.S3FileTransferResultsDto)2 MultipartUpload (com.amazonaws.services.s3.model.MultipartUpload)1 PutObjectRequest (com.amazonaws.services.s3.model.PutObjectRequest)1 MultipleFileUpload (com.amazonaws.services.s3.transfer.MultipleFileUpload)1 TransferProgress (com.amazonaws.services.s3.transfer.TransferProgress)1 Upload (com.amazonaws.services.s3.transfer.Upload)1 MultipleFileUploadImpl (com.amazonaws.services.s3.transfer.internal.MultipleFileUploadImpl)1 UploadImpl (com.amazonaws.services.s3.transfer.internal.UploadImpl)1 ArrayList (java.util.ArrayList)1