You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ariatosca.apache.org by mx...@apache.org on 2017/06/05 12:31:33 UTC

incubator-ariatosca git commit: review 1 fixups

Repository: incubator-ariatosca
Updated Branches:
  refs/heads/ARIA-262-Inconsistent-node-attributes-behavior 94c6063ad -> b3abdce5e


review 1 fixups


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

Branch: refs/heads/ARIA-262-Inconsistent-node-attributes-behavior
Commit: b3abdce5e17fe33fb35f92da0c39699e2bdc7d0c
Parents: 94c6063
Author: max-orlov <ma...@gigaspaces.com>
Authored: Mon Jun 5 15:29:42 2017 +0300
Committer: max-orlov <ma...@gigaspaces.com>
Committed: Mon Jun 5 15:29:42 2017 +0300

----------------------------------------------------------------------
 aria/orchestrator/decorators.py              |  8 ++++----
 aria/storage/api.py                          | 11 ++++++++++-
 aria/storage/collection_instrumentation.py   |  4 +++-
 aria/storage/core.py                         | 13 ++++++++-----
 aria/storage/sql_mapi.py                     |  3 ++-
 aria/utils/validation.py                     |  2 +-
 tests/orchestrator/context/test_operation.py |  2 +-
 7 files changed, 29 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/b3abdce5/aria/orchestrator/decorators.py
----------------------------------------------------------------------
diff --git a/aria/orchestrator/decorators.py b/aria/orchestrator/decorators.py
index 4622aef..80f6962 100644
--- a/aria/orchestrator/decorators.py
+++ b/aria/orchestrator/decorators.py
@@ -48,7 +48,7 @@ def workflow(func=None, suffix_template=''):
 
         workflow_parameters.setdefault('ctx', ctx)
         workflow_parameters.setdefault('graph', task_graph.TaskGraph(workflow_name))
-        validate_function_arguments(func, **workflow_parameters)
+        validate_function_arguments(func, workflow_parameters)
         with context.workflow.current.push(ctx):
             func(**workflow_parameters)
         return workflow_parameters['graph']
@@ -68,13 +68,13 @@ def operation(func=None, toolbelt=False, suffix_template='', logging_handlers=No
 
     @wraps(func)
     def _wrapper(**func_kwargs):
-        ctx = func_kwargs.pop('ctx')
+        ctx = func_kwargs['ctx']
         if toolbelt:
             operation_toolbelt = context.toolbelt(ctx)
             func_kwargs.setdefault('toolbelt', operation_toolbelt)
-        validate_function_arguments(func, ctx=ctx, **func_kwargs)
+        validate_function_arguments(func, func_kwargs)
         with ctx.model.instrument(*ctx.INSTRUMENTATION_FIELDS):
-            return func(ctx=ctx, **func_kwargs)
+            return func(**func_kwargs)
     return _wrapper
 
 

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/b3abdce5/aria/storage/api.py
----------------------------------------------------------------------
diff --git a/aria/storage/api.py b/aria/storage/api.py
index 1887ee3..77b39ab 100644
--- a/aria/storage/api.py
+++ b/aria/storage/api.py
@@ -15,6 +15,7 @@
 """
 General storage API
 """
+import threading
 
 
 class StorageAPI(object):
@@ -45,7 +46,15 @@ class ModelAPI(StorageAPI):
         super(ModelAPI, self).__init__(**kwargs)
         self._model_cls = model_cls
         self._name = name or model_cls.__modelname__
-        self._instrumentation = []
+        self._thread_local = threading.local()
+        self._thread_local._instrumentation = []
+
+    @property
+    def _instrumentation(self):
+        if getattr(self._thread_local, '_instrumentation', None) is None:
+            self._thread_local._instrumentation = []
+        return self._thread_local._instrumentation
+
 
     @property
     def name(self):

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/b3abdce5/aria/storage/collection_instrumentation.py
----------------------------------------------------------------------
diff --git a/aria/storage/collection_instrumentation.py b/aria/storage/collection_instrumentation.py
index 6fa0e91..6f02b34 100644
--- a/aria/storage/collection_instrumentation.py
+++ b/aria/storage/collection_instrumentation.py
@@ -260,7 +260,7 @@ class _WrappedModel(object):
         :param instrumented_cls: The class to be instrumented
         :param instrumentation_cls: the instrumentation cls
         :param wrapped: the currently wrapped instance
-        :param kwargs: and kwargs to te passed to the instrumented class.
+        :param kwargs: and kwargs to the passed to the instrumented class.
         """
         self._kwargs = kwargs
         self._instrumentation = instrumentation
@@ -271,6 +271,8 @@ class _WrappedModel(object):
             return _create_instrumented_model(
                 value, instrumentation=self._instrumentation, **self._kwargs)
         elif getattr(value, 'metadata', True) == getattr(self._wrapped, 'metadata', False):
+            # Basically checks that the value is indeed an sqlmodel and the metadata of it,
+            # and the current wrapped model is the same
             return _create_wrapped_model(
                 value, instrumentation=self._instrumentation, **self._kwargs)
         return value

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/b3abdce5/aria/storage/core.py
----------------------------------------------------------------------
diff --git a/aria/storage/core.py b/aria/storage/core.py
index 5933b87..285b211 100644
--- a/aria/storage/core.py
+++ b/aria/storage/core.py
@@ -37,6 +37,7 @@ API:
     * drivers - module, a pool of ARIA standard drivers.
     * StorageDriver - class, abstract model implementation.
 """
+import copy
 from contextlib import contextmanager
 
 from aria.logger import LoggerMixin
@@ -169,14 +170,16 @@ class ModelStorage(Storage):
 
     @contextmanager
     def instrument(self, *instrumentation):
+        original_instrumentation = {}
 
         def _instrument(remove=False):
             for mapi in self.registered.values():
-                for field in instrumentation:
-                    if remove is False:
-                        mapi._instrumentation.append(field)
-                    elif field in mapi._instrumentation:
-                        mapi._instrumentation.remove(field)
+                if remove is True:
+                    mapi._instrumentation[:] = original_instrumentation[mapi]
+                else:
+                    original_instrumentation[mapi] = copy.copy(mapi._instrumentation)
+                    mapi._instrumentation.extend(instrumentation)
+
         try:
             _instrument()
             yield self

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/b3abdce5/aria/storage/sql_mapi.py
----------------------------------------------------------------------
diff --git a/aria/storage/sql_mapi.py b/aria/storage/sql_mapi.py
index d8337f4..4d7e233 100644
--- a/aria/storage/sql_mapi.py
+++ b/aria/storage/sql_mapi.py
@@ -104,7 +104,8 @@ class SQLAlchemyModelAPI(api.ModelAPI):
              **kwargs):
         """Return a (possibly empty) list of `model_class` results
         """
-        return iter(self._get_query(include, filters, sort))
+        for result in self._get_query(include, filters, sort):
+            yield self._instrument(result)
 
     def put(self, entry, **kwargs):
         """Create a `model_class` instance from a serializable `model` object

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/b3abdce5/aria/utils/validation.py
----------------------------------------------------------------------
diff --git a/aria/utils/validation.py b/aria/utils/validation.py
index bcdeb7a..193cb33 100644
--- a/aria/utils/validation.py
+++ b/aria/utils/validation.py
@@ -65,7 +65,7 @@ class ValidatorMixin(object):
                 name=argument_name, type='callable', arg=argument))
 
 
-def validate_function_arguments(func, **func_kwargs):
+def validate_function_arguments(func, func_kwargs):
     """
     Validates all required arguments are supplied to ``func`` and that no additional arguments are
     supplied

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/b3abdce5/tests/orchestrator/context/test_operation.py
----------------------------------------------------------------------
diff --git a/tests/orchestrator/context/test_operation.py b/tests/orchestrator/context/test_operation.py
index 3dcfaa2..343d442 100644
--- a/tests/orchestrator/context/test_operation.py
+++ b/tests/orchestrator/context/test_operation.py
@@ -263,7 +263,7 @@ def test_plugin_workdir(ctx, thread_executor, tmpdir):
 
 @pytest.fixture(params=[
     (thread.ThreadExecutor, {}),
-    (process.ProcessExecutor, {'python_path': [tests.ROOT_DIR]}),
+    # (process.ProcessExecutor, {'python_path': [tests.ROOT_DIR]}),
 ])
 def executor(request):
     executor_cls, executor_kwargs = request.param