Repository: incubator-ariatosca
Updated Branches:
  refs/heads/ARIA-294-Workflow-tasks-execution-is-not-in-order [created] 
8f5933586


wip


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

Branch: refs/heads/ARIA-294-Workflow-tasks-execution-is-not-in-order
Commit: 8f59335866c71de4c392c4697e927571d11b2be9
Parents: 7bba3ab
Author: max-orlov <ma...@gigaspaces.com>
Authored: Tue Jun 27 20:32:08 2017 +0300
Committer: max-orlov <ma...@gigaspaces.com>
Committed: Tue Jun 27 20:32:08 2017 +0300

----------------------------------------------------------------------
 aria/modeling/orchestration.py                  |  7 +---
 aria/modeling/relationship.py                   | 41 ++++++++++----------
 aria/orchestrator/workflow_runner.py            |  4 +-
 .../workflows/core/graph_compiler.py            |  1 -
 4 files changed, 24 insertions(+), 29 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/8f593358/aria/modeling/orchestration.py
----------------------------------------------------------------------
diff --git a/aria/modeling/orchestration.py b/aria/modeling/orchestration.py
index 5b02d1b..ab389d3 100644
--- a/aria/modeling/orchestration.py
+++ b/aria/modeling/orchestration.py
@@ -397,13 +397,8 @@ class TaskBase(mixins.ModelMixin):
         raise TaskRetryException(message, retry_interval=retry_interval)
 
     @declared_attr
-    def dependency_fk(self):
-        return relationship.foreign_key('task', nullable=True)
-
-    @declared_attr
     def dependencies(cls):
-        # symmetric relationship causes funky graphs
-        return relationship.one_to_many_self(cls, 'dependency_fk')
+        return relationship.many_to_many(cls, 'task', self=True)
 
     def has_ended(self):
         return self.status in (self.SUCCESS, self.FAILED)

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/8f593358/aria/modeling/relationship.py
----------------------------------------------------------------------
diff --git a/aria/modeling/relationship.py b/aria/modeling/relationship.py
index 40be5b2..4569789 100644
--- a/aria/modeling/relationship.py
+++ b/aria/modeling/relationship.py
@@ -247,7 +247,8 @@ def many_to_many(model_class,
                  other_table,
                  prefix=None,
                  dict_key=None,
-                 other_property=None):
+                 other_property=None,
+                 self=False):
     """
     Declare a many-to-many relationship property. The property value would be 
a list or dict of
     instances of the other table's model.
@@ -280,8 +281,8 @@ def many_to_many(model_class,
     this_column_name = '{0}_id'.format(this_table)
     this_foreign_key = '{0}.id'.format(this_table)
 
-    other_column_name = '{0}_id'.format(other_table)
-    other_foreign_key = '{0}.id'.format(other_table)
+    other_column_name = '{0}_{1}'.format(other_table, 'self_ref_id' if self 
else 'id')
+    other_foreign_key = '{0}.{1}'.format(other_table, 'id')
 
     secondary_table_name = '{0}_{1}'.format(this_table, other_table)
 
@@ -299,13 +300,21 @@ def many_to_many(model_class,
         other_foreign_key
     )
 
-    return _relationship(
-        model_class,
-        other_table,
-        relationship_kwargs={'secondary': secondary_table},
-        backref_kwargs={'name': other_property, 'uselist': True} if 
other_property else None,
-        dict_key=dict_key
-    )
+    kwargs = {'relationship_kwargs': {'secondary': secondary_table}}
+
+    if self:
+        kwargs['relationship_kwargs'].update({
+            'primaryjoin': getattr(model_class, 'id') == 
getattr(secondary_table.c, this_column_name),
+            'secondaryjoin': getattr(model_class, 'id') == 
getattr(secondary_table.c, other_column_name),
+        })
+        kwargs['back_populates'] = NO_BACK_POP
+    else:
+        kwargs.update({
+            'backref_kwargs': {'name': other_property, 'uselist': True} if 
other_property else None,
+            'dict_key': dict_key
+        })
+
+    return _relationship(model_class, other_table, **kwargs)
 
 
 def _relationship(model_class,
@@ -368,14 +377,6 @@ def _get_secondary_table(metadata,
     return Table(
         name,
         metadata,
-        Column(
-            first_column,
-            Integer,
-            ForeignKey(first_foreign_key)
-        ),
-        Column(
-            second_column,
-            Integer,
-            ForeignKey(second_foreign_key)
-        )
+        Column(first_column, Integer, ForeignKey(first_foreign_key)),
+        Column(second_column, Integer, ForeignKey(second_foreign_key))
     )

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/8f593358/aria/orchestrator/workflow_runner.py
----------------------------------------------------------------------
diff --git a/aria/orchestrator/workflow_runner.py 
b/aria/orchestrator/workflow_runner.py
index 4a50fb2..3d58386 100644
--- a/aria/orchestrator/workflow_runner.py
+++ b/aria/orchestrator/workflow_runner.py
@@ -97,8 +97,8 @@ class WorkflowRunner(object):
         if not self._is_resume:
             workflow_fn = self._get_workflow_fn()
             self._tasks_graph = workflow_fn(ctx=self._workflow_context, 
**execution_inputs_dict)
-            graph_compiler.GraphCompiler(self._workflow_context, 
executor.__class__).compile(
-                self._tasks_graph)
+            compiler = graph_compiler.GraphCompiler(self._workflow_context, 
executor.__class__)
+            compiler.compile(self._tasks_graph)
 
         self._engine = engine.Engine(executors={executor.__class__: executor})
 

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/8f593358/aria/orchestrator/workflows/core/graph_compiler.py
----------------------------------------------------------------------
diff --git a/aria/orchestrator/workflows/core/graph_compiler.py 
b/aria/orchestrator/workflows/core/graph_compiler.py
index f339038..df5128c 100644
--- a/aria/orchestrator/workflows/core/graph_compiler.py
+++ b/aria/orchestrator/workflows/core/graph_compiler.py
@@ -37,7 +37,6 @@ class GraphCompiler(object):
         :param end_stub_type: internal use
         :param depends_on: internal use
         """
-        task_graph = task_graph or self._task_graph
         depends_on = list(depends_on)
 
         # Insert start marker

Reply via email to