예제 #1
0
파일: engine.py 프로젝트: lexplua/murano
    def _execute(self, pkg_loader):
        get_plugin_loader().register_in_loader(pkg_loader)

        executor = dsl_executor.MuranoDslExecutor(pkg_loader, ContextManager(),
                                                  self.session)
        try:
            obj = executor.load(self.model)
        except Exception as e:
            return self.exception_result(e, None, '<load>')

        if obj is not None:
            try:
                self._validate_model(obj.object, pkg_loader, executor)
            except Exception as e:
                return self.exception_result(e, obj, '<validate>')

        try:
            LOG.debug('Invoking pre-cleanup hooks')
            self.session.start()
            executor.cleanup(self._model)
        except Exception as e:
            return self.exception_result(e, obj, '<GC>')
        finally:
            LOG.debug('Invoking post-cleanup hooks')
            self.session.finish()
        self._model['ObjectsCopy'] = copy.deepcopy(self._model.get('Objects'))

        action_result = None
        if self.action:
            try:
                LOG.debug('Invoking pre-execution hooks')
                self.session.start()
                try:
                    action_result = self._invoke(executor)
                finally:
                    try:
                        self._model, alive_object_ids = \
                            serializer.serialize_model(obj, executor)
                        LOG.debug('Cleaning up orphan objects')
                        n = executor.cleanup_orphans(alive_object_ids)
                        LOG.debug('{} orphan objects were destroyed'.format(n))

                    except Exception as e:
                        return self.exception_result(e, None, '<model>')
            except Exception as e:
                return self.exception_result(e, obj, self.action['method'])
            finally:
                LOG.debug('Invoking post-execution hooks')
                self.session.finish()

        try:
            action_result = serializer.serialize(action_result, executor)
        except Exception as e:
            return self.exception_result(e, None, '<result>')

        pkg_loader.compact_fixation_table()
        return {'action': {'result': action_result, 'isException': False}}
예제 #2
0
    def _execute(self, pkg_loader):
        get_plugin_loader().register_in_loader(pkg_loader)

        executor = dsl_executor.MuranoDslExecutor(
            pkg_loader, ContextManager(), self.environment)
        try:
            obj = executor.load(self.model)
        except Exception as e:
            return self.exception_result(e, None, '<load>')

        if obj is not None:
            try:
                self._validate_model(obj.object, pkg_loader)
            except Exception as e:
                return self.exception_result(e, obj, '<validate>')

        try:
            LOG.debug('Invoking pre-cleanup hooks')
            self.environment.start()
            executor.cleanup(self._model)
        except Exception as e:
            return self.exception_result(e, obj, '<GC>')
        finally:
            LOG.debug('Invoking post-cleanup hooks')
            self.environment.finish()
        self._model['ObjectsCopy'] = copy.deepcopy(self._model.get('Objects'))

        action_result = None
        if self.action:
            try:
                LOG.debug('Invoking pre-execution hooks')
                self.environment.start()
                try:
                    action_result = self._invoke(executor)
                finally:
                    try:
                        self._model = serializer.serialize_model(obj, executor)
                    except Exception as e:
                        return self.exception_result(e, None, '<model>')
            except Exception as e:
                return self.exception_result(e, obj, self.action['method'])
            finally:
                LOG.debug('Invoking post-execution hooks')
                self.environment.finish()

        try:
            action_result = serializer.serialize(action_result)
        except Exception as e:
            return self.exception_result(e, None, '<result>')

        return {
            'action': {
                'result': action_result,
                'isException': False
            }
        }
예제 #3
0
    def _execute(self, pkg_loader):
        get_plugin_loader().register_in_loader(pkg_loader)

        executor = dsl_executor.MuranoDslExecutor(
            pkg_loader, ContextManager(), self.environment)
        try:
            obj = executor.load(self.model)
        except Exception as e:
            return self.exception_result(e, None, '<load>')

        if obj is not None:
            try:
                self._validate_model(obj.object, pkg_loader)
            except Exception as e:
                return self.exception_result(e, obj, '<validate>')

        try:
            LOG.debug('Invoking pre-cleanup hooks')
            self.environment.start()
            executor.cleanup(self._model)
        except Exception as e:
            return self.exception_result(e, obj, '<GC>')
        finally:
            LOG.debug('Invoking post-cleanup hooks')
            self.environment.finish()
        self._model['ObjectsCopy'] = copy.deepcopy(self._model.get('Objects'))

        action_result = None
        if self.action:
            try:
                LOG.debug('Invoking pre-execution hooks')
                self.environment.start()
                try:
                    action_result = self._invoke(executor)
                finally:
                    try:
                        self._model = serializer.serialize_model(obj, executor)
                    except Exception as e:
                        return self.exception_result(e, None, '<model>')
            except Exception as e:
                return self.exception_result(e, obj, self.action['method'])
            finally:
                LOG.debug('Invoking post-execution hooks')
                self.environment.finish()

        try:
            action_result = serializer.serialize(action_result)
        except Exception as e:
            return self.exception_result(e, None, '<result>')

        return {
            'action': {
                'result': action_result,
                'isException': False
            }
        }
예제 #4
0
파일: engine.py 프로젝트: schaertelr/murano
    def _execute(self, pkg_loader):
        class_loader = package_class_loader.PackageClassLoader(pkg_loader)
        system_objects.register(class_loader, pkg_loader)
        get_plugin_loader().register_in_loader(class_loader)

        exc = executor.MuranoDslExecutor(class_loader, self.environment)
        obj = exc.load(self.model)

        self._validate_model(obj, self.action, class_loader)
        action_result = None
        exception = None
        exception_traceback = None

        try:
            LOG.info(_LI('Invoking pre-cleanup hooks'))
            self.environment.start()
            exc.cleanup(self._model)
        except Exception as e:
            exception = e
            exception_traceback = TaskExecutor._log_exception(e, obj, '<GC>')
        finally:
            LOG.info(_LI('Invoking post-cleanup hooks'))
            self.environment.finish()

        if exception is None and self.action:
            try:
                LOG.info(_LI('Invoking pre-execution hooks'))
                self.environment.start()
                action_result = self._invoke(exc)
            except Exception as e:
                exception = e
                exception_traceback = TaskExecutor._log_exception(
                    e, obj, self.action['method'])
            finally:
                LOG.info(_LI('Invoking post-execution hooks'))
                self.environment.finish()

        model = serializer.serialize_model(obj, exc)
        model['SystemData'] = self._environment.system_attributes
        result = {
            'model': model,
            'action': {
                'result': None,
                'isException': False
            }
        }
        if exception is not None:
            result['action'] = TaskExecutor.exception_result(
                exception, exception_traceback)
        else:
            result['action']['result'] = serializer.serialize_object(
                action_result)

        return result
예제 #5
0
파일: engine.py 프로젝트: finalbro/murano
    def _execute(self, pkg_loader):
        class_loader = package_class_loader.PackageClassLoader(pkg_loader)
        system_objects.register(class_loader, pkg_loader)
        get_plugin_loader().register_in_loader(class_loader)

        exc = executor.MuranoDslExecutor(class_loader, self.environment)
        obj = exc.load(self.model)

        self._validate_model(obj, self.action, class_loader)
        action_result = None
        exception = None
        exception_traceback = None
        try:
            LOG.info(_LI('Invoking pre-execution hooks'))
            self.environment.start()
            # Skip execution of action in case no action is provided.
            # Model will be just loaded, cleaned-up and unloaded.
            # Most of the time this is used for deletion of environments.
            if self.action:
                action_result = self._invoke(exc)
        except Exception as e:
            exception = e
            if isinstance(e, dsl_exception.MuranoPlException):
                LOG.error('\n' + e.format(prefix='  '))
            else:
                exception_traceback = traceback.format_exc()
                LOG.exception(
                    _LE("Exception %(exc)s occured"
                        " during invocation of %(method)s"),
                    {'exc': e, 'method': self.action['method']})
            reporter = status_reporter.StatusReporter()
            reporter.initialize(obj)
            reporter.report_error(obj, str(e))
        finally:
            LOG.info(_LI('Invoking post-execution hooks'))
            self.environment.finish()

        model = serializer.serialize_model(obj, exc)
        model['SystemData'] = self._environment.system_attributes
        result = {
            'model': model,
            'action': {
                'result': None,
                'isException': False
            }
        }
        if exception is not None:
            result['action'] = TaskExecutor.exception_result(
                exception, exception_traceback)
        else:
            result['action']['result'] = serializer.serialize_object(
                action_result)

        return result
예제 #6
0
 def finalize(self, model_root=None):
     # NOTE(ksnihyr): should be no-except
     try:
         if model_root:
             used_objects = serializer.collect_objects(model_root)
             self.object_store.prepare_finalize(used_objects)
             model = serializer.serialize_model(model_root, self)
             self.object_store.finalize()
         else:
             model = None
             self.object_store.prepare_finalize(None)
             self.object_store.finalize()
         self._static_properties.clear()
         return model
     except Exception as e:
         LOG.exception(
             "Exception %s occurred"
             " during MuranoDslExecutor finalization", e)
         return None
예제 #7
0
    def _execute(self, pkg_loader):
        class_loader = package_class_loader.PackageClassLoader(pkg_loader)
        system_objects.register(class_loader, pkg_loader)
        get_plugin_loader().register_in_loader(class_loader)

        exc = executor.MuranoDslExecutor(class_loader, self.environment)
        obj = exc.load(self.model)

        self._validate_model(obj, self.action, class_loader)
        action_result = None
        exception = None
        exception_traceback = None

        try:
            LOG.info(_LI('Invoking pre-cleanup hooks'))
            self.environment.start()
            exc.cleanup(self._model)
        except Exception as e:
            exception = e
            exception_traceback = TaskExecutor._log_exception(e, obj, '<GC>')
        finally:
            LOG.info(_LI('Invoking post-cleanup hooks'))
            self.environment.finish()

        if exception is None and self.action:
            try:
                LOG.info(_LI('Invoking pre-execution hooks'))
                self.environment.start()
                action_result = self._invoke(exc)
            except Exception as e:
                exception = e
                exception_traceback = TaskExecutor._log_exception(
                    e, obj, self.action['method'])
            finally:
                LOG.info(_LI('Invoking post-execution hooks'))
                self.environment.finish()

        model = serializer.serialize_model(obj, exc)
        model['SystemData'] = self._environment.system_attributes
        result = {
            'model': model,
            'action': {
                'result': None,
                'isException': False
            }
        }
        if exception is not None:
            result['action'] = TaskExecutor.exception_result(
                exception, exception_traceback)
            # NOTE(kzaitsev): Exception here means that it happened during
            # cleanup. ObjectsCopy and Attributes would be empty if obj
            # is empty. This would cause failed env to be deleted.
            # Therefore restore these attrs from self._model
            for attr in ['ObjectsCopy', 'Attributes']:
                if not model.get(attr):
                    model[attr] = self._model[attr]
        else:
            result['action']['result'] = serializer.serialize_object(
                action_result)

        return result
예제 #8
0
 def serialized_model(self):
     return serializer.serialize_model(self._root, self.executor)
예제 #9
0
파일: runner.py 프로젝트: ldreamke/murano
 def serialized_model(self):
     return serializer.serialize_model(self._root, self.executor)
예제 #10
0
    def _execute(self, pkg_loader):
        get_plugin_loader().register_in_loader(pkg_loader)

        executor = dsl_executor.MuranoDslExecutor(
            pkg_loader, ContextManager(), self.session)
        try:
            obj = executor.load(self.model)
        except Exception as e:
            return self.exception_result(e, None, '<load>')

        if obj is not None:
            try:
                self._validate_model(obj.object, pkg_loader)
            except Exception as e:
                return self.exception_result(e, obj, '<validate>')

        try:
            LOG.debug('Invoking pre-cleanup hooks')
            self.session.start()
            executor.cleanup(self._model)
        except Exception as e:
            return self.exception_result(e, obj, '<GC>')
        finally:
            LOG.debug('Invoking post-cleanup hooks')
            self.session.finish()
        self._model['ObjectsCopy'] = copy.deepcopy(self._model.get('Objects'))

        action_result = None
        if self.action:
            try:
                LOG.debug('Invoking pre-execution hooks')
                self.session.start()
                try:
                    action_result = self._invoke(executor)
                finally:
                    try:
                        self._model, alive_object_ids = \
                            serializer.serialize_model(obj, executor)
                        LOG.debug('Cleaning up orphan objects')
                        n = executor.cleanup_orphans(alive_object_ids)
                        LOG.debug('{} orphan objects were destroyed'.format(n))

                    except Exception as e:
                        return self.exception_result(e, None, '<model>')
            except Exception as e:
                return self.exception_result(e, obj, self.action['method'])
            finally:
                LOG.debug('Invoking post-execution hooks')
                self.session.finish()

        try:
            action_result = serializer.serialize(action_result, executor)
        except Exception as e:
            return self.exception_result(e, None, '<result>')

        pkg_loader.compact_fixation_table()
        return {
            'action': {
                'result': action_result,
                'isException': False
            }
        }