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

Python reactor.Trigger类代码示例

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

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



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

示例1: test_create_or_update_trigger_db_simple_triggers

    def test_create_or_update_trigger_db_simple_triggers(self):
        test_fixtures = {
            'triggertypes': ['triggertype1.json']
        }
        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.json']['name'],
            pack=triggertypes['triggertype1.json']['pack'])

        trigger = {
            'name': triggertypes['triggertype1.json']['name'],
            'pack': triggertypes['triggertype1.json']['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.json']['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.json']['name'])
开发者ID:BlazeMediaGroup,项目名称:st2,代码行数:26,代码来源:test_trigger_services.py


示例2: 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_rules_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_rules_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:BlazeMediaGroup,项目名称:st2,代码行数:25,代码来源:test_sensor_and_rule_registration.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()

        timer = St2Timer()
        timer._scheduler = Mock()
        timer._trigger_watcher.run = 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(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:BlazeMediaGroup,项目名称:st2,代码行数:27,代码来源:test_timer.py


示例4: setUp

 def setUp(self):
     RUNNER_TYPE.id = None
     RunnerType.add_or_update(RUNNER_TYPE)
     ACTION.id = None
     ACTION.runner_type = {'name': RUNNER_TYPE.name}
     Action.add_or_update(ACTION)
     TRIGGER.id = None
     Trigger.add_or_update(TRIGGER)
开发者ID:ojacques,项目名称:st2,代码行数:8,代码来源:test_rules.py


示例5: _delete_shadow_trigger

 def _delete_shadow_trigger(triggertype_db):
     # shadow Trigger's have the same name as the shadowed TriggerType.
     trigger_db = TriggerService.get_trigger_db(triggertype_db.name)
     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)
     LOG.audit('Trigger deleted. Trigger=%s', trigger_db)
开发者ID:bjoernbessert,项目名称:st2,代码行数:12,代码来源:triggers.py


示例6: _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:BlazeMediaGroup,项目名称:st2,代码行数:15,代码来源:triggers.py


示例7: _get_trigger_db_by_name_and_pack

def _get_trigger_db_by_name_and_pack(name, pack):
    try:
        return Trigger.query(name=name, pack=pack).first()
    except ValueError as e:
        LOG.debug('Database lookup for name="%s",pack="%s" resulted ' +
                  'in exception : %s.', name, pack, e, exc_info=True)
        return None
开发者ID:bjoernbessert,项目名称:st2,代码行数:7,代码来源:triggers.py


示例8: _setup_sample_triggers

    def _setup_sample_triggers(self, names=['st2.test.trigger1', 'st2.test.trigger2',
                                            'st2.test.trigger3']):
        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
            created.parameters = {}
            created = Trigger.add_or_update(created)
            trigger_dbs.append(created)

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


示例9: _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:BlazeMediaGroup,项目名称:st2,代码行数:16,代码来源:test_rule_matcher.py


示例10: 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:BlazeMediaGroup,项目名称:st2,代码行数:34,代码来源:triggers.py


示例11: _get_trigger_db

def _get_trigger_db(type=None, parameters=None):
    try:
        return Trigger.query(type=type,
                             parameters=parameters).first()
    except ValueError as e:
        LOG.debug('Database lookup for type="%s" parameters="%s" resulted ' +
                  'in exception : %s.', type, parameters, e, exc_info=True)
        return None
开发者ID:bjoernbessert,项目名称:st2,代码行数:8,代码来源:triggers.py


示例12: 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:BlazeMediaGroup,项目名称:st2,代码行数:8,代码来源:test_reference.py


示例13: _get_trigger_instance_db

 def _get_trigger_instance_db(self):
     if self._trigger_instance_file_path:
         return self._get_trigger_instance_db_from_file(file_path=os.path.realpath(self._trigger_instance_file_path))
     elif self._trigger_instance_id:
         trigger_instance_db = TriggerInstance.get_by_id(self._trigger_instance_id)
         trigger_db = Trigger.get_by_ref(trigger_instance_db.trigger)
         return trigger_instance_db, trigger_db
     raise ValueError("One of _trigger_instance_file_path or" "_trigger_instance_id should be specified.")
开发者ID:rlugojr,项目名称:st2,代码行数:8,代码来源:tester.py


示例14: _create_save_triggertype

 def _create_save_triggertype():
     created = TriggerTypeDB()
     created.pack = 'dummy_pack_1'
     created.name = 'triggertype-1'
     created.description = ''
     created.payload_schema = {}
     created.parameters_schema = {}
     return Trigger.add_or_update(created)
开发者ID:srenatus,项目名称:st2,代码行数:8,代码来源:test_db.py


示例15: _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:srenatus,项目名称:st2,代码行数:8,代码来源:test_db.py


示例16: get_trigger_db_given_type_and_params

def get_trigger_db_given_type_and_params(type=None, parameters=None):
    try:
        parameters = parameters or {}

        trigger_db = Trigger.query(type=type,
                                   parameters=parameters).first()

        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 ValueError as e:
        LOG.debug('Database lookup for type="%s" parameters="%s" resulted ' +
                  'in exception : %s.', type, parameters, e, exc_info=True)
        return None
开发者ID:BlazeMediaGroup,项目名称:st2,代码行数:18,代码来源:triggers.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:srenatus,项目名称:st2,代码行数:9,代码来源:test_db.py


示例18: delete

    def delete(self, trigger_id):
        """
            Delete a trigger.

            Handles requests:
                DELETE /triggers/1
        """
        LOG.info('DELETE /triggers/ with id=%s', trigger_id)
        trigger_db = TriggerController.__get_by_id(trigger_id)
        try:
            Trigger.delete(trigger_db)
        except Exception as e:
            LOG.exception('Database delete encountered exception during delete of id="%s". ',
                          trigger_id)
            abort(http_client.INTERNAL_SERVER_ERROR, str(e))
            return

        LOG.audit('Trigger deleted. Trigger=%s', trigger_db)
开发者ID:bjoernbessert,项目名称:st2,代码行数:18,代码来源:triggers.py


示例19: create_trigger_db

def create_trigger_db(trigger):
    trigger_api = trigger
    if isinstance(trigger, dict):
        trigger_api = TriggerAPI(**trigger)
    trigger_db = get_trigger_db(trigger_api)
    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:bjoernbessert,项目名称:st2,代码行数:10,代码来源:triggers.py


示例20: get_all

    def get_all(self, **kw):
        """
            List all triggers.

            Handles requests:
                GET /triggers/
        """
        trigger_dbs = Trigger.get_all(**kw)
        trigger_apis = [TriggerAPI.from_model(trigger_db) for trigger_db in trigger_dbs]
        return trigger_apis
开发者ID:BlazeMediaGroup,项目名称:st2,代码行数:10,代码来源:triggers.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python rule.Rule类代码示例发布时间:2022-05-27
下一篇:
Python rbac.UserRoleAssignment类代码示例发布时间: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