ariatosca-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mxm...@apache.org
Subject incubator-ariatosca git commit: initial commit [Forced Update!]
Date Mon, 13 Mar 2017 14:44:00 GMT
Repository: incubator-ariatosca
Updated Branches:
  refs/heads/ARIA-120-Builtin-workflows-relationship-operations-execution-order 3086b6616
-> 6ff078adc (forced update)


initial commit


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

Branch: refs/heads/ARIA-120-Builtin-workflows-relationship-operations-execution-order
Commit: 6ff078adcc1e3c68f37a0087caf4ab7a54ed7a4d
Parents: 95177d0
Author: max-orlov <maxim@gigaspaces.com>
Authored: Mon Mar 13 16:35:10 2017 +0200
Committer: max-orlov <maxim@gigaspaces.com>
Committed: Mon Mar 13 16:43:50 2017 +0200

----------------------------------------------------------------------
 aria/orchestrator/workflows/builtin/utils.py    | 60 +++++++++++---
 .../orchestrator/workflows/builtin/workflows.py | 87 ++++----------------
 2 files changed, 63 insertions(+), 84 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/6ff078ad/aria/orchestrator/workflows/builtin/utils.py
----------------------------------------------------------------------
diff --git a/aria/orchestrator/workflows/builtin/utils.py b/aria/orchestrator/workflows/builtin/utils.py
index c9dbc6b..78f2d37 100644
--- a/aria/orchestrator/workflows/builtin/utils.py
+++ b/aria/orchestrator/workflows/builtin/utils.py
@@ -12,11 +12,12 @@
 # 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
 
 
-def create_node_task(operation_name, node):
+def create_node_task(node, operation_name):
     """
     Returns a new operation task if the operation exists in the node, otherwise returns None.
     """
@@ -27,21 +28,54 @@ def create_node_task(operation_name, node):
     return None
 
 
-def create_relationship_tasks(operation_name, runs_on, node):
+def create_relationships_tasks(node, source_operation_name=None, target_operation_name=None):
     """
-    Returns a list of operation tasks for each outbound relationship of the node if the operation
-    exists there.
+    Creates a relationship task (source and target) for all of a node_instance relationships.
+    :param basestring source_operation_name: the relationship operation name.
+    :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)
 
-    sequence = []
-    for relationship in node.outbound_relationships:
-        if _has_operation(relationship.interfaces, operation_name):
-            sequence.append(
-                OperationTask.relationship(instance=relationship,
-                                           name=operation_name,
-                                           edge='source',
-                                           runs_on=runs_on))
-    return sequence
+    sub_tasks = []
+    for _, (_, relationship_group) in enumerate(relationships_groups):
+        for relationship in relationship_group:
+            relationship_operations = relationship_tasks(
+                relationship=relationship,
+                source_operation_name=source_operation_name,
+                target_operation_name=target_operation_name)
+            sub_tasks.append(relationship_operations)
+
+    return sub_tasks
+
+
+def relationship_tasks(relationship, source_operation_name=None, target_operation_name=None):
+    """
+    Creates a relationship task source and target.
+    :param Relationship relationship: the relationship instance itself
+    :param source_operation_name:
+    :param target_operation_name:
+
+    :return:
+    """
+    operations = []
+    if source_operation_name and _has_operation(relationship.interfaces, source_operation_name):
+        operations.append(
+            OperationTask.relationship(instance=relationship,
+                                       name=source_operation_name,
+                                       edge=OperationTask.SOURCE_OPERATION)
+        )
+    if target_operation_name and _has_operation(relationship.interfaces, target_operation_name):
+        operations.append(
+            OperationTask.relationship(instance=relationship,
+                                       name=target_operation_name,
+                                       edge=OperationTask.TARGET_OPERATION)
+        )
+
+    return operations
 
 
 def create_node_task_dependencies(graph, tasks_and_nodes, reverse=False):

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/6ff078ad/aria/orchestrator/workflows/builtin/workflows.py
----------------------------------------------------------------------
diff --git a/aria/orchestrator/workflows/builtin/workflows.py b/aria/orchestrator/workflows/builtin/workflows.py
index 180b4e9..cc99a1a 100644
--- a/aria/orchestrator/workflows/builtin/workflows.py
+++ b/aria/orchestrator/workflows/builtin/workflows.py
@@ -17,7 +17,7 @@
 A set of builtin workflows.
 """
 
-from .utils import (create_node_task, create_relationship_tasks)
+from .utils import (create_node_task, create_relationships_tasks)
 from ... import workflow
 
 
@@ -66,40 +66,17 @@ __all__ = (
 
 @workflow(suffix_template='{node.id}')
 def install_node(graph, node, **kwargs):
-    sequence = []
-
     # Create
-    sequence.append(
-        create_node_task(
-            NORMATIVE_CREATE,
-            node))
+    sequence = [create_node_task(node, NORMATIVE_CREATE)]
 
     # Configure
-    sequence += \
-        create_relationship_tasks(
-            NORMATIVE_PRE_CONFIGURE_SOURCE,
-            'source',
-            node)
-    sequence += \
-        create_relationship_tasks(
-            NORMATIVE_PRE_CONFIGURE_TARGET,
-            'target',
-            node)
-    sequence.append(
-        create_node_task(
-            NORMATIVE_CONFIGURE,
-            node))
-    sequence += \
-        create_relationship_tasks(
-            NORMATIVE_POST_CONFIGURE_SOURCE,
-            'source',
-            node)
-    sequence += \
-        create_relationship_tasks(
-            NORMATIVE_POST_CONFIGURE_TARGET,
-            'target',
-            node)
-
+    sequence += create_relationships_tasks(node,
+                                           NORMATIVE_PRE_CONFIGURE_SOURCE,
+                                           NORMATIVE_PRE_CONFIGURE_TARGET)
+    sequence.append(create_node_task(node, NORMATIVE_CONFIGURE))
+    sequence += create_relationships_tasks(node,
+                                           NORMATIVE_POST_CONFIGURE_SOURCE,
+                                           NORMATIVE_POST_CONFIGURE_TARGET)
     # Start
     sequence += _create_start_tasks(node)
 
@@ -112,10 +89,7 @@ def uninstall_node(graph, node, **kwargs):
     sequence = _create_stop_tasks(node)
 
     # Delete
-    sequence.append(
-        create_node_task(
-            NORMATIVE_DELETE,
-            node))
+    sequence.append(create_node_task(node, NORMATIVE_DELETE))
 
     graph.sequence(*sequence)
 
@@ -131,43 +105,14 @@ def stop_node(graph, node, **kwargs):
 
 
 def _create_start_tasks(node):
-    sequence = []
-    sequence.append(
-        create_node_task(
-            NORMATIVE_START,
-            node))
-    sequence += \
-        create_relationship_tasks(
-            NORMATIVE_ADD_SOURCE,
-            'source',
-            node)
-    sequence += \
-        create_relationship_tasks(
-            NORMATIVE_ADD_TARGET,
-            'target',
-            node)
-    sequence += \
-        create_relationship_tasks(
-            NORMATIVE_TARGET_CHANGED,
-            'target',
-            node)
+    sequence = [create_node_task(node, NORMATIVE_START)]
+    sequence += create_relationships_tasks(node, NORMATIVE_ADD_SOURCE, NORMATIVE_ADD_TARGET)
+    sequence += create_relationships_tasks(node, target_operation_name=NORMATIVE_TARGET_CHANGED)
     return sequence
 
 
 def _create_stop_tasks(node):
-    sequence = []
-    sequence += \
-        create_relationship_tasks(
-            NORMATIVE_REMOVE_TARGET,
-            'target',
-            node)
-    sequence += \
-        create_relationship_tasks(
-            NORMATIVE_TARGET_CHANGED,
-            'target',
-            node)
-    sequence.append(
-        create_node_task(
-            NORMATIVE_STOP,
-            node))
+    sequence = create_relationships_tasks(node, target_operation_name=NORMATIVE_REMOVE_TARGET)
+    sequence += create_relationships_tasks(node, target_operation_name=NORMATIVE_TARGET_CHANGED)
+    sequence.append(create_node_task(node, NORMATIVE_STOP))
     return sequence


Mime
View raw message