Beispiel #1
0
 def payload(__context, __receiver, *args, **kwargs):
     args = tuple(dsl.to_mutable(arg, engine) for arg in args)
     kwargs = dsl.to_mutable(kwargs, engine)
     with helpers.contextual(__context):
         __context[constants.CTX_NAMES_SCOPE] = murano_class
         result = helpers.evaluate(cls(*args, **kwargs), __context)
         __receiver.object.extension = result
Beispiel #2
0
 def extension_payload(__context, __receiver, *args, **kwargs):
     args = tuple(dsl.to_mutable(arg, engine) for arg in args)
     kwargs = dsl.to_mutable(kwargs, engine)
     return helpers.evaluate(
         murano_method.invoke(murano_method.declaring_type,
                              (__receiver, ) + args, kwargs, __context,
                              True), __context)
Beispiel #3
0
 def payload(__context, __receiver, *args, **kwargs):
     args = tuple(dsl.to_mutable(arg, engine) for arg in args)
     kwargs = dsl.to_mutable(kwargs, engine)
     with helpers.contextual(__context):
         __context[constants.CTX_NAMES_SCOPE] = \
             murano_class
         return helpers.evaluate(cls(*args, **kwargs), __context)
Beispiel #4
0
 def extension_payload(__context, __receiver, *args, **kwargs):
     executor = helpers.get_executor(__context)
     args = tuple(dsl.to_mutable(arg, engine) for arg in args)
     kwargs = dsl.to_mutable(kwargs, engine)
     return helpers.evaluate(murano_method.invoke(
         executor, murano_method.declaring_type,
         (__receiver,) + args, kwargs, __context, True), __context)
Beispiel #5
0
def patch_(engine, obj, patch):
    if not isinstance(patch, tuple):
        patch = (patch, )
    patch = dsl.to_mutable(patch, engine)
    patch = jsonpatch.JsonPatch(patch)
    try:
        obj = dsl.to_mutable(obj, engine)
        return patch.apply(obj, in_place=True)
    except jsonpointer.JsonPointerException:
        return obj
Beispiel #6
0
def patch_(engine, obj, patch):
    if not isinstance(patch, tuple):
        patch = (patch,)
    patch = dsl.to_mutable(patch, engine)
    patch = jsonpatch.JsonPatch(patch)
    try:
        obj = dsl.to_mutable(obj, engine)
        return patch.apply(obj, in_place=True)
    except jsonpointer.JsonPointerException:
        return obj
Beispiel #7
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 #8
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 #9
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 #10
0
        def template(engine,
                     value,
                     type_,
                     exclude_properties=None,
                     default_type=None,
                     version_spec=None):
            object_store = helpers.get_object_store()
            passkey = None
            if not default_type:
                default_type = type_
            murano_class = type_.type
            if value is None:
                return None
            if isinstance(value, dsl_types.MuranoObject):
                obj = value
            elif isinstance(value, dsl_types.MuranoObjectInterface):
                obj = value.object
            elif isinstance(value, utils.MappingType):
                passkey = utils.create_marker('<Contract Passkey>')
                if exclude_properties:
                    parsed = helpers.parse_object_definition(
                        value, calling_type, context)
                    props = dsl.to_mutable(parsed['properties'], engine)
                    for p in exclude_properties:
                        helpers.patch_dict(props, p, passkey)
                    parsed['properties'] = props
                    value = helpers.assemble_object_definition(parsed)
                with helpers.thread_local_attribute(
                        constants.TL_CONTRACT_PASSKEY, passkey):
                    with helpers.thread_local_attribute(
                            constants.TL_OBJECTS_DRY_RUN, True):
                        obj = object_store.load(value,
                                                owner,
                                                context=context,
                                                default_type=default_type,
                                                scope_type=calling_type)
            else:
                raise exceptions.ContractViolationException(
                    'Value {0} cannot be represented as class {1}'.format(
                        format_scalar(value), type_))
            if not helpers.is_instance_of(
                    obj, murano_class.name, version_spec
                    or helpers.get_type(root_context)):
                raise exceptions.ContractViolationException(
                    'Object of type {0} is not compatible with '
                    'requested type {1}'.format(obj.type.name, type_))

            with helpers.thread_local_attribute(constants.TL_CONTRACT_PASSKEY,
                                                passkey):
                result = serializer.serialize(obj.real_this,
                                              object_store.executor,
                                              dsl_types.DumpTypes.Mixed)
                if exclude_properties:
                    for p in exclude_properties:
                        helpers.patch_dict(result, p, utils.NO_VALUE)
                return result
Beispiel #11
0
 def transform(self):
     object_store = helpers.get_object_store()
     if self.value is None:
         return None
     if isinstance(self.value, dsl_types.MuranoObject):
         obj = self.value
     elif isinstance(self.value, dsl_types.MuranoObjectInterface):
         obj = self.value.object
     elif isinstance(self.value, utils.MappingType):
         passkey = utils.create_marker('<Contract Passkey>')
         if self.exclude_properties:
             parsed = helpers.parse_object_definition(
                 self.value, self.calling_type, self.context)
             props = dsl.to_mutable(parsed['properties'], self.engine)
             for p in self.exclude_properties:
                 helpers.patch_dict(props, p, passkey)
             parsed['properties'] = props
             value = helpers.assemble_object_definition(parsed)
         else:
             value = self.value
         with helpers.thread_local_attribute(constants.TL_CONTRACT_PASSKEY,
                                             passkey):
             with helpers.thread_local_attribute(
                     constants.TL_OBJECTS_DRY_RUN, True):
                 obj = object_store.load(value,
                                         self.owner,
                                         context=self.context,
                                         default_type=self.default_type,
                                         scope_type=self.calling_type)
                 obj.__passkey__ = passkey
     else:
         raise exceptions.ContractViolationException(
             'Value {0} cannot be represented as class {1}'.format(
                 helpers.format_scalar(self.value), self.type))
     self.value = obj
     return self.validate()
Beispiel #12
0
 def static_payload(__context, __receiver, *args, **kwargs):
     args = tuple(dsl.to_mutable(arg, engine) for arg in args)
     kwargs = dsl.to_mutable(kwargs, engine)
     return helpers.evaluate(
         murano_method.invoke(__receiver, args, kwargs, __context, True),
         __context)
 def payload(__context, __sender, *args, **kwargs):
     assert __sender is None
     args = tuple(dsl.to_mutable(arg, engine) for arg in args)
     kwargs = dsl.to_mutable(kwargs, engine)
     with helpers.contextual(__context):
         return helpers.evaluate(cls(*args, **kwargs), __context)
Beispiel #14
0
 def payload(__context, __sender, *args, **kwargs):
     assert __sender is None
     args = tuple(dsl.to_mutable(arg, engine) for arg in args)
     kwargs = dsl.to_mutable(kwargs, engine)
     with helpers.contextual(__context):
         return cls(*args, **kwargs)
Beispiel #15
0
 def payload(__context, __sender, *args, **kwargs):
     executor = helpers.get_executor(__context)
     args = tuple(dsl.to_mutable(arg, engine) for arg in args)
     kwargs = dsl.to_mutable(kwargs, engine)
     return murano_method.invoke(executor, __sender, args, kwargs,
                                 __context, True)
 def payload(__context, __sender, *args, **kwargs):
     executor = helpers.get_executor(__context)
     args = tuple(dsl.to_mutable(arg, engine) for arg in args)
     kwargs = dsl.to_mutable(kwargs, engine)
     return helpers.evaluate(murano_method.invoke(
         executor, __sender, args, kwargs, __context, True), __context)
Beispiel #17
0
 def static_payload(__context, __receiver, *args, **kwargs):
     args = tuple(dsl.to_mutable(arg, engine) for arg in args)
     kwargs = dsl.to_mutable(kwargs, engine)
     return helpers.evaluate(murano_method.invoke(
         __receiver, args, kwargs, __context, True), __context)