List of usage examples for com.amazonaws.services.s3.model RestoreObjectRequest getBucketName
public String getBucketName()
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 w ww . j a v a2s. 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); } }