ariatosca-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mxm...@apache.org
Subject [1/2] incubator-ariatosca git commit: some remodeling
Date Wed, 09 Nov 2016 16:24:11 GMT
Repository: incubator-ariatosca
Updated Branches:
  refs/heads/ARIA-9-API-for-operation-context 101bbd28a -> b71174f26


some remodeling


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

Branch: refs/heads/ARIA-9-API-for-operation-context
Commit: d3f45eb97a45795f00736fb2199cfedc93d52aa5
Parents: 101bbd2
Author: mxmrlv <mxmrlv@gmail.com>
Authored: Wed Nov 9 13:44:10 2016 +0200
Committer: mxmrlv <mxmrlv@gmail.com>
Committed: Wed Nov 9 13:44:10 2016 +0200

----------------------------------------------------------------------
 aria/context/operation.py         | 36 +++++----------------------
 aria/workflows/api/task.py        |  6 -----
 aria/workflows/core/task.py       | 24 ++++++++++++------
 tests/workflows/core/test_task.py | 45 +++++++++++++++++++++-------------
 4 files changed, 51 insertions(+), 60 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/d3f45eb9/aria/context/operation.py
----------------------------------------------------------------------
diff --git a/aria/context/operation.py b/aria/context/operation.py
index 858f13e..76a42a2 100644
--- a/aria/context/operation.py
+++ b/aria/context/operation.py
@@ -21,8 +21,6 @@ from uuid import uuid4
 
 from aria.logger import LoggerMixin
 
-from . import workflow
-
 
 class OperationContext(LoggerMixin):
     """
@@ -34,36 +32,17 @@ class OperationContext(LoggerMixin):
             name,
             operation_details,
             operation_host,
-            workflow_context=None,
+            execution,
+            task_model,
             inputs=None):
         super(OperationContext, self).__init__()
         self.name = name
         self._id = str(uuid4())
         self._operation_details = operation_details
         self._operation_host = operation_host
-        workflow_context = workflow_context or workflow.current.get()
-        self._execution = workflow_context.execution
+        self._execution = execution
         self._inputs = inputs or {}
-
-    @property
-    def operation_details(self):
-        return self._operation_details
-
-    @property
-    def inputs(self):
-        return self._inputs
-
-    @property
-    def operation_host(self):
-        return self._operation_host
-
-    @property
-    def execution_id(self):
-        return self.execution.id
-
-    @property
-    def execution(self):
-        return self._execution
+        self._task_model = task_model
 
     def __repr__(self):
         details = ', '.join(
@@ -72,10 +51,7 @@ class OperationContext(LoggerMixin):
         return '{name}({0})'.format(details, name=self.name)
 
     def __getattr__(self, attr):
-        # The retrieval order is as follows:
-        # 1. from the operation host (node_instance/relationship_instance)
-        # 3. from the operation_context
         try:
-            return getattr(self.operation_host, attr)
+            return getattr(self._operation_host, attr)
         except AttributeError:
-            return super(OperationContext, self).__getattribute__(attr)
+            return getattr(self._task_model, attr)

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/d3f45eb9/aria/workflows/api/task.py
----------------------------------------------------------------------
diff --git a/aria/workflows/api/task.py b/aria/workflows/api/task.py
index b48f7b7..e2f471a 100644
--- a/aria/workflows/api/task.py
+++ b/aria/workflows/api/task.py
@@ -71,12 +71,6 @@ class OperationTask(BaseTask):
         self.operation_details = operation_details
         self.operation_host = operation_host
         self.inputs = inputs or {}
-        self.context = context.operation.OperationContext(
-            name=name,
-            operation_details=operation_details,
-            operation_host=operation_host,
-            inputs=inputs,
-        )
 
 
 class WorkflowTask(BaseTask):

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/d3f45eb9/aria/workflows/core/task.py
----------------------------------------------------------------------
diff --git a/aria/workflows/core/task.py b/aria/workflows/core/task.py
index 96fc7f8..45a4dc6 100644
--- a/aria/workflows/core/task.py
+++ b/aria/workflows/core/task.py
@@ -21,6 +21,7 @@ from datetime import datetime
 
 from ... import logger
 from ...storage import models
+from ... import context
 from .. import exceptions
 
 
@@ -85,23 +86,32 @@ class OperationTask(BaseTask, logger.LoggerMixin):
     Operation tasks
     """
 
-    def __init__(self, api_task, *args, **kwargs):
+    def __init__(self, api_task, **kwargs):
         super(OperationTask, self).__init__(id=api_task.id, **kwargs)
         self._workflow_ctx = api_task.workflow_context
         task_model = api_task.workflow_context.model.task.model_cls
-        self._context = api_task.context
-        task = task_model(
+        operation_task = task_model(
             id=api_task.id,
             name=api_task.name,
             operation_details=api_task.operation_details,
             operation_host=api_task.operation_host,
             inputs=api_task.inputs,
             status=task_model.PENDING,
-            execution_id=self.workflow_context.execution_id,
+            execution_id=self.workflow_context.execution.id,
             max_retries=self.workflow_context.parameters.get('max_retries', 1),
         )
-        self.workflow_context.model.task.store(task)
-        self._task_id = task.id
+
+        self._ctx = context.operation.OperationContext(
+            name=api_task.name,
+            operation_details=api_task.operation_details,
+            operation_host=api_task.operation_host,
+            execution=self.workflow_context.execution,
+            inputs=api_task.inputs,
+            task_model=operation_task
+        )
+
+        self.workflow_context.model.task.store(operation_task)
+        self._task_id = operation_task.id
         self._update_fields = None
 
     @contextmanager
@@ -141,7 +151,7 @@ class OperationTask(BaseTask, logger.LoggerMixin):
 
     @property
     def context(self):
-        return self._context
+        return self._ctx
 
     @property
     def status(self):

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/d3f45eb9/tests/workflows/core/test_task.py
----------------------------------------------------------------------
diff --git a/tests/workflows/core/test_task.py b/tests/workflows/core/test_task.py
index 96f957e..ad8e82e 100644
--- a/tests/workflows/core/test_task.py
+++ b/tests/workflows/core/test_task.py
@@ -15,11 +15,15 @@
 
 import pytest
 
-from aria import (context,
-                  decorators)
-from aria.workflows import (api,
-                            core,
-                            executor)
+from aria import (
+    context,
+    decorators,
+)
+from aria.workflows import (
+    api,
+    core,
+)
+from aria.workflows.executor import blocking
 
 from ... import mock
 
@@ -43,6 +47,11 @@ def ctx():
     return simple_context
 
 
+@pytest.fixture(autouse=True)
+def clear_global_test_operation_holder():
+    global_test_holder.clear()
+
+
 class TestOperationTask(object):
 
     def test_operation_task_creation(self, ctx):
@@ -72,29 +81,31 @@ class TestOperationTask(object):
         operation_details = {'operation': 'tests.workflows.core.test_task.foo'}
 
         @decorators.workflow
-        def basic_workflow(graph, **kwargs):
-            api_task = api.task.OperationTask(
-                name=operation_name,
-                operation_details=operation_details,
-                operation_host=node_instance,
+        def basic_workflow(graph, **_):
+            graph.add_tasks(
+                api.task.OperationTask(
+                    name=operation_name,
+                    operation_details=operation_details,
+                    operation_host=node_instance,
+                )
             )
-            graph.add_tasks(api_task)
 
-        engine = core.engine.Engine(executor=executor.blocking.CurrentThreadBlockingExecutor(),
+        engine = core.engine.Engine(executor=blocking.CurrentThreadBlockingExecutor(),
                                     workflow_context=ctx,
                                     tasks_graph=basic_workflow(ctx=ctx))
         engine.execute()
-        operation_value = global_test_operation_holder[operation_name]
-        assert operation_value.operation_host == node_instance
+        operation_value = global_test_holder[operation_name]
+        for key, value in node_instance.fields_dict.items():
+            assert getattr(operation_value, key) == value
         assert operation_value.operation_details == operation_details
         assert operation_value.name == operation_name
-        assert operation_value.execution.id == ctx.execution.id
+        assert operation_value.execution_id == ctx.execution.id
 
 
-global_test_operation_holder = {}
+global_test_holder = {}
 
 
 @decorators.operation
 def foo(ctx, **kwargs):
-    global_test_operation_holder[ctx.name] = ctx
+    global_test_holder[ctx.name] = ctx
 


Mime
View raw message