use of com.talend.shaded.com.amazonaws.services.s3.model.ObjectMetadata in project herd by FINRAOS.
the class S3DaoImpl method restoreObjects.
@Override
public void restoreObjects(final S3FileTransferRequestParamsDto params, int expirationInDays) {
LOGGER.info("Restoring a list of objects in S3... s3KeyPrefix=\"{}\" s3BucketName=\"{}\" s3KeyCount={}", params.getS3KeyPrefix(), params.getS3BucketName(), params.getFiles().size());
if (!CollectionUtils.isEmpty(params.getFiles())) {
// Initialize a key value pair for the error message in the catch block.
String key = params.getFiles().get(0).getPath().replaceAll("\\\\", "/");
try {
// Create an S3 client.
AmazonS3Client s3Client = getAmazonS3(params);
// Create a restore object request.
RestoreObjectRequest requestRestore = new RestoreObjectRequest(params.getS3BucketName(), null, expirationInDays);
// Make Bulk as default glacier retrieval option
requestRestore.setGlacierJobParameters(new GlacierJobParameters().withTier(GLACIER_RETRIEVAL_OPTION));
try {
for (File file : params.getFiles()) {
key = file.getPath().replaceAll("\\\\", "/");
ObjectMetadata objectMetadata = s3Operations.getObjectMetadata(params.getS3BucketName(), key, s3Client);
// Request a restore for objects that are not already being restored.
if (BooleanUtils.isNotTrue(objectMetadata.getOngoingRestore())) {
requestRestore.setKey(key);
s3Operations.restoreObject(requestRestore, s3Client);
}
}
} finally {
s3Client.shutdown();
}
} catch (Exception e) {
throw new IllegalStateException(String.format("Failed to initiate a restore request for \"%s\" key in \"%s\" bucket. Reason: %s", key, params.getS3BucketName(), e.getMessage()), e);
}
}
}
use of com.talend.shaded.com.amazonaws.services.s3.model.ObjectMetadata 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;
}
use of com.talend.shaded.com.amazonaws.services.s3.model.ObjectMetadata 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;
}
use of com.talend.shaded.com.amazonaws.services.s3.model.ObjectMetadata in project herd by FINRAOS.
the class S3DaoImpl method uploadFile.
@Override
public S3FileTransferResultsDto uploadFile(final S3FileTransferRequestParamsDto params) throws InterruptedException {
LOGGER.info("Uploading local file to S3... localPath=\"{}\" s3Key=\"{}\" s3BucketName=\"{}\"", params.getLocalPath(), params.getS3KeyPrefix(), params.getS3BucketName());
// Perform the transfer.
S3FileTransferResultsDto results = performTransfer(params, new Transferer() {
@Override
public Transfer performTransfer(TransferManager transferManager) {
// Get a handle to the local file.
File localFile = new File(params.getLocalPath());
// Create and prepare the metadata.
ObjectMetadata metadata = new ObjectMetadata();
prepareMetadata(params, metadata);
// Create a put request and a transfer manager with the parameters and the metadata.
PutObjectRequest putObjectRequest = new PutObjectRequest(params.getS3BucketName(), params.getS3KeyPrefix(), localFile);
putObjectRequest.setMetadata(metadata);
return s3Operations.upload(putObjectRequest, transferManager);
}
});
LOGGER.info("Uploaded local file to the S3. localPath=\"{}\" s3Key=\"{}\" s3BucketName=\"{}\" totalBytesTransferred={} transferDuration=\"{}\"", params.getLocalPath(), params.getS3KeyPrefix(), params.getS3BucketName(), results.getTotalBytesTransferred(), HerdDateUtils.formatDuration(results.getDurationMillis()));
logOverallTransferRate(results);
return results;
}
use of com.talend.shaded.com.amazonaws.services.s3.model.ObjectMetadata in project adeptj-modules by AdeptJ.
the class UploadResource method uploadFile.
@POST
@Path(PATH_UPLOAD)
@Consumes(MULTIPART_FORM_DATA)
@RequiresJwt
public Response uploadFile(@MultipartForm FileUploadForm form) {
try {
ObjectMetadata metadata = new ObjectMetadata();
metadata.setContentLength((long) form.getData().length);
this.storageService.uploadFile(S3Request.builder().bucketName(form.getBucketName()).key(form.getKey()).data(IOUtils.buffer(new ByteArrayInputStream(form.getData()))).metadata(metadata).cannedACL(CannedAccessControlList.valueOf(form.getAccess())).build());
return Response.ok("File uploaded successfully!!").build();
} catch (Exception ex) {
// NOSONAR
throw JaxRSException.builder().message(ex.getMessage()).cause(ex).status(STATUS_SERVER_ERROR).logException(true).build();
}
}
Aggregations