/** * Converts the RestoreObjectRequest to an XML fragment that can be sent to * the RestoreObject operation of Amazon S3. * * @param restoreObjectRequest * The container which provides options for restoring an object, * which was transitioned to the Glacier from S3 when it was * expired, into S3 again. * * @return A byte array containing the data * * @throws SdkClientException */ public static byte[] convertToXmlByteArray(RestoreObjectRequest restoreObjectRequest) throws SdkClientException { XmlWriter xml = new XmlWriter(); xml.start("RestoreRequest"); xml.start("Days").value(Integer.toString(restoreObjectRequest.getExpirationInDays())).end(); final GlacierJobParameters glacierJobParameters = restoreObjectRequest.getGlacierJobParameters(); if (glacierJobParameters != null) { xml.start("GlacierJobParameters"); addIfNotNull(xml, "Tier", glacierJobParameters.getTier()); xml.end(); } xml.end(); return xml.getBytes(); }
@Override public void restoreObject(RestoreObjectRequest copyGlacierObjectRequest) throws AmazonServiceException { delegate.restoreObject(copyGlacierObjectRequest); }
@Override public void restoreObject(RestoreObjectRequest request) throws AmazonServiceException { run(() -> getDelegate().restoreObject(request)); }
@Override public void restoreObject(RestoreObjectRequest requestRestore, AmazonS3 s3Client) { s3Client.restoreObject(requestRestore); }
@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); } } }
@Override public void restoreObject(RestoreObjectRequest request) throws AmazonServiceException { }
public void run() { String message = null; AWSCredentials credentials = new BasicAWSCredentials(access_key, secret_key); File file = new File(what); AmazonS3 s3Client = new AmazonS3Client(credentials, new ClientConfiguration()); if (endpoint.contains("amazonaws.com")) { String aws_endpoint = s3Client.getBucketLocation(new GetBucketLocationRequest(bucket)); if (aws_endpoint.contains("US")) { s3Client.setEndpoint("https://s3.amazonaws.com"); } else if (aws_endpoint.contains("us-west")) { s3Client.setEndpoint("https://s3-" + aws_endpoint + ".amazonaws.com"); } else if (aws_endpoint.contains("eu-west")) { s3Client.setEndpoint("https://s3-" + aws_endpoint + ".amazonaws.com"); } else if (aws_endpoint.contains("ap-")) { s3Client.setEndpoint("https://s3-" + aws_endpoint + ".amazonaws.com"); } else if (aws_endpoint.contains("sa-east-1")) { s3Client.setEndpoint("https://s3-" + aws_endpoint + ".amazonaws.com"); } else { s3Client.setEndpoint("https://s3." + aws_endpoint + ".amazonaws.com"); } } else { s3Client.setS3ClientOptions(S3ClientOptions.builder().setPathStyleAccess(true).build()); s3Client.setEndpoint(endpoint); } try { RestoreObjectRequest requestRestore = new RestoreObjectRequest(bucket, what, 2); s3Client.restoreObject(requestRestore); GetObjectMetadataRequest requestCheck = new GetObjectMetadataRequest(bucket, what); ObjectMetadata response = s3Client.getObjectMetadata(requestCheck); Boolean restoreFlag = response.getOngoingRestore(); mainFrame.jTextArea1.append("\nRestoration in progress. Please try to access the file again in a few hours."); calibrate(); } catch (AmazonS3Exception amazonS3Exception) { mainFrame.jTextArea1.append("\nAn Amazon S3 error occurred. Exception: %s" + amazonS3Exception.toString()); calibrate(); } catch (Exception ex) { mainFrame.jTextArea1.append("\nException: %s" + ex.toString()); calibrate(); } calibrate(); }
@Override public void restoreObject(RestoreObjectRequest request) throws AmazonServiceException { // TODO Auto-generated method stub }
/** * Requests to restore an object, which was transitioned to Amazon Glacier from Amazon S3 when it was expired, into Amazon S3 again. * * @param requestRestore the request object containing all the options for restoring an object * @param s3Client the {@link AmazonS3} implementation to use */ public void restoreObject(RestoreObjectRequest requestRestore, AmazonS3 s3Client);