• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python event.EventListener类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中pulp.server.db.model.event.EventListener的典型用法代码示例。如果您正苦于以下问题:Python EventListener类的具体用法?Python EventListener怎么用?Python EventListener使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了EventListener类的19个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: get

    def get(self, event_listener_id):
        """
        Retrieves the given event listener if it exists. If not, an exception
        is raised.

        @param event_listener_id: listener to retrieve
        @type  event_listener_id: str

        @return: listener instance from the database
        @rtype:  dict

        @raise MissingResource: if no listener exists at the given ID
        """
        collection = EventListener.get_collection()

        try:
            id = ObjectId(event_listener_id)
        except InvalidId:
            raise MissingResource(event_listener=event_listener_id), None, sys.exc_info()[2]

        listener = collection.find_one({'_id' : id})

        if listener is None:
            raise MissingResource(event_listener=event_listener_id)
        else:
            return listener
开发者ID:AndreaGiardini,项目名称:pulp,代码行数:26,代码来源:crud.py


示例2: test_post

    def test_post(self):
        # Setup
        params = {
            'notifier_type_id' : http.TYPE_ID,
            'notifier_config' : {'a' : 'a'},
            'event_types' : [event_data.TYPE_REPO_SYNC_STARTED],
        }

        # Test
        status, body = self.post('/v2/events/', params)

        # Verify
        self.assertEqual(status, 201)
        self.assertEqual(body['notifier_type_id'], params['notifier_type_id'])
        self.assertEqual(body['notifier_config'], params['notifier_config'])
        self.assertEqual(body['event_types'], params['event_types'])

        db_listener = EventListener.get_collection().find_one({'id' : body['id']})
        self.assertTrue(db_listener is not None)
        self.assertEqual(db_listener['notifier_type_id'], params['notifier_type_id'])
        self.assertEqual(db_listener['notifier_config'], params['notifier_config'])
        self.assertEqual(db_listener['event_types'], params['event_types'])

        expected_href = '/v2/events/%s/' % body['id']
        self.assertEqual(body['_href'], expected_href)
开发者ID:AndreaGiardini,项目名称:pulp,代码行数:25,代码来源:test_event_controller.py


示例3: _do_fire

    def _do_fire(self, event):
        """
        Performs the actual act of firing an event to all appropriate
        listeners. This call will log but otherwise suppress any exception
        that comes out of a notifier.

        @param event: event object to fire
        @type  event: pulp.server.event.data.Event
        """
        # Determine which listeners should be notified
        listeners = list(
            EventListener.get_collection().find({"$or": ({"event_types": event.event_type}, {"event_types": "*"})})
        )

        # For each listener, retrieve the notifier and invoke it. Be sure that
        # an exception from a notifier is logged but does not interrupt the
        # remainder of the firing, nor bubble up.
        for l in listeners:
            notifier_type_id = l["notifier_type_id"]
            f = notifiers.get_notifier_function(notifier_type_id)

            try:
                f(l["notifier_config"], event)
            except Exception:
                _logger.exception("Exception from notifier of type [%s]" % notifier_type_id)
开发者ID:maxamillion,项目名称:pulp,代码行数:25,代码来源:fire.py


示例4: list

    def list(self):
        """
        Returns all event listeners.

        @return: list of event listener SON documents from the database; empty
                 list if there are none
        @rtype:  list
        """
        listeners = list(EventListener.get_collection().find())
        return listeners
开发者ID:AndreaGiardini,项目名称:pulp,代码行数:10,代码来源:crud.py


示例5: test_delete

    def test_delete(self):
        # Setup
        created = self.manager.create(http.TYPE_ID, {}, [event_data.TYPE_REPO_SYNC_STARTED])

        # Test
        self.manager.delete(created['_id'])

        # Verify
        all_event_listeners = list(EventListener.get_collection().find())
        self.assertEqual(0, len(all_event_listeners))
开发者ID:CUXIDUMDUM,项目名称:pulp,代码行数:10,代码来源:test_event_crud.py


示例6: test_create

    def test_create(self):
        # Test
        created = self.manager.create(http.TYPE_ID, None, [event_data.TYPE_REPO_SYNC_STARTED])

        # Verify
        self.assertEqual(created['notifier_type_id'], http.TYPE_ID)
        self.assertEqual(created['notifier_config'], {})
        self.assertEqual(created['event_types'], [event_data.TYPE_REPO_SYNC_STARTED])

        all_event_listeners = list(EventListener.get_collection().find())
        self.assertEqual(1, len(all_event_listeners))
开发者ID:CUXIDUMDUM,项目名称:pulp,代码行数:11,代码来源:test_event_crud.py


示例7: update

    def update(self, event_listener_id, notifier_config=None, event_types=None):
        """
        Changes the configuration of an existing event listener. The notifier
        type cannot be changed; in such cases the event listener should be
        deleted and a new one created.

        If specified, the notifier_config follows the given conventions:
        - If a key is specified with a value of None, the effect is that the
          key is removed from the configuration
        - If an existing key is unspecified, its value is unaffected

        Event types must be the *complete* list of event types to listen for.
        This method does not support deltas on the event types.

        @param event_listener_id: listener being edited
        @type  event_listener_id: str

        @param notifier_config: contains only configuration properties to change
        @type  notifier_config: dict

        @param event_types: complete list of event types that should be fired on
        @type  event_types: list

        @return: updated listener instance from the database
        """
        collection = EventListener.get_collection()

        # Validation
        existing = self.get(event_listener_id) # will raise MissingResource

        # Munge the existing configuration if it was specified
        if notifier_config is not None:
            munged_config = dict(existing['notifier_config'])

            remove_us = [k for k in notifier_config.keys() if notifier_config[k] is None]
            for k in remove_us:
                munged_config.pop(k, None)
                notifier_config.pop(k)

            munged_config.update(notifier_config)
            existing['notifier_config'] = munged_config

        # Update the event list
        if event_types is not None:
            _validate_event_types(event_types)
            existing['event_types'] = event_types

        # Update the database
        collection.save(existing, safe=True)

        # Reload to return
        existing = collection.find_one({'_id' : ObjectId(event_listener_id)})
        return existing
开发者ID:AndreaGiardini,项目名称:pulp,代码行数:53,代码来源:crud.py


示例8: test_delete

    def test_delete(self):
        # Setup
        manager = manager_factory.event_listener_manager()
        created = manager.create(http.TYPE_ID, {'a' : 'a'}, [event_data.TYPE_REPO_SYNC_STARTED])

        # Test
        status, body = self.delete('/v2/events/%s/' % created['id'])

        # Verify
        self.assertEqual(200, status)

        deleted = EventListener.get_collection().find_one({'_id' : ObjectId(created['_id'])})
        self.assertTrue(deleted is None)
开发者ID:AndreaGiardini,项目名称:pulp,代码行数:13,代码来源:test_event_controller.py


示例9: delete

    def delete(self, event_listener_id):
        """
        Deletes the event listener with the given ID. No exception is raised
        if no event listener exists at the given ID.

        @param event_listener_id: database ID for the event listener
        @type  event_listener_id: str

        @raise MissingResource: if no listener exists at the given ID
        """
        collection = EventListener.get_collection()

        self.get(event_listener_id) # check for MissingResource

        collection.remove({'_id' : ObjectId(event_listener_id)})
开发者ID:AndreaGiardini,项目名称:pulp,代码行数:15,代码来源:crud.py


示例10: test_database_integration

    def test_database_integration(self):
        # make sure the migration works on a live document in mongo
        collection = EventListener.get_collection()
        event_listener_id = str(
            collection.insert({"notifier_type_id": "rest-api", "event_types": ["*"], "notifier_config": {}}, safe=True)
        )
        event_listener_factory = managers.factory.event_listener_manager()

        module = MigrationModule("pulp.server.db.migrations.0002_rename_http_notifier")._module
        module.migrate()

        event_listener = event_listener_factory.get(event_listener_id)
        self.assertEqual(event_listener["notifier_type_id"], "http")

        # cleanup
        collection.remove()
开发者ID:credativ,项目名称:pulp,代码行数:16,代码来源:test_0002_rename_http_notifier.py


示例11: create

    def create(self, notifier_type_id, notifier_config, event_types):
        """
        Creates a new event listener in the server. The listener will listen
        for events of the given types and use the given notifier to react
        to them. The notifier will be passed the given configuration to
        drive how it behaves; values in the configuration vary based on the
        notifier being used.

        For instance, a message bus notifier will likely accept in its
        configuration the message bus and queue on which to broadcast the event.

        @param notifier_type_id: identifies the type of notification to produce
        @type  notifier_type_id: str

        @param notifier_config: used to control how the notifier behaves

        @param event_types: list of event types to listen for; valid values
               can be found in pulp.server.event.notifiers
        @type  event_types: list

        @return: created event listener instance from the database (i.e. _id
                 will be populated)

        @raise InvalidValue: if the notifier or event type ID aren't found
        """

        # Validation
        _validate_event_types(event_types)

        if not notifiers.is_valid_notifier_type_id(notifier_type_id):
            raise InvalidValue(['notifier_type_id'])

        # There's no need to check for a conflict; it's possible to use the
        # same notifier for the same event type but a different configuration

        # Make sure the configuration is at very least empty
        if notifier_config is None:
            notifier_config = {}

        # Create the database entry
        el = EventListener(notifier_type_id, notifier_config, event_types)
        collection = EventListener.get_collection()
        created_id = collection.save(el, safe=True)
        created = collection.find_one(created_id)

        return created
开发者ID:AndreaGiardini,项目名称:pulp,代码行数:46,代码来源:crud.py


示例12: test_update_only_event_types

    def test_update_only_event_types(self):
        # Setup
        manager = manager_factory.event_listener_manager()
        created = manager.create(http.TYPE_ID, {'a' : 'a', 'b' : 'b'}, [event_data.TYPE_REPO_SYNC_STARTED])

        # Test
        new_event_types = [event_data.TYPE_REPO_SYNC_FINISHED]
        body = {
            'event_types' : new_event_types,
        }

        status, body = self.put('/v2/events/%s/' % created['id'], body)

        # Verify
        self.assertEqual(200, status)

        updated = EventListener.get_collection().find_one({'_id' : ObjectId(created['_id'])})
        self.assertEqual(updated['event_types'], new_event_types)
开发者ID:AndreaGiardini,项目名称:pulp,代码行数:18,代码来源:test_event_controller.py


示例13: test_database_integration

    def test_database_integration(self):
        # make sure the migration works on a live document in mongo
        collection = EventListener.get_collection()
        event_listener_id = str(collection.insert({
            'notifier_type_id': 'rest-api',
            'event_types': ['*'],
            'notifier_config': {},
        }))
        event_listener_factory = managers.factory.event_listener_manager()

        module = MigrationModule('pulp.server.db.migrations.0002_rename_http_notifier')._module
        module.migrate()

        event_listener = event_listener_factory.get(event_listener_id)
        self.assertEqual(event_listener['notifier_type_id'], 'http')

        # cleanup
        collection.remove()
开发者ID:jeremycline,项目名称:pulp,代码行数:18,代码来源:test_0002_rename_http_notifier.py


示例14: test_update_only_config

    def test_update_only_config(self):
        # Setup
        manager = manager_factory.event_listener_manager()
        created = manager.create(http.TYPE_ID, {'a' : 'a', 'b' : 'b'}, [event_data.TYPE_REPO_SYNC_STARTED])

        # Test
        new_config = {'a' : 'x', 'c' : 'c'}
        body = {
            'notifier_config' : new_config,
        }

        status, body = self.put('/v2/events/%s/' % created['id'], body)

        # Verify
        self.assertEqual(200, status)

        updated = EventListener.get_collection().find_one({'_id' : ObjectId(created['_id'])})
        expected_config = {'a' : 'x', 'b' : 'b', 'c' : 'c'}
        self.assertEqual(updated['notifier_config'], expected_config)
开发者ID:AndreaGiardini,项目名称:pulp,代码行数:19,代码来源:test_event_controller.py


示例15: tearDown

    def tearDown(self):
        super(EventFireManagerTests, self).tearDown()

        EventListener.get_collection().remove()
        notifiers.reset()
开发者ID:AndreaGiardini,项目名称:pulp,代码行数:5,代码来源:test_event_fire.py


示例16: migrate

def migrate(*args, **kwargs):
    """
    Change the type id from 'rest-api' to 'http'
    """
    collection = EventListener.get_collection()
    collection.update({'notifier_type_id':'rest-api'}, {'$set': {'notifier_type_id':'http'}})
开发者ID:AndreaGiardini,项目名称:pulp,代码行数:6,代码来源:0002_rename_http_notifier.py


示例17: clean

 def clean(self):
     super(EventListenerManagerTests, self).clean()
     EventListener.get_collection().remove()
开发者ID:CUXIDUMDUM,项目名称:pulp,代码行数:3,代码来源:test_event_crud.py


示例18: _validate_event_listener

def _validate_event_listener():
    objectdb = EventListener.get_collection()
    reference = EventListener('', {}, [])
    return _validate_model(EventListener.__name__, objectdb, reference)
开发者ID:ehelms,项目名称:pulp,代码行数:4,代码来源:validate.py


示例19: clean

    def clean(self):
        super(EventResourceControllerTests, self).clean()

        EventListener.get_collection().remove()
开发者ID:AndreaGiardini,项目名称:pulp,代码行数:4,代码来源:test_event_controller.py



注:本文中的pulp.server.db.model.event.EventListener类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python migration_tracker.MigrationTracker类代码示例发布时间:2022-05-25
下一篇:
Python dispatch.TaskStatus类代码示例发布时间:2022-05-25
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap