本文整理匯總了Python中st2common.persistence.trace.Trace.get_by_id方法的典型用法代碼示例。如果您正苦於以下問題:Python Trace.get_by_id方法的具體用法?Python Trace.get_by_id怎麽用?Python Trace.get_by_id使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類st2common.persistence.trace.Trace
的用法示例。
在下文中一共展示了Trace.get_by_id方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_add_or_update_given_trace_context_new
# 需要導入模塊: from st2common.persistence.trace import Trace [as 別名]
# 或者: from st2common.persistence.trace.Trace import get_by_id [as 別名]
def test_add_or_update_given_trace_context_new(self):
trace_context = {'trace_tag': 'awesome_test_trace'}
action_execution_id = 'action_execution_1'
rule_id = 'rule_1'
trigger_instance_id = 'trigger_instance_1'
pre_add_or_update_traces = len(Trace.get_all())
trace_db = trace_service.add_or_update_given_trace_context(
trace_context,
action_executions=[action_execution_id],
rules=[rule_id],
trigger_instances=[trigger_instance_id])
post_add_or_update_traces = len(Trace.get_all())
self.assertTrue(post_add_or_update_traces > pre_add_or_update_traces,
'Expected new Trace to be created.')
retrieved_trace_db = Trace.get_by_id(trace_db.id)
self.assertEqual(len(retrieved_trace_db.action_executions), 1,
'Expected updated action_executions.')
self.assertEqual(retrieved_trace_db.action_executions[0].object_id, action_execution_id,
'Expected updated action_executions.')
self.assertEqual(len(retrieved_trace_db.rules), 1, 'Expected updated rules.')
self.assertEqual(retrieved_trace_db.rules[0].object_id, rule_id, 'Expected updated rules.')
self.assertEqual(len(retrieved_trace_db.trigger_instances), 1,
'Expected updated trigger_instances.')
self.assertEqual(retrieved_trace_db.trigger_instances[0].object_id, trigger_instance_id,
'Expected updated trigger_instances.')
Trace.delete(retrieved_trace_db)
示例2: test_add_or_update_given_trace_context
# 需要導入模塊: from st2common.persistence.trace import Trace [as 別名]
# 或者: from st2common.persistence.trace.Trace import get_by_id [as 別名]
def test_add_or_update_given_trace_context(self):
trace_context = {'id_': str(self.trace_empty.id)}
action_execution_id = 'action_execution_1'
rule_id = 'rule_1'
trigger_instance_id = 'trigger_instance_1'
trace_service.add_or_update_given_trace_context(
trace_context,
action_executions=[action_execution_id],
rules=[rule_id],
trigger_instances=[trigger_instance_id])
retrieved_trace_db = Trace.get_by_id(self.trace_empty.id)
self.assertEqual(len(retrieved_trace_db.action_executions), 1,
'Expected updated action_executions.')
self.assertEqual(retrieved_trace_db.action_executions[0].object_id, action_execution_id,
'Expected updated action_executions.')
self.assertEqual(len(retrieved_trace_db.rules), 1, 'Expected updated rules.')
self.assertEqual(retrieved_trace_db.rules[0].object_id, rule_id, 'Expected updated rules.')
self.assertEqual(len(retrieved_trace_db.trigger_instances), 1,
'Expected updated trigger_instances.')
self.assertEqual(retrieved_trace_db.trigger_instances[0].object_id, trigger_instance_id,
'Expected updated trigger_instances.')
Trace.delete(retrieved_trace_db)
Trace.add_or_update(self.trace_empty)
示例3: test_add_or_update_given_trace_db
# 需要導入模塊: from st2common.persistence.trace import Trace [as 別名]
# 或者: from st2common.persistence.trace.Trace import get_by_id [as 別名]
def test_add_or_update_given_trace_db(self):
action_execution_id = 'action_execution_1'
rule_id = 'rule_1'
trigger_instance_id = 'trigger_instance_1'
to_save = copy.copy(self.trace_empty)
to_save.id = None
saved = trace_service.add_or_update_given_trace_db(
to_save,
action_executions=[action_execution_id],
rules=[rule_id],
trigger_instances=[trigger_instance_id])
retrieved_trace_db = Trace.get_by_id(saved.id)
self.assertEqual(len(retrieved_trace_db.action_executions), 1,
'Expected updated action_executions.')
self.assertEqual(retrieved_trace_db.action_executions[0].object_id, action_execution_id,
'Expected updated action_executions.')
self.assertEqual(len(retrieved_trace_db.rules), 1, 'Expected updated rules.')
self.assertEqual(retrieved_trace_db.rules[0].object_id, rule_id, 'Expected updated rules.')
self.assertEqual(len(retrieved_trace_db.trigger_instances), 1,
'Expected updated trigger_instances.')
self.assertEqual(retrieved_trace_db.trigger_instances[0].object_id, trigger_instance_id,
'Expected updated trigger_instances.')
# Now add more TraceComponents and validated that they are added properly.
saved = trace_service.add_or_update_given_trace_db(
retrieved_trace_db,
action_executions=[str(bson.ObjectId()), str(bson.ObjectId())],
rules=[str(bson.ObjectId())],
trigger_instances=[str(bson.ObjectId()), str(bson.ObjectId()), str(bson.ObjectId())])
retrieved_trace_db = Trace.get_by_id(saved.id)
self.assertEqual(len(retrieved_trace_db.action_executions), 3,
'Expected updated action_executions.')
self.assertEqual(len(retrieved_trace_db.rules), 2, 'Expected updated rules.')
self.assertEqual(len(retrieved_trace_db.trigger_instances), 4,
'Expected updated trigger_instances.')
Trace.delete(retrieved_trace_db)
示例4: test_add_or_update_given_trace_context_new_with_causals
# 需要導入模塊: from st2common.persistence.trace import Trace [as 別名]
# 或者: from st2common.persistence.trace.Trace import get_by_id [as 別名]
def test_add_or_update_given_trace_context_new_with_causals(self):
trace_context = {'trace_tag': 'causal_test_trace'}
action_execution_id = 'action_execution_1'
rule_id = 'rule_1'
trigger_instance_id = 'trigger_instance_1'
pre_add_or_update_traces = len(Trace.get_all())
trace_db = trace_service.add_or_update_given_trace_context(
trace_context,
action_executions=[{'id': action_execution_id,
'caused_by': {'id': '%s:%s' % (rule_id, trigger_instance_id),
'type': 'rule'}}],
rules=[{'id': rule_id,
'caused_by': {'id': trigger_instance_id, 'type': 'trigger-instance'}}],
trigger_instances=[trigger_instance_id])
post_add_or_update_traces = len(Trace.get_all())
self.assertTrue(post_add_or_update_traces > pre_add_or_update_traces,
'Expected new Trace to be created.')
retrieved_trace_db = Trace.get_by_id(trace_db.id)
self.assertEqual(len(retrieved_trace_db.action_executions), 1,
'Expected updated action_executions.')
self.assertEqual(retrieved_trace_db.action_executions[0].object_id, action_execution_id,
'Expected updated action_executions.')
self.assertEqual(retrieved_trace_db.action_executions[0].caused_by,
{'id': '%s:%s' % (rule_id, trigger_instance_id),
'type': 'rule'},
'Expected updated action_executions.')
self.assertEqual(len(retrieved_trace_db.rules), 1, 'Expected updated rules.')
self.assertEqual(retrieved_trace_db.rules[0].object_id, rule_id, 'Expected updated rules.')
self.assertEqual(retrieved_trace_db.rules[0].caused_by,
{'id': trigger_instance_id, 'type': 'trigger-instance'},
'Expected updated rules.')
self.assertEqual(len(retrieved_trace_db.trigger_instances), 1,
'Expected updated trigger_instances.')
self.assertEqual(retrieved_trace_db.trigger_instances[0].object_id, trigger_instance_id,
'Expected updated trigger_instances.')
self.assertEqual(retrieved_trace_db.trigger_instances[0].caused_by, {},
'Expected updated rules.')
Trace.delete(retrieved_trace_db)
示例5: get_trace
# 需要導入模塊: from st2common.persistence.trace import Trace [as 別名]
# 或者: from st2common.persistence.trace.Trace import get_by_id [as 別名]
def get_trace(trace_context, ignore_trace_tag=False):
"""
:param trace_context: context object using which a trace can be found.
:type trace_context: ``dict`` or ``TraceContext``
:param ignore_trace_tag: Even if a trace_tag is provided will be ignored.
:type ignore_trace_tag: ``str``
:rtype: ``TraceDB``
"""
trace_context = _get_valid_trace_context(trace_context)
if not trace_context.id_ and not trace_context.trace_tag:
raise ValueError('Atleast one of id_ or trace_tag should be specified.')
if trace_context.id_:
try:
return Trace.get_by_id(trace_context.id_)
except (ValidationError, ValueError):
LOG.warning('Database lookup for Trace with id="%s" failed.',
trace_context.id_, exc_info=True)
raise StackStormDBObjectNotFoundError(
'Unable to find Trace with id="%s"' % trace_context.id_)
if ignore_trace_tag:
return None
traces = Trace.query(trace_tag=trace_context.trace_tag)
# Assume this method only handles 1 trace.
if len(traces) > 1:
raise UniqueTraceNotFoundException(
'More than 1 Trace matching %s found.' % trace_context.trace_tag)
return traces[0]