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


Python Trace.query方法代碼示例

本文整理匯總了Python中st2common.persistence.trace.Trace.query方法的典型用法代碼示例。如果您正苦於以下問題:Python Trace.query方法的具體用法?Python Trace.query怎麽用?Python Trace.query使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在st2common.persistence.trace.Trace的用法示例。


在下文中一共展示了Trace.query方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_update

# 需要導入模塊: from st2common.persistence.trace import Trace [as 別名]
# 或者: from st2common.persistence.trace.Trace import query [as 別名]
    def test_update(self):
        saved = TraceDBTest._create_save_trace(
            trace_tag='test_trace',
            action_executions=[],
            rules=[],
            trigger_instances=[])
        retrieved = Trace.query(trace_tag=saved.trace_tag)
        self.assertEquals(len(retrieved), 1, 'Should have 1 trace.')
        self.assertEquals(retrieved[0].id, saved.id, 'Incorrect trace retrieved.')

        no_action_executions = 4
        no_rules = 4
        no_trigger_instances = 5
        saved = TraceDBTest._create_save_trace(
            trace_tag='test_trace',
            id_=retrieved[0].id,
            action_executions=[str(bson.ObjectId()) for _ in range(no_action_executions)],
            rules=[str(bson.ObjectId()) for _ in range(no_rules)],
            trigger_instances=[str(bson.ObjectId()) for _ in range(no_trigger_instances)])
        retrieved = Trace.query(trace_tag=saved.trace_tag)

        self.assertEquals(len(retrieved), 1, 'Should have 1 trace.')
        self.assertEquals(retrieved[0].id, saved.id, 'Incorrect trace retrieved.')
        # validate update
        self.assertEquals(len(retrieved[0].action_executions), no_action_executions,
                          'Failed to update action_executions.')
        self.assertEquals(len(retrieved[0].rules), no_rules, 'Failed to update rules.')
        self.assertEquals(len(retrieved[0].trigger_instances), no_trigger_instances,
                          'Failed to update trigger_instances.')
開發者ID:AlexeyDeyneko,項目名稱:st2,代碼行數:31,代碼來源:test_db_trace.py

示例2: test_trace_tag_resuse

# 需要導入模塊: from st2common.persistence.trace import Trace [as 別名]
# 或者: from st2common.persistence.trace.Trace import query [as 別名]
 def test_trace_tag_resuse(self):
     self.traceable_liveaction['context']['trace_context'] = {'trace_tag': 'blank space'}
     action_services.request(self.traceable_liveaction)
     # Let's use same trace tag again and we should see two trace objects in db.
     action_services.request(self.traceable_liveaction)
     traces = Trace.query(**{'trace_tag': 'blank space'})
     self.assertEqual(len(traces), 2)
開發者ID:StackStorm,項目名稱:st2,代碼行數:9,代碼來源:test_trace_injection_action_services.py

示例3: test_query

# 需要導入模塊: from st2common.persistence.trace import Trace [as 別名]
# 或者: from st2common.persistence.trace.Trace import query [as 別名]
    def test_query(self):
        saved = TraceDBTest._create_save_trace(
            trace_tag='test_trace',
            action_executions=[str(bson.ObjectId()) for _ in range(4)],
            rules=[str(bson.ObjectId()) for _ in range(4)],
            trigger_instances=[str(bson.ObjectId()) for _ in range(5)])
        retrieved = Trace.query(trace_tag=saved.trace_tag)
        self.assertEquals(len(retrieved), 1, 'Should have 1 trace.')
        self.assertEquals(retrieved[0].id, saved.id, 'Incorrect trace retrieved.')

        # Add another trace with same trace_tag and confirm that we support.
        # This is most likley an anti-pattern for the trace_tag but it is an unknown.
        saved = TraceDBTest._create_save_trace(
            trace_tag='test_trace',
            action_executions=[str(bson.ObjectId()) for _ in range(2)],
            rules=[str(bson.ObjectId()) for _ in range(4)],
            trigger_instances=[str(bson.ObjectId()) for _ in range(3)])
        retrieved = Trace.query(trace_tag=saved.trace_tag)
        self.assertEquals(len(retrieved), 2, 'Should have 2 traces.')
開發者ID:AlexeyDeyneko,項目名稱:st2,代碼行數:21,代碼來源:test_db_trace.py

示例4: _get_single_trace_by_component

# 需要導入模塊: from st2common.persistence.trace import Trace [as 別名]
# 或者: from st2common.persistence.trace.Trace import query [as 別名]
def _get_single_trace_by_component(**component_filter):
    """
    Tries to return a single Trace mathing component_filter. Raises an exception
    when a filter matches multiple.
    """
    traces = Trace.query(**component_filter)
    if len(traces) == 0:
        return None
    elif len(traces) > 1:
        raise UniqueTraceNotFoundException(
            'More than 1 trace matching %s found.' % component_filter)
    return traces[0]
開發者ID:azamsheriff,項目名稱:st2,代碼行數:14,代碼來源:trace.py

示例5: get_trace

# 需要導入模塊: from st2common.persistence.trace import Trace [as 別名]
# 或者: from st2common.persistence.trace.Trace import query [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]
開發者ID:azamsheriff,項目名稱:st2,代碼行數:38,代碼來源:trace.py

示例6: get_trace_db_by_rule

# 需要導入模塊: from st2common.persistence.trace import Trace [as 別名]
# 或者: from st2common.persistence.trace.Trace import query [as 別名]
def get_trace_db_by_rule(rule=None, rule_id=None):
    if rule:
        rule_id = str(rule.id)
    # by rule could return multiple traces
    return Trace.query(rules__object_id=rule_id)
開發者ID:azamsheriff,項目名稱:st2,代碼行數:7,代碼來源:trace.py


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