You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ariatosca.apache.org by mx...@apache.org on 2017/06/27 20:06:43 UTC
incubator-ariatosca git commit: improved translation test
Repository: incubator-ariatosca
Updated Branches:
refs/heads/ARIA-294-Workflow-tasks-execution-is-not-in-order 8f5933586 -> defd5acf9
improved translation test
Project: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/commit/defd5acf
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/defd5acf
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/defd5acf
Branch: refs/heads/ARIA-294-Workflow-tasks-execution-is-not-in-order
Commit: defd5acf9e74c768f24253e3e5137bb70019dbc2
Parents: 8f59335
Author: max-orlov <ma...@gigaspaces.com>
Authored: Tue Jun 27 23:04:18 2017 +0300
Committer: max-orlov <ma...@gigaspaces.com>
Committed: Tue Jun 27 23:04:18 2017 +0300
----------------------------------------------------------------------
aria/modeling/relationship.py | 81 ++++++++------------
aria/modeling/service_common.py | 2 +-
aria/modeling/service_instance.py | 4 +-
aria/modeling/service_template.py | 2 +-
.../test_task_graph_into_execution_graph.py | 66 +++++++++++++---
5 files changed, 90 insertions(+), 65 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/defd5acf/aria/modeling/relationship.py
----------------------------------------------------------------------
diff --git a/aria/modeling/relationship.py b/aria/modeling/relationship.py
index 4569789..30d174f 100644
--- a/aria/modeling/relationship.py
+++ b/aria/modeling/relationship.py
@@ -90,35 +90,6 @@ def one_to_one_self(model_class, fk):
)
-def one_to_many_self(model_class, fk, dict_key=None):
- """
- Declare a one-to-many relationship property. The property value would be a list or dict of
- instances of the same model.
-
- You will need an associated foreign key to our own table.
-
- *This utility method should only be used during class creation.*
-
- :param model_class: The class in which this relationship will be declared
- :type model_class: type
- :param fk: Foreign key name
- :type fk: basestring
- :param dict_key: If set the value will be a dict with this key as the dict key; otherwise will
- be a list
- :type dict_key: basestring
- """
- return _relationship(
- model_class,
- model_class.__tablename__,
- relationship_kwargs={
- 'remote_side': '{model_class}.{remote_column}'.format(
- model_class=model_class.__name__, remote_column=fk)
- },
- back_populates=False,
- dict_key=dict_key
- )
-
-
def one_to_one(model_class,
other_table,
fk=None,
@@ -162,11 +133,12 @@ def one_to_one(model_class,
def one_to_many(model_class,
- child_table,
- child_fk=None,
+ other_table=None,
+ other_fk=None,
dict_key=None,
back_populates=None,
- rel_kwargs=None):
+ rel_kwargs=None,
+ self=False):
"""
Declare a one-to-many relationship property. The property value would be a list or dict of
instances of the child table's model.
@@ -181,9 +153,9 @@ def one_to_many(model_class,
:param model_class: The class in which this relationship will be declared
:type model_class: type
:param child_table: Child table name
- :type child_table: basestring
- :param child_fk: Foreign key name at the child table (no need specify if there's no ambiguity)
- :type child_fk: basestring
+ :type other_table: basestring
+ :param other_fk: Foreign key name at the child table (no need specify if there's no ambiguity)
+ :type other_fk: basestring
:param dict_key: If set the value will be a dict with this key as the dict key; otherwise will
be a list
:type dict_key: basestring
@@ -191,18 +163,28 @@ def one_to_many(model_class,
false to disable
:type back_populates: basestring|bool
"""
- rel_kwargs = rel_kwargs or {}
- rel_kwargs.setdefault('cascade', 'all')
- if back_populates is None:
- back_populates = model_class.__tablename__
+ relationship_kwargs = rel_kwargs or {}
+ if self:
+ assert other_fk
+ other_table_name = model_class.__tablename__
+ back_populates = False
+ relationship_kwargs['remote_side'] = '{model}.{column}'.format(model=model_class.__name__,
+ column=other_fk)
+
+ else:
+ assert other_table
+ other_table_name = other_table
+ if back_populates is None:
+ back_populates = model_class.__tablename__
+ relationship_kwargs.setdefault('cascade', 'all')
return _relationship(
model_class,
- child_table,
+ other_table_name,
back_populates=back_populates,
- other_fk=child_fk,
+ other_fk=other_fk,
dict_key=dict_key,
- relationship_kwargs=rel_kwargs)
+ relationship_kwargs=relationship_kwargs)
def many_to_one(model_class,
@@ -303,16 +285,15 @@ def many_to_many(model_class,
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
+ kwargs['relationship_kwargs']['primaryjoin'] = \
+ getattr(model_class, 'id') == getattr(secondary_table.c, this_column_name)
+ kwargs['relationship_kwargs']['secondaryjoin'] = \
+ getattr(model_class, 'id') == getattr(secondary_table.c, other_column_name)
else:
- kwargs.update({
- 'backref_kwargs': {'name': other_property, 'uselist': True} if other_property else None,
- 'dict_key': dict_key
- })
+ kwargs['backref_kwargs'] = \
+ {'name': other_property, 'uselist': True} if other_property else None
+ kwargs['dict_key'] = dict_key
return _relationship(model_class, other_table, **kwargs)
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/defd5acf/aria/modeling/service_common.py
----------------------------------------------------------------------
diff --git a/aria/modeling/service_common.py b/aria/modeling/service_common.py
index 272dfd7..0bb861f 100644
--- a/aria/modeling/service_common.py
+++ b/aria/modeling/service_common.py
@@ -320,7 +320,7 @@ class TypeBase(InstanceModelMixin):
@declared_attr
def children(cls):
- return relationship.one_to_many_self(cls, 'parent_type_fk')
+ return relationship.one_to_many(cls, other_fk='parent_type_fk', self=True)
# region foreign keys
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/defd5acf/aria/modeling/service_instance.py
----------------------------------------------------------------------
diff --git a/aria/modeling/service_instance.py b/aria/modeling/service_instance.py
index 2bf9872..b451889 100644
--- a/aria/modeling/service_instance.py
+++ b/aria/modeling/service_instance.py
@@ -483,7 +483,7 @@ class NodeBase(InstanceModelMixin):
@declared_attr
def outbound_relationships(cls):
return relationship.one_to_many(
- cls, 'relationship', child_fk='source_node_fk', back_populates='source_node',
+ cls, 'relationship', other_fk='source_node_fk', back_populates='source_node',
rel_kwargs=dict(
order_by='Relationship.source_position',
collection_class=ordering_list('source_position', count_from=0)
@@ -493,7 +493,7 @@ class NodeBase(InstanceModelMixin):
@declared_attr
def inbound_relationships(cls):
return relationship.one_to_many(
- cls, 'relationship', child_fk='target_node_fk', back_populates='target_node',
+ cls, 'relationship', other_fk='target_node_fk', back_populates='target_node',
rel_kwargs=dict(
order_by='Relationship.target_position',
collection_class=ordering_list('target_position', count_from=0)
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/defd5acf/aria/modeling/service_template.py
----------------------------------------------------------------------
diff --git a/aria/modeling/service_template.py b/aria/modeling/service_template.py
index 4d1e837..344da6d 100644
--- a/aria/modeling/service_template.py
+++ b/aria/modeling/service_template.py
@@ -493,7 +493,7 @@ class NodeTemplateBase(TemplateModelMixin):
@declared_attr
def requirement_templates(cls):
- return relationship.one_to_many(cls, 'requirement_template', child_fk='node_template_fk')
+ return relationship.one_to_many(cls, 'requirement_template', other_fk='node_template_fk')
@declared_attr
def properties(cls):
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/defd5acf/tests/orchestrator/workflows/core/test_task_graph_into_execution_graph.py
----------------------------------------------------------------------
diff --git a/tests/orchestrator/workflows/core/test_task_graph_into_execution_graph.py b/tests/orchestrator/workflows/core/test_task_graph_into_execution_graph.py
index f0d2b26..9b41dd4 100644
--- a/tests/orchestrator/workflows/core/test_task_graph_into_execution_graph.py
+++ b/tests/orchestrator/workflows/core/test_task_graph_into_execution_graph.py
@@ -35,6 +35,8 @@ def test_task_graph_into_execution_graph(tmpdir):
operation_name,
operation_kwargs=dict(function='test')
)
+ interface.operations['configure'] = mock.models.create_operation('configure')
+ interface.operations['start'] = mock.models.create_operation('start')
node.interfaces[interface.name] = interface
workflow_context.model.node.update(node)
@@ -53,11 +55,24 @@ def test_task_graph_into_execution_graph(tmpdir):
operation_name=operation_name)
inner_task_graph = api.task.WorkflowTask(sub_workflow, name='test_inner_task_graph')
- inner_task = api.task.OperationTask(
+ inner_task_1 = api.task.OperationTask(
node,
interface_name=interface_name,
operation_name=operation_name)
- inner_task_graph.add_tasks(inner_task)
+ inner_task_2 = api.task.OperationTask(
+ node,
+ interface_name=interface_name,
+ operation_name='configure')
+ inner_task_3 = api.task.OperationTask(
+ node,
+ interface_name=interface_name,
+ operation_name='start')
+ inner_task_graph.add_tasks(inner_task_1)
+ inner_task_graph.add_tasks(inner_task_2)
+ inner_task_graph.add_tasks(inner_task_3)
+ inner_task_graph.add_dependency(inner_task_2, inner_task_1)
+ inner_task_graph.add_dependency(inner_task_3, inner_task_1)
+ inner_task_graph.add_dependency(inner_task_3, inner_task_2)
test_task_graph.add_tasks(simple_before_task)
test_task_graph.add_tasks(simple_after_task)
@@ -70,13 +85,15 @@ def test_task_graph_into_execution_graph(tmpdir):
execution_tasks = topological_sort(_graph(workflow_context.execution.tasks))
- assert len(execution_tasks) == 7
+ assert len(execution_tasks) == 9
expected_tasks_names = [
'{0}-Start'.format(test_task_graph.id),
simple_before_task.id,
'{0}-Start'.format(inner_task_graph.id),
- inner_task.id,
+ inner_task_1.id,
+ inner_task_2.id,
+ inner_task_3.id,
'{0}-End'.format(inner_task_graph.id),
simple_after_task.id,
'{0}-End'.format(test_task_graph.id)
@@ -86,13 +103,40 @@ def test_task_graph_into_execution_graph(tmpdir):
assert all(isinstance(task, models.Task) for task in execution_tasks)
execution_tasks = iter(execution_tasks)
- assert next(execution_tasks)._stub_type == models.Task.START_WORKFLOW
- _assert_execution_is_api_task(next(execution_tasks), simple_before_task)
- assert next(execution_tasks)._stub_type == models.Task.START_SUBWROFKLOW
- _assert_execution_is_api_task(next(execution_tasks), inner_task)
- assert next(execution_tasks)._stub_type == models.Task.END_SUBWORKFLOW
- _assert_execution_is_api_task(next(execution_tasks), simple_after_task)
- assert next(execution_tasks)._stub_type == models.Task.END_WORKFLOW
+ start_workflow_exec_task = next(execution_tasks)
+ assert start_workflow_exec_task._stub_type == models.Task.START_WORKFLOW
+
+ before_exec_task = next(execution_tasks)
+ _assert_execution_is_api_task(before_exec_task, simple_before_task)
+ assert before_exec_task.dependencies == [start_workflow_exec_task]
+
+ start_subworkflow_exec_task = next(execution_tasks)
+ assert start_subworkflow_exec_task._stub_type == models.Task.START_SUBWROFKLOW
+ assert start_subworkflow_exec_task.dependencies == [before_exec_task]
+
+ inner_exec_task_1 = next(execution_tasks)
+ _assert_execution_is_api_task(inner_exec_task_1, inner_task_1)
+ assert inner_exec_task_1.dependencies == [start_subworkflow_exec_task]
+
+ inner_exec_task_2 = next(execution_tasks)
+ _assert_execution_is_api_task(inner_exec_task_2, inner_task_2)
+ assert inner_exec_task_2.dependencies == [inner_exec_task_1]
+
+ inner_exec_task_3 = next(execution_tasks)
+ _assert_execution_is_api_task(inner_exec_task_3, inner_task_3)
+ assert sorted(inner_exec_task_3.dependencies) == sorted([inner_exec_task_1, inner_exec_task_2])
+
+ end_subworkflow_exec_task = next(execution_tasks)
+ assert end_subworkflow_exec_task._stub_type == models.Task.END_SUBWORKFLOW
+ assert end_subworkflow_exec_task.dependencies == [inner_exec_task_3]
+
+ after_exec_task = next(execution_tasks)
+ _assert_execution_is_api_task(after_exec_task, simple_after_task)
+ assert after_exec_task.dependencies == [end_subworkflow_exec_task]
+
+ end_workflow_exec_task = next(execution_tasks)
+ assert end_workflow_exec_task._stub_type == models.Task.END_WORKFLOW
+ assert end_workflow_exec_task.dependencies == [after_exec_task]
storage.release_sqlite_storage(workflow_context.model)