org.duracloud.s3storage
Class S3StorageProvider

java.lang.Object
  extended by org.duracloud.storage.provider.StorageProviderBase
      extended by 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 interface org.duracloud.storage.provider.StorageProvider
StorageProvider.AccessType
 
Field Summary
protected static int MAX_ITEM_COUNT
           
 
Fields inherited from interface org.duracloud.storage.provider.StorageProvider
CONTENT_METADATA_SUFFIX, DEFAULT_MAX_RESULTS, DEFAULT_MIMETYPE, HTTP_NOT_FOUND, METADATA_CONTENT_CHECKSUM, METADATA_CONTENT_MD5, METADATA_CONTENT_MIMETYPE, METADATA_CONTENT_MODIFIED, METADATA_CONTENT_SIZE, METADATA_SPACE_ACCESS, METADATA_SPACE_COUNT, METADATA_SPACE_CREATED, METADATA_SPACE_SIZE, RFC822_DATE_FORMAT, SPACE_METADATA_SUFFIX
 
Constructor Summary
S3StorageProvider(com.amazonaws.services.s3.AmazonS3Client s3Client, java.lang.String accessKey)
           
S3StorageProvider(java.lang.String accessKey, java.lang.String secretKey)
           
 
Method Summary
 java.lang.String addContent(java.lang.String spaceId, java.lang.String contentId, java.lang.String contentMimeType, long contentSize, java.lang.String contentChecksum, java.io.InputStream content)
          Adds content to a space.
 void createSpace(java.lang.String spaceId)
          Creates a new space.
 void deleteContent(java.lang.String spaceId, java.lang.String contentId)
          Removes content from a space.
 void deleteSpace(java.lang.String spaceId)
          Deletes a space.
 java.lang.String getBucketName(java.lang.String spaceId)
          Converts a DuraCloud spaceId into its corresponding Amazon S3 bucket name
 java.io.InputStream getContent(java.lang.String spaceId, java.lang.String contentId)
          Gets content from a space.
 java.util.Map<java.lang.String,java.lang.String> getContentMetadata(java.lang.String spaceId, java.lang.String contentId)
          Retrieves the metadata associated with content.
protected  java.lang.String getETagValue(java.lang.String etag)
           
 java.util.Iterator<java.lang.String> getSpaceContents(java.lang.String spaceId, java.lang.String prefix)
          Provides access to the content files within a space.
 java.util.List<java.lang.String> getSpaceContentsChunked(java.lang.String spaceId, java.lang.String prefix, long maxResults, java.lang.String marker)
          Provides a listing of the content files within a space.
protected  java.lang.String getSpaceCount(java.lang.String spaceId, int maxCount)
           
protected  java.lang.String getSpaceId(java.lang.String bucketName)
          Converts a bucket name into what could be passed in as a space ID.
 java.util.Map<java.lang.String,java.lang.String> getSpaceMetadata(java.lang.String spaceId)
          Retrieves the metadata associated with a space.
 java.util.Iterator<java.lang.String> getSpaces()
          Provides a listing of all spaces owned by a customer.
protected  boolean isSpace(java.lang.String bucketName)
          Determines if an S3 bucket is a DuraCloud space
 void setContentMetadata(java.lang.String spaceId, java.lang.String contentId, java.util.Map<java.lang.String,java.lang.String> contentMetadata)
          Sets the metadata associated with content.
 void setSpaceMetadata(java.lang.String spaceId, java.util.Map<java.lang.String,java.lang.String> spaceMetadata)
          Sets the metadata associated with a space.
protected  void throwIfSpaceNotExist(java.lang.String spaceId)
           
 
Methods inherited from class org.duracloud.storage.provider.StorageProviderBase
getSpaceAccess, setSpaceAccess
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MAX_ITEM_COUNT

protected static final int MAX_ITEM_COUNT
See Also:
Constant Field Values
Constructor Detail

S3StorageProvider

public S3StorageProvider(java.lang.String accessKey,
                         java.lang.String secretKey)

S3StorageProvider

public S3StorageProvider(com.amazonaws.services.s3.AmazonS3Client s3Client,
                         java.lang.String accessKey)
Method Detail

getSpaces

public java.util.Iterator<java.lang.String> getSpaces()
Provides a listing of all spaces owned by a customer.

Returns:
Iterator listing spaceIds

getSpaceContents

public java.util.Iterator<java.lang.String> getSpaceContents(java.lang.String spaceId,
                                                             java.lang.String prefix)
Provides access to the content files within a space. Chunking of the list is handled internally. Prefix can be set to return only content IDs starting with the prefix value.

Parameters:
spaceId - - ID of the space
prefix - - The prefix of the content id (null for no constraints)
Returns:
Iterator of contentIds

getSpaceContentsChunked

public java.util.List<java.lang.String> getSpaceContentsChunked(java.lang.String spaceId,
                                                                java.lang.String prefix,
                                                                long maxResults,
                                                                java.lang.String marker)
Provides a listing of the content files within a space. The number of items returned is limited to maxResults (default is 1000). Retrieve further results by including the last content ID in the previous list as the marker. Set prefix to return only content IDs starting with the prefix value.

Parameters:
spaceId - - ID of the space
prefix - - Only retrieve content IDs with this prefix (null for all content ids)
maxResults - - The maximum number of content IDs to return in the list (0 indicates default (1000))
marker - - The content ID marking the last item in the previous set (null indicates the first set of ids)
Returns:
List of contentIds

throwIfSpaceNotExist

protected void throwIfSpaceNotExist(java.lang.String spaceId)
Specified by:
throwIfSpaceNotExist in class StorageProviderBase

createSpace

public void createSpace(java.lang.String spaceId)
Creates a new space. Depending on the storage implementation, the spaceId may be changed somewhat to comply with the naming rules of the underlying storage provider. The same spaceId value used here can be used in all other methods, as the conversion will be applied internally, however a call to getSpaces() may not include a space with exactly this same name.

Parameters:
spaceId - - ID of the space

deleteSpace

public void deleteSpace(java.lang.String spaceId)
Deletes a space.

Parameters:
spaceId - - ID of the space

getSpaceMetadata

public java.util.Map<java.lang.String,java.lang.String> getSpaceMetadata(java.lang.String spaceId)
Retrieves the metadata associated with a space.

Parameters:
spaceId - - ID of the space
Returns:
Map of space metadata or null if no metadata exists

getSpaceCount

protected java.lang.String getSpaceCount(java.lang.String spaceId,
                                         int maxCount)

setSpaceMetadata

public void setSpaceMetadata(java.lang.String spaceId,
                             java.util.Map<java.lang.String,java.lang.String> spaceMetadata)
Sets the metadata associated with a space.

Parameters:
spaceId - - ID of the space
spaceMetadata - - Updated space metadata

addContent

public java.lang.String addContent(java.lang.String spaceId,
                                   java.lang.String contentId,
                                   java.lang.String contentMimeType,
                                   long contentSize,
                                   java.lang.String contentChecksum,
                                   java.io.InputStream content)
Adds content to a space. Computes the checksum of the provided content and checks this against the checksum of the uploaded content to protect against loss or corruption during transfer.

Parameters:
spaceId - - ID of the space
contentId - - ID of the content in the space
contentMimeType - - the MIME type of the content being added
contentSize - - the file size (in bytes) of the content being added
contentChecksum - - the MD5 checksum of the content being added (null if no checksum is known)
content - - content to add
Returns:
The checksum of the provided content

getContent

public java.io.InputStream getContent(java.lang.String spaceId,
                                      java.lang.String contentId)
Gets content from a space.

Parameters:
spaceId - - ID of the space
contentId - - ID of the content in the space
Returns:
the content stream

deleteContent

public void deleteContent(java.lang.String spaceId,
                          java.lang.String contentId)
Removes content from a space.

Parameters:
spaceId - - ID of the space
contentId - - ID of the content in the space

setContentMetadata

public void setContentMetadata(java.lang.String spaceId,
                               java.lang.String contentId,
                               java.util.Map<java.lang.String,java.lang.String> contentMetadata)
Sets the metadata associated with content. This effectively removes all of the current content metadata and adds a new set of metadata. Some metadata, such as system metadata provided by the underlying storage system, cannot be updated or removed. Some of the values which cannot be updated or removed: Content-MD5 ETag Last-Modified Content-Type cannot be removed, but it can be updated

Parameters:
spaceId - - ID of the space
contentId - - ID of the content in the space
contentMetadata - - new content metadata

getContentMetadata

public java.util.Map<java.lang.String,java.lang.String> getContentMetadata(java.lang.String spaceId,
                                                                           java.lang.String contentId)
Retrieves the metadata associated with content. This includes both metadata generated by the underlying storage system as well as custom metadata. Use the METADATA_CONTENT_* constants to retrieve standard metadata values.

Parameters:
spaceId - - ID of the space
contentId - - ID of the content in the space
Returns:
content metadata

getETagValue

protected java.lang.String getETagValue(java.lang.String etag)

getBucketName

public java.lang.String getBucketName(java.lang.String spaceId)
Converts a DuraCloud spaceId into its corresponding Amazon S3 bucket name

Parameters:
spaceId - the space Id to convert into an S3 bucket name
Returns:
S3 bucket name of a given DuraCloud space

getSpaceId

protected java.lang.String getSpaceId(java.lang.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(java.lang.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


Copyright © 2009-2011 DuraSpace. All Rights Reserved.