ariatosca-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mxm...@apache.org
Subject [3/3] incubator-ariatosca git commit: code review fixups
Date Mon, 27 Mar 2017 20:38:46 GMT
code review 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/95c692c8
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/95c692c8
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/95c692c8

Branch: refs/heads/ARIA-120-Builtin-workflows-relationship-operations-execution-order
Commit: 95c692c8c257c5c8380e0e506e79fd308ebbda82
Parents: 8542729
Author: max-orlov <maxim@gigaspaces.com>
Authored: Mon Mar 27 17:55:03 2017 +0300
Committer: max-orlov <maxim@gigaspaces.com>
Committed: Mon Mar 27 23:38:37 2017 +0300

----------------------------------------------------------------------
 aria/orchestrator/workflows/api/task.py         | 26 +++++++++++---------
 aria/orchestrator/workflows/builtin/utils.py    | 25 ++++++-------------
 .../orchestrator/workflows/builtin/workflows.py |  2 +-
 .../workflows/core/events_handler.py            |  6 ++---
 aria/orchestrator/workflows/core/task.py        |  2 ++
 .../orchestrator/workflows/builtin/__init__.py  | 14 ++++-------
 .../workflows/executor/test_executor.py         |  2 ++
 .../workflows/executor/test_process_executor.py |  4 ++-
 8 files changed, 38 insertions(+), 43 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/95c692c8/aria/orchestrator/workflows/api/task.py
----------------------------------------------------------------------
diff --git a/aria/orchestrator/workflows/api/task.py b/aria/orchestrator/workflows/api/task.py
index 25d631d..f49ec2e 100644
--- a/aria/orchestrator/workflows/api/task.py
+++ b/aria/orchestrator/workflows/api/task.py
@@ -90,6 +90,8 @@ class OperationTask(BaseTask):
         self.ignore_failure = (self.workflow_context._task_ignore_failure
                                if ignore_failure is None else ignore_failure)
         self.runs_on = runs_on
+        self.interface_name = interface_name
+        self.operation_name = operation_name
 
         # Wrap inputs
         inputs = copy.deepcopy(inputs) if inputs else {}
@@ -101,11 +103,11 @@ class OperationTask(BaseTask):
         # model, because they are different from the operation inputs. If we do this, then
the two
         # kinds of inputs should *not* be merged here.
 
-        operation = self._get_operation(interface_name, operation_name)
+        operation = self._get_operation()
         if operation is None:
             raise exceptions.OperationNotFoundException(
                 'Could not find operation "{0}" on interface "{1}" for {2} "{3}"'
-                .format(operation_name, interface_name, actor_type, actor.name))
+                .format(self.operation_name, self.interface_name, actor_type, actor.name))
 
         self.plugin = None
         if operation.plugin_specification:
@@ -113,19 +115,27 @@ class OperationTask(BaseTask):
             if self.plugin is None:
                 raise exceptions.PluginNotFoundException(
                     'Could not find plugin of operation "{0}" on interface "{1}" for {2}
"{3}"'
-                    .format(operation_name, interface_name, actor_type, actor.name))
+                    .format(self.operation_name, self.interface_name, actor_type, actor.name))
 
         self.implementation = operation.implementation
         self.inputs = OperationTask._merge_inputs(operation.inputs, inputs)
 
         self.name = OperationTask.NAME_FORMAT.format(type=actor_type,
                                                      name=actor.name,
-                                                     interface=interface_name,
-                                                     operation=operation_name)
+                                                     interface=self.interface_name,
+                                                     operation=self.operation_name)
 
     def __repr__(self):
         return self.name
 
+    def _get_operation(self):
+        interface = self.actor.interfaces.get(self.interface_name)
+        if interface:
+            return interface.operations.get(self.operation_name)
+        return None
+
+
+
     @classmethod
     def for_node(cls,
                  node,
@@ -201,12 +211,6 @@ class OperationTask(BaseTask):
             ignore_failure=ignore_failure,
             inputs=inputs)
 
-    def _get_operation(self, interface_name, operation_name):
-        interface = self.actor.interfaces.get(interface_name)
-        if interface is not None:
-            return interface.operations.get(operation_name)
-        return None
-
     @staticmethod
     def _find_plugin(plugin_specification):
         workflow_context = context.workflow.current.get()

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/95c692c8/aria/orchestrator/workflows/builtin/utils.py
----------------------------------------------------------------------
diff --git a/aria/orchestrator/workflows/builtin/utils.py b/aria/orchestrator/workflows/builtin/utils.py
index 79d02ab..d79318f 100644
--- a/aria/orchestrator/workflows/builtin/utils.py
+++ b/aria/orchestrator/workflows/builtin/utils.py
@@ -12,8 +12,6 @@
 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 # See the License for the specific language governing permissions and
 # limitations under the License.
-from itertools import groupby
-
 from ..api.task import OperationTask
 from .. import exceptions
 
@@ -37,24 +35,24 @@ def create_relationships_tasks(
     """
     Creates a relationship task (source and target) for all of a node_instance relationships.
     :param basestring source_operation_name: the relationship operation name.
+    :param basestring interface_name: the name of the interface.
     :param source_operation_name:
     :param target_operation_name:
     :param NodeInstance node: the source_node
     :return:
     """
-    relationships_groups = groupby(node.outbound_relationships,
-                                   key=lambda relationship: relationship.target_node.id)
-
     sub_tasks = []
-    for _, (_, relationship_group) in enumerate(relationships_groups):
-        for relationship in relationship_group:
+    for relationship in node.outbound_relationships:
+        try:
             relationship_operations = relationship_tasks(
                 relationship,
                 interface_name,
                 source_operation_name=source_operation_name,
                 target_operation_name=target_operation_name)
             sub_tasks.append(relationship_operations)
-
+        except exceptions.OperationNotFoundException:
+            # We will skip relationships which do not have the operation
+            pass
     return sub_tasks
 
 
@@ -69,14 +67,14 @@ def relationship_tasks(
     :return:
     """
     operations = []
-    if source_operation_name and _has_operation(relationship.interfaces, source_operation_name):
+    if source_operation_name:
         operations.append(
             OperationTask.for_relationship(relationship=relationship,
                                            interface_name=interface_name,
                                            operation_name=source_operation_name,
                                            runs_on='source')
         )
-    if target_operation_name and _has_operation(relationship.interfaces, target_operation_name):
+    if target_operation_name:
         operations.append(
             OperationTask.for_relationship(relationship=relationship,
                                            interface_name=interface_name,
@@ -110,10 +108,3 @@ def create_node_task_dependencies(graph, tasks_and_nodes, reverse=False):
                     graph.add_dependency(dependency, task)
             else:
                 graph.add_dependency(task, dependencies)
-
-
-def _has_operation(interfaces, operation_name):
-    for interface in interfaces.values():
-        if operation_name in interface.operations:
-            return True
-    return False

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/95c692c8/aria/orchestrator/workflows/builtin/workflows.py
----------------------------------------------------------------------
diff --git a/aria/orchestrator/workflows/builtin/workflows.py b/aria/orchestrator/workflows/builtin/workflows.py
index 67badcf..60f14ed 100644
--- a/aria/orchestrator/workflows/builtin/workflows.py
+++ b/aria/orchestrator/workflows/builtin/workflows.py
@@ -28,11 +28,11 @@ NORMATIVE_STANDARD_INTERFACE = 'Standard' # 'tosca.interfaces.node.lifecycle.Sta
 NORMATIVE_CONFIGURE_INTERFACE = 'Configure' # 'tosca.interfaces.relationship.Configure'
 
 NORMATIVE_CREATE = 'create'
+NORMATIVE_CONFIGURE = 'configure'
 NORMATIVE_START = 'start'
 NORMATIVE_STOP = 'stop'
 NORMATIVE_DELETE = 'delete'
 
-NORMATIVE_CONFIGURE = 'configure'
 NORMATIVE_PRE_CONFIGURE_SOURCE = 'pre_configure_source'
 NORMATIVE_PRE_CONFIGURE_TARGET = 'pre_configure_target'
 NORMATIVE_POST_CONFIGURE_SOURCE = 'post_configure_source'

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/95c692c8/aria/orchestrator/workflows/core/events_handler.py
----------------------------------------------------------------------
diff --git a/aria/orchestrator/workflows/core/events_handler.py b/aria/orchestrator/workflows/core/events_handler.py
index 4ac4b64..7d19784 100644
--- a/aria/orchestrator/workflows/core/events_handler.py
+++ b/aria/orchestrator/workflows/core/events_handler.py
@@ -126,11 +126,9 @@ def _workflow_cancelling(workflow_context, *args, **kwargs):
 
 
 def _update_node_state_if_necessary(task, is_transitional=False):
-    match = re.search(r'^(?:tosca.interfaces.node.lifecycle.Standard|Standard):(\S+)@node',
-                      task.name)
-    if match:
+    if task.interface_name in ['tosca.interfaces.node.lifecycle.Standard', 'Standard']:
         node = task.runs_on
-        state = node.determine_state(op_name=match.group(1), is_transitional=is_transitional)
+        state = node.determine_state(op_name=task.operation_name, is_transitional=is_transitional)
         if state:
             node.state = state
             task.context.model.node.update(node)

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/95c692c8/aria/orchestrator/workflows/core/task.py
----------------------------------------------------------------------
diff --git a/aria/orchestrator/workflows/core/task.py b/aria/orchestrator/workflows/core/task.py
index f23312d..1e13588 100644
--- a/aria/orchestrator/workflows/core/task.py
+++ b/aria/orchestrator/workflows/core/task.py
@@ -106,6 +106,8 @@ class OperationTask(BaseTask):
     def __init__(self, api_task, *args, **kwargs):
         super(OperationTask, self).__init__(id=api_task.id, **kwargs)
         self._workflow_context = api_task._workflow_context
+        self.interface_name = api_task.interface_name
+        self.operation_name = api_task.operation_name
         model_storage = api_task._workflow_context.model
         plugin = api_task.plugin
 

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/95c692c8/tests/orchestrator/workflows/builtin/__init__.py
----------------------------------------------------------------------
diff --git a/tests/orchestrator/workflows/builtin/__init__.py b/tests/orchestrator/workflows/builtin/__init__.py
index 5ea761c..2aef2cf 100644
--- a/tests/orchestrator/workflows/builtin/__init__.py
+++ b/tests/orchestrator/workflows/builtin/__init__.py
@@ -40,7 +40,6 @@ def _assert_relationships(operations, expected_op_full_name, relationships=0):
         _assert_cfg_interface_op(operation, expected_op_name)
 
         assert relationship_id_1 == relationship_id_2
-        print '++++' + edge1, edge2
         assert edge1 != edge2
 
 
@@ -64,14 +63,11 @@ def assert_node_uninstall_operations(operations, relationships=0):
 
 
 def _assert_cfg_interface_op(op, operation_name):
-    op = op.name.split('@', 1)[0].rsplit('_', 1)[0].lower()
-    predicted_name = \
-        '{0}:{1}'.format(workflows.NORMATIVE_CONFIGURE_INTERFACE, operation_name).lower()
-    assert op == predicted_name
+    predicted_name = '{0}:{1}'.format(workflows.NORMATIVE_CONFIGURE_INTERFACE, operation_name)
+    operation_name = op.operation_name.rsplit('_', 1)[0]
+    assert '{0}:{1}'.format(op.interface_name, operation_name).lower() == predicted_name.lower()
 
 
 def _assert_std_interface_op(op, operation_name):
-    op = op.name.split('@', 1)[0].lower()
-    predicted_name = '{0}:{1}'\
-        .format(workflows.NORMATIVE_STANDARD_INTERFACE, operation_name).lower()
-    assert op == predicted_name
+    predicted_name = '{0}:{1}'.format(workflows.NORMATIVE_STANDARD_INTERFACE, operation_name)
+    assert '{op.interface_name}:{op.operation_name}'.format(op=op).lower() == predicted_name.lower()

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/95c692c8/tests/orchestrator/workflows/executor/test_executor.py
----------------------------------------------------------------------
diff --git a/tests/orchestrator/workflows/executor/test_executor.py b/tests/orchestrator/workflows/executor/test_executor.py
index 0a2280d..9dde1ce 100644
--- a/tests/orchestrator/workflows/executor/test_executor.py
+++ b/tests/orchestrator/workflows/executor/test_executor.py
@@ -118,6 +118,8 @@ class MockTask(object):
         self.max_attempts = 1
         self.plugin_fk = None
         self.ignore_failure = False
+        self.interface_name = 'interface_name'
+        self.operation_name = 'operation_name'
 
         for state in models.Task.STATES:
             setattr(self, state.upper(), state)

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/95c692c8/tests/orchestrator/workflows/executor/test_process_executor.py
----------------------------------------------------------------------
diff --git a/tests/orchestrator/workflows/executor/test_process_executor.py b/tests/orchestrator/workflows/executor/test_process_executor.py
index 3cd1c47..761c9f7 100644
--- a/tests/orchestrator/workflows/executor/test_process_executor.py
+++ b/tests/orchestrator/workflows/executor/test_process_executor.py
@@ -140,7 +140,9 @@ class MockTask(object):
         self.plugin_fk = plugin.id
         self.plugin = plugin
         self.ignore_failure = False
-
+        self.interface_name = 'interface_name'
+        self.operation_name = 'operation_name'
+        
         for state in aria_models.Task.STATES:
             setattr(self, state.upper(), state)
 


Mime
View raw message