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/03/27 19:47:34 UTC

incubator-ariatosca git commit: code review fixups [Forced Update!]

Repository: incubator-ariatosca
Updated Branches:
  refs/heads/ARIA-120-Builtin-workflows-relationship-operations-execution-order 446cd19ff -> d07cc3a5e (forced update)


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/d07cc3a5
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/d07cc3a5
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/d07cc3a5

Branch: refs/heads/ARIA-120-Builtin-workflows-relationship-operations-execution-order
Commit: d07cc3a5e4ea78a58cc623b75c5c554147d651ed
Parents: 6bd69d7
Author: max-orlov <ma...@gigaspaces.com>
Authored: Mon Mar 27 17:55:03 2017 +0300
Committer: max-orlov <ma...@gigaspaces.com>
Committed: Mon Mar 27 22:47:27 2017 +0300

----------------------------------------------------------------------
 aria/orchestrator/workflows/api/task.py         | 26 +++++++++++---------
 aria/orchestrator/workflows/builtin/utils.py    | 25 ++++++-------------
 .../orchestrator/workflows/builtin/workflows.py |  2 +-
 .../orchestrator/workflows/builtin/__init__.py  | 14 ++++-------
 4 files changed, 29 insertions(+), 38 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/d07cc3a5/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/d07cc3a5/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/d07cc3a5/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/d07cc3a5/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()