List of usage examples for com.amazonaws.services.s3.model RestoreObjectRequest RestoreObjectRequest
public RestoreObjectRequest(String bucketName, String key, int expirationInDays)
Constructs a new RestoreObjectRequest.
From source file:nl.nn.adapterframework.filesystem.AmazonS3FileSystem.java
License:Apache License
public String restoreObject(String fileName) throws SenderException { Boolean restoreFlag;/*from w w w. j a va2 s . c o m*/ try { bucketDoesNotExist(bucketName); fileDoesNotExist(bucketName, fileName); RestoreObjectRequest requestRestore = new RestoreObjectRequest(bucketName, fileName, expirationInDays) .withTier(tier); s3Client.restoreObjectV2(requestRestore); log.debug("Object with fileName [" + fileName + "] and bucketName [" + bucketName + "] restored from Amazon S3 Glacier"); ObjectMetadata response = s3Client.getObjectMetadata(bucketName, fileName); restoreFlag = response.getOngoingRestore(); System.out.format("Restoration status: %s.\n", restoreFlag ? "in progress" : "not in progress (finished or failed)"); } catch (AmazonServiceException e) { log.error("Failed to perform [restore] action, and restore object with fileName [" + fileName + "] from Amazon S3 Glacier"); throw new SenderException("Failed to perform [restore] action, and restore object with fileName [" + fileName + "] from Amazon S3 Glacier"); } String prefix = "Restoration status: %s.\n"; return restoreFlag ? prefix + "in progress" : prefix + "not in progress (finished or failed)"; }
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 {/*from w ww. j av a 2 s. 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); } } }
From source file:org.opendedup.sdfs.filestore.cloud.BatchAwsS3ChunkStore.java
License:Open Source License
@Override public synchronized String restoreBlock(long id, byte[] hash) throws IOException { this.s3clientLock.readLock().lock(); try {// w w w . j a va2s.c om if (id == -1) { SDFSLogger.getLog().warn("Hash not found for " + StringUtils.getHexString(hash)); return null; } String haName = this.restoreRequests.get(new Long(id)); if (haName == null) haName = EncyptUtils.encHashArchiveName(id, Main.chunkStoreEncryptionEnabled); else if (haName.equalsIgnoreCase("InvalidObjectState")) return null; else { return haName; } try { RestoreObjectRequest request = new RestoreObjectRequest(this.name, "blocks/" + haName, 2); s3Service.restoreObject(request); if (blockRestored(haName)) { restoreRequests.put(new Long(id), "InvalidObjectState"); return null; } restoreRequests.put(new Long(id), haName); return haName; } catch (AmazonS3Exception e) { if (e.getErrorCode().equalsIgnoreCase("InvalidObjectState")) { restoreRequests.put(new Long(id), "InvalidObjectState"); return null; } if (e.getErrorCode().equalsIgnoreCase("RestoreAlreadyInProgress")) { restoreRequests.put(new Long(id), haName); return haName; } else { SDFSLogger.getLog().error("Error while restoring block " + e.getErrorCode() + " id=" + id + " name=blocks/" + haName); throw e; } } } finally { this.s3clientLock.readLock().unlock(); } }