Package org.dspace.storage.bitstore
Class S3BitStoreService
- java.lang.Object
-
- org.dspace.storage.bitstore.BaseBitStoreService
-
- org.dspace.storage.bitstore.S3BitStoreService
-
- All Implemented Interfaces:
BitStoreService
public class S3BitStoreService extends BaseBitStoreService
Asset store using Amazon's Simple Storage Service (S3). S3 is a commercial, web-service accessible, remote storage facility. NB: you must have obtained an account with Amazon to use this store- Author:
- Richard Rodgers, Peter Dietz, Vincenzo Mecca (vins01-4science - vincenzo.mecca at 4science.com)
-
-
Field Summary
Fields Modifier and Type Field Description protected static StringDEFAULT_BUCKET_PREFIXprotected static intdigitsPerLevelprotected static intdirectoryLevelsprotected StringREGISTERED_FLAG-
Fields inherited from class org.dspace.storage.bitstore.BaseBitStoreService
CHECKSUM, CHECKSUM_ALGORITHM, initialized, MODIFIED, SIZE_BYTES
-
-
Constructor Summary
Constructors Modifier Constructor Description S3BitStoreService()protectedS3BitStoreService(com.amazonaws.services.s3.AmazonS3 s3Service)This constructor is used for test purpose.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Map<String,Object>about(Bitstream bitstream, List<String> attrs)Obtain technical metadata about an asset in the asset store.protected static Supplier<com.amazonaws.services.s3.AmazonS3>amazonClientBuilderBy(@NotNull com.amazonaws.regions.Regions regions, @NotNull com.amazonaws.auth.AWSCredentials awsCredentials)Utility method for generate AmazonS3 builderStringgenerateId()Return an identifier unique to this asset store instanceInputStreamget(Bitstream bitstream)Retrieve the bits for the asset with ID.StringgetAwsAccessKey()StringgetAwsRegionName()StringgetAwsSecretKey()StringgetBucketName()StringgetFullKey(String id)Utility Method: Prefix the key with a subfolder, if this instance assets are stored within subfolderStringgetRelativePath(String sInternalId)there are 2 cases: - conventional bitstream, conventional storage - registered bitstream, conventional storage conventional bitstream: dspace ingested, dspace random name/path registered bitstream: registered to dspace, any name/pathStringgetSubfolder()voidinit()Initialize the asset store S3 Requires: - access key - secret key - bucket namebooleanisEnabled()Determines if a store is enabled, by default is enabledbooleanisRegisteredBitstream(String internalId)Is this a registered bitstream? (not stored via this service originally)booleanisUseRelativePath()static voidmain(String[] args)Contains a command-line testing tool.voidput(Bitstream bitstream, InputStream in)Store a stream of bits.voidremove(Bitstream bitstream)Remove an asset from the asset store.voidsetAwsAccessKey(String awsAccessKey)voidsetAwsRegionName(String awsRegionName)voidsetAwsSecretKey(String awsSecretKey)voidsetBucketName(String bucketName)voidsetEnabled(boolean enabled)voidsetSubfolder(String subfolder)voidsetUseRelativePath(boolean useRelativePath)-
Methods inherited from class org.dspace.storage.bitstore.BaseBitStoreService
about, appendSeparator, endsWithSeparator, extractSubstringFrom, getIntermediatePath, isInitialized, isLonger, populatePathSplittingId, putValueIfExistsKey, sanitizeIdentifier
-
-
-
-
Field Detail
-
DEFAULT_BUCKET_PREFIX
protected static final String DEFAULT_BUCKET_PREFIX
- See Also:
- Constant Field Values
-
REGISTERED_FLAG
protected final String REGISTERED_FLAG
- See Also:
- Constant Field Values
-
digitsPerLevel
protected static final int digitsPerLevel
- See Also:
- Constant Field Values
-
directoryLevels
protected static final int directoryLevels
- See Also:
- Constant Field Values
-
-
Method Detail
-
amazonClientBuilderBy
protected static Supplier<com.amazonaws.services.s3.AmazonS3> amazonClientBuilderBy(@NotNull @NotNull com.amazonaws.regions.Regions regions, @NotNull @NotNull com.amazonaws.auth.AWSCredentials awsCredentials)
Utility method for generate AmazonS3 builder- Parameters:
regions- wanted regions in clientawsCredentials- credentials of the client- Returns:
- builder with the specified parameters
-
isEnabled
public boolean isEnabled()
Description copied from interface:BitStoreServiceDetermines if a store is enabled, by default is enabled- Returns:
booleantrue if enabled, false otherwise
-
init
public void init() throws IOExceptionInitialize the asset store S3 Requires: - access key - secret key - bucket name- Throws:
IOException- A general class of exceptions produced by failed or interrupted I/O operations.
-
generateId
public String generateId()
Return an identifier unique to this asset store instance- Returns:
- a unique ID
-
get
public InputStream get(Bitstream bitstream) throws IOException
Retrieve the bits for the asset with ID. If the asset does not exist, returns null.- Parameters:
bitstream- The ID of the asset to retrieve- Returns:
- The stream of bits, or null
- Throws:
IOException- If a problem occurs while retrieving the bits
-
put
public void put(Bitstream bitstream, InputStream in) throws IOException
Store a stream of bits.If this method returns successfully, the bits have been stored. If an exception is thrown, the bits have not been stored.
- Parameters:
in- The stream of bits to storebitstream- The bitstream object- Throws:
IOException- If a problem occurs while storing the bits
-
about
public Map<String,Object> about(Bitstream bitstream, List<String> attrs) throws IOException
Obtain technical metadata about an asset in the asset store. Checksum used is (ETag) hex encoded 128-bit MD5 digest of an object's content as calculated by Amazon S3 (Does not use getContentMD5, as that is 128-bit MD5 digest calculated on caller's side)- Parameters:
bitstream- The asset to describeattrs- A List of desired metadata fields- Returns:
- attrs A Map with key/value pairs of desired metadata If file not found, then return null
- Throws:
IOException- If a problem occurs while obtaining metadata
-
remove
public void remove(Bitstream bitstream) throws IOException
Remove an asset from the asset store. An irreversible operation.- Parameters:
bitstream- The asset to delete- Throws:
IOException- If a problem occurs while removing the asset
-
getFullKey
public String getFullKey(String id)
Utility Method: Prefix the key with a subfolder, if this instance assets are stored within subfolder- Parameters:
id- DSpace bitstream internal ID- Returns:
- full key prefixed with a subfolder, if applicable
-
getRelativePath
public String getRelativePath(String sInternalId)
there are 2 cases: - conventional bitstream, conventional storage - registered bitstream, conventional storage conventional bitstream: dspace ingested, dspace random name/path registered bitstream: registered to dspace, any name/path- Parameters:
sInternalId-- Returns:
- Computed Relative path
-
setEnabled
public void setEnabled(boolean enabled)
-
getAwsAccessKey
public String getAwsAccessKey()
-
setAwsAccessKey
@Autowired(required=true) public void setAwsAccessKey(String awsAccessKey)
-
getAwsSecretKey
public String getAwsSecretKey()
-
setAwsSecretKey
@Autowired(required=true) public void setAwsSecretKey(String awsSecretKey)
-
getAwsRegionName
public String getAwsRegionName()
-
setAwsRegionName
public void setAwsRegionName(String awsRegionName)
-
getBucketName
@Autowired(required=true) public String getBucketName()
-
setBucketName
public void setBucketName(String bucketName)
-
getSubfolder
public String getSubfolder()
-
setSubfolder
public void setSubfolder(String subfolder)
-
isUseRelativePath
public boolean isUseRelativePath()
-
setUseRelativePath
public void setUseRelativePath(boolean useRelativePath)
-
main
public static void main(String[] args) throws Exception
Contains a command-line testing tool. Expects arguments: -a accessKey -s secretKey -f assetFileName- Parameters:
args- the command line arguments given- Throws:
Exception- generic exception
-
isRegisteredBitstream
public boolean isRegisteredBitstream(String internalId)
Is this a registered bitstream? (not stored via this service originally)- Parameters:
internalId-- Returns:
-
-