Example usage for com.amazonaws.services.s3.model RestoreObjectRequest setGlacierJobParameters

List of usage examples for com.amazonaws.services.s3.model RestoreObjectRequest setGlacierJobParameters

Introduction

In this page you can find the example usage for com.amazonaws.services.s3.model RestoreObjectRequest setGlacierJobParameters.

Prototype

public void setGlacierJobParameters(GlacierJobParameters glacierJobParameters) 

Source Link

Document

Sets Glacier related parameters pertaining to this job.

Usage

From source file:org.finra.herd.dao.impl.S3DaoImpl.java

License:Apache License

@Override
public void restoreObjects(final S3FileTransferRequestParamsDto params, int expirationInDays,
        String archiveRetrievalOption) {
    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 {//  w  w w .  j a v a2s .c o  m
            // Create an S3 client.
            AmazonS3Client s3Client = getAmazonS3(params);

            // Create a restore object request.
            RestoreObjectRequest requestRestore = new RestoreObjectRequest(params.getS3BucketName(), null,
                    expirationInDays);
            // Make Bulk the default archive retrieval option if the option is not provided
            requestRestore.setGlacierJobParameters(new GlacierJobParameters()
                    .withTier(StringUtils.isNotEmpty(archiveRetrievalOption) ? archiveRetrievalOption
                            : Tier.Bulk.toString()));

            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);
        }
    }
}