Ejemplo n.º 1
0
 def is_valid(self, raise_exception):
     if not super(TransformTask, self).is_valid(raise_exception):
         return False
     if (hasattr(self, u'user') and self.user is not None and
         (not isinstance(self.user, User) or not self.user.is_valid(False))):
         self._E(raise_exception, u'user is not a valid instance of user')
     # Remark: An integer is also considered as a valid user id to simplify the integration with EBU-io
     if hasattr(self, u'user_id') and not (valid_uuid(self.user_id, none_allowed=False) or valid_int(self.user_id)):
         self._E(raise_exception, u'user_id is not a valid uuid string neither a valid integer')
     if (hasattr(self, u'media_in') and self.media_in is not None and
         (not isinstance(self.media_in, Media) or not self.media_in.is_valid(False))):
         self._E(raise_exception, u'media_in is not a valid instance of media')
     if hasattr(self, u'media_in_id') and not valid_uuid(self.media_in_id, none_allowed=False):
         self._E(raise_exception, u'media_in_id is not a valid uuid string')
     if (hasattr(self, u'media_out') and self.media_out is not None and
         (not isinstance(self.media_out, Media) or not self.media_out.is_valid(False))):
         self._E(raise_exception, u'media_out is not a valid instance of media')
     if hasattr(self, u'media_out_id') and not valid_uuid(self.media_out_id, none_allowed=False):
         self._E(raise_exception, u'media_out_id is not a valid uuid string')
     if (hasattr(self, u'profile') and self.profile is not None and
         (not isinstance(self.profile, TransformProfile) or not self.profile.is_valid(False))):
         self._E(raise_exception, u'profile is not a valid instance of transformation profile')
     if hasattr(self, u'profile_id') and not valid_uuid(self.profile_id, none_allowed=False):
         self._E(raise_exception, u'profile_id is not a valid uuid string')
     # FIXME check send_email
     return True
Ejemplo n.º 2
0
 def revoke_publisher_task(self, task, callback_url, terminate=False, remove=False):
     u"""
     This do not delete tasks from tasks database (if remove=False) but set revoked attribute in tasks database and
     broadcast revoke request to publication units with celery.
     If the task is actually running it will be cancelled if terminated = True.
     In any case, the output media asset will be deleted (task running or successfully finished).
     """
     if valid_uuid(task, none_allowed=False):
         task = self.get_publisher_task({u'_id': task})
     task.is_valid(True)
     if task.status in PublisherTask.CANCELED_STATUS:
         raise ValueError(to_bytes(u'Cannot revoke a publication task with status {0}.'.format(task.status)))
     if not self.config.is_mock:
         revoke(task._id, terminate=terminate)
     if task.status == PublisherTask.SUCCESS and not self.config.is_mock:
         # Send revoke task to the worker that published the media
         callback = Callback(self.config.api_url + callback_url, u'node', self.config.node_secret)
         queue = task.get_hostname()
         result = PublisherWorker.revoke_publisher_task.apply_async(
             args=(task.publish_uri, object2json(callback, False)), queue=queue)
         if not result.id:
             raise ValueError(to_bytes(u'Unable to transmit task to queue {0}.'.format(queue)))
         logging.info(u'New revoke publication task {0} -> queue {1}.'.format(result.id, queue))
         self.update_publisher_task_and_media(task, revoke_task_id=result.id, status=PublisherTask.REVOKING)
     else:
         self.update_publisher_task_and_media(task, status=PublisherTask.REVOKED)
     if remove:
         self._db.publisher_tasks.remove({u'_id': task._id})
Ejemplo n.º 3
0
 def is_valid(self, raise_exception):
     if not super(PublisherTask, self).is_valid(raise_exception):
         return False
     if (hasattr(self, u'user') and self.user is not None and
         (not isinstance(self.user, User) or not self.user.is_valid(False))):
         self._E(raise_exception, u'user is not a valid instance of user')
     # Remark: An integer is also considered as a valid user id to simplify the integration with EBU-io
     if hasattr(self, u'user_id') and not (valid_uuid(self.user_id, none_allowed=False) or valid_int(self.user_id)):
         self._E(raise_exception, u'user_id is not a valid uuid string neither a valid integer')
     if (hasattr(self, u'media') and self.media is not None and
         (not isinstance(self.media, Media) or not self.media.is_valid(False))):
         self._E(raise_exception, u'media is not a valid instance of media')
     if hasattr(self, u'media_id') and not valid_uuid(self.media_id, none_allowed=False):
         self._E(raise_exception, u'media_id is not a valid uuid string')
     # FIXME check publish_uri
     if not valid_uuid(self.revoke_task_id, none_allowed=True):
         self._E(raise_exception, u'revoke_task_id is not a valid uuid string')
     # FIXME check send_email
     return True
Ejemplo n.º 4
0
 def delete_user(self, user):
     self.only_standalone()
     # FIXME issue #16 (https://github.com/ebu/OSCIED/issues/16)
     # entity = self.get_user({'_id': user_id}, {'secret': 0})
     # if not entity:
     #     raise IndexError(to_bytes(u'No user with id {0}.'.format(id)))
     # self._db.users.remove({'_id': entity._id})
     # return dict2object(User, entity, inspect_constructor=True)
     if valid_uuid(user, none_allowed=False):
         user = self.get_user({u'_id': user}, {u'secret': 0})
     user.is_valid(True)
     self._db.users.remove({u'_id': user._id})
Ejemplo n.º 5
0
 def is_valid(self, raise_exception):
     if not super(Media, self).is_valid(raise_exception):
         return False
     # FIXME check user XOR user_id ...
     if (hasattr(self, u'user') and self.user is not None and
         (not isinstance(self.user, User) or not self.user.is_valid(False))):
         self._E(raise_exception, u'user is not a valid instance of user')
     # Remark: An integer is also considered as a valid user id to simplify the integration with EBU-io
     if hasattr(self, u'user_id') and not (valid_uuid(self.user_id, none_allowed=False) or valid_int(self.user_id)):
         self._E(raise_exception, u'user_id is not a valid uuid string neither a valid integer')
     if (hasattr(self, u'parent') and self.parent is not None and
         (not isinstance(self.parent, Media) or not self.parent.is_valid(False))):
         self._E(raise_exception, u'parent is not a valid instance of media')
     if hasattr(self, u'parent_id') and not valid_uuid(self.parent_id, none_allowed=True):
         self._E(raise_exception, u'parent_id is not a valid uuid string')
     # FIXME check uri
     # FIXME check public_uris
     if not valid_filename(self.filename):
         self._E(raise_exception, u'filename is not a valid file-name')
     # FIXME check metadata
     if not self.status in Media.ALL_STATUS:
         self._E(raise_exception, u'status is not in {0}'.format(Media.ALL_STATUS))
     return True
Ejemplo n.º 6
0
 def revoke_transform_task(self, task, terminate=False, remove=False, delete_media=False):
     u"""
     This do not delete tasks from tasks database (if remove=False) but set revoked attribute in tasks database and
     broadcast revoke request to transformation units with Celery. If the task is actually running it will be
     cancelled if terminated = True. The output media will be deleted if corresponding argument, delete_media = True.
     """
     # FIXME verify that no pending tasks needs the media that will be created by the task !
     if valid_uuid(task, none_allowed=False):
         task = self.get_transform_task({u'_id': task})
     task.is_valid(True)
     if task.status == TransformTask.CANCELED_STATUS:
         raise ValueError(to_bytes(u'Transformation task {0} is already revoked !'.format(task._id)))
     if task.status in TransformTask.FINAL_STATUS:
         raise ValueError(to_bytes(u'Cannot revoke a transformation task with status {0}.'.format(task.status)))
     task.status = TransformTask.REVOKED
     if self.config.is_mock:
         pass  # FIXME TODO
     else:
         revoke(task._id, terminate=terminate)
     self._db.transform_tasks.save(task.__dict__, safe=True)
     if delete_media and valid_uuid(task.media_out_id, none_allowed=False):
         self.delete_media(task.media_out_id)
     if remove:
         self._db.transform_tasks.remove({u'_id': task._id})
Ejemplo n.º 7
0
 def delete_media(self, media):
     if valid_uuid(media, none_allowed=False):
         media = self.get_media({u'_id': media})
     media.is_valid(True)
     task = self.get_transform_task({u'media_in_id': media._id}, append_result=True)
     if task and task.status in TransformTask.WORK_IN_PROGRESS_STATUS:
         raise ValueError(to_bytes(u'Cannot delete the media asset, it is actually in use by transformation task wit'
                          'h id {0} and status {1}.'.format(task._id, task.status)))
     task = self.get_publisher_task({u'media_id': media._id}, append_result=True)
     if task and task.status in TransformTask.WORK_IN_PROGRESS_STATUS:
         raise ValueError(to_bytes(u'Cannot delete the media asset, it is actually in use by publication task with i'
                          'd {0} and status {1}.'.format(task._id, task.status)))
     media.status = Media.DELETED
     self.save_media(media)
     #self._db.medias.remove({'_id': media._id})
     Storage.delete_media(self.config, media)
Ejemplo n.º 8
0
 def is_valid(self, raise_exception):
     u"""
     >>> p = TransformProfile(title=u'test', encoder_name=u'ffmpeg')
     >>> assert(p.dash_options is None and p.dash_config is None)
     >>> p.encoder_name = u'dashcast'
     >>> p.encoder_string = u'--seg-dur 1000 --frag-dur 200 / [v1] type=video width=960 height=540 bitrate=1536000 [v2] type=video width=640 height=360 bitrate=819200 [v3] type=video width=480 height=270 bitrate=512000 [v4] type=video width=160 height=90 bitrate=256000 [a1] type=audio bitrate=98304'
     >>> print(p.dash_options)
     --seg-dur 1000 --frag-dur 200
     >>> print(p.dash_config)
     [v1]
     type=video
     width=960
     height=540
     bitrate=1536000
     [v2]
     type=video
     width=640
     height=360
     bitrate=819200
     [v3]
     type=video
     width=480
     height=270
     bitrate=512000
     [v4]
     type=video
     width=160
     height=90
     bitrate=256000
     [a1]
     type=audio
     bitrate=98304
     """
     if not valid_uuid(self._id, none_allowed=False):
         self._E(raise_exception, u'_id is not a valid uuid string')
     if not self.title or not self.title.strip():
         self._E(raise_exception, u'title is required')
     if not self.description or not self.title.strip():
         self._E(raise_exception, u'description is required')
     if not self.encoder_name in ENCODERS_NAMES:
         self._E(raise_exception, u'encoder_name is not a valid encoder')
     return True
Ejemplo n.º 9
0
 def delete_transform_profile(self, profile):
     if valid_uuid(profile, none_allowed=False):
         profile = self.get_profile({u'_id': profile})
     profile.is_valid(True)
     self._db.transform_profiles.remove({u'_id': profile._id})