Esempio n. 1
0
    def initialize(self, _context, includeNativeFrames=True):
        frames = []
        context = _context
        while True:
            if not context:
                break
            frames.append(compose_stack_frame(context))
            context = helpers.get_caller_context(context)
        frames.pop()
        frames.reverse()

        if includeNativeFrames:
            native_frames = []
            for frame in inspect.trace()[1:]:
                location = yaql_expression.YaqlExpressionFilePosition(
                    os.path.abspath(frame[1]), frame[2], -1, -1, -1, -1, -1)
                method = frame[3]
                native_frames.append({
                    'instruction': frame[4][0].strip(),
                    'location': location,
                    'method': method,
                    'class': None
                })
            frames.extend(native_frames)

        self.set_property('frames', frames)
Esempio n. 2
0
    def _log_method(self, context, args, kwargs):
        method = helpers.get_current_method(context)
        param_gen = itertools.chain(
            (six.text_type(arg) for arg in args),
            (u'{0} => {1}'.format(name, value)
             for name, value in six.iteritems(kwargs)))
        params_str = u', '.join(param_gen)
        method_name = '::'.join((method.declaring_type.name, method.name))
        thread_id = helpers.get_current_thread_id()
        caller_str = ''
        caller_ctx = helpers.get_caller_context(context)
        if caller_ctx is not None:
            frame = stack_trace.compose_stack_frame(caller_ctx)
            if frame['location']:
                caller_str = ' called from ' + stack_trace.format_frame(frame)

        LOG.trace(u'{thread}: Begin execution {method}({params}){caller}'
                  .format(thread=thread_id, method=method_name,
                          params=params_str, caller=caller_str))
        try:
            def log_result(result):
                LOG.trace(
                    u'{thread}: End execution {method} with result '
                    u'{result}'.format(
                        thread=thread_id, method=method_name, result=result))
            yield log_result
        except Exception as e:
            LOG.trace(
                u'{thread}: End execution {method} with exception '
                u'{exc}'.format(thread=thread_id, method=method_name, exc=e))
            raise
Esempio n. 3
0
    def _log_method(self, context, args, kwargs):
        method = helpers.get_current_method(context)
        param_gen = itertools.chain(
            (six.text_type(arg) for arg in args),
            (u'{0} => {1}'.format(name, value)
             for name, value in kwargs.items()))
        params_str = u', '.join(param_gen)
        method_name = '::'.join((method.declaring_type.name, method.name))
        thread_id = helpers.get_current_thread_id()
        caller_str = ''
        caller_ctx = helpers.get_caller_context(context)
        if caller_ctx is not None:
            frame = stack_trace.compose_stack_frame(caller_ctx)
            if frame['location']:
                caller_str = ' called from ' + stack_trace.format_frame(frame)

        LOG.trace(u'{thread}: Begin execution {method}({params}){caller}'
                  .format(thread=thread_id, method=method_name,
                          params=params_str, caller=caller_str))
        try:
            def log_result(result):
                LOG.trace(
                    u'{thread}: End execution {method} with result '
                    u'{result}'.format(
                        thread=thread_id, method=method_name, result=result))
            yield log_result
        except Exception as e:
            LOG.trace(
                u'{thread}: End execution {method} with exception '
                u'{exc}'.format(thread=thread_id, method=method_name, exc=e))
            raise
Esempio n. 4
0
    def __init__(self, this, context, include_native_frames=True):
        frames = []
        caller_context = context
        while True:
            if not caller_context:
                break
            frame = compose_stack_frame(caller_context)
            frames.append(frame)
            caller_context = helpers.get_caller_context(caller_context)
        frames.reverse()
        frames.pop()

        if include_native_frames:
            native_frames = []
            for frame in inspect.trace()[1:]:
                location = dsl_types.ExpressionFilePosition(
                    os.path.abspath(frame[1]), frame[2],
                    -1, frame[2], -1)
                method = frame[3]
                native_frames.append({
                    'instruction': frame[4][0].strip(),
                    'location': location,
                    'methodName': method,
                    'typeName': None
                })
            frames.extend(native_frames)

        this.properties.frames = frames
Esempio n. 5
0
    def __init__(self, this, context, include_native_frames=True):
        frames = []
        caller_context = context
        while True:
            if not caller_context:
                break
            frame = compose_stack_frame(caller_context)
            frames.append(frame)
            caller_context = helpers.get_caller_context(caller_context)
        frames.reverse()
        frames.pop()

        if include_native_frames:
            native_frames = []
            for frame in inspect.trace()[1:]:
                location = dsl_types.ExpressionFilePosition(
                    os.path.abspath(frame[1]), frame[2], -1, frame[2], -1)
                method = frame[3]
                native_frames.append({
                    'instruction': frame[4][0].strip(),
                    'location': location,
                    'methodName': method,
                    'typeName': None
                })
            frames.extend(native_frames)

        this.properties.frames = frames
Esempio n. 6
0
    def initialize(self, _context, includeNativeFrames=True):
        frames = []
        context = _context
        while True:
            if not context:
                break
            frames.append(compose_stack_frame(context))
            context = helpers.get_caller_context(context)
        frames.pop()
        frames.reverse()

        if includeNativeFrames:
            native_frames = []
            for frame in inspect.trace()[1:]:
                location = yaql_expression.YaqlExpressionFilePosition(
                    os.path.abspath(frame[1]), frame[2],
                    -1, -1, -1, -1, -1)
                method = frame[3]
                native_frames.append({
                    'instruction': frame[4][0].strip(),
                    'location': location,
                    'method': method,
                    'class': None
                })
            frames.extend(native_frames)

        self.set_property('frames', frames)
Esempio n. 7
0
 def caller(self):
     caller_context = helpers.get_caller_context()
     if caller_context is None:
         return None
     caller = helpers.get_this(caller_context)
     if caller is None:
         return None
     return MuranoObjectInterface(caller)
Esempio n. 8
0
    def setAttr(self, _context, name, value, owner=None):
        if owner is None:
            owner = helpers.get_type(helpers.get_caller_context(_context))
        if not isinstance(owner, murano_class.MuranoClass):
            raise TypeError()

        attribute_store = helpers.get_attribute_store(_context)
        attribute_store.set(self, owner, name, value)
Esempio n. 9
0
 def _get_package(owner, receiver):
     if owner is None:
         if isinstance(receiver, dsl_types.MuranoObjectInterface):
             return receiver.extension._package
         murano_class = helpers.get_type(helpers.get_caller_context())
     else:
         murano_class = owner.type
     return murano_class.package
 def _get_package(owner, receiver):
     if owner is None:
         if isinstance(receiver, dsl_types.MuranoObjectInterface):
             return receiver.extension._package
         murano_class = helpers.get_type(helpers.get_caller_context())
     else:
         murano_class = owner.type
     return murano_class.package
Esempio n. 11
0
    def get_attr(self, this, context, name, default=None, owner=None):
        if owner is None:
            owner = helpers.get_type(helpers.get_caller_context(context))

        attribute_store = helpers.get_attribute_store(context)

        result = attribute_store.get(this.object, owner, name)
        return default if result is None else result
Esempio n. 12
0
 def caller(self):
     caller_context = helpers.get_caller_context()
     if caller_context is None:
         return None
     caller = helpers.get_this(caller_context)
     if caller is None:
         return None
     return MuranoObjectInterface(caller)
Esempio n. 13
0
    def _invoke_method_implementation(self, method, this, context, params):
        body = method.body
        if not body:
            return None

        murano_class = method.murano_class
        current_thread = eventlet.greenthread.getcurrent()
        if not hasattr(current_thread, '_muranopl_thread_marker'):
            thread_marker = current_thread._muranopl_thread_marker = \
                uuid.uuid4().hex
        else:
            thread_marker = current_thread._muranopl_thread_marker

        method_id = id(body)
        this_id = this.object_id

        while True:
            event, marker = self._locks.get((method_id, this_id), (None, None))
            if event:
                if marker == thread_marker:
                    return self._invoke_method_implementation_gt(
                        body, this, params, murano_class, context)
                event.wait()
            else:
                break

        event = eventlet.event.Event()
        self._locks[(method_id, this_id)] = (event, thread_marker)
        # noinspection PyProtectedMember
        method_info = '{0}.{1} ({2})'.format(murano_class.name, method._name,
                                             hash((method_id, this_id)))
        # Prepare caller information
        caller_ctx = helpers.get_caller_context(context)
        if caller_ctx:
            caller_info = trace.compose_stack_frame(caller_ctx)
            LOG.debug('{0}: Begin execution: {1} called from {2}'.format(
                thread_marker, method_info, trace.format_frame(caller_info)))
        else:
            LOG.debug('{0}: Begin execution: {1}'.format(
                thread_marker, method_info))

        try:
            gt = eventlet.spawn(self._invoke_method_implementation_gt, body,
                                this, params, murano_class, context,
                                thread_marker)
            result = gt.wait()
        except Exception as e:
            LOG.debug("{0}: End execution: {1} with exception {2}".format(
                thread_marker, method_info, e))
            raise
        else:
            LOG.debug("{0}: End execution: {1}".format(thread_marker,
                                                       method_info))
        finally:
            del self._locks[(method_id, this_id)]
            event.send()

        return result
Esempio n. 14
0
    def getAttr(self, _context, name, default=None, owner=None):
        if owner is None:
            owner = helpers.get_type(helpers.get_caller_context(_context))
        if not isinstance(owner, murano_class.MuranoClass):
            raise TypeError()

        attribute_store = helpers.get_attribute_store(_context)

        result = attribute_store.get(self, owner, name)
        return default if result is None else result
Esempio n. 15
0
    def _invoke_method_implementation(self, method, this, context, params):
        body = method.body
        if not body:
            return None

        murano_class = method.murano_class
        current_thread = eventlet.greenthread.getcurrent()
        if not hasattr(current_thread, '_muranopl_thread_marker'):
            thread_marker = current_thread._muranopl_thread_marker = \
                uuid.uuid4().hex
        else:
            thread_marker = current_thread._muranopl_thread_marker

        method_id = id(body)
        this_id = this.object_id

        while True:
            event, marker = self._locks.get((method_id, this_id), (None, None))
            if event:
                if marker == thread_marker:
                    return self._invoke_method_implementation_gt(
                        body, this, params, murano_class, context)
                event.wait()
            else:
                break

        event = eventlet.event.Event()
        self._locks[(method_id, this_id)] = (event, thread_marker)
        # noinspection PyProtectedMember
        method_info = '{0}.{1} ({2})'.format(murano_class.name, method._name,
                                             hash((method_id, this_id)))
        # Prepare caller information
        caller_ctx = helpers.get_caller_context(context)
        if caller_ctx:
            caller_info = trace.compose_stack_frame(caller_ctx)
            LOG.debug(
                '{0}: Begin execution: {1} called from {2}'.format(
                    thread_marker, method_info, trace.format_frame(
                        caller_info)))
        else:
            LOG.debug(
                '{0}: Begin execution: {1}'.format(
                    thread_marker, method_info))

        gt = eventlet.spawn(self._invoke_method_implementation_gt, body,
                            this, params, murano_class, context,
                            thread_marker)
        result = gt.wait()
        del self._locks[(method_id, this_id)]
        LOG.debug(
            "{0}: End execution: {1}".format(thread_marker, method_info))
        event.send()
        return result
Esempio n. 16
0
 def convert(self, value, sender, context, function_spec, engine,
             *args, **kwargs):
     context = self._context or context
     if isinstance(value, yaql_expressions.Expression):
         value = value(utils.NO_VALUE, context, engine)
     value = super(MuranoTypeName, self).convert(
         value, sender, context, function_spec, engine)
     if isinstance(value, six.string_types):
         if function_spec.meta.get(constants.META_MURANO_METHOD):
             context = helpers.get_caller_context(context)
         murano_type = helpers.get_type(context)
         value = helpers.get_class(
             murano_type.namespace_resolver.resolve_name(value),
             context).get_reference()
     return value
Esempio n. 17
0
    def initialize(self, _context, includeNativeFrames=True):
        frames = []
        context = _context
        while True:
            if not context:
                break
            instruction = helpers.get_current_instruction(context)
            frames.append({
                'instruction': None if instruction is None
                else str(instruction),

                'location': None if instruction is None
                else instruction.source_file_position,

                'method': helpers.get_current_method(context),
                'class': helpers.get_type(context)
            })
            context = helpers.get_caller_context(context)
        frames.pop()
        frames.reverse()

        if includeNativeFrames:
            class InstructionStub(object):
                def __init__(self, title, position):
                    self._title = title
                    self.source_file_position = position

                def __str__(self):
                    return self._title

            native_frames = []
            for frame in inspect.trace()[1:]:
                info = inspect.getframeinfo(frame[0])
                position = yaql_expression.YaqlExpressionFilePosition(
                    os.path.abspath(info.filename), info.lineno,
                    -1, -1, -1, -1, -1)
                instruction = InstructionStub(
                    info.code_context[0].strip(), position)
                method = info.function
                native_frames.append({
                    'instruction': instruction,
                    'method': method,
                    'class': None
                })
            frames.extend(native_frames)

        self.set_property('frames', frames)
Esempio n. 18
0
    def _log_method(self, context, args, kwargs):
        method = helpers.get_current_method(context)
        param_gen = itertools.chain(
            (six.text_type(arg) for arg in args),
            (u"{0} => {1}".format(name, value) for name, value in six.iteritems(kwargs)),
        )
        params_str = u", ".join(param_gen)
        method_name = "{0}::{1}".format(method.murano_class.name, method.name)
        thread_id = helpers.get_current_thread_id()
        caller_str = ""
        caller_ctx = helpers.get_caller_context(context)
        if caller_ctx is not None:
            frame = stack_trace.compose_stack_frame(caller_ctx)
            if frame["location"]:
                caller_str = " called from " + stack_trace.format_frame(frame)

        LOG.trace(
            u"{thread}: Begin execution {method}({params}){caller}".format(
                thread=thread_id, method=method_name, params=params_str, caller=caller_str
            )
        )
        try:

            def log_result(result):
                LOG.trace(
                    u"{thread}: End execution {method} with result "
                    u"{result}".format(thread=thread_id, method=method_name, result=result)
                )

            yield log_result
        except Exception as e:
            LOG.trace(
                u"{thread}: End execution {method} with exception "
                u"{exc}".format(thread=thread_id, method=method_name, exc=e)
            )
            raise
Esempio n. 19
0
 def caller(self):
     caller_context = helpers.get_caller_context()
     if caller_context is None:
         return None
     return get_this(caller_context)
 def __init__(self, context):
     murano_class = helpers.get_type(helpers.get_caller_context(context))
     self._package = murano_class.package
Esempio n. 21
0
 def caller(self):
     caller_context = helpers.get_caller_context()
     if caller_context is None:
         return None
     return get_this(caller_context)
 def __init__(self, context):
     murano_class = helpers.get_type(helpers.get_caller_context(context))
     self._package = murano_class.package
Esempio n. 23
0
    def set_attr(self, this, context, name, value, owner=None):
        if owner is None:
            owner = helpers.get_type(helpers.get_caller_context(context))

        attribute_store = helpers.get_attribute_store(context)
        attribute_store.set(this.object, owner, name, value)