当前位置: 首页>>代码示例>>Python>>正文


Python EventListener.get_collection方法代码示例

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


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

示例1: get

# 需要导入模块: from pulp.server.db.model.event import EventListener [as 别名]
# 或者: from pulp.server.db.model.event.EventListener import get_collection [as 别名]
    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,代码行数:28,代码来源:crud.py

示例2: test_post

# 需要导入模块: from pulp.server.db.model.event import EventListener [as 别名]
# 或者: from pulp.server.db.model.event.EventListener import get_collection [as 别名]
    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,代码行数:27,代码来源:test_event_controller.py

示例3: _do_fire

# 需要导入模块: from pulp.server.db.model.event import EventListener [as 别名]
# 或者: from pulp.server.db.model.event.EventListener import get_collection [as 别名]
    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,代码行数:27,代码来源:fire.py

示例4: list

# 需要导入模块: from pulp.server.db.model.event import EventListener [as 别名]
# 或者: from pulp.server.db.model.event.EventListener import get_collection [as 别名]
    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,代码行数:12,代码来源:crud.py

示例5: test_delete

# 需要导入模块: from pulp.server.db.model.event import EventListener [as 别名]
# 或者: from pulp.server.db.model.event.EventListener import get_collection [as 别名]
    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,代码行数:12,代码来源:test_event_crud.py

示例6: test_create

# 需要导入模块: from pulp.server.db.model.event import EventListener [as 别名]
# 或者: from pulp.server.db.model.event.EventListener import get_collection [as 别名]
    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,代码行数:13,代码来源:test_event_crud.py

示例7: update

# 需要导入模块: from pulp.server.db.model.event import EventListener [as 别名]
# 或者: from pulp.server.db.model.event.EventListener import get_collection [as 别名]
    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,代码行数:55,代码来源:crud.py

示例8: test_delete

# 需要导入模块: from pulp.server.db.model.event import EventListener [as 别名]
# 或者: from pulp.server.db.model.event.EventListener import get_collection [as 别名]
    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,代码行数:15,代码来源:test_event_controller.py

示例9: delete

# 需要导入模块: from pulp.server.db.model.event import EventListener [as 别名]
# 或者: from pulp.server.db.model.event.EventListener import get_collection [as 别名]
    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,代码行数:17,代码来源:crud.py

示例10: test_database_integration

# 需要导入模块: from pulp.server.db.model.event import EventListener [as 别名]
# 或者: from pulp.server.db.model.event.EventListener import get_collection [as 别名]
    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,代码行数:18,代码来源:test_0002_rename_http_notifier.py

示例11: create

# 需要导入模块: from pulp.server.db.model.event import EventListener [as 别名]
# 或者: from pulp.server.db.model.event.EventListener import get_collection [as 别名]
    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,代码行数:48,代码来源:crud.py

示例12: test_update_only_event_types

# 需要导入模块: from pulp.server.db.model.event import EventListener [as 别名]
# 或者: from pulp.server.db.model.event.EventListener import get_collection [as 别名]
    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,代码行数:20,代码来源:test_event_controller.py

示例13: test_database_integration

# 需要导入模块: from pulp.server.db.model.event import EventListener [as 别名]
# 或者: from pulp.server.db.model.event.EventListener import get_collection [as 别名]
    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,代码行数:20,代码来源:test_0002_rename_http_notifier.py

示例14: test_update_only_config

# 需要导入模块: from pulp.server.db.model.event import EventListener [as 别名]
# 或者: from pulp.server.db.model.event.EventListener import get_collection [as 别名]
    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,代码行数:21,代码来源:test_event_controller.py

示例15: tearDown

# 需要导入模块: from pulp.server.db.model.event import EventListener [as 别名]
# 或者: from pulp.server.db.model.event.EventListener import get_collection [as 别名]
    def tearDown(self):
        super(EventFireManagerTests, self).tearDown()

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


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