From e87d4d35dd9359970a5db3f6b7be35dfa38a0e41 Mon Sep 17 00:00:00 2001 From: Stan Lagun Date: Sat, 7 Jun 2014 16:06:33 +0400 Subject: [PATCH] Automatically call MuranoPL initialize/destroy methods Implements: blueprint muranopl-auto-call-init-destroy Change-Id: I58f815e7b1ab8301aad101688daae673dd199141 --- meta/io.murano/Classes/Object.yaml | 1 + murano/dsl/executor.py | 6 ++++++ murano/dsl/murano_class.py | 18 ++++++++++-------- murano/dsl/murano_method.py | 3 ++- murano/dsl/object_store.py | 1 + 5 files changed, 20 insertions(+), 9 deletions(-) diff --git a/meta/io.murano/Classes/Object.yaml b/meta/io.murano/Classes/Object.yaml index 1d35eaad..8ea57491 100644 --- a/meta/io.murano/Classes/Object.yaml +++ b/meta/io.murano/Classes/Object.yaml @@ -4,3 +4,4 @@ Name: Object Workflow: initialize: + destroy: diff --git a/murano/dsl/executor.py b/murano/dsl/executor.py index 5130993a..d4087174 100644 --- a/murano/dsl/executor.py +++ b/murano/dsl/executor.py @@ -83,6 +83,12 @@ class MuranoDslExecutor(object): raise Exception('{0} is not an action'.format(method.name)) # TODO (slagun): check method accessibility from murano_class + if not external_call and is_special_method: + LOG.deprecated('initialize/destroy methods are called ' + 'automatically by engine. This call is no-op ' + 'and will become exception in the future') + return None + # restore this from upcast object (no change if there was no upcast) this = this.real_this arguments_scheme = method.arguments_scheme diff --git a/murano/dsl/murano_class.py b/murano/dsl/murano_class.py index 68ddf9fa..d723bc82 100644 --- a/murano/dsl/murano_class.py +++ b/murano/dsl/murano_class.py @@ -130,14 +130,16 @@ class MuranoClass(object): return result[0] def find_all_methods(self, name): - #resolved_name = self._namespace_resolver.resolve_name(name, self.name) - if name in self._methods: - return [self.methods[name]] - if not self._parents: - return [] - return list(reduce( - lambda x, y: x + [t for t in y if t not in x], - [p.find_all_methods(name) for p in self._parents])) + result = [] + queue = collections.deque([self]) + while queue: + c = queue.popleft() + if name in c.methods: + method = c.methods[name] + if method not in result: + result.append(method) + queue.extend(c.parents) + return result def find_property(self, name): types = collections.deque([self]) diff --git a/murano/dsl/murano_method.py b/murano/dsl/murano_method.py index 2efacbd5..d6d0dcef 100644 --- a/murano/dsl/murano_method.py +++ b/murano/dsl/murano_method.py @@ -109,7 +109,8 @@ class MuranoMethod(object): return macros.MethodBlock(body) def __repr__(self): - return 'MuranoMethod({0})'.format(self.name) + return 'MuranoMethod({0}::{1})'.format( + self.murano_class.name, self.name) def invoke(self, executor, this, parameters): return self.murano_class.invoke(self.name, executor, this, parameters) diff --git a/murano/dsl/object_store.py b/murano/dsl/object_store.py index a28e1c93..e550600c 100644 --- a/murano/dsl/object_store.py +++ b/murano/dsl/object_store.py @@ -88,6 +88,7 @@ class ObjectStore(object): if not self.initializing: executor = helpers.get_executor(context) methods = obj.type.find_all_methods('initialize') + methods.reverse() for method in methods: method.invoke(executor, obj, {}) return obj