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

Python trigger.Trigger类代码示例

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

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



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

示例1: test_register_rules

    def test_register_rules(self):
        # Verify DB is empty at the beginning
        self.assertEqual(len(Rule.get_all()), 0)
        self.assertEqual(len(Trigger.get_all()), 0)

        registrar = RulesRegistrar()
        registrar.register_from_packs(base_dirs=[PACKS_DIR])

        # Verify modeles are created
        rule_dbs = Rule.get_all()
        trigger_dbs = Trigger.get_all()
        self.assertEqual(len(rule_dbs), 2)
        self.assertEqual(len(trigger_dbs), 1)

        self.assertEqual(rule_dbs[0].name, 'sample.with_the_same_timer')
        self.assertEqual(rule_dbs[1].name, 'sample.with_timer')
        self.assertTrue(trigger_dbs[0].name is not None)

        # Verify second register call updates existing models
        registrar.register_from_packs(base_dirs=[PACKS_DIR])

        rule_dbs = Rule.get_all()
        trigger_dbs = Trigger.get_all()
        self.assertEqual(len(rule_dbs), 2)
        self.assertEqual(len(trigger_dbs), 1)
开发者ID:LindsayHill,项目名称:st2,代码行数:25,代码来源:test_sensor_and_rule_registration.py


示例2: test_create_or_update_trigger_db_simple_triggers

    def test_create_or_update_trigger_db_simple_triggers(self):
        test_fixtures = {
            'triggertypes': ['triggertype1.yaml']
        }
        loader = FixturesLoader()
        fixtures = loader.save_fixtures_to_db(fixtures_pack='generic', fixtures_dict=test_fixtures)
        triggertypes = fixtures['triggertypes']
        trigger_type_ref = ResourceReference.to_string_reference(
            name=triggertypes['triggertype1.yaml']['name'],
            pack=triggertypes['triggertype1.yaml']['pack'])

        trigger = {
            'name': triggertypes['triggertype1.yaml']['name'],
            'pack': triggertypes['triggertype1.yaml']['pack'],
            'type': trigger_type_ref
        }
        trigger_service.create_or_update_trigger_db(trigger)
        triggers = Trigger.get_all()
        self.assertTrue(len(triggers) == 1, 'Only one trigger should be created.')
        self.assertTrue(triggers[0]['name'] == triggertypes['triggertype1.yaml']['name'])

        # Try adding duplicate
        trigger_service.create_or_update_trigger_db(trigger)
        triggers = Trigger.get_all()
        self.assertTrue(len(triggers) == 1, 'Only one trigger should be present.')
        self.assertTrue(triggers[0]['name'] == triggertypes['triggertype1.yaml']['name'])
开发者ID:lyandut,项目名称:st2,代码行数:26,代码来源:test_trigger_services.py


示例3: test_existing_rules_are_loaded_on_start

    def test_existing_rules_are_loaded_on_start(self):
        # Assert that we dispatch message for every existing Trigger object
        St2Timer._handle_create_trigger = mock.Mock()

        timer = St2Timer()
        timer._scheduler = mock.Mock()
        timer._trigger_watcher.run = mock.Mock()

        # Verify there are no Trigger and TriggerType in the db wh:w
        self.assertItemsEqual(Trigger.get_all(), [])
        self.assertItemsEqual(TriggerType.get_all(), [])

        # Add a dummy timer Trigger object
        type_ = TIMER_TRIGGER_TYPES.keys()[0]
        parameters = {'unit': 'seconds', 'delta': 1000}
        trigger_db = TriggerDB(id=bson.ObjectId(), name='test_trigger_1', pack='dummy',
                               type=type_, parameters=parameters)
        trigger_db = Trigger.add_or_update(trigger_db)

        # Verify object has been added
        self.assertEqual(len(Trigger.get_all()), 1)

        timer.start()
        timer._trigger_watcher._load_thread.wait()

        # Verify handlers are called
        timer._handle_create_trigger.assert_called_with(trigger_db)
开发者ID:jonico,项目名称:st2,代码行数:27,代码来源:test_timer.py


示例4: _setup_sample_trigger

    def _setup_sample_trigger(self, name):
        trigtype = TriggerTypeDB(name=name, pack='dummy_pack_1', payload_schema={},
                                 parameters_schema={})
        TriggerType.add_or_update(trigtype)

        created = TriggerDB(name=name, pack='dummy_pack_1', type=trigtype.get_reference().ref,
                            parameters={})
        Trigger.add_or_update(created)
开发者ID:StackStorm,项目名称:st2,代码行数:8,代码来源:test_rule_matcher.py


示例5: cleanup_trigger_db_for_rule

def cleanup_trigger_db_for_rule(rule_db):
    # rule.trigger is actually trigger_db ref.
    existing_trigger_db = get_trigger_db_by_ref(rule_db.trigger)
    if not existing_trigger_db or not existing_trigger_db.parameters:
        # nothing to be done here so moving on.
        LOG.debug('ref_count decrement for %s not required.', existing_trigger_db)
        return
    Trigger.update(existing_trigger_db, dec__ref_count=1)
    Trigger.delete_if_unreferenced(existing_trigger_db)
开发者ID:lyandut,项目名称:st2,代码行数:9,代码来源:triggers.py


示例6: get_trigger_db_given_type_and_params

def get_trigger_db_given_type_and_params(type=None, parameters=None):
    try:
        parameters = parameters or {}
        trigger_dbs = Trigger.query(type=type, parameters=parameters)

        trigger_db = trigger_dbs[0] if len(trigger_dbs) > 0 else None

        # NOTE: This is a work-around which we might be able to remove once we upgrade
        # pymongo and mongoengine
        # Work around for cron-timer when in some scenarios finding an object fails when Python
        # value types are unicode :/
        is_cron_trigger = type == CRON_TIMER_TRIGGER_REF
        has_parameters = bool(parameters)

        if not trigger_db and six.PY2 and is_cron_trigger and has_parameters:
            non_unicode_literal_parameters = {}
            for key, value in six.iteritems(parameters):
                key = key.encode("utf-8")

                if isinstance(value, six.text_type):
                    # We only encode unicode to str
                    value = value.encode("utf-8")

                non_unicode_literal_parameters[key] = value
            parameters = non_unicode_literal_parameters

            trigger_dbs = Trigger.query(type=type, parameters=non_unicode_literal_parameters).no_cache()

            # Note: We need to directly access the object, using len or accessing the query set
            # twice won't work - there seems to bug a bug with cursor where accessing it twice
            # will throw an exception
            try:
                trigger_db = trigger_dbs[0]
            except IndexError:
                trigger_db = None

        if not parameters and not trigger_db:
            # We need to do double query because some TriggeDB objects without
            # parameters have "parameters" attribute stored in the db and others
            # don't
            trigger_db = Trigger.query(type=type, parameters=None).first()

        return trigger_db
    except StackStormDBObjectNotFoundError as e:
        LOG.debug(
            'Database lookup for type="%s" parameters="%s" resulted ' + "in exception : %s.",
            type,
            parameters,
            e,
            exc_info=True,
        )
        return None
开发者ID:rlugojr,项目名称:st2,代码行数:52,代码来源:triggers.py


示例7: increment_trigger_ref_count

def increment_trigger_ref_count(rule_api):
    """
    Given the rule figures out the TriggerType with parameter and increments
    reference count on the appropriate Trigger.

    :param rule_api: Rule object used to infer the Trigger.
    :type rule_api: ``RuleApi``
    """
    trigger_dict = _get_trigger_dict_given_rule(rule_api)

    # Special reference counting for trigger with parameters.
    if trigger_dict.get('parameters', None):
        trigger_db = _get_trigger_db(trigger_dict)
        Trigger.update(trigger_db, inc__ref_count=1)
开发者ID:lyandut,项目名称:st2,代码行数:14,代码来源:triggers.py


示例8: test_get_trigger_db_given_type_and_params

    def test_get_trigger_db_given_type_and_params(self):
        # Add dummy triggers
        trigger_1 = TriggerDB(pack='testpack', name='testtrigger1', type='testpack.testtrigger1')

        trigger_2 = TriggerDB(pack='testpack', name='testtrigger2', type='testpack.testtrigger2')

        trigger_3 = TriggerDB(pack='testpack', name='testtrigger3', type='testpack.testtrigger3')

        trigger_4 = TriggerDB(pack='testpack', name='testtrigger4', type='testpack.testtrigger4',
                              parameters={'ponies': 'unicorn'})

        Trigger.add_or_update(trigger_1)
        Trigger.add_or_update(trigger_2)
        Trigger.add_or_update(trigger_3)
        Trigger.add_or_update(trigger_4)

        # Trigger with no parameters, parameters={} in db
        trigger_db = trigger_service.get_trigger_db_given_type_and_params(type=trigger_1.type,
                                                                          parameters={})
        self.assertEqual(trigger_db, trigger_1)

        trigger_db = trigger_service.get_trigger_db_given_type_and_params(type=trigger_1.type,
                                                                          parameters=None)
        self.assertEqual(trigger_db, trigger_1)

        trigger_db = trigger_service.get_trigger_db_given_type_and_params(type=trigger_1.type,
                                                                          parameters={'fo': 'bar'})
        self.assertEqual(trigger_db, None)

        # Trigger with no parameters, no parameters attribute in the db
        trigger_db = trigger_service.get_trigger_db_given_type_and_params(type=trigger_2.type,
                                                                          parameters={})
        self.assertEqual(trigger_db, trigger_2)

        trigger_db = trigger_service.get_trigger_db_given_type_and_params(type=trigger_2.type,
                                                                          parameters=None)
        self.assertEqual(trigger_db, trigger_2)

        trigger_db = trigger_service.get_trigger_db_given_type_and_params(type=trigger_2.type,
                                                                          parameters={'fo': 'bar'})
        self.assertEqual(trigger_db, None)

        trigger_db = trigger_service.get_trigger_db_given_type_and_params(type=trigger_3.type,
                                                                          parameters={})
        self.assertEqual(trigger_db, trigger_3)

        trigger_db = trigger_service.get_trigger_db_given_type_and_params(type=trigger_3.type,
                                                                          parameters=None)
        self.assertEqual(trigger_db, trigger_3)

        # Trigger with parameters
        trigger_db = trigger_service.get_trigger_db_given_type_and_params(
            type=trigger_4.type,
            parameters=trigger_4.parameters)
        self.assertEqual(trigger_db, trigger_4)

        trigger_db = trigger_service.get_trigger_db_given_type_and_params(type=trigger_4.type,
                                                                          parameters=None)
        self.assertEqual(trigger_db, None)
开发者ID:lyandut,项目名称:st2,代码行数:59,代码来源:test_trigger_services.py


示例9: _delete_shadow_trigger

    def _delete_shadow_trigger(triggertype_db):
        # shadow Trigger's have the same name as the shadowed TriggerType.
        triggertype_ref = ResourceReference(name=triggertype_db.name, pack=triggertype_db.pack)
        trigger_db = TriggerService.get_trigger_db_by_ref(triggertype_ref.ref)
        if not trigger_db:
            LOG.warn('No shadow trigger found for %s. Will skip delete.', triggertype_db)
            return
        try:
            Trigger.delete(trigger_db)
        except Exception:
            LOG.exception('Database delete encountered exception during delete of id="%s". ',
                          trigger_db.id)

        extra = {'trigger_db': trigger_db}
        LOG.audit('Trigger deleted. Trigger.id=%s' % (trigger_db.id), extra=extra)
开发者ID:StackStorm,项目名称:st2,代码行数:15,代码来源:triggers.py


示例10: setUp

    def setUp(self):
        super(ContainerUtilsTest, self).setUp()

        # Insert mock TriggerDB
        trigger_db = TriggerDB(name='name1', pack='pack1', type='type1',
                               parameters={'a': 1, 'b': '2', 'c': 'foo'})
        self.trigger_db = Trigger.add_or_update(trigger_db)
开发者ID:lyandut,项目名称:st2,代码行数:7,代码来源:test_container_utils.py


示例11: _setup_sample_triggers

    def _setup_sample_triggers(
        self, names=["st2.test.trigger1", "st2.test.trigger2", "st2.test.trigger3", "st2.test.trigger4"]
    ):
        trigger_dbs = []
        for name in names:
            trigtype = None
            try:
                trigtype = TriggerTypeDB()
                trigtype.pack = "dummy_pack_1"
                trigtype.name = name
                trigtype.description = ""
                trigtype.payload_schema = {}
                trigtype.parameters_schema = {}
                try:
                    trigtype = TriggerType.get_by_name(name)
                except:
                    trigtype = TriggerType.add_or_update(trigtype)
            except NotUniqueError:
                pass

            created = TriggerDB()
            created.name = name
            created.pack = "dummy_pack_1"
            created.description = ""
            created.type = trigtype.get_reference().ref

            if name in ["st2.test.trigger4"]:
                created.parameters = {"url": "sample"}
            else:
                created.parameters = {}

            created = Trigger.add_or_update(created)
            trigger_dbs.append(created)

        return trigger_dbs
开发者ID:ipv1337,项目名称:st2,代码行数:35,代码来源:test_rule_engine.py


示例12: test_register_triggers_from_pack

    def test_register_triggers_from_pack(self):
        base_path = get_fixtures_base_path()
        pack_dir = os.path.join(base_path, 'dummy_pack_1')

        trigger_type_dbs = TriggerType.get_all()
        self.assertEqual(len(trigger_type_dbs), 0)

        count = triggers_registrar.register_triggers(pack_dir=pack_dir)
        self.assertEqual(count, 2)

        # Verify TriggerTypeDB and corresponding TriggerDB objects have been created
        trigger_type_dbs = TriggerType.get_all()
        trigger_dbs = Trigger.get_all()
        self.assertEqual(len(trigger_type_dbs), 2)
        self.assertEqual(len(trigger_dbs), 2)

        self.assertEqual(trigger_type_dbs[0].name, 'event_handler')
        self.assertEqual(trigger_type_dbs[0].pack, 'dummy_pack_1')
        self.assertEqual(trigger_dbs[0].name, 'event_handler')
        self.assertEqual(trigger_dbs[0].pack, 'dummy_pack_1')
        self.assertEqual(trigger_dbs[0].type, 'dummy_pack_1.event_handler')

        self.assertEqual(trigger_type_dbs[1].name, 'head_sha_monitor')
        self.assertEqual(trigger_type_dbs[1].pack, 'dummy_pack_1')
        self.assertEqual(trigger_type_dbs[1].payload_schema['type'], 'object')
开发者ID:ddevalco,项目名称:st2,代码行数:25,代码来源:test_triggers_registrar.py


示例13: get_all

    def get_all(self, exclude_attributes=None, include_attributes=None, sort=None, offset=0,
                limit=None, requester_user=None, **raw_filters):
        """
            List all triggerinstances.

            Handles requests:
                GET /triggerinstances/
        """
        # If trigger_type filter is provided, filter based on the TriggerType via Trigger object
        trigger_type_ref = raw_filters.get('trigger_type', None)

        if trigger_type_ref:
            # 1. Retrieve TriggerType object id which match this trigger_type ref
            trigger_dbs = Trigger.query(type=trigger_type_ref,
                                        only_fields=['ref', 'name', 'pack', 'type'])
            trigger_refs = [trigger_db.ref for trigger_db in trigger_dbs]
            raw_filters['trigger'] = trigger_refs

        if trigger_type_ref and len(raw_filters.get('trigger', [])) == 0:
            # Empty list means trigger_type_ref filter was provided, but we matched no Triggers so
            # we should return back empty result
            return []

        trigger_instances = self._get_trigger_instances(exclude_fields=exclude_attributes,
                                                        include_fields=include_attributes,
                                                        sort=sort,
                                                        offset=offset,
                                                        limit=limit,
                                                        raw_filters=raw_filters,
                                                        requester_user=requester_user)
        return trigger_instances
开发者ID:StackStorm,项目名称:st2,代码行数:31,代码来源:triggers.py


示例14: create_or_update_trigger_db

def create_or_update_trigger_db(trigger):
    """
    Create a new TriggerDB model if one doesn't exist yet or update existing
    one.

    :param trigger: Trigger info.
    :type trigger: ``dict``
    """
    assert isinstance(trigger, dict)

    existing_trigger_db = _get_trigger_db(trigger)

    if existing_trigger_db:
        is_update = True
    else:
        is_update = False

    trigger_api = TriggerAPI(**trigger)
    trigger_api.validate()
    trigger_db = TriggerAPI.to_model(trigger_api)

    if is_update:
        trigger_db.id = existing_trigger_db.id

    trigger_db = Trigger.add_or_update(trigger_db)

    extra = {'trigger_db': trigger_db}

    if is_update:
        LOG.audit('Trigger updated. Trigger.id=%s' % (trigger_db.id), extra=extra)
    else:
        LOG.audit('Trigger created. Trigger.id=%s' % (trigger_db.id), extra=extra)

    return trigger_db
开发者ID:ruslantum,项目名称:st2,代码行数:34,代码来源:triggers.py


示例15: _setup_sample_triggers

    def _setup_sample_triggers(self, names=['st2.test.trigger1', 'st2.test.trigger2',
                                            'st2.test.trigger3', 'st2.test.trigger4']):
        trigger_dbs = []
        for name in names:
            trigtype = None
            try:
                trigtype = TriggerTypeDB(pack='dummy_pack_1', name=name, description='',
                                         payload_schema={}, parameters_schema={})
                try:
                    trigtype = TriggerType.get_by_name(name)
                except:
                    trigtype = TriggerType.add_or_update(trigtype)
            except NotUniqueError:
                pass

            created = TriggerDB(pack='dummy_pack_1', name=name, description='',
                                type=trigtype.get_reference().ref)

            if name in ['st2.test.trigger4']:
                created.parameters = {'url': 'sample'}
            else:
                created.parameters = {}

            created = Trigger.add_or_update(created)
            trigger_dbs.append(created)

        return trigger_dbs
开发者ID:AlexeyDeyneko,项目名称:st2,代码行数:27,代码来源:test_rule_engine.py


示例16: _setup_sample_trigger

    def _setup_sample_trigger(self, name):
        trigtype = TriggerTypeDB()
        trigtype.name = name
        trigtype.pack = 'dummy_pack_1'
        trigtype.description = ''
        trigtype.payload_schema = {}
        trigtype.parameters_schema = {}
        TriggerType.add_or_update(trigtype)

        created = TriggerDB()
        created.name = name
        created.pack = 'dummy_pack_1'
        created.description = ''
        created.type = trigtype.get_reference().ref
        created.parameters = {}
        Trigger.add_or_update(created)
开发者ID:ipv1337,项目名称:st2,代码行数:16,代码来源:test_rule_matcher.py


示例17: test_trigger_lookup

 def test_trigger_lookup(self):
     triggertype = ReactorModelTest._create_save_triggertype()
     saved = ReactorModelTest._create_save_trigger(triggertype)
     retrievedtriggers = Trigger.query(name=saved.name)
     self.assertEqual(1, len(retrievedtriggers), "No triggers found.")
     for retrievedtrigger in retrievedtriggers:
         self.assertEqual(saved.id, retrievedtrigger.id, "Incorrect trigger returned.")
     ReactorModelTest._delete([saved, triggertype])
开发者ID:rlugojr,项目名称:st2,代码行数:8,代码来源:test_db.py


示例18: _create_save_trigger

 def _create_save_trigger(triggertype):
     created = TriggerDB()
     created.name = 'trigger-1'
     created.pack = 'dummy_pack_1'
     created.description = ''
     created.type = triggertype.get_reference().ref
     created.parameters = {}
     return Trigger.add_or_update(created)
开发者ID:ipv1337,项目名称:st2,代码行数:8,代码来源:test_db.py


示例19: setUpClass

 def setUpClass(cls):
     super(ReferenceTest, cls).setUpClass()
     trigger = TriggerDB()
     trigger.name = 'trigger-1'
     trigger.pack = 'dummy_pack_1'
     cls.__model = Trigger.add_or_update(trigger)
     cls.__ref = {'id': str(cls.__model.id),
                  'name': cls.__model.name}
开发者ID:Kailashkatheth1,项目名称:st2,代码行数:8,代码来源:test_reference.py


示例20: create_trigger_db

def create_trigger_db(trigger_api):
    # TODO: This is used only in trigger API controller. We should get rid of this.
    trigger_ref = ResourceReference.to_string_reference(name=trigger_api.name, pack=trigger_api.pack)
    trigger_db = get_trigger_db_by_ref(trigger_ref)
    if not trigger_db:
        trigger_db = TriggerAPI.to_model(trigger_api)
        LOG.debug("Verified trigger and formulated TriggerDB=%s", trigger_db)
        trigger_db = Trigger.add_or_update(trigger_db)
    return trigger_db
开发者ID:rlugojr,项目名称:st2,代码行数:9,代码来源:triggers.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python trigger.TriggerInstance类代码示例发布时间:2022-05-27
下一篇:
Python trace.Trace类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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