Class AwsS3DistributionServiceImpl
java.lang.Object
org.opencastproject.job.api.AbstractJobProducer
org.opencastproject.distribution.api.AbstractDistributionService
org.opencastproject.distribution.aws.s3.AwsS3DistributionServiceImpl
- All Implemented Interfaces:
DistributionService,DownloadDistributionService,AwsS3DistributionService,JobProducer
public class AwsS3DistributionServiceImpl
extends AbstractDistributionService
implements AwsS3DistributionService, DistributionService
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumList of available operations on jobs -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final intstatic final floatThe load on the system introduced by creating a distribute jobstatic final intstatic final intstatic final Stringstatic final intDefault expiration time for presigned URL in millis, 6 hoursstatic final floatThe load on the system introduced by creating a retract jobstatic final Stringstatic final Stringstatic final StringJob typestatic final Stringstatic final StringFields inherited from class org.opencastproject.distribution.api.AbstractDistributionService
distributionChannel, distributionDirectory, organizationDirectoryService, securityService, serviceRegistry, serviceUrl, trustedHttpClient, userDirectoryService, workspaceFields inherited from class org.opencastproject.job.api.AbstractJobProducer
ACCEPT_JOB_LOADS_EXCEEDING_PROPERTY, acceptJobLoadsExeedingMaxLoad, DEFAULT_ACCEPT_JOB_LOADS_EXCEEDING, executor, jobTypeFields inherited from interface org.opencastproject.distribution.api.DistributionService
CONFIG_KEY_STORE_TYPE, JOB_TYPE_PREFIX -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new instance of the AWS S3 distribution service. -
Method Summary
Modifier and TypeMethodDescriptionvoidactivate(org.osgi.service.component.ComponentContext cc) OSGI activate method.protected StringBuilds the aws s3 object name using the raw elementID and filenameprotected StringbuildObjectName(String channelId, String mpId, MediaPackageElement element) Builds the aws s3 object name.protected voidCreates the AWS S3 bucket if it doesn't exist yet.voiddistribute(String channelId, MediaPackage mediapackage, String elementId) Distribute a media package element.distribute(String channelId, MediaPackage mediaPackage, String elementId, boolean checkAvailability) distribute(String channelId, MediaPackage mediaPackage, Set<String> elementIds, boolean checkAvailability) distribute(String pubChannelId, MediaPackage mediaPackage, Set<String> downloadIds, boolean checkAvailability, boolean preserveReference) distributeElement(String channelId, MediaPackage mediaPackage, MediaPackageElement element, boolean checkAvailability) Distribute a media package element to AWS S3.distributeElements(String channelId, MediaPackage mediapackage, Set<String> elementIds, boolean checkAvailability) Distribute Mediapackage elements to the download distribution service.distributeSync(String channelId, MediaPackage mediapackage, String elementId) Distributes a media package element synchronously, bypassing the Opencast job system.distributeSync(String channelId, MediaPackage mediapackage, Set<String> elementIds, boolean checkAvailability) Distributes the given elements synchronously.protected StringGets the distributed object's name.Returns the distribution type for this service.protected URIgetDistributionUri(String objectName) Gets the URI for the element to be distributed.presignedURI(URI uri) protected StringAsks the overriding class to process the arguments using the given operation.retract(String channelId, MediaPackage mediapackage, String elementId) Retract a media package element from the distribution channel.retract(String channelId, MediaPackage mediapackage, Set<String> elementIds) protected MediaPackageElementretractElement(String channelId, MediaPackage mediaPackage, MediaPackageElement element) Retracts the media package element with the given identifier from the distribution channel.protected MediaPackageElement[]retractElements(String channelId, MediaPackage mediapackage, Set<String> elementIds) Retract a media package element from the distribution channel.retractSync(String channelId, MediaPackage mediapackage, String elementId) Retract a media package element from the distribution channel synchronously, bypassing the Opencast job system.retractSync(String channelId, MediaPackage mediaPackage, Set<String> elementIds) Retracts the given elements synchronously.protected voidsetBucketName(String orgId, String bucketName) protected voidsetOpencastDistributionUrl(String distributionUrl) voidsetOrganizationDirectoryService(OrganizationDirectoryService organizationDirectoryService) Sets a reference to the organization directory service.protected voidsetS3(com.amazonaws.services.s3.AmazonS3 s3) The methods below are used by the test classprotected voidsetS3TransferManager(com.amazonaws.services.s3.transfer.TransferManager s3TransferManager) voidsetSecurityService(SecurityService securityService) Callback for setting the security service.voidsetServiceRegistry(ServiceRegistry serviceRegistry) Callback for the OSGi environment to set the service registry reference.protected voidsetStorageTmp(String path) voidsetUserDirectoryService(UserDirectoryService userDirectoryService) Callback for setting the user directory service.voidsetWorkspace(Workspace workspace) Callback for the OSGi environment to set the workspace reference.Methods inherited from class org.opencastproject.distribution.api.AbstractDistributionService
getOrganizationDirectoryService, getSecurityService, getServiceRegistry, getTrustedHttpClient, getUserDirectoryService, setTrustedHttpClientMethods inherited from class org.opencastproject.job.api.AbstractJobProducer
acceptJob, countJobs, finallyUpdateJob, getJobType, incident, isReadyToAccept, isReadyToAcceptJobs
-
Field Details
-
JOB_TYPE
Job type- See Also:
-
AWS_S3_DISTRIBUTION_ENABLE
- See Also:
-
AWS_S3_DISTRIBUTION_BASE_CONFIG
- See Also:
-
AWS_S3_ACCESS_KEY_ID_CONFIG
- See Also:
-
AWS_S3_SECRET_ACCESS_KEY_CONFIG
- See Also:
-
AWS_S3_REGION_CONFIG
- See Also:
-
AWS_S3_BUCKET_CONFIG
- See Also:
-
AWS_S3_BUCKET_CONFIG_PREFIX
- See Also:
-
AWS_S3_ENDPOINT_CONFIG
- See Also:
-
AWS_S3_PATH_STYLE_CONFIG
- See Also:
-
AWS_S3_PRESIGNED_URL_CONFIG
- See Also:
-
AWS_S3_PRESIGNED_URL_VALID_DURATION_CONFIG
- See Also:
-
AWS_S3_MAX_CONNECTIONS
- See Also:
-
AWS_S3_CONNECTION_TIMEOUT
- See Also:
-
AWS_S3_MAX_RETRIES
- See Also:
-
DISTRIBUTE_JOB_LOAD_KEY
- See Also:
-
RETRACT_JOB_LOAD_KEY
- See Also:
-
OPENCAST_STORAGE_DIR
- See Also:
-
DEFAULT_TEMP_DIR
- See Also:
-
DEFAULT_MAX_CONNECTIONS
public static final int DEFAULT_MAX_CONNECTIONS- See Also:
-
DEFAULT_CONNECTION_TIMEOUT
public static final int DEFAULT_CONNECTION_TIMEOUT- See Also:
-
DEFAULT_MAX_RETRIES
public static final int DEFAULT_MAX_RETRIES- See Also:
-
DEFAULT_DISTRIBUTE_JOB_LOAD
public static final float DEFAULT_DISTRIBUTE_JOB_LOADThe load on the system introduced by creating a distribute job- See Also:
-
DEFAULT_RETRACT_JOB_LOAD
public static final float DEFAULT_RETRACT_JOB_LOADThe load on the system introduced by creating a retract job- See Also:
-
DEFAULT_PRESIGNED_URL_EXPIRE_MILLIS
public static final int DEFAULT_PRESIGNED_URL_EXPIRE_MILLISDefault expiration time for presigned URL in millis, 6 hours- See Also:
-
DEFAULT_ORG_KEY
- See Also:
-
-
Constructor Details
-
AwsS3DistributionServiceImpl
public AwsS3DistributionServiceImpl()Creates a new instance of the AWS S3 distribution service.
-
-
Method Details
-
activate
public void activate(org.osgi.service.component.ComponentContext cc) Description copied from class:AbstractJobProducerOSGI activate method.- Overrides:
activatein classAbstractJobProducer- Parameters:
cc- OSGI component context
-
getDistributionType
Description copied from interface:DistributionServiceReturns the distribution type for this service. This type should be unique within an Opencast instance, and is used to select where file distribution happens.- Specified by:
getDistributionTypein interfaceDistributionService- Returns:
- The distribution type. A string like "download", or "streaming"
-
deactivate
public void deactivate() -
distribute
public Job distribute(String pubChannelId, MediaPackage mediaPackage, Set<String> downloadIds, boolean checkAvailability, boolean preserveReference) throws DistributionException, MediaPackageException - Specified by:
distributein interfaceDownloadDistributionService- Throws:
DistributionExceptionMediaPackageException
-
distribute
public Job distribute(String channelId, MediaPackage mediaPackage, Set<String> elementIds, boolean checkAvailability) throws DistributionException, MediaPackageException - Specified by:
distributein interfaceDownloadDistributionService- Throws:
DistributionExceptionMediaPackageException- See Also:
-
distribute
public Job distribute(String channelId, MediaPackage mediapackage, String elementId) throws DistributionException, MediaPackageException Distribute a media package element.- Specified by:
distributein interfaceDistributionService- Parameters:
mediapackage- the media packageelementId- the element in the media package to distribute- Returns:
- The job
- Throws:
DistributionException- if there was a problem distributing the mediaMediaPackageException- if there was a problem with the mediapackage element- See Also:
-
distribute
public Job distribute(String channelId, MediaPackage mediaPackage, String elementId, boolean checkAvailability) throws DistributionException, MediaPackageException - Specified by:
distributein interfaceDownloadDistributionService- Throws:
DistributionExceptionMediaPackageException- See Also:
-
distributeElements
public MediaPackageElement[] distributeElements(String channelId, MediaPackage mediapackage, Set<String> elementIds, boolean checkAvailability) throws DistributionException Distribute Mediapackage elements to the download distribution service.- Parameters:
channelId- # The id of the publication channel to be distributed to.mediapackage- The media package that contains the elements to be distributed.elementIds- The ids of the elements that should be distributed contained within the media package.checkAvailability- Check the availability of the distributed element via http.- Returns:
- A reference to the MediaPackageElements that have been distributed.
- Throws:
DistributionException- Thrown if the parent directory of the MediaPackageElement cannot be created, if the MediaPackageElement cannot be copied or another unexpected exception occurs.
-
distributeElement
public MediaPackageElement distributeElement(String channelId, MediaPackage mediaPackage, MediaPackageElement element, boolean checkAvailability) throws DistributionException Distribute a media package element to AWS S3.- Parameters:
mediaPackage- The media package that contains the element to distribute.element- The element that should be distributed contained within the media package.checkAvailability- Checks if the distributed element is available- Returns:
- A reference to the MediaPackageElement that has been distributed.
- Throws:
DistributionException
-
retract
public Job retract(String channelId, MediaPackage mediapackage, String elementId) throws DistributionException Description copied from interface:DistributionServiceRetract a media package element from the distribution channel.- Specified by:
retractin interfaceDistributionService- Parameters:
mediapackage- the media packageelementId- the media package element to retract- Throws:
DistributionException- if there was a problem retracting the mediapackage
-
retract
public Job retract(String channelId, MediaPackage mediapackage, Set<String> elementIds) throws DistributionException - Specified by:
retractin interfaceDownloadDistributionService- Throws:
DistributionException
-
distributeSync
public List<MediaPackageElement> distributeSync(String channelId, MediaPackage mediapackage, String elementId) throws DistributionException, MediaPackageException Description copied from interface:DistributionServiceDistributes a media package element synchronously, bypassing the Opencast job system.- Specified by:
distributeSyncin interfaceDistributionService- Parameters:
mediapackage- the media packageelementId- the element in the media package to distribute- Returns:
- list of distributed media package elements
- Throws:
DistributionException- if there was a problem distributing the mediaMediaPackageException- if there was a problem with the mediapackage element
-
distributeSync
public List<MediaPackageElement> distributeSync(String channelId, MediaPackage mediapackage, Set<String> elementIds, boolean checkAvailability) throws DistributionException Description copied from interface:DownloadDistributionServiceDistributes the given elements synchronously. This should be used rarely since load balancing will be unavailable. However, since the dispatching logic is bypassed, synchronous execution is much faster. It is useful in interactive scenarios where you synchronously wait for job execution anyway and you don't want to make the user waiting for too long.- Specified by:
distributeSyncin interfaceDownloadDistributionService- Parameters:
channelId- The channel to retract from.mediapackage- A media package holding the elements to retract.elementIds- The IDs of the elements to retract.checkAvailability- Whether to check if the distributed elements are available through their URI.- Returns:
- The distributed elements.
- Throws:
DistributionException- In case distribution fails.
-
retractSync
public List<MediaPackageElement> retractSync(String channelId, MediaPackage mediapackage, String elementId) throws DistributionException Description copied from interface:DistributionServiceRetract a media package element from the distribution channel synchronously, bypassing the Opencast job system.- Specified by:
retractSyncin interfaceDistributionService- Parameters:
mediapackage- the media packageelementId- the media package element to retract- Returns:
- list of retracted media package elements
- Throws:
DistributionException- if there was a problem retracting the mediapackage
-
retractSync
public List<MediaPackageElement> retractSync(String channelId, MediaPackage mediaPackage, Set<String> elementIds) throws DistributionException Description copied from interface:DownloadDistributionServiceRetracts the given elements synchronously. This should be used rarely since load balancing will be unavailable. However, since the dispatching logic is bypassed, synchronous execution is much faster. It is useful in interactive scenarios where you synchronously wait for job execution anyway and you don't want to make the user waiting for too long.- Specified by:
retractSyncin interfaceDownloadDistributionService- Parameters:
channelId- The channel to retract from.mediaPackage- A media package holding the elements to retract.elementIds- The IDs of the elements to retract.- Returns:
- The retracted elements.
- Throws:
DistributionException- In case retraction fails.
-
retractElement
protected MediaPackageElement retractElement(String channelId, MediaPackage mediaPackage, MediaPackageElement element) throws DistributionException Retracts the media package element with the given identifier from the distribution channel.- Parameters:
channelId- the channel idmediaPackage- the media packageelement- the element- Returns:
- the retracted element or
nullif the element was not retracted - Throws:
DistributionException
-
retractElements
protected MediaPackageElement[] retractElements(String channelId, MediaPackage mediapackage, Set<String> elementIds) throws DistributionException Retract a media package element from the distribution channel. The retracted element must not necessarily be the one given as parameterelementId. Instead, the element's distribution URI will be calculated. This way you are able to retract elements by providing the "original" element here.- Parameters:
channelId- the channel idmediapackage- the mediapackageelementIds- the element identifiers- Returns:
- the retracted element or
nullif the element was not retracted - Throws:
DistributionException- in case of an error
-
buildObjectName
Builds the aws s3 object name.- Parameters:
channelId-mpId-element-- Returns:
-
buildObjectName
protected String buildObjectName(String orgId, String channelId, String mpId, String elementId, String fileName) Builds the aws s3 object name using the raw elementID and filename- Parameters:
orgId-channelId-mpId-elementId-fileName-- Returns:
-
getDistributionUri
Gets the URI for the element to be distributed.- Returns:
- The resulting URI after distribution
- Throws:
URISyntaxException- if the concrete implementation tries to create a malformed uri
-
getDistributedObjectName
Gets the distributed object's name.- Returns:
- The distributed object name
-
process
Asks the overriding class to process the arguments using the given operation. The result will be added to the associated job as the payload.- Specified by:
processin classAbstractJobProducer- Parameters:
job- the job to process- Returns:
- the operation result
- Throws:
Exception- See Also:
-
createAWSBucket
protected void createAWSBucket()Creates the AWS S3 bucket if it doesn't exist yet. -
presignedURI
- Throws:
URISyntaxException
-
setS3
protected void setS3(com.amazonaws.services.s3.AmazonS3 s3) The methods below are used by the test class -
setS3TransferManager
protected void setS3TransferManager(com.amazonaws.services.s3.transfer.TransferManager s3TransferManager) -
setBucketName
-
setOpencastDistributionUrl
-
setStorageTmp
-
setWorkspace
Description copied from class:AbstractDistributionServiceCallback for the OSGi environment to set the workspace reference.- Overrides:
setWorkspacein classAbstractDistributionService- Parameters:
workspace- the workspace
-
setServiceRegistry
Description copied from class:AbstractDistributionServiceCallback for the OSGi environment to set the service registry reference.- Overrides:
setServiceRegistryin classAbstractDistributionService- Parameters:
serviceRegistry- the service registry
-
setSecurityService
Description copied from class:AbstractDistributionServiceCallback for setting the security service.- Overrides:
setSecurityServicein classAbstractDistributionService- Parameters:
securityService- the securityService to set
-
setUserDirectoryService
Description copied from class:AbstractDistributionServiceCallback for setting the user directory service.- Overrides:
setUserDirectoryServicein classAbstractDistributionService- Parameters:
userDirectoryService- the userDirectoryService to set
-
setOrganizationDirectoryService
public void setOrganizationDirectoryService(OrganizationDirectoryService organizationDirectoryService) Description copied from class:AbstractDistributionServiceSets a reference to the organization directory service.- Overrides:
setOrganizationDirectoryServicein classAbstractDistributionService- Parameters:
organizationDirectoryService- the organization directory
-