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


Python reactor.Trigger類代碼示例

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


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


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