當前位置: 首頁>>代碼示例>>Python>>正文


Python event.EventListener類代碼示例

本文整理匯總了Python中pulp.server.db.model.event.EventListener的典型用法代碼示例。如果您正苦於以下問題:Python EventListener類的具體用法?Python EventListener怎麽用?Python EventListener使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了EventListener類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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


注:本文中的pulp.server.db.model.event.EventListener類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。