List of usage examples for com.amazonaws.services.s3.model ObjectMetadata getOngoingRestore
public Boolean getOngoingRestore()
From source file:cloudExplorer.RestoreObject.java
License:Open Source License
public void run() { String message = null;//w w w . ja va 2 s. com AWSCredentials credentials = new BasicAWSCredentials(access_key, secret_key); File file = new File(what); AmazonS3 s3Client = new AmazonS3Client(credentials, new ClientConfiguration().withSignerOverride("S3SignerType")); s3Client.setEndpoint(endpoint); try { GetObjectMetadataRequest request = new GetObjectMetadataRequest(bucket, what); ObjectMetadata response = s3Client.getObjectMetadata(request); response.getOngoingRestore(); mainFrame.jTextArea1.append("\nRestored operation ran for Object: " + what + ". Please examiene this window for any errors."); mainFrame.calibrateTextArea(); } catch (Exception get) { // mainFrame.jTextArea1.append("\n\nError Message: " + get.getMessage()); } calibrate(); }
From source file:nl.nn.adapterframework.filesystem.AmazonS3FileSystem.java
License:Apache License
public String restoreObject(String fileName) throws SenderException { Boolean restoreFlag;/*from w ww . ja v a 2 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.MockS3OperationsImpl.java
License:Apache License
@Override public void restoreObject(RestoreObjectRequest requestRestore, AmazonS3 s3Client) { if (requestRestore.getKey().endsWith(MockAwsOperationsHelper.AMAZON_THROTTLING_EXCEPTION)) { AmazonServiceException throttlingException = new AmazonServiceException("test throttling exception"); throttlingException.setErrorCode("ThrottlingException"); throw throttlingException; } else if (MOCK_S3_BUCKET_NAME_NO_SUCH_BUCKET_EXCEPTION.equals(requestRestore.getBucketName())) { AmazonServiceException amazonServiceException = new AmazonServiceException( S3Operations.ERROR_CODE_NO_SUCH_BUCKET); amazonServiceException.setStatusCode(404); throw amazonServiceException; } else if (MOCK_S3_BUCKET_NAME_ACCESS_DENIED.equals(requestRestore.getBucketName())) { AmazonServiceException amazonServiceException = new AmazonServiceException( S3Operations.ERROR_CODE_ACCESS_DENIED); amazonServiceException.setStatusCode(403); throw amazonServiceException; } else if (MOCK_S3_BUCKET_NAME_INTERNAL_ERROR.equals(requestRestore.getBucketName()) || requestRestore.getKey().endsWith(MOCK_S3_FILE_NAME_SERVICE_EXCEPTION)) { throw new AmazonServiceException(S3Operations.ERROR_CODE_INTERNAL_ERROR); } else {/*from ww w. j a v a 2s .c o m*/ MockS3Bucket mockS3Bucket = getOrCreateBucket(requestRestore.getBucketName()); MockS3Object mockS3Object = mockS3Bucket.getObjects().get(requestRestore.getKey()); if (mockS3Object == null) { AmazonServiceException amazonServiceException = new AmazonServiceException( S3Operations.ERROR_CODE_NO_SUCH_KEY); amazonServiceException.setStatusCode(404); throw amazonServiceException; } // Get object metadata. ObjectMetadata objectMetadata = mockS3Object.getObjectMetadata(); // Fail if the object is not in Glacier. if (!StorageClass.Glacier.toString().equals(objectMetadata.getStorageClass())) { AmazonServiceException amazonServiceException = new AmazonServiceException( "object is not in Glacier"); throw amazonServiceException; } // Fail if the object is already being restored. if (objectMetadata.getOngoingRestore()) { AmazonServiceException amazonServiceException = new AmazonServiceException( "object is already being restored"); throw amazonServiceException; } // Update the object metadata to indicate that there is an ongoing restore request. objectMetadata.setOngoingRestore(true); } }
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 a va 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.finra.herd.dao.impl.S3DaoImpl.java
License:Apache License
@Override public void validateGlacierS3FilesRestored(S3FileTransferRequestParamsDto params) throws RuntimeException { LOGGER.info(/*from w ww . jav a 2s. c o m*/ "Checking for already restored Glacier storage class objects... 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); try { for (File file : params.getFiles()) { key = file.getPath().replaceAll("\\\\", "/"); ObjectMetadata objectMetadata = s3Operations.getObjectMetadata(params.getS3BucketName(), key, s3Client); // Fail if a not already restored object is detected. if (BooleanUtils.isNotFalse(objectMetadata.getOngoingRestore())) { throw new IllegalArgumentException(String.format( "Archived Glacier S3 file \"%s\" is not restored. StorageClass {%s}, OngoingRestore flag {%s}, S3 bucket name {%s}", key, objectMetadata.getStorageClass(), objectMetadata.getOngoingRestore(), params.getS3BucketName())); } } } finally { s3Client.shutdown(); } } catch (AmazonServiceException e) { throw new IllegalStateException( String.format("Fail to check restore status 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 boolean blockRestored(String id) { this.s3clientLock.readLock().lock(); try {/*from w w w .ja v a 2s . co m*/ ObjectMetadata omd = s3Service.getObjectMetadata(this.name, "blocks/" + id); if (omd.getOngoingRestore()) return false; else return true; } finally { this.s3clientLock.readLock().unlock(); } }
From source file:org.xmlsh.aws.util.AWSS3Command.java
License:BSD License
protected void writeMeta(ObjectMetadata m) throws InvalidArgumentException, XMLStreamException, SaxonApiException { mLogger.entry(m);/* w w w . j a v a2 s. co m*/ startElement(sMetaDataElem); attribute("cache-control", m.getCacheControl()); attribute("content-disposition", m.getContentDisposition()); attribute("content-encoding", m.getContentEncoding()); attribute("md5", m.getContentMD5()); attribute("etag", m.getETag()); attribute("version-id", m.getVersionId()); attribute("content-length", String.valueOf(m.getContentLength())); attribute("last-modified", Util.formatXSDateTime(m.getLastModified())); attribute("expiration-time", Util.formatXSDateTime(m.getExpirationTime())); attribute("expiration-time-rule-id", m.getExpirationTimeRuleId()); attribute("httpExpiresDate", Util.formatXSDateTime(m.getHttpExpiresDate())); attribute("ongoingRestore", m.getOngoingRestore()); attribute("restore-expiration-time", Util.formatXSDateTime(m.getRestoreExpirationTime())); attribute("instance-length", m.getInstanceLength()); attribute("sse-algorithm", m.getSSEAlgorithm()); attribute("sse-aws-kms-key-id", m.getSSEAwsKmsKeyId()); attribute("sse-customer-algorithm", m.getSSECustomerAlgorithm()); attribute("sse-customer-key-md5", m.getSSECustomerKeyMd5()); attribute("storage-class", m.getStorageClass()); startElement("user-metadata"); for (Entry<String, String> user : m.getUserMetadata().entrySet()) { startElement(sUserMetaDataElem); attribute("name", user.getKey()); attribute("value", user.getValue()); endElement(); } endElement(); endElement(); mLogger.exit(); }