Package org.dspace.storage.bitstore
Class S3BitStoreService
java.lang.Object
org.dspace.storage.bitstore.BaseBitStoreService
org.dspace.storage.bitstore.S3BitStoreService
- All Implemented Interfaces:
BitStoreService
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)
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionclassThis inner class represent an InputStream that uses temporary files to represent chunk of the object downloaded from S3. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final Stringprotected static final intprotected static final intprotected final StringFields inherited from class org.dspace.storage.bitstore.BaseBitStoreService
CHECKSUM, CHECKSUM_ALGORITHM, initialized, MODIFIED, SIZE_BYTES -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedS3BitStoreService(com.amazonaws.services.s3.AmazonS3 s3Service) This constructor is used for test purpose. -
Method Summary
Modifier and TypeMethodDescriptionObtain 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 builderReturn an identifier unique to this asset store instanceRetrieve the bits for the asset with ID.getFullKey(String id) Utility Method: Prefix the key with a subfolder, if this instance assets are stored within subfoldergetRelativePath(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/pathvoidinit()Initialize the asset store S3 Requires: - access key - secret key - bucket namebooleanDetermines if a store is enabled, by default is enabledbooleanisRegisteredBitstream(String internalId) Is this a registered bitstream?booleanstatic voidContains a command-line testing tool.voidput(Bitstream bitstream, InputStream in) Store a stream of bits.voidRemove an asset from the asset store.voidsetAwsAccessKey(String awsAccessKey) voidsetAwsRegionName(String awsRegionName) voidsetAwsSecretKey(String awsSecretKey) voidsetBucketName(String bucketName) voidsetBufferSize(long bufferSize) 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 Details
-
DEFAULT_BUCKET_PREFIX
- See Also:
-
REGISTERED_FLAG
- See Also:
-
digitsPerLevel
protected static final int digitsPerLevel- See Also:
-
directoryLevels
protected static final int directoryLevels- See Also:
-
-
Constructor Details
-
S3BitStoreService
public S3BitStoreService() -
S3BitStoreService
protected S3BitStoreService(com.amazonaws.services.s3.AmazonS3 s3Service) This constructor is used for test purpose.- Parameters:
s3Service- AmazonS3 service
-
-
Method Details
-
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
Initialize 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
Return an identifier unique to this asset store instance- Returns:
- a unique ID
-
get
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
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
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
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
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
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
-
setAwsAccessKey
-
getAwsSecretKey
-
setAwsSecretKey
-
getAwsRegionName
-
setAwsRegionName
-
getBucketName
-
setBucketName
-
getSubfolder
-
setSubfolder
-
isUseRelativePath
public boolean isUseRelativePath() -
setUseRelativePath
public void setUseRelativePath(boolean useRelativePath) -
main
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
Is this a registered bitstream? (not stored via this service originally)- Parameters:
internalId-- Returns:
-
setBufferSize
public void setBufferSize(long bufferSize)
-