Beispiel #1
0
 def _execute(self, name, obj, *args, **kwargs):
     try:
         final_args = []
         final_kwargs = {}
         for arg in args:
             if isinstance(arg, object_model.Object):
                 arg = object_model.build_model(arg)
             final_args.append(arg)
         for name, arg in kwargs.items():
             if isinstance(arg, object_model.Object):
                 arg = object_model.build_model(arg)
             final_kwargs[name] = arg
         cls = obj if isinstance(obj, dsl_types.MuranoType) else obj.type
         runtime_version = cls.package.runtime_version
         yaql_engine = yaql_integration.choose_yaql_engine(runtime_version)
         with helpers.with_object_store(self.executor.object_store):
             return dsl.to_mutable(
                 cls.invoke(name, obj, tuple(final_args), final_kwargs),
                 yaql_engine)
     except dsl_exception.MuranoPlException as e:
         if not self.preserve_exception:
             original_exception = getattr(e, 'original_exception', None)
             if original_exception and not isinstance(
                     original_exception, dsl_exception.MuranoPlException):
                 exc_traceback = getattr(e, 'original_traceback',
                                         None) or sys.exc_info()[2]
                 utils.reraise(type(original_exception), original_exception,
                               exc_traceback)
         raise
Beispiel #2
0
 def _execute(self, name, object_id, *args, **kwargs):
     obj = self.executor.object_store.get(object_id)
     try:
         final_args = []
         final_kwargs = {}
         for arg in args:
             if isinstance(arg, object_model.Object):
                 arg = object_model.build_model(arg)
             final_args.append(arg)
         for name, arg in kwargs.iteritems():
             if isinstance(arg, object_model.Object):
                 arg = object_model.build_model(arg)
             final_kwargs[name] = arg
         runtime_version = obj.type.package.runtime_version
         yaql_engine = yaql_integration.choose_yaql_engine(runtime_version)
         return dsl.to_mutable(
             obj.type.invoke(name, self.executor, obj, tuple(final_args), final_kwargs), yaql_engine
         )
     except dsl_exception.MuranoPlException as e:
         if not self.preserve_exception:
             original_exception = getattr(e, "original_exception", None)
             if original_exception and not isinstance(original_exception, dsl_exception.MuranoPlException):
                 exc_traceback = getattr(e, "original_traceback", None) or sys.exc_info()[2]
                 raise type(original_exception), original_exception, exc_traceback
         raise
Beispiel #3
0
 def _execute(self, name, object_id, *args, **kwargs):
     obj = self.executor.object_store.get(object_id)
     try:
         final_args = []
         final_kwargs = {}
         for arg in args:
             if isinstance(arg, object_model.Object):
                 arg = object_model.build_model(arg)
             final_args.append(arg)
         for name, arg in six.iteritems(kwargs):
             if isinstance(arg, object_model.Object):
                 arg = object_model.build_model(arg)
             final_kwargs[name] = arg
         runtime_version = obj.type.package.runtime_version
         yaql_engine = yaql_integration.choose_yaql_engine(runtime_version)
         return dsl.to_mutable(obj.type.invoke(
             name, self.executor, obj, tuple(final_args), final_kwargs),
             yaql_engine)
     except dsl_exception.MuranoPlException as e:
         if not self.preserve_exception:
             original_exception = getattr(e, 'original_exception', None)
             if original_exception and not isinstance(
                     original_exception, dsl_exception.MuranoPlException):
                 exc_traceback = getattr(
                     e, 'original_traceback', None) or sys.exc_info()[2]
                 six.reraise(
                     type(original_exception),
                     original_exception,
                     exc_traceback)
         raise
Beispiel #4
0
    def invoke_method(self,
                      method,
                      this,
                      context,
                      args,
                      kwargs,
                      skip_stub=False):
        if isinstance(this, dsl.MuranoObjectInterface):
            this = this.object
        kwargs = helpers.filter_parameters_dict(kwargs)
        runtime_version = method.murano_class.package.runtime_version
        yaql_engine = yaql_integration.choose_yaql_engine(runtime_version)
        if context is None or not skip_stub:
            actions_only = context is None and not method.name.startswith('.')
            method_context = self.create_method_context(
                self.create_object_context(this, context), method)
            method_context[constants.CTX_SKIP_FRAME] = True
            method_context[constants.CTX_ACTIONS_ONLY] = actions_only
            return method.yaql_function_definition(yaql_engine, method_context,
                                                   this.real_this)(*args,
                                                                   **kwargs)

        if (context[constants.CTX_ACTIONS_ONLY]
                and method.usage != murano_method.MethodUsages.Action):
            raise Exception('{0} is not an action'.format(method.name))

        context = self.create_method_context(
            self.create_object_context(this, context), method)
        this = this.real_this

        if method.arguments_scheme is not None:
            args, kwargs = self._canonize_parameters(method.arguments_scheme,
                                                     args, kwargs)

        with self._acquire_method_lock(method, this):
            for i, arg in enumerate(args, 2):
                context[str(i)] = arg
            for key, value in kwargs.iteritems():
                context[key] = value

            def call():
                if isinstance(method.body, specs.FunctionDefinition):
                    native_this = this.cast(method.murano_class).extension
                    return method.body(yaql_engine, context,
                                       native_this)(*args, **kwargs)
                else:
                    return (None if method.body is None else
                            method.body.execute(context))

            if (not isinstance(method.body, specs.FunctionDefinition)
                    or not method.body.meta.get(constants.META_NO_TRACE)):
                with self._log_method(context, args, kwargs) as log:
                    result = call()
                    log(result)
                    return result
            else:
                return call()
Beispiel #5
0
    def _invoke_method(self, method, this, context, args, kwargs,
                       skip_stub=False):
        if isinstance(this, dsl.MuranoObjectInterface):
            this = this.object
        kwargs = utils.filter_parameters_dict(kwargs)
        runtime_version = method.murano_class.package.runtime_version
        yaql_engine = yaql_integration.choose_yaql_engine(runtime_version)
        if context is None or not skip_stub:
            actions_only = context is None and not method.name.startswith('.')
            method_context = self.create_method_context(
                self.create_object_context(this, context), method)
            method_context[constants.CTX_SKIP_FRAME] = True
            method_context[constants.CTX_ACTIONS_ONLY] = actions_only
            return method.yaql_function_definition(
                yaql_engine, method_context, this.real_this)(*args, **kwargs)

        if (context[constants.CTX_ACTIONS_ONLY] and method.usage !=
                murano_method.MethodUsages.Action):
            raise Exception('{0} is not an action'.format(method.name))

        context = self.create_method_context(
            self.create_object_context(this, context), method)

        if isinstance(this, dsl_types.MuranoObject):
            this = this.real_this

        if method.arguments_scheme is not None:
            args, kwargs = self._canonize_parameters(
                method.arguments_scheme, args, kwargs)

        with self._acquire_method_lock(method, this):
            for i, arg in enumerate(args, 2):
                context[str(i)] = arg
            for key, value in six.iteritems(kwargs):
                context[key] = value

            def call():
                if isinstance(method.body, specs.FunctionDefinition):
                    native_this = this.cast(
                        method.murano_class).extension
                    return method.body(
                        yaql_engine, context, native_this)(*args, **kwargs)
                else:
                    return (None if method.body is None
                            else method.body.execute(context))

            if (not isinstance(method.body, specs.FunctionDefinition) or
                    not method.body.meta.get(constants.META_NO_TRACE)):
                with self._log_method(context, args, kwargs) as log:
                    result = call()
                    log(result)
                    return result
            else:
                return call()
Beispiel #6
0
    def invoke_method(self, method, this, context, args, kwargs,
                      skip_stub=False):
        if isinstance(this, dsl.MuranoObjectInterface):
            this = this.object
        kwargs = utils.filter_parameters_dict(kwargs)
        runtime_version = method.declaring_type.package.runtime_version
        yaql_engine = yaql_integration.choose_yaql_engine(runtime_version)
        if context is None or not skip_stub:
            actions_only = context is None and not method.name.startswith('.')
            method_context = self.create_method_context(
                self.create_object_context(this, context), method)
            method_context[constants.CTX_SKIP_FRAME] = True
            method_context[constants.CTX_ACTIONS_ONLY] = actions_only

            stub = method.static_stub if isinstance(
                this, dsl_types.MuranoType) else method.instance_stub
            if stub is None:
                raise ValueError(
                    'Method {0} cannot be called on receiver {1}'.format(
                        method, this))

            real_this = this.real_this if isinstance(
                this, dsl_types.MuranoObject) else this.get_reference()
            return stub(yaql_engine, method_context, real_this)(
                *args, **kwargs)

        if context[constants.CTX_ACTIONS_ONLY] and not method.is_action:
            raise dsl_exceptions.MethodNotExposed(
                '{0} is not an action'.format(method.name))

        if method.is_static:
            obj_context = self.create_object_context(
                method.declaring_type, context)
        else:
            obj_context = self.create_object_context(this, context)
        context = self.create_method_context(obj_context, method)

        if isinstance(this, dsl_types.MuranoObject):
            this = this.real_this

        if method.arguments_scheme is not None:
            args, kwargs = self._canonize_parameters(
                method.arguments_scheme, args, kwargs, method.name, this)

        this_lock = this
        arg_values_for_lock = {}
        method_meta = [m for m in method.get_meta(context)
                       if m.type.name == ('io.murano.metadata.'
                                          'engine.Synchronize')]
        if method_meta:
            method_meta = method_meta[0]

        if method_meta:
            if not method_meta.get_property('onThis', context):
                this_lock = None
            for arg_name in method_meta.get_property('onArgs', context):
                arg_val = kwargs.get(arg_name)
                if arg_val is not None:
                    arg_values_for_lock[arg_name] = arg_val

        arg_values_for_lock = utils.filter_parameters_dict(arg_values_for_lock)

        with self._acquire_method_lock(method, this_lock, arg_values_for_lock):
            for i, arg in enumerate(args, 2):
                context[str(i)] = arg
            for key, value in six.iteritems(kwargs):
                context[key] = value

            def call():
                if isinstance(method.body, specs.FunctionDefinition):
                    if isinstance(this, dsl_types.MuranoType):
                        native_this = this.get_reference()
                    else:
                        native_this = dsl.MuranoObjectInterface(this.cast(
                            method.declaring_type))
                    return method.body(
                        yaql_engine, context, native_this)(*args, **kwargs)
                else:
                    context[constants.CTX_NAMES_SCOPE] = \
                        method.declaring_type
                    return (None if method.body is None
                            else method.body.execute(context))

            if (not isinstance(method.body, specs.FunctionDefinition) or
                    not method.body.meta.get(constants.META_NO_TRACE)):
                with self._log_method(context, args, kwargs) as log:
                    result = call()
                    log(result)
                    return result
            else:
                return call()
Beispiel #7
0
    def _invoke_method(self,
                       method,
                       this,
                       context,
                       args,
                       kwargs,
                       skip_stub=False):
        if isinstance(this, dsl.MuranoObjectInterface):
            this = this.object
        kwargs = utils.filter_parameters_dict(kwargs)
        runtime_version = method.declaring_type.package.runtime_version
        yaql_engine = yaql_integration.choose_yaql_engine(runtime_version)
        if context is None or not skip_stub:
            actions_only = context is None and not method.name.startswith('.')
            method_context = self.create_method_context(
                self.create_object_context(this, context), method)
            method_context[constants.CTX_SKIP_FRAME] = True
            method_context[constants.CTX_ACTIONS_ONLY] = actions_only

            stub = method.static_stub if isinstance(
                this, dsl_types.MuranoType) else method.instance_stub
            if stub is None:
                raise ValueError(
                    'Method {0} cannot be called on receiver {1}'.format(
                        method, this))

            return stub(yaql_engine, method_context, this.real_this)(*args,
                                                                     **kwargs)

        if (context[constants.CTX_ACTIONS_ONLY]
                and method.usage != dsl_types.MethodUsages.Action):
            raise Exception('{0} is not an action'.format(method.name))

        if method.is_static:
            obj_context = self.create_object_context(method.declaring_type,
                                                     context)
        else:
            obj_context = self.create_object_context(this, context)
        context = self.create_method_context(obj_context, method)

        if isinstance(this, dsl_types.MuranoObject):
            this = this.real_this

        if method.arguments_scheme is not None:
            args, kwargs = self._canonize_parameters(method.arguments_scheme,
                                                     args, kwargs)

        with self._acquire_method_lock(method, this):
            for i, arg in enumerate(args, 2):
                context[str(i)] = arg
            for key, value in six.iteritems(kwargs):
                context[key] = value

            def call():
                if isinstance(method.body, specs.FunctionDefinition):
                    if isinstance(this, dsl_types.MuranoType):
                        native_this = this.get_reference()
                    else:
                        native_this = dsl.MuranoObjectInterface(
                            this.cast(method.declaring_type), self)
                    return method.body(yaql_engine, context,
                                       native_this)(*args, **kwargs)
                else:
                    context[constants.CTX_NAMES_SCOPE] = \
                        method.declaring_type
                    return (None if method.body is None else
                            method.body.execute(context))

            if (not isinstance(method.body, specs.FunctionDefinition)
                    or not method.body.meta.get(constants.META_NO_TRACE)):
                with self._log_method(context, args, kwargs) as log:
                    result = call()
                    log(result)
                    return result
            else:
                return call()
Beispiel #8
0
    def invoke_method(self, method, this, context, args, kwargs,
                      skip_stub=False, invoke_action=True):
        if isinstance(this, dsl.MuranoObjectInterface):
            this = this.object
        kwargs = utils.filter_parameters_dict(kwargs)
        runtime_version = method.declaring_type.package.runtime_version
        yaql_engine = yaql_integration.choose_yaql_engine(runtime_version)
        if context is None or not skip_stub:
            actions_only = (context is None and not method.name.startswith('.')
                            and invoke_action)
            method_context = self.create_method_context(
                self.create_object_context(this, context), method)
            method_context[constants.CTX_SKIP_FRAME] = True
            method_context[constants.CTX_ACTIONS_ONLY] = actions_only

            stub = method.static_stub if isinstance(
                this, dsl_types.MuranoType) else method.instance_stub
            if stub is None:
                raise ValueError(
                    'Method {0} cannot be called on receiver {1}'.format(
                        method, this))

            real_this = this.real_this if isinstance(
                this, dsl_types.MuranoObject) else this.get_reference()
            return stub(yaql_engine, method_context, real_this)(
                *args, **kwargs)

        if context[constants.CTX_ACTIONS_ONLY] and not method.is_action:
            raise dsl_exceptions.MethodNotExposed(
                '{0} is not an action'.format(method.name))

        if method.is_static:
            obj_context = self.create_object_context(
                method.declaring_type, context)
        else:
            obj_context = self.create_object_context(this, context)
        context = self.create_method_context(obj_context, method)

        if isinstance(this, dsl_types.MuranoObject):
            if this.destroyed:
                raise dsl_exceptions.ObjectDestroyedError(this)
            this = this.real_this

        if method.arguments_scheme is not None:
            args, kwargs = self._canonize_parameters(
                method.arguments_scheme, args, kwargs, method.name, this)

        this_lock = this
        arg_values_for_lock = {}
        method_meta = [m for m in method.get_meta(context)
                       if m.type.name == ('io.murano.metadata.'
                                          'engine.Synchronize')]
        if method_meta:
            method_meta = method_meta[0]

        if method_meta:
            if not method_meta.get_property('onThis', context):
                this_lock = None
            for arg_name in method_meta.get_property('onArgs', context):
                arg_val = kwargs.get(arg_name)
                if arg_val is not None:
                    arg_values_for_lock[arg_name] = arg_val

        arg_values_for_lock = utils.filter_parameters_dict(arg_values_for_lock)

        with self._acquire_method_lock(method, this_lock, arg_values_for_lock):
            for i, arg in enumerate(args, 2):
                context[str(i)] = arg
            for key, value in kwargs.items():
                context[key] = value

            def call():
                if isinstance(method.body, specs.FunctionDefinition):
                    if isinstance(this, dsl_types.MuranoType):
                        native_this = this.get_reference()
                    else:
                        native_this = dsl.MuranoObjectInterface(this.cast(
                            method.declaring_type))
                    return method.body(
                        yaql_engine, context, native_this)(*args, **kwargs)
                else:
                    context[constants.CTX_NAMES_SCOPE] = \
                        method.declaring_type
                    return (None if method.body is None
                            else method.body.execute(context))

            if (not isinstance(method.body, specs.FunctionDefinition) or
                    not method.body.meta.get(constants.META_NO_TRACE)):
                with self._log_method(context, args, kwargs) as log:
                    result = call()
                    log(result)
                    return result
            else:
                return call()