Repository: incubator-ariatosca
Updated Branches:
  refs/heads/ARIA-185-NullPool-logging-messages-appear-during-execution 
57555fe91 -> 1f093d06f


fix1


Project: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/repo
Commit: 
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/commit/1f093d06
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/1f093d06
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/1f093d06

Branch: refs/heads/ARIA-185-NullPool-logging-messages-appear-during-execution
Commit: 1f093d06ff8ba3ec2d14716ae1d05530c8d0e7f9
Parents: 57555fe
Author: max-orlov <ma...@gigaspaces.com>
Authored: Mon May 22 19:07:37 2017 +0300
Committer: max-orlov <ma...@gigaspaces.com>
Committed: Mon May 22 19:10:13 2017 +0300

----------------------------------------------------------------------
 aria/orchestrator/context/common.py                   |  4 ----
 aria/orchestrator/context/operation.py                | 14 +++++++++++---
 .../orchestrator/execution_plugin/ctx_proxy/server.py |  2 +-
 aria/orchestrator/workflows/executor/process.py       |  4 ++--
 .../execution_plugin/test_ctx_proxy_server.py         |  3 ++-
 tests/orchestrator/workflows/executor/__init__.py     |  5 +++++
 6 files changed, 21 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/1f093d06/aria/orchestrator/context/common.py
----------------------------------------------------------------------
diff --git a/aria/orchestrator/context/common.py 
b/aria/orchestrator/context/common.py
index 3918408..c98e026 100644
--- a/aria/orchestrator/context/common.py
+++ b/aria/orchestrator/context/common.py
@@ -194,7 +194,3 @@ class BaseContext(object):
         variables.setdefault('ctx', self)
         resource_template = jinja2.Template(resource_content)
         return resource_template.render(variables)
-
-    def _teardown_db_resources(self):
-        self.model.log._session.remove()
-        self.model.log._engine.dispose()

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/1f093d06/aria/orchestrator/context/operation.py
----------------------------------------------------------------------
diff --git a/aria/orchestrator/context/operation.py 
b/aria/orchestrator/context/operation.py
index 68a02aa..47ebddb 100644
--- a/aria/orchestrator/context/operation.py
+++ b/aria/orchestrator/context/operation.py
@@ -29,10 +29,11 @@ class BaseOperationContext(BaseContext):
     Context object used during operation creation and execution
     """
 
-    def __init__(self, task_id, actor_id, **kwargs):
+    def __init__(self, task_id, actor_id, instantiated_from_dict=False, 
**kwargs):
         self._task_id = task_id
         self._actor_id = actor_id
         self._thread_local = threading.local()
+        self._instantiated_from_dict = instantiated_from_dict
         logger_level = kwargs.pop('logger_level', None)
         super(BaseOperationContext, self).__init__(**kwargs)
         self._register_logger(task_id=self.task.id, level=logger_level)
@@ -90,14 +91,21 @@ class BaseOperationContext(BaseContext):
         }
 
     @classmethod
-    def deserialize_from_dict(cls, model_storage=None, resource_storage=None, 
**kwargs):
+    def instantiate_from_dict(cls, model_storage=None, resource_storage=None, 
**kwargs):
         if model_storage:
             model_storage = aria.application_model_storage(**model_storage)
         if resource_storage:
             resource_storage = 
aria.application_resource_storage(**resource_storage)
 
-        return cls(model_storage=model_storage, 
resource_storage=resource_storage, **kwargs)
+        return cls(model_storage=model_storage,
+                   resource_storage=resource_storage,
+                   instantiated_from_dict=True,
+                   **kwargs)
 
+    def close(self):
+        if self._instantiated_from_dict:
+            self.model.log._session.remove()
+            self.model.log._engine.dispose()
 
 class NodeOperationContext(BaseOperationContext):
     """

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/1f093d06/aria/orchestrator/execution_plugin/ctx_proxy/server.py
----------------------------------------------------------------------
diff --git a/aria/orchestrator/execution_plugin/ctx_proxy/server.py 
b/aria/orchestrator/execution_plugin/ctx_proxy/server.py
index ef25491..e3496b9 100644
--- a/aria/orchestrator/execution_plugin/ctx_proxy/server.py
+++ b/aria/orchestrator/execution_plugin/ctx_proxy/server.py
@@ -128,7 +128,7 @@ class CtxProxy(object):
         finally:
             # Since this runs in a daemon thread, we need to close the session 
each time we process
             # a request (a new session would be supplied by SQLAlchemy 
scoped_session).
-            # log mapi is chosen randomly.
+            # log mapi is chosen arbitrarily.
             self.ctx.model.log._session.remove()
 
         return result

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/1f093d06/aria/orchestrator/workflows/executor/process.py
----------------------------------------------------------------------
diff --git a/aria/orchestrator/workflows/executor/process.py 
b/aria/orchestrator/workflows/executor/process.py
index 1060aed..b6c8584 100644
--- a/aria/orchestrator/workflows/executor/process.py
+++ b/aria/orchestrator/workflows/executor/process.py
@@ -373,7 +373,7 @@ def _main():
     # See docstring of `remove_mutable_association_listener` for further 
details
     modeling_types.remove_mutable_association_listener()
     try:
-        ctx = 
context_dict['context_cls'].deserialize_from_dict(**context_dict['context'])
+        ctx = 
context_dict['context_cls'].instantiate_from_dict(**context_dict['context'])
     except BaseException as e:
         messenger.failed(exception=e, tracked_changes=None, new_instances=None)
         return
@@ -395,7 +395,7 @@ def _main():
                              new_instances=instrument.new_instances)
         finally:
             instrument.expunge_session()
-            ctx._teardown_db_resources()
+            ctx.close()
 
 if __name__ == '__main__':
     _main()

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/1f093d06/tests/orchestrator/execution_plugin/test_ctx_proxy_server.py
----------------------------------------------------------------------
diff --git a/tests/orchestrator/execution_plugin/test_ctx_proxy_server.py 
b/tests/orchestrator/execution_plugin/test_ctx_proxy_server.py
index 98ceff9..a41f9f0 100644
--- a/tests/orchestrator/execution_plugin/test_ctx_proxy_server.py
+++ b/tests/orchestrator/execution_plugin/test_ctx_proxy_server.py
@@ -136,7 +136,7 @@ class TestCtxProxy(object):
             kwargs=kwargs)
 
     @pytest.fixture
-    def ctx(self):
+    def ctx(self, mocker):
         class MockCtx(object):
             pass
         ctx = MockCtx()
@@ -160,6 +160,7 @@ class TestCtxProxy(object):
         ctx.stub_args = self.stub_args
         ctx.stub_attr = self.StubAttribute()
         ctx.node = self.NodeAttribute(properties)
+        ctx.model = mocker.MagicMock()
         return ctx
 
     @pytest.fixture

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/1f093d06/tests/orchestrator/workflows/executor/__init__.py
----------------------------------------------------------------------
diff --git a/tests/orchestrator/workflows/executor/__init__.py 
b/tests/orchestrator/workflows/executor/__init__.py
index 8ad8edb..fca6247 100644
--- a/tests/orchestrator/workflows/executor/__init__.py
+++ b/tests/orchestrator/workflows/executor/__init__.py
@@ -74,3 +74,8 @@ class MockContext(object):
             return cls(storage=aria.application_model_storage(**kwargs))
         else:
             return cls()
+
+    @staticmethod
+    def close():
+        pass
+

Reply via email to