Package org.duracloud.s3storage
Class S3StorageProvider
- java.lang.Object
-
- org.duracloud.storage.provider.StorageProviderBase
-
- org.duracloud.s3storage.S3StorageProvider
-
- All Implemented Interfaces:
StorageProvider
public class S3StorageProvider extends StorageProviderBase
Provides content storage backed by Amazon's Simple Storage Service.- Author:
- Bill Branan
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.duracloud.storage.provider.StorageProviderBase
StorageProviderBase.SpaceDeleteWorker
-
-
Field Summary
Fields Modifier and Type Field Description protected StringaccessKeyIdprotected static com.amazonaws.services.s3.model.StorageClassDEFAULT_STORAGE_CLASSprotected static StringHEADER_KEY_SUFFIXprotected static StringHEADER_VALUE_PREFIXstatic StringHIDDEN_SPACE_PREFIXprotected static intMAX_ITEM_COUNTprotected com.amazonaws.services.s3.AmazonS3s3Client-
Fields inherited from class org.duracloud.storage.provider.StorageProviderBase
ACL_DELIM, ACL_GROUP_READ, ACL_GROUP_WRITE, ACL_USER_READ, ACL_USER_WRITE
-
Fields inherited from interface org.duracloud.storage.provider.StorageProvider
DEFAULT_MAX_RESULTS, DEFAULT_MIMETYPE, ISO8601_DATE_FORMAT, PROPERTIES_BUCKET, PROPERTIES_CONTENT_CHECKSUM, PROPERTIES_CONTENT_CREATOR, PROPERTIES_CONTENT_FILE_CREATED, PROPERTIES_CONTENT_FILE_LAST_ACCESSED, PROPERTIES_CONTENT_FILE_MODIFIED, PROPERTIES_CONTENT_FILE_PATH, PROPERTIES_CONTENT_MD5, PROPERTIES_CONTENT_MIMETYPE, PROPERTIES_CONTENT_MODIFIED, PROPERTIES_CONTENT_SIZE, PROPERTIES_COPY_SOURCE, PROPERTIES_COPY_SOURCE_STORE, PROPERTIES_HLS_STREAMING_HOST, PROPERTIES_HLS_STREAMING_TYPE, PROPERTIES_SPACE_ACL, PROPERTIES_SPACE_ACL_GROUP, PROPERTIES_SPACE_ACL_PUBLIC, PROPERTIES_SPACE_COUNT, PROPERTIES_SPACE_CREATED, PROPERTIES_SPACE_SIZE
-
-
Constructor Summary
Constructors Constructor Description S3StorageProvider(com.amazonaws.services.s3.AmazonS3 s3Client, String accessKey, Map<String,String> options)S3StorageProvider(String accessKey, String secretKey)S3StorageProvider(String accessKey, String secretKey, Map<String,String> options)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description StringaddContent(String spaceId, String contentId, String contentMimeType, Map<String,String> userProperties, long contentSize, String contentChecksum, InputStream content)StringaddHiddenContent(String spaceId, String contentId, String contentMimeType, InputStream content)Adds content to a hidden space.StringcopyContent(String sourceSpaceId, String sourceContentId, String destSpaceId, String destContentId)protected com.amazonaws.services.s3.model.BucketcreateBucket(String spaceId)StringcreateHiddenSpace(String spaceId, int expirationInDays)Creates a "hidden" space.voidcreateSpace(String spaceId)protected static StringdecodeHeaderKey(String userMetaName)protected static StringdecodeHeaderValue(String userMetaValue)voiddeleteContent(String spaceId, String contentId)protected StringdoesContentExistWithExpectedChecksum(String bucketName, String contentId, String expectedChecksum)protected voiddoSetSpaceProperties(String spaceId, Map<String,String> spaceProperties)protected static StringencodeHeaderKey(String userMetaName)Ensures compliance with https://tools.ietf.org/html/rfc5987#section-3.2.2protected static StringencodeHeaderValue(String userMetaValue)Ensures compliance with https://tools.ietf.org/html/rfc5987#section-3.2.2protected StringformattedDate(Date date)protected Map<String,String>getAllSpaceProperties(String spaceId)protected StringgetBucketCreationDate(String bucketName)StringgetBucketName(String spaceId)Gets the name of an existing bucket based on a space ID.RetrievedContentgetContent(String spaceId, String contentId)RetrievedContentgetContent(String spaceId, String contentId, String range)Map<String,String>getContentProperties(String spaceId, String contentId)protected StringgetETagValue(String etag)protected StringgetHiddenBucketName(String spaceId)protected StringgetNewBucketName(String spaceId)Iterator<String>getSpaceContents(String spaceId, String prefix)List<String>getSpaceContentsChunked(String spaceId, String prefix, long maxResults, String marker)protected StringgetSpaceCount(String spaceId, int maxCount)protected StringgetSpaceFree(String name)Replaces all spaces with "%20"protected StringgetSpaceId(String bucketName)Converts a bucket name into what could be passed in as a space ID.Map<String,String>getSpaceProperties(String spaceId)Iterator<String>getSpaces()protected StoragePolicygetStoragePolicy()Defines the storage policy for the primary S3 provider.StorageProviderTypegetStorageProviderType()protected StringgetWithSpace(String name)Converts "%20" back to spacesprotected booleanisSpace(String bucketName)Determines if an S3 bucket is a DuraCloud spaceprotected Map<String,String>prepContentProperties(com.amazonaws.services.s3.model.ObjectMetadata objMetadata)protected Map<String,String>removeCalculatedProperties(Map<String,String> contentProperties)voidremoveSpace(String spaceId)protected Map<String,String>replaceInMapValues(Map<String,String> map, String oldVal, String newVal)voidsetContentProperties(String spaceId, String contentId, Map<String,String> contentProperties)voidsetSpaceLifecycle(String bucketName, com.amazonaws.services.s3.model.BucketLifecycleConfiguration config)Sets a lifecycle policy on an S3 bucket based on the given configurationprotected booleanspaceExists(String spaceId)protected voidthrowIfContentNotExist(String bucketName, String contentId)protected voidupdateObjectProperties(String bucketName, String contentId, com.amazonaws.services.s3.model.ObjectMetadata objMetadata)protected voidwait(int seconds)-
Methods inherited from class org.duracloud.storage.provider.StorageProviderBase
deleteSpace, deleteSpaceSync, getSpaceACLs, getSpaceDeleteWorker, packACLs, setNewSpaceProperties, setNewSpaceProperties, setSpaceACLs, setWrappedStorageProvider, throwIfSpaceNotExist, throwIfSpaceNotExist, unpackACLs
-
-
-
-
Field Detail
-
MAX_ITEM_COUNT
protected static final int MAX_ITEM_COUNT
- See Also:
- Constant Field Values
-
DEFAULT_STORAGE_CLASS
protected static final com.amazonaws.services.s3.model.StorageClass DEFAULT_STORAGE_CLASS
-
HIDDEN_SPACE_PREFIX
public static final String HIDDEN_SPACE_PREFIX
- See Also:
- Constant Field Values
-
HEADER_VALUE_PREFIX
protected static final String HEADER_VALUE_PREFIX
-
HEADER_KEY_SUFFIX
protected static final String HEADER_KEY_SUFFIX
- See Also:
- Constant Field Values
-
accessKeyId
protected String accessKeyId
-
s3Client
protected com.amazonaws.services.s3.AmazonS3 s3Client
-
-
Method Detail
-
getStorageProviderType
public StorageProviderType getStorageProviderType()
-
getSpaceContentsChunked
public List<String> getSpaceContentsChunked(String spaceId, String prefix, long maxResults, String marker)
-
spaceExists
protected boolean spaceExists(String spaceId)
- Specified by:
spaceExistsin classStorageProviderBase
-
createSpace
public void createSpace(String spaceId)
-
createBucket
protected com.amazonaws.services.s3.model.Bucket createBucket(String spaceId)
-
createHiddenSpace
public String createHiddenSpace(String spaceId, int expirationInDays)
Creates a "hidden" space. This space will not be returned by the StorageProvider.getSpaces() method. It can be accessed using the getSpace* methods. You must know the name of the space in order to access it.- Parameters:
spaceId- The spaceIdexpirationInDays- The number of days before content in the space is automatically deleted.- Returns:
-
getStoragePolicy
protected StoragePolicy getStoragePolicy()
Defines the storage policy for the primary S3 provider. Subclasses can define different policy choices.- Returns:
- storage policy to set, or null if no policy should be defined
-
setSpaceLifecycle
public void setSpaceLifecycle(String bucketName, com.amazonaws.services.s3.model.BucketLifecycleConfiguration config)
Sets a lifecycle policy on an S3 bucket based on the given configuration- Parameters:
bucketName- name of the bucket to updateconfig- bucket lifecycle configuration
-
removeSpace
public void removeSpace(String spaceId)
- Specified by:
removeSpacein classStorageProviderBase
-
getAllSpaceProperties
protected Map<String,String> getAllSpaceProperties(String spaceId)
- Specified by:
getAllSpacePropertiesin classStorageProviderBase
-
doSetSpaceProperties
protected void doSetSpaceProperties(String spaceId, Map<String,String> spaceProperties)
- Specified by:
doSetSpacePropertiesin classStorageProviderBase
-
replaceInMapValues
protected Map<String,String> replaceInMapValues(Map<String,String> map, String oldVal, String newVal)
-
addHiddenContent
public String addHiddenContent(String spaceId, String contentId, String contentMimeType, InputStream content)
Adds content to a hidden space.- Parameters:
spaceId- hidden spaceIdcontentId-contentMimeType-content-- Returns:
-
addContent
public String addContent(String spaceId, String contentId, String contentMimeType, Map<String,String> userProperties, long contentSize, String contentChecksum, InputStream content)
-
doesContentExistWithExpectedChecksum
protected String doesContentExistWithExpectedChecksum(String bucketName, String contentId, String expectedChecksum)
-
wait
protected void wait(int seconds)
-
copyContent
public String copyContent(String sourceSpaceId, String sourceContentId, String destSpaceId, String destContentId)
-
getContent
public RetrievedContent getContent(String spaceId, String contentId)
-
getContent
public RetrievedContent getContent(String spaceId, String contentId, String range)
-
setContentProperties
public void setContentProperties(String spaceId, String contentId, Map<String,String> contentProperties)
-
removeCalculatedProperties
protected Map<String,String> removeCalculatedProperties(Map<String,String> contentProperties)
- Overrides:
removeCalculatedPropertiesin classStorageProviderBase
-
updateObjectProperties
protected void updateObjectProperties(String bucketName, String contentId, com.amazonaws.services.s3.model.ObjectMetadata objMetadata)
-
getContentProperties
public Map<String,String> getContentProperties(String spaceId, String contentId)
-
getSpaceProperties
public Map<String,String> getSpaceProperties(String spaceId)
- Specified by:
getSpacePropertiesin interfaceStorageProvider- Overrides:
getSpacePropertiesin classStorageProviderBase
-
prepContentProperties
protected Map<String,String> prepContentProperties(com.amazonaws.services.s3.model.ObjectMetadata objMetadata)
-
getBucketName
public String getBucketName(String spaceId)
Gets the name of an existing bucket based on a space ID. If no bucket with this spaceId exists, throws a NotFoundException- Parameters:
spaceId- the space Id to convert into an S3 bucket name- Returns:
- S3 bucket name of a given DuraCloud space
- Throws:
NotFoundException- if no bucket matches this spaceID
-
getSpaceId
protected String getSpaceId(String bucketName)
Converts a bucket name into what could be passed in as a space ID.- Parameters:
bucketName- name of the S3 bucket- Returns:
- the DuraCloud space name equivalent to a given S3 bucket Id
-
isSpace
protected boolean isSpace(String bucketName)
Determines if an S3 bucket is a DuraCloud space- Parameters:
bucketName- name of the S3 bucket- Returns:
- true if the given S3 bucket name is named according to the DuraCloud space naming conventions, false otherwise
-
getSpaceFree
protected String getSpaceFree(String name)
Replaces all spaces with "%20"- Parameters:
name- string with possible space- Returns:
- converted to string without spaces
-
getWithSpace
protected String getWithSpace(String name)
Converts "%20" back to spaces- Parameters:
name- string- Returns:
- converted to spaces
-
encodeHeaderValue
protected static String encodeHeaderValue(String userMetaValue)
Ensures compliance with https://tools.ietf.org/html/rfc5987#section-3.2.2- Parameters:
userMetaValue-- Returns:
-
encodeHeaderKey
protected static String encodeHeaderKey(String userMetaName)
Ensures compliance with https://tools.ietf.org/html/rfc5987#section-3.2.2- Parameters:
userMetaName-- Returns:
-
-