本文整理汇总了Python中st2common.persistence.trigger.Trigger.add_or_update方法的典型用法代码示例。如果您正苦于以下问题:Python Trigger.add_or_update方法的具体用法?Python Trigger.add_or_update怎么用?Python Trigger.add_or_update使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类st2common.persistence.trigger.Trigger
的用法示例。
在下文中一共展示了Trigger.add_or_update方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _setup_sample_trigger
# 需要导入模块: from st2common.persistence.trigger import Trigger [as 别名]
# 或者: from st2common.persistence.trigger.Trigger import add_or_update [as 别名]
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)
示例2: test_get_trigger_db_given_type_and_params
# 需要导入模块: from st2common.persistence.trigger import Trigger [as 别名]
# 或者: from st2common.persistence.trigger.Trigger import add_or_update [as 别名]
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)
示例3: _setup_sample_triggers
# 需要导入模块: from st2common.persistence.trigger import Trigger [as 别名]
# 或者: from st2common.persistence.trigger.Trigger import add_or_update [as 别名]
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
示例4: test_existing_rules_are_loaded_on_start
# 需要导入模块: from st2common.persistence.trigger import Trigger [as 别名]
# 或者: from st2common.persistence.trigger.Trigger import add_or_update [as 别名]
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)
示例5: setUp
# 需要导入模块: from st2common.persistence.trigger import Trigger [as 别名]
# 或者: from st2common.persistence.trigger.Trigger import add_or_update [as 别名]
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)
示例6: create_or_update_trigger_db
# 需要导入模块: from st2common.persistence.trigger import Trigger [as 别名]
# 或者: from st2common.persistence.trigger.Trigger import add_or_update [as 别名]
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
示例7: _setup_sample_triggers
# 需要导入模块: from st2common.persistence.trigger import Trigger [as 别名]
# 或者: from st2common.persistence.trigger.Trigger import add_or_update [as 别名]
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
示例8: _setup_sample_trigger
# 需要导入模块: from st2common.persistence.trigger import Trigger [as 别名]
# 或者: from st2common.persistence.trigger.Trigger import add_or_update [as 别名]
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)
示例9: _create_save_trigger
# 需要导入模块: from st2common.persistence.trigger import Trigger [as 别名]
# 或者: from st2common.persistence.trigger.Trigger import add_or_update [as 别名]
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)
示例10: setUpClass
# 需要导入模块: from st2common.persistence.trigger import Trigger [as 别名]
# 或者: from st2common.persistence.trigger.Trigger import add_or_update [as 别名]
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}
示例11: create_trigger_db
# 需要导入模块: from st2common.persistence.trigger import Trigger [as 别名]
# 或者: from st2common.persistence.trigger.Trigger import add_or_update [as 别名]
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
示例12: _create_save_triggertype
# 需要导入模块: from st2common.persistence.trigger import Trigger [as 别名]
# 或者: from st2common.persistence.trigger.Trigger import add_or_update [as 别名]
def _create_save_triggertype():
created = TriggerTypeDB()
created.pack = 'dummy_pack_1'
created.name = 'triggertype-1'
created.stupid = 'stupid'
created.description = ''
created.payload_schema = {}
created.parameters_schema = {}
return Trigger.add_or_update(created)
示例13: test_triggered_execution
# 需要导入模块: from st2common.persistence.trigger import Trigger [as 别名]
# 或者: from st2common.persistence.trigger.Trigger import add_or_update [as 别名]
def test_triggered_execution(self):
docs = {
'trigger_type': copy.deepcopy(fixture.ARTIFACTS['trigger_type']),
'trigger': copy.deepcopy(fixture.ARTIFACTS['trigger']),
'rule': copy.deepcopy(fixture.ARTIFACTS['rule']),
'trigger_instance': copy.deepcopy(fixture.ARTIFACTS['trigger_instance'])}
# Trigger an action execution.
trigger_type = TriggerType.add_or_update(
TriggerTypeAPI.to_model(TriggerTypeAPI(**docs['trigger_type'])))
trigger = Trigger.add_or_update(TriggerAPI.to_model(TriggerAPI(**docs['trigger'])))
rule = RuleAPI.to_model(RuleAPI(**docs['rule']))
rule.trigger = reference.get_str_resource_ref_from_model(trigger)
rule = Rule.add_or_update(rule)
trigger_instance = TriggerInstance.add_or_update(
TriggerInstanceAPI.to_model(TriggerInstanceAPI(**docs['trigger_instance'])))
trace_service.add_or_update_given_trace_context(
trace_context={'trace_tag': 'test_triggered_execution_trace'},
trigger_instances=[str(trigger_instance.id)])
enforcer = RuleEnforcer(trigger_instance, rule)
enforcer.enforce()
# Wait for the action execution to complete and then confirm outcome.
liveaction = LiveAction.get(context__trigger_instance__id=str(trigger_instance.id))
self.assertIsNotNone(liveaction)
liveaction = self._wait_on_status(liveaction, action_constants.LIVEACTION_STATUS_FAILED)
execution = self._get_action_execution(
liveaction__id=str(liveaction.id),
raise_exception=True
)
self.assertDictEqual(execution.trigger, vars(TriggerAPI.from_model(trigger)))
self.assertDictEqual(execution.trigger_type, vars(TriggerTypeAPI.from_model(trigger_type)))
self.assertDictEqual(execution.trigger_instance,
vars(TriggerInstanceAPI.from_model(trigger_instance)))
self.assertDictEqual(execution.rule, vars(RuleAPI.from_model(rule)))
action = action_utils.get_action_by_ref(liveaction.action)
self.assertDictEqual(execution.action, vars(ActionAPI.from_model(action)))
runner = RunnerType.get_by_name(action.runner_type['name'])
self.assertDictEqual(execution.runner, vars(RunnerTypeAPI.from_model(runner)))
liveaction = LiveAction.get_by_id(str(liveaction.id))
self.assertEqual(execution.start_timestamp, liveaction.start_timestamp)
self.assertEqual(execution.end_timestamp, liveaction.end_timestamp)
self.assertEqual(execution.result, liveaction.result)
self.assertEqual(execution.status, liveaction.status)
self.assertEqual(execution.context, liveaction.context)
self.assertEqual(execution.liveaction['callback'], liveaction.callback)
self.assertEqual(execution.liveaction['action'], liveaction.action)
示例14: test_trigger_crud
# 需要导入模块: from st2common.persistence.trigger import Trigger [as 别名]
# 或者: from st2common.persistence.trigger.Trigger import add_or_update [as 别名]
def test_trigger_crud(self):
triggertype = ReactorModelTest._create_save_triggertype()
saved = ReactorModelTest._create_save_trigger(triggertype)
retrieved = Trigger.get_by_id(saved.id)
self.assertEqual(saved.name, retrieved.name, "Same trigger was not returned.")
# test update
self.assertEqual(retrieved.description, "")
retrieved.description = DUMMY_DESCRIPTION
saved = Trigger.add_or_update(retrieved)
retrieved = Trigger.get_by_id(saved.id)
self.assertEqual(retrieved.description, DUMMY_DESCRIPTION, "Update to trigger failed.")
# cleanup
ReactorModelTest._delete([retrieved, triggertype])
try:
retrieved = Trigger.get_by_id(saved.id)
except StackStormDBObjectNotFoundError:
retrieved = None
self.assertIsNone(retrieved, "managed to retrieve after failure.")
示例15: put
# 需要导入模块: from st2common.persistence.trigger import Trigger [as 别名]
# 或者: from st2common.persistence.trigger.Trigger import add_or_update [as 别名]
def put(self, trigger, trigger_id):
trigger_db = TriggerController.__get_by_id(trigger_id)
try:
if trigger.id is not None and trigger.id != '' and trigger.id != trigger_id:
LOG.warning('Discarding mismatched id=%s found in payload and using uri_id=%s.',
trigger.id, trigger_id)
trigger_db = TriggerAPI.to_model(trigger)
trigger_db.id = trigger_id
trigger_db = Trigger.add_or_update(trigger_db)
except (ValidationError, ValueError) as e:
LOG.exception('Validation failed for trigger data=%s', trigger)
abort(http_client.BAD_REQUEST, six.text_type(e))
return
extra = {'old_trigger_db': trigger, 'new_trigger_db': trigger_db}
LOG.audit('Trigger updated. Trigger.id=%s' % (trigger.id), extra=extra)
trigger_api = TriggerAPI.from_model(trigger_db)
return trigger_api