Use more generic "type" name instead of "murano_class"

Because the're going to be many different types of classes
(like meta-classes) it is reasonable to distinguish murano_class
from a "type", that can refer to any type of class (type)

Change-Id: I05993eb7a37627aaeacbc6c828250791e145d706
This commit is contained in:
Stan Lagun
2016-02-26 00:13:58 +03:00
parent b4d8e93c00
commit 7c200d66f1
24 changed files with 175 additions and 175 deletions

View File

@@ -20,5 +20,5 @@ Properties:
Contract: Contract:
- instruction: $.string() - instruction: $.string()
location: $ location: $
method: $ methodName: $
class: $ typeName: $

View File

@@ -24,7 +24,7 @@ class AttributeStore(object):
@staticmethod @staticmethod
def _get_attribute_key(tagged_object, owner_type, name): def _get_attribute_key(tagged_object, owner_type, name):
if isinstance(owner_type, dsl_types.MuranoTypeReference): if isinstance(owner_type, dsl_types.MuranoTypeReference):
owner_type = owner_type.murano_class owner_type = owner_type.type
if isinstance(tagged_object, dsl_types.MuranoObjectInterface): if isinstance(tagged_object, dsl_types.MuranoObjectInterface):
tagged_object = tagged_object.object tagged_object = tagged_object.object
return tagged_object.object_id, owner_type.name, name return tagged_object.object_id, owner_type.name, name

View File

@@ -30,8 +30,8 @@ class ContextManager(object):
def create_package_context(self, package): def create_package_context(self, package):
return package.context return package.context
def create_class_context(self, murano_class): def create_type_context(self, murano_type):
return murano_class.context return murano_type.context
def create_object_context(self, obj): def create_object_context(self, obj):
return None return None

View File

@@ -204,7 +204,7 @@ class MuranoObjectInterface(dsl_types.MuranoObjectInterface):
if isinstance(type, six.string_types): if isinstance(type, six.string_types):
type = helpers.get_class(type) type = helpers.get_class(type)
elif isinstance(type, dsl_types.MuranoTypeReference): elif isinstance(type, dsl_types.MuranoTypeReference):
type = type.murano_class type = type.type
p = self.owner p = self.owner
while p is not None: while p is not None:
if type.is_compatible(p): if type.is_compatible(p):

View File

@@ -13,7 +13,11 @@
# under the License. # under the License.
class MuranoClass(object): class MuranoType(object):
pass
class MuranoClass(MuranoType):
pass pass
@@ -38,23 +42,23 @@ class MuranoProperty(object):
class MuranoTypeReference(object): class MuranoTypeReference(object):
def __init__(self, murano_class): def __init__(self, murano_type):
self.__murano_class = murano_class self.__murano_type = murano_type
@property @property
def murano_class(self): def type(self):
return self.__murano_class return self.__murano_type
def __repr__(self): def __repr__(self):
return '*' + repr(self.murano_class) return '*' + repr(self.type)
def __eq__(self, other): def __eq__(self, other):
if not isinstance(other, MuranoTypeReference): if not isinstance(other, MuranoTypeReference):
return False return False
return self.murano_class == other.murano_class return self.type == other.type
def __hash__(self): def __hash__(self):
return hash(self.murano_class) return hash(self.type)
class YaqlExpression(object): class YaqlExpression(object):

View File

@@ -75,7 +75,7 @@ class MuranoDslExecutor(object):
if isinstance(this, dsl.MuranoObjectInterface): if isinstance(this, dsl.MuranoObjectInterface):
this = this.object this = this.object
kwargs = utils.filter_parameters_dict(kwargs) kwargs = utils.filter_parameters_dict(kwargs)
runtime_version = method.murano_class.package.runtime_version runtime_version = method.declaring_type.package.runtime_version
yaql_engine = yaql_integration.choose_yaql_engine(runtime_version) yaql_engine = yaql_integration.choose_yaql_engine(runtime_version)
if context is None or not skip_stub: if context is None or not skip_stub:
actions_only = context is None and not method.name.startswith('.') actions_only = context is None and not method.name.startswith('.')
@@ -92,7 +92,7 @@ class MuranoDslExecutor(object):
if method.is_static: if method.is_static:
obj_context = self.create_object_context( obj_context = self.create_object_context(
method.murano_class, context) method.declaring_type, context)
else: else:
obj_context = self.create_object_context(this, context) obj_context = self.create_object_context(this, context)
context = self.create_method_context(obj_context, method) context = self.create_method_context(obj_context, method)
@@ -112,11 +112,11 @@ class MuranoDslExecutor(object):
def call(): def call():
if isinstance(method.body, specs.FunctionDefinition): if isinstance(method.body, specs.FunctionDefinition):
if isinstance(this, dsl_types.MuranoClass): if isinstance(this, dsl_types.MuranoType):
native_this = this.get_reference() native_this = this.get_reference()
else: else:
native_this = dsl.MuranoObjectInterface(this.cast( native_this = dsl.MuranoObjectInterface(this.cast(
method.murano_class), self) method.declaring_type), self)
return method.body( return method.body(
yaql_engine, context, native_this)(*args, **kwargs) yaql_engine, context, native_this)(*args, **kwargs)
else: else:
@@ -136,7 +136,7 @@ class MuranoDslExecutor(object):
def _acquire_method_lock(self, method, this): def _acquire_method_lock(self, method, this):
method_id = id(method) method_id = id(method)
if method.is_static: if method.is_static:
this_id = id(method.murano_class) this_id = id(method.declaring_type)
else: else:
this_id = this.object_id this_id = this.object_id
thread_id = helpers.get_current_thread_id() thread_id = helpers.get_current_thread_id()
@@ -168,7 +168,7 @@ class MuranoDslExecutor(object):
(u'{0} => {1}'.format(name, value) (u'{0} => {1}'.format(name, value)
for name, value in six.iteritems(kwargs))) for name, value in six.iteritems(kwargs)))
params_str = u', '.join(param_gen) params_str = u', '.join(param_gen)
method_name = '{0}::{1}'.format(method.murano_class.name, method.name) method_name = '::'.join((method.declaring_type.name, method.name))
thread_id = helpers.get_current_thread_id() thread_id = helpers.get_current_thread_id()
caller_str = '' caller_str = ''
caller_ctx = helpers.get_caller_context(context) caller_ctx = helpers.get_caller_context(context)
@@ -278,14 +278,14 @@ class MuranoDslExecutor(object):
self.context_manager.create_package_context(package)) self.context_manager.create_package_context(package))
return context return context
def create_class_context(self, murano_class): def create_type_context(self, murano_type):
package_context = self.create_package_context( package_context = self.create_package_context(
murano_class.package) murano_type.package)
context = helpers.link_contexts( context = helpers.link_contexts(
package_context, package_context,
self.context_manager.create_class_context( self.context_manager.create_type_context(
murano_class)).create_child_context() murano_type)).create_child_context()
context[constants.CTX_TYPE] = murano_class context[constants.CTX_TYPE] = murano_type
return context return context
def create_object_context(self, obj, caller_context=None): def create_object_context(self, obj, caller_context=None):
@@ -294,7 +294,7 @@ class MuranoDslExecutor(object):
obj = None obj = None
else: else:
obj_type = obj.type obj_type = obj.type
class_context = self.create_class_context(obj_type) class_context = self.create_type_context(obj_type)
if obj is not None: if obj is not None:
context = helpers.link_contexts( context = helpers.link_contexts(
class_context, self.context_manager.create_object_context( class_context, self.context_manager.create_object_context(

View File

@@ -303,14 +303,14 @@ def traverse(seed, producer=None, track_visited=True):
def cast(obj, murano_class, pov_or_version_spec=None): def cast(obj, murano_class, pov_or_version_spec=None):
if isinstance(obj, dsl_types.MuranoObjectInterface): if isinstance(obj, dsl_types.MuranoObjectInterface):
obj = obj.object obj = obj.object
if isinstance(pov_or_version_spec, dsl_types.MuranoClass): if isinstance(pov_or_version_spec, dsl_types.MuranoType):
pov_or_version_spec = pov_or_version_spec.package pov_or_version_spec = pov_or_version_spec.package
elif isinstance(pov_or_version_spec, six.string_types): elif isinstance(pov_or_version_spec, six.string_types):
pov_or_version_spec = parse_version_spec(pov_or_version_spec) pov_or_version_spec = parse_version_spec(pov_or_version_spec)
if isinstance(murano_class, dsl_types.MuranoTypeReference): if isinstance(murano_class, dsl_types.MuranoTypeReference):
murano_class = murano_class.murano_class murano_class = murano_class.type
if isinstance(murano_class, dsl_types.MuranoClass): if isinstance(murano_class, dsl_types.MuranoType):
if pov_or_version_spec is None: if pov_or_version_spec is None:
pov_or_version_spec = parse_version_spec(murano_class.version) pov_or_version_spec = parse_version_spec(murano_class.version)
murano_class = murano_class.name murano_class = murano_class.name

View File

@@ -72,9 +72,9 @@ class LhsExpression(object):
src.set_property(key, value, root_context) src.set_property(key, value, root_context)
elif isinstance(src, ( elif isinstance(src, (
dsl_types.MuranoTypeReference, dsl_types.MuranoTypeReference,
dsl_types.MuranoClass)): dsl_types.MuranoType)):
if not isinstance(src, dsl_types.MuranoClass): if isinstance(src, dsl_types.MuranoTypeReference):
mc = src.murano_class mc = src.type
else: else:
mc = src mc = src
mc.set_property(key, value, root_context) mc.set_property(key, value, root_context)

View File

@@ -41,10 +41,10 @@ class MethodUsages(object):
class MuranoMethod(dsl_types.MuranoMethod): class MuranoMethod(dsl_types.MuranoMethod):
def __init__(self, murano_class, name, payload, original_name=None): def __init__(self, declaring_type, name, payload, original_name=None):
self._name = name self._name = name
original_name = original_name or name original_name = original_name or name
self._murano_class = weakref.ref(murano_class) self._declaring_type = weakref.ref(declaring_type)
if callable(payload): if callable(payload):
if isinstance(payload, specs.FunctionDefinition): if isinstance(payload, specs.FunctionDefinition):
@@ -55,9 +55,9 @@ class MuranoMethod(dsl_types.MuranoMethod):
self._arguments_scheme = None self._arguments_scheme = None
if any(( if any((
helpers.inspect_is_static( helpers.inspect_is_static(
murano_class.extension_class, original_name), declaring_type.extension_class, original_name),
helpers.inspect_is_classmethod( helpers.inspect_is_classmethod(
murano_class.extension_class, original_name))): declaring_type.extension_class, original_name))):
self._usage = MethodUsages.Static self._usage = MethodUsages.Static
else: else:
self._usage = (self._body.meta.get('usage') or self._usage = (self._body.meta.get('usage') or
@@ -92,8 +92,8 @@ class MuranoMethod(dsl_types.MuranoMethod):
return self._name return self._name
@property @property
def murano_class(self): def declaring_type(self):
return self._murano_class() return self._declaring_type()
@property @property
def arguments_scheme(self): def arguments_scheme(self):
@@ -121,21 +121,21 @@ class MuranoMethod(dsl_types.MuranoMethod):
def __repr__(self): def __repr__(self):
return 'MuranoMethod({0}::{1})'.format( return 'MuranoMethod({0}::{1})'.format(
self.murano_class.name, self.name) self.declaring_type.name, self.name)
def invoke(self, executor, this, args, kwargs, context=None, def invoke(self, executor, this, args, kwargs, context=None,
skip_stub=False): skip_stub=False):
if isinstance(this, dsl.MuranoObjectInterface): if isinstance(this, dsl.MuranoObjectInterface):
this = this.object this = this.object
if this and not self.murano_class.is_compatible(this): if this and not self.declaring_type.is_compatible(this):
raise Exception("'this' must be of compatible type") raise Exception("'this' must be of compatible type")
if not this and not self.is_static: if not this and not self.is_static:
raise Exception("A class instance is required") raise Exception("A class instance is required")
if isinstance(this, dsl_types.MuranoObject): if isinstance(this, dsl_types.MuranoObject):
this = this.cast(self.murano_class) this = this.cast(self.declaring_type)
else: else:
this = self.murano_class this = self.declaring_type
return executor.invoke_method( return executor.invoke_method(
self, this, context, args, kwargs, skip_stub) self, this, context, args, kwargs, skip_stub)
@@ -143,7 +143,7 @@ class MuranoMethod(dsl_types.MuranoMethod):
class MuranoMethodArgument(dsl_types.MuranoMethodArgument, typespec.Spec): class MuranoMethodArgument(dsl_types.MuranoMethodArgument, typespec.Spec):
def __init__(self, murano_method, method_name, arg_name, declaration): def __init__(self, murano_method, method_name, arg_name, declaration):
super(MuranoMethodArgument, self).__init__( super(MuranoMethodArgument, self).__init__(
declaration, murano_method.murano_class) declaration, murano_method.declaring_type)
self._method_name = method_name self._method_name = method_name
self._arg_name = arg_name self._arg_name = arg_name
self._murano_method = weakref.ref(murano_method) self._murano_method = weakref.ref(murano_method)
@@ -153,7 +153,7 @@ class MuranoMethodArgument(dsl_types.MuranoMethodArgument, typespec.Spec):
return super(MuranoMethodArgument, self).validate(*args, **kwargs) return super(MuranoMethodArgument, self).validate(*args, **kwargs)
except exceptions.ContractViolationException as e: except exceptions.ContractViolationException as e:
msg = u'[{0}::{1}({2}{3})] {4}'.format( msg = u'[{0}::{1}({2}{3})] {4}'.format(
self.murano_method.murano_class.name, self.murano_method.declaring_type.name,
self.murano_method.name, self.name, self.murano_method.name, self.name,
e.path, six.text_type(e)) e.path, six.text_type(e))
six.reraise(exceptions.ContractViolationException, six.reraise(exceptions.ContractViolationException,

View File

@@ -184,16 +184,16 @@ class MuranoObject(dsl_types.MuranoObject):
if name in start_type.properties: if name in start_type.properties:
spec = start_type.properties[name] spec = start_type.properties[name]
if spec.usage == typespec.PropertyUsages.Static: if spec.usage == typespec.PropertyUsages.Static:
return spec.murano_class.get_property(name, context) return spec.declaring_type.get_property(name, context)
else: else:
return self.cast(start_type)._get_property_value(name) return self.cast(start_type)._get_property_value(name)
else: else:
try: try:
spec = start_type.find_single_property(name) spec = start_type.find_single_property(name)
if spec.usage == typespec.PropertyUsages.Static: if spec.usage == typespec.PropertyUsages.Static:
return spec.murano_class.get_property(name, context) return spec.declaring_type.get_property(name, context)
else: else:
return self.cast(spec.murano_class).__properties[name] return self.cast(spec.declaring_type).__properties[name]
except exceptions.NoPropertyFound: except exceptions.NoPropertyFound:
if derived: if derived:
return self.cast(caller_class)._get_property_value(name) return self.cast(caller_class)._get_property_value(name)
@@ -229,13 +229,13 @@ class MuranoObject(dsl_types.MuranoObject):
raise exceptions.NoWriteAccessError(name) raise exceptions.NoWriteAccessError(name)
if spec.usage == typespec.PropertyUsages.Static: if spec.usage == typespec.PropertyUsages.Static:
classes_for_static_properties.append(spec.murano_class) classes_for_static_properties.append(spec.declaring_type)
else: else:
default = self.__config.get(name, spec.default) default = self.__config.get(name, spec.default)
default = self.__defaults.get(name, default) default = self.__defaults.get(name, default)
default = helpers.evaluate(default, context) default = helpers.evaluate(default, context)
obj = self.cast(spec.murano_class) obj = self.cast(spec.declaring_type)
values_to_assign.append((obj, spec.validate( values_to_assign.append((obj, spec.validate(
value, self.real_this, value, self.real_this,
self.real_this, context, default=default))) self.real_this, context, default=default)))

View File

@@ -22,8 +22,8 @@ from murano.dsl import constants
from murano.dsl import dsl_types from murano.dsl import dsl_types
from murano.dsl import exceptions from murano.dsl import exceptions
from murano.dsl import helpers from murano.dsl import helpers
from murano.dsl import murano_class
from murano.dsl import murano_object from murano.dsl import murano_object
from murano.dsl import murano_type
from murano.dsl import principal_objects from murano.dsl import principal_objects
from murano.dsl import yaql_integration from murano.dsl import yaql_integration
@@ -88,7 +88,7 @@ class MuranoPackage(dsl_types.MuranoPackage):
def _register_mpl_class(self, data, name=None): def _register_mpl_class(self, data, name=None):
type_obj = self._classes.get(name) type_obj = self._classes.get(name)
if not type_obj: if not type_obj:
type_obj = murano_class.MuranoClass.create(data, self, name) type_obj = murano_type.create(data, self, name)
self._classes[name] = type_obj self._classes[name] = type_obj
return type_obj return type_obj
@@ -131,7 +131,7 @@ class MuranoPackage(dsl_types.MuranoPackage):
self._register_native_class(cls, name) self._register_native_class(cls, name)
else: else:
self._native_load_queue[name] = cls self._native_load_queue[name] = cls
elif isinstance(cls, murano_class.MuranoClass): elif isinstance(cls, dsl_types.MuranoType):
self._classes[cls.name] = cls self._classes[cls.name] = cls
else: else:
self._load_queue[name] = cls self._load_queue[name] = cls

View File

@@ -23,23 +23,23 @@ from murano.dsl import typespec
class MuranoProperty(dsl_types.MuranoProperty, typespec.Spec): class MuranoProperty(dsl_types.MuranoProperty, typespec.Spec):
def __init__(self, murano_class, property_name, declaration): def __init__(self, declaring_type, property_name, declaration):
super(MuranoProperty, self).__init__(declaration, murano_class) super(MuranoProperty, self).__init__(declaration, declaring_type)
self._property_name = property_name self._property_name = property_name
self._murano_class = weakref.ref(murano_class) self._declaring_type = weakref.ref(declaring_type)
def validate(self, *args, **kwargs): def validate(self, *args, **kwargs):
try: try:
return super(MuranoProperty, self).validate(*args, **kwargs) return super(MuranoProperty, self).validate(*args, **kwargs)
except exceptions.ContractViolationException as e: except exceptions.ContractViolationException as e:
msg = u'[{0}.{1}{2}] {3}'.format( msg = u'[{0}.{1}{2}] {3}'.format(
self.murano_class.name, self.name, e.path, six.text_type(e)) self.declaring_type.name, self.name, e.path, six.text_type(e))
six.reraise(exceptions.ContractViolationException, six.reraise(exceptions.ContractViolationException,
msg, sys.exc_info()[2]) msg, sys.exc_info()[2])
@property @property
def murano_class(self): def declaring_type(self):
return self._murano_class() return self._declaring_type()
@property @property
def name(self): def name(self):
@@ -47,4 +47,4 @@ class MuranoProperty(dsl_types.MuranoProperty, typespec.Spec):
def __repr__(self): def __repr__(self):
return 'MuranoProperty({type}::{name})'.format( return 'MuranoProperty({type}::{name})'.format(
type=self.murano_class.name, name=self.name) type=self.declaring_type.name, name=self.name)

View File

@@ -31,61 +31,11 @@ from murano.dsl import namespace_resolver
from murano.dsl import yaql_integration from murano.dsl import yaql_integration
class MuranoClass(dsl_types.MuranoClass): class MuranoType(dsl_types.MuranoType):
def __init__(self, ns_resolver, name, package, parents=None): def __init__(self, ns_resolver, name, package):
self._package = weakref.ref(package)
self._methods = {}
self._namespace_resolver = ns_resolver self._namespace_resolver = ns_resolver
self._name = name self._name = name
self._properties = {} self._package = weakref.ref(package)
self._config = {}
self._extension_class = None
if self._name == constants.CORE_LIBRARY_OBJECT:
self._parents = []
else:
self._parents = parents or [
package.find_class(constants.CORE_LIBRARY_OBJECT)]
self._context = None
self._parent_mappings = self._build_parent_remappings()
self._property_values = {}
@classmethod
def create(cls, data, package, name=None):
namespaces = data.get('Namespaces') or {}
ns_resolver = namespace_resolver.NamespaceResolver(namespaces)
if not name:
name = ns_resolver.resolve_name(str(data['Name']))
parent_class_names = data.get('Extends')
parent_classes = []
if parent_class_names:
if not utils.is_sequence(parent_class_names):
parent_class_names = [parent_class_names]
for parent_name in parent_class_names:
full_name = ns_resolver.resolve_name(str(parent_name))
parent_classes.append(package.find_class(full_name))
type_obj = cls(ns_resolver, name, package, parent_classes)
properties = data.get('Properties') or {}
for property_name, property_spec in six.iteritems(properties):
spec = murano_property.MuranoProperty(
type_obj, property_name, property_spec)
type_obj.add_property(property_name, spec)
methods = data.get('Methods') or data.get('Workflow') or {}
method_mappings = {
'initialize': '.init',
'destroy': '.destroy'
}
for method_name, payload in six.iteritems(methods):
type_obj.add_method(
method_mappings.get(method_name, method_name), payload)
return type_obj
@property @property
def name(self): def name(self):
@@ -99,6 +49,23 @@ class MuranoClass(dsl_types.MuranoClass):
def namespace_resolver(self): def namespace_resolver(self):
return self._namespace_resolver return self._namespace_resolver
class MuranoClass(dsl_types.MuranoClass, MuranoType):
def __init__(self, ns_resolver, name, package, parents=None):
super(MuranoClass, self).__init__(ns_resolver, name, package)
self._methods = {}
self._properties = {}
self._config = {}
self._extension_class = None
if self._name == constants.CORE_LIBRARY_OBJECT:
self._parents = []
else:
self._parents = parents or [
package.find_class(constants.CORE_LIBRARY_OBJECT)]
self._context = None
self._parent_mappings = self._build_parent_remappings()
self._property_values = {}
@property @property
def declared_parents(self): def declared_parents(self):
return self._parents return self._parents
@@ -257,10 +224,9 @@ class MuranoClass(dsl_types.MuranoClass):
def is_compatible(self, obj): def is_compatible(self, obj):
if isinstance(obj, (murano_object.MuranoObject, if isinstance(obj, (murano_object.MuranoObject,
dsl.MuranoObjectInterface)): dsl.MuranoObjectInterface,
dsl_types.MuranoTypeReference)):
obj = obj.type obj = obj.type
elif isinstance(obj, dsl_types.MuranoTypeReference):
obj = obj.murano_class
if obj is self: if obj is self:
return True return True
return any(cls is self for cls in obj.ancestors()) return any(cls is self for cls in obj.ancestors())
@@ -386,14 +352,52 @@ class MuranoClass(dsl_types.MuranoClass):
def get_property(self, name, context): def get_property(self, name, context):
prop = self.find_static_property(name) prop = self.find_static_property(name)
cls = prop.murano_class cls = prop.declaring_type
value = cls._property_values.get(name, prop.default) value = cls._property_values.get(name, prop.default)
return prop.validate(value, cls, None, context) return prop.validate(value, cls, None, context)
def set_property(self, name, value, context): def set_property(self, name, value, context):
prop = self.find_static_property(name) prop = self.find_static_property(name)
cls = prop.murano_class cls = prop.declaring_type
cls._property_values[name] = prop.validate(value, cls, None, context) cls._property_values[name] = prop.validate(value, cls, None, context)
def get_reference(self): def get_reference(self):
return dsl_types.MuranoTypeReference(self) return dsl_types.MuranoTypeReference(self)
def create(data, package, name=None):
namespaces = data.get('Namespaces') or {}
ns_resolver = namespace_resolver.NamespaceResolver(namespaces)
if not name:
name = ns_resolver.resolve_name(str(data['Name']))
parent_class_names = data.get('Extends')
parent_classes = []
if parent_class_names:
if not utils.is_sequence(parent_class_names):
parent_class_names = [parent_class_names]
for parent_name in parent_class_names:
full_name = ns_resolver.resolve_name(str(parent_name))
parent_classes.append(package.find_class(full_name))
type_obj = MuranoClass(ns_resolver, name, package, parent_classes)
properties = data.get('Properties') or {}
for property_name, property_spec in six.iteritems(properties):
spec = murano_property.MuranoProperty(
type_obj, property_name, property_spec)
type_obj.add_property(property_name, spec)
methods = data.get('Methods') or data.get('Workflow') or {}
method_mappings = {
'initialize': '.init',
'destroy': '.destroy'
}
for method_name, payload in six.iteritems(methods):
type_obj.add_method(
method_mappings.get(method_name, method_name), payload)
return type_obj

View File

@@ -49,8 +49,8 @@ class StackTrace(object):
native_frames.append({ native_frames.append({
'instruction': frame[4][0].strip(), 'instruction': frame[4][0].strip(),
'location': location, 'location': location,
'method': method, 'methodName': method,
'class': None 'typeName': None
}) })
frames.extend(native_frames) frames.extend(native_frames)
@@ -72,18 +72,18 @@ def compose_stack_frame(context):
'location': None if instruction is None 'location': None if instruction is None
else instruction.source_file_position, else instruction.source_file_position,
'method': None if method is None else method.name, 'methodName': None if method is None else method.name,
'class': None if method is None else method.murano_class.name 'typeName': None if method is None else method.declaring_type.name
} }
def format_frame(frame, prefix=''): def format_frame(frame, prefix=''):
instruction = frame['instruction'] instruction = frame['instruction']
method = frame['method'] method_name = frame['methodName']
murano_class = frame['class'] type_name = frame['typeName']
location = frame['location'] location = frame['location']
if murano_class: if type_name:
method += ' of class ' + murano_class method_name += ' of type ' + type_name
if location: if location:
args = ( args = (
@@ -91,7 +91,7 @@ def format_frame(frame, prefix=''):
location.start_line, location.start_line,
':' + str(location.start_column) ':' + str(location.start_column)
if location.start_column >= 0 else '', if location.start_column >= 0 else '',
method, method_name,
instruction, instruction,
prefix prefix
) )
@@ -99,7 +99,7 @@ def format_frame(frame, prefix=''):
u'{5} {4}').format(*args) u'{5} {4}').format(*args)
else: else:
return u'{2}File <unknown> in method {0}\n{2} {1}'.format( return u'{2}File <unknown> in method {0}\n{2} {1}'.format(
method, instruction, prefix) method_name, instruction, prefix)
def create_stack_trace(context, include_native_frames=True): def create_stack_trace(context, include_native_frames=True):

View File

@@ -21,7 +21,7 @@ from murano.dsl import dsl_types
from murano.dsl import helpers from murano.dsl import helpers
@specs.yaql_property(dsl_types.MuranoClass) @specs.yaql_property(dsl_types.MuranoType)
@specs.name('name') @specs.name('name')
def class_name(murano_class): def class_name(murano_class):
return murano_class.name return murano_class.name
@@ -93,7 +93,7 @@ def property_usage(murano_property):
@specs.yaql_property(dsl_types.MuranoProperty) @specs.yaql_property(dsl_types.MuranoProperty)
@specs.name('declaring_type') @specs.name('declaring_type')
def property_owner(murano_property): def property_owner(murano_property):
return murano_property.murano_class return murano_property.declaring_type
@specs.name('get_value') @specs.name('get_value')
@@ -103,9 +103,9 @@ def property_owner(murano_property):
@specs.method @specs.method
def property_get_value(context, property_, object_): def property_get_value(context, property_, object_):
if object_ is None: if object_ is None:
return property_.murano_class.get_property( return property_.declaring_type.get_property(
name=property_.name, context=context) name=property_.name, context=context)
return object_.cast(property_.murano_class).get_property( return object_.cast(property_.declaring_type).get_property(
name=property_.name, context=context) name=property_.name, context=context)
@@ -116,10 +116,10 @@ def property_get_value(context, property_, object_):
@specs.method @specs.method
def property_set_value(context, property_, object_, value): def property_set_value(context, property_, object_, value):
if object_ is None: if object_ is None:
property_.murano_class.set_property( property_.declaring_type.set_property(
name=property_.name, value=value, context=context) name=property_.name, value=value, context=context)
else: else:
object_.cast(property_.murano_class).set_property( object_.cast(property_.declaring_type).set_property(
name=property_.name, value=value, context=context) name=property_.name, value=value, context=context)
@@ -139,7 +139,7 @@ def arguments(murano_method):
@specs.yaql_property(dsl_types.MuranoMethod) @specs.yaql_property(dsl_types.MuranoMethod)
@specs.name('declaring_type') @specs.name('declaring_type')
def method_owner(murano_method): def method_owner(murano_method):
return murano_method.murano_class return murano_method.declaring_type
@specs.parameter('method', dsl_types.MuranoMethod) @specs.parameter('method', dsl_types.MuranoMethod)

View File

@@ -156,7 +156,7 @@ class TypeScheme(object):
object_store = this.object_store object_store = this.object_store
if not default_name: if not default_name:
default_name = name default_name = name
murano_class = name.murano_class murano_class = name.type
if value is None: if value is None:
return None return None
if isinstance(value, dsl_types.MuranoObject): if isinstance(value, dsl_types.MuranoObject):
@@ -167,8 +167,8 @@ class TypeScheme(object):
if '?' not in value: if '?' not in value:
new_value = {'?': { new_value = {'?': {
'id': uuid.uuid4().hex, 'id': uuid.uuid4().hex,
'type': default_name.murano_class.name, 'type': default_name.type.name,
'classVersion': str(default_name.murano_class.version) 'classVersion': str(default_name.type.version)
}} }}
new_value.update(value) new_value.update(value)
value = new_value value = new_value

View File

@@ -48,7 +48,7 @@ class Spec(object):
if default is None: if default is None:
default = self.default default = self.default
executor = helpers.get_executor(context) executor = helpers.get_executor(context)
if isinstance(this, dsl_types.MuranoClass): if isinstance(this, dsl_types.MuranoType):
return self._contract( return self._contract(
value, executor.create_object_context(this), value, executor.create_object_context(this),
None, None, default) None, None, default)

View File

@@ -35,7 +35,7 @@ def id_(object_):
@specs.parameter('version_spec', yaqltypes.String(True)) @specs.parameter('version_spec', yaqltypes.String(True))
def cast(context, object_, type__, version_spec=None): def cast(context, object_, type__, version_spec=None):
return helpers.cast( return helpers.cast(
object_, type__.murano_class.name, object_, type__.type.name,
version_spec or helpers.get_type(context)) version_spec or helpers.get_type(context))
@@ -52,7 +52,7 @@ def new(__context, __type_name, __owner=None, __object_name=None, __extra=None,
for key, value in six.iteritems(parameters): for key, value in six.iteritems(parameters):
if utils.is_keyword(key): if utils.is_keyword(key):
new_context[key] = value new_context[key] = value
return __type_name.murano_class.new( return __type_name.type.new(
__owner, object_store, executor, name=__object_name)( __owner, object_store, executor, name=__object_name)(
new_context, **parameters) new_context, **parameters)
@@ -131,7 +131,7 @@ def typeinfo(object_):
@specs.parameter('cls', dsl.MuranoTypeParameter()) @specs.parameter('cls', dsl.MuranoTypeParameter())
@specs.name('typeinfo') @specs.name('typeinfo')
def typeinfo_for_class(cls): def typeinfo_for_class(cls):
return cls.murano_class return cls.type
@specs.parameter('object_', dsl.MuranoObjectParameter(nullable=True)) @specs.parameter('object_', dsl.MuranoObjectParameter(nullable=True))
@@ -150,7 +150,7 @@ def obj_attribution(context, obj, property_name):
@specs.parameter('property_name', yaqltypes.Keyword()) @specs.parameter('property_name', yaqltypes.Keyword())
@specs.name('#operator_.') @specs.name('#operator_.')
def obj_attribution_static(context, cls, property_name): def obj_attribution_static(context, cls, property_name):
return cls.murano_class.get_property(property_name, context) return cls.type.get_property(property_name, context)
@specs.parameter('receiver', dsl.MuranoObjectParameter(decorate=False)) @specs.parameter('receiver', dsl.MuranoObjectParameter(decorate=False))
@@ -159,7 +159,7 @@ def obj_attribution_static(context, cls, property_name):
@specs.name('#operator_.') @specs.name('#operator_.')
def op_dot(context, receiver, expr, operator): def op_dot(context, receiver, expr, operator):
executor = helpers.get_executor(context) executor = helpers.get_executor(context)
type_context = executor.context_manager.create_class_context(receiver.type) type_context = executor.context_manager.create_type_context(receiver.type)
obj_context = executor.context_manager.create_object_context(receiver) obj_context = executor.context_manager.create_object_context(receiver)
ctx2 = helpers.link_contexts( ctx2 = helpers.link_contexts(
helpers.link_contexts(context, type_context), helpers.link_contexts(context, type_context),
@@ -173,8 +173,8 @@ def op_dot(context, receiver, expr, operator):
@specs.name('#operator_.') @specs.name('#operator_.')
def op_dot_static(context, receiver, expr, operator): def op_dot_static(context, receiver, expr, operator):
executor = helpers.get_executor(context) executor = helpers.get_executor(context)
type_context = executor.context_manager.create_class_context( type_context = executor.context_manager.create_type_context(
receiver.murano_class) receiver.type)
ctx2 = helpers.link_contexts(context, type_context) ctx2 = helpers.link_contexts(context, type_context)
return operator(ctx2, receiver, expr) return operator(ctx2, receiver, expr)
@@ -201,7 +201,7 @@ def ns_resolve_unary(context, name):
def is_instance_of(obj, type_): def is_instance_of(obj, type_):
if obj is None: if obj is None:
return False return False
return type_.murano_class.is_compatible(obj) return type_.type.is_compatible(obj)
def register(context, runtime_version): def register(context, runtime_version):

View File

@@ -149,7 +149,7 @@ def get_function_definition(func, murano_method, original_name):
param_type_func = lambda name: _infer_parameter_type( param_type_func = lambda name: _infer_parameter_type(
name, cls.__name__) name, cls.__name__)
body = func body = func
cls = murano_method.murano_class.extension_class cls = murano_method.declaring_type.extension_class
if helpers.inspect_is_method(cls, original_name): if helpers.inspect_is_method(cls, original_name):
body = func.im_func body = func.im_func
if helpers.inspect_is_classmethod(cls, original_name): if helpers.inspect_is_classmethod(cls, original_name):
@@ -162,7 +162,7 @@ def get_function_definition(func, murano_method, original_name):
if helpers.inspect_is_method(cls, original_name): if helpers.inspect_is_method(cls, original_name):
fd.set_parameter( fd.set_parameter(
0, 0,
dsl.MuranoObjectParameter(murano_method.murano_class), dsl.MuranoObjectParameter(murano_method.declaring_type),
overwrite=True) overwrite=True)
if helpers.inspect_is_classmethod(cls, original_name): if helpers.inspect_is_classmethod(cls, original_name):
_remove_first_parameter(fd) _remove_first_parameter(fd)
@@ -220,7 +220,7 @@ def build_wrapper_function_definition(murano_method):
def _build_native_wrapper_function_definition(murano_method): def _build_native_wrapper_function_definition(murano_method):
runtime_version = murano_method.murano_class.package.runtime_version runtime_version = murano_method.declaring_type.package.runtime_version
engine = choose_yaql_engine(runtime_version) engine = choose_yaql_engine(runtime_version)
@specs.method @specs.method
@@ -256,10 +256,10 @@ def _build_mpl_wrapper_function_definition(murano_method):
'__context', yaqltypes.Context(), 0)) '__context', yaqltypes.Context(), 0))
receiver_type = dsl.MuranoObjectParameter( receiver_type = dsl.MuranoObjectParameter(
weakref.proxy(murano_method.murano_class), decorate=False) weakref.proxy(murano_method.declaring_type), decorate=False)
if murano_method.is_static: if murano_method.is_static:
receiver_type = yaqltypes.AnyOf(dsl.MuranoTypeParameter( receiver_type = yaqltypes.AnyOf(dsl.MuranoTypeParameter(
weakref.proxy(murano_method.murano_class)), receiver_type) weakref.proxy(murano_method.declaring_type)), receiver_type)
fd.set_parameter(specs.ParameterDefinition('__receiver', receiver_type, 1)) fd.set_parameter(specs.ParameterDefinition('__receiver', receiver_type, 1))
fd.meta[constants.META_MURANO_METHOD] = murano_method fd.meta[constants.META_MURANO_METHOD] = murano_method

View File

@@ -20,7 +20,6 @@ from yaql.language import yaqltypes
from murano.common import engine from murano.common import engine
from murano.dsl import constants from murano.dsl import constants
from murano.dsl import dsl from murano.dsl import dsl
from murano.dsl import dsl_types
from murano.dsl import helpers from murano.dsl import helpers
from murano.dsl import yaql_integration from murano.dsl import yaql_integration
@@ -52,11 +51,11 @@ class MockContextManager(engine.ContextManager):
new_context = self._create_new_ctx(self.obj_mock_ctx[obj_id]) new_context = self._create_new_ctx(self.obj_mock_ctx[obj_id])
return new_context return new_context
def create_class_context(self, murano_class): def create_type_context(self, murano_type):
original_context = super(MockContextManager, original_context = super(
self).create_class_context(murano_class) MockContextManager, self).create_type_context(murano_type)
mock_context = self._create_new_ctx_for_class(murano_class.name) mock_context = self._create_new_ctx_for_class(murano_type.name)
if mock_context: if mock_context:
result_context = helpers.link_contexts( result_context = helpers.link_contexts(
original_context, mock_context).create_child_context() original_context, mock_context).create_child_context()
@@ -65,8 +64,8 @@ class MockContextManager(engine.ContextManager):
return result_context return result_context
def create_object_context(self, murano_obj): def create_object_context(self, murano_obj):
original_context = super(MockContextManager, original_context = super(
self).create_object_context(murano_obj) MockContextManager, self).create_object_context(murano_obj)
mock_context = self._create_new_ctx_for_obj(murano_obj.type.name) mock_context = self._create_new_ctx_for_obj(murano_obj.type.name)
if mock_context: if mock_context:
@@ -109,11 +108,7 @@ def inject_method_with_str(context, target, target_method,
current_class = helpers.get_type(context) current_class = helpers.get_type(context)
mock_func = current_class.find_single_method(mock_name) mock_func = current_class.find_single_method(mock_name)
original_class = target.type
if isinstance(target, dsl_types.MuranoTypeReference):
original_class = target.murano_class
else:
original_class = target.type
original_function = original_class.find_single_method(target_method) original_function = original_class.find_single_method(target_method)
result_fd = original_function.yaql_function_definition.clone() result_fd = original_function.yaql_function_definition.clone()
@@ -136,10 +131,7 @@ def inject_method_with_str(context, target, target_method,
@specs.parameter('expr', yaqltypes.Lambda(with_context=True)) @specs.parameter('expr', yaqltypes.Lambda(with_context=True))
def inject_method_with_yaql_expr(context, target, target_method, expr): def inject_method_with_yaql_expr(context, target, target_method, expr):
ctx_manager = helpers.get_executor(context).context_manager ctx_manager = helpers.get_executor(context).context_manager
if isinstance(target, dsl_types.MuranoTypeReference): original_class = target.type
original_class = target.murano_class
else:
original_class = target.type
original_function = original_class.find_single_method(target_method) original_function = original_class.find_single_method(target_method)
result_fd = original_function.yaql_function_definition.clone() result_fd = original_function.yaql_function_definition.clone()

View File

@@ -77,5 +77,5 @@ class ResourceManager(object):
return receiver.extension._package return receiver.extension._package
murano_class = helpers.get_type(helpers.get_caller_context()) murano_class = helpers.get_type(helpers.get_caller_context())
else: else:
murano_class = owner.murano_class murano_class = owner.type
return murano_class.package return murano_class.package

View File

@@ -90,7 +90,7 @@ class TestExceptions(test_case.DslTestCase):
matchers.MatchesRegex( matchers.MatchesRegex(
r'.*^ File \".*ExceptionHandling\.yaml\", ' r'.*^ File \".*ExceptionHandling\.yaml\", '
r'line \d+:\d+ in method testStackTrace .*' r'line \d+:\d+ in method testStackTrace .*'
r'of class ExceptionHandling$.*' r'of type ExceptionHandling$.*'
r'^ File \".*{0}\", line {1} ' r'^ File \".*{0}\", line {1} '
r'in method exception_func$.*'.format(filename, line), r'in method exception_func$.*'.format(filename, line),
re.MULTILINE | re.DOTALL)) re.MULTILINE | re.DOTALL))

View File

@@ -17,8 +17,8 @@ import os
import mock import mock
import yaml as yamllib import yaml as yamllib
from murano.dsl import murano_class
from murano.dsl import murano_object from murano.dsl import murano_object
from murano.dsl import murano_type
from murano.dsl import object_store from murano.dsl import object_store
from murano.engine.system import agent from murano.engine.system import agent
from murano.engine.system import resource_manager from murano.engine.system import resource_manager
@@ -33,7 +33,7 @@ class TestExecutionPlan(base.MuranoTestCase):
else: else:
self.yaml_loader = yamllib.SafeLoader self.yaml_loader = yamllib.SafeLoader
self.mock_murano_class = mock.Mock(spec=murano_class.MuranoClass) self.mock_murano_class = mock.Mock(spec=murano_type.MuranoClass)
self.mock_murano_class.name = 'io.murano.system.Agent' self.mock_murano_class.name = 'io.murano.system.Agent'
self.mock_murano_class.declared_parents = [] self.mock_murano_class.declared_parents = []
self.mock_object_store = mock.Mock(spec=object_store.ObjectStore) self.mock_object_store = mock.Mock(spec=object_store.ObjectStore)

View File

@@ -17,7 +17,7 @@ from yaql import specs
from murano.dsl import constants from murano.dsl import constants
from murano.dsl import executor from murano.dsl import executor
from murano.dsl import murano_class from murano.dsl import murano_type
from murano.engine import execution_session from murano.engine import execution_session
from murano.engine import mock_context_manager from murano.engine import mock_context_manager
from murano.engine.system import test_fixture from murano.engine.system import test_fixture
@@ -64,9 +64,9 @@ class MockRunner(runner.Runner):
class TestMockManager(base.MuranoTestCase): class TestMockManager(base.MuranoTestCase):
def test_create_class_context(self): def test_create_type_context(self):
mock_manager = mock_context_manager.MockContextManager() mock_manager = mock_context_manager.MockContextManager()
mock_murano_class = mock.MagicMock(spec=murano_class.MuranoClass) mock_murano_class = mock.MagicMock(spec=murano_type.MuranoClass)
mock_murano_class.name = FIXTURE_CLASS mock_murano_class.name = FIXTURE_CLASS
original_function = mock.MagicMock(spec=specs.FunctionDefinition) original_function = mock.MagicMock(spec=specs.FunctionDefinition)
original_function.is_method = True original_function.is_method = True
@@ -84,7 +84,7 @@ class TestMockManager(base.MuranoTestCase):
mock_manager.class_mock_ctx[FIXTURE_CLASS] = [mock_function] mock_manager.class_mock_ctx[FIXTURE_CLASS] = [mock_function]
result_context = mock_manager.create_class_context(mock_murano_class) result_context = mock_manager.create_type_context(mock_murano_class)
all_functions = result_context.collect_functions(FIXTURE_FUNC) all_functions = result_context.collect_functions(FIXTURE_FUNC)
# Mock function should go first, but result context should contain both # Mock function should go first, but result context should contain both