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: reverted the 'safe' behavior back to a function
Date Wed, 03 May 2017 17:05:04 GMT
Repository: incubator-ariatosca
Updated Branches:
  refs/heads/ARIA-163-Update-node-state-for-stub-tasks c56ab97ac -> 1303f0925


reverted the 'safe' behavior back to a function


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

Branch: refs/heads/ARIA-163-Update-node-state-for-stub-tasks
Commit: 1303f0925a03f07b3e70685174a8a22ea8864005
Parents: c56ab97
Author: max-orlov <maxim@gigaspaces.com>
Authored: Wed May 3 20:04:59 2017 +0300
Committer: max-orlov <maxim@gigaspaces.com>
Committed: Wed May 3 20:04:59 2017 +0300

----------------------------------------------------------------------
 aria/orchestrator/workflows/api/task.py         | 66 +++++++++++++-------
 .../orchestrator/workflows/builtin/workflows.py | 10 +--
 aria/orchestrator/workflows/core/translation.py |  2 +-
 aria/orchestrator/workflows/events_logging.py   |  9 +--
 .../orchestrator/workflows/core/test_engine.py  | 32 +++++-----
 5 files changed, 68 insertions(+), 51 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/1303f092/aria/orchestrator/workflows/api/task.py
----------------------------------------------------------------------
diff --git a/aria/orchestrator/workflows/api/task.py b/aria/orchestrator/workflows/api/task.py
index 889a86a..523a52f 100644
--- a/aria/orchestrator/workflows/api/task.py
+++ b/aria/orchestrator/workflows/api/task.py
@@ -92,43 +92,44 @@ class OperationTask(BaseTask):
                                                      name=actor.name,
                                                      interface=self.interface_name,
                                                      operation=self.operation_name)
-        if self.is_empty:
+        # Creating OperationTask directly should raise an error when there is no
+        # interface/operation.
+        if self.has_implementation is False:
             self.plugin = None
             self.inputs = {}
             self.implementation = None
-        else:
+        elif self.has_implementation is True:
             operation = self.actor.interfaces[self.interface_name].operations[self.operation_name]
             self.plugin = operation.plugin
             self.inputs = modeling_utils.create_inputs(inputs or {}, operation.inputs)
             self.implementation = operation.implementation
+        else:
+            raise exceptions.OperationNotFoundException(
+                'Could not find operation "{self.operation_name}" on interface '
+                '"{self.interface_name}" for {actor_type} "{actor.name}"'.format(
+                    self=self,
+                    actor_type=type(actor).__name__.lower(),
+                    actor=actor)
+            )
 
     def __repr__(self):
         return self.name
 
-    # def __new__(cls, actor, interface_name, operation_name, *args, **kwargs):
-    #     """
-    #     Returns a new operation task if the operation exists in the node, otherwise returns
None.
-    #     """
-    #     try:
-    #         cls.is_empty(actor, interface_name, operation_name)
-    #         return super(OperationTask, cls).__new__(cls)
-    #     except exceptions.OperationNotFoundException:
-    #         return None
-
     @property
-    def is_empty(self):
+    def has_implementation(self):
         interface = self.actor.interfaces.get(self.interface_name)
         if interface:
             operation = interface.operations.get(self.operation_name)
             if operation:
                 return operation.implementation is None
 
-        raise exceptions.OperationNotFoundException(
-            'Could not find operation "{0}" on interface "{1}" for {2} "{3}"'
-            .format(self.operation_name,
-                    self.interface_name,
-                    type(self.actor).__name__.lower(),
-                    self.actor.name))
+
+def operation_exists(actor, interface_name, operation_name):
+    interface = actor.interfaces.get(interface_name)
+    if interface:
+        operation = interface.operations.get(operation_name)
+        if operation:
+            return operation.implementation is None
 
 
 class WorkflowTask(BaseTask):
@@ -161,6 +162,27 @@ class WorkflowTask(BaseTask):
             return super(WorkflowTask, self).__getattribute__(item)
 
 
+def create_task(actor, interface_name, operation_name, **kwargs):
+    """
+    This helper function enables safe creation of OperationTask, if the supplied interface
and 
+    operation have no implementation, None is returned.
+    :param node: 
+    :param interface_name: 
+    :param operation_name: 
+    :param kwargs: 
+    :return: 
+    """
+    try:
+        return OperationTask(
+            actor,
+            interface_name=interface_name,
+            operation_name=operation_name,
+            **kwargs
+        )
+    except exceptions.OperationNotFoundException:
+        return None
+
+
 def create_relationships_tasks(
         node, interface_name, source_operation_name=None, target_operation_name=None, **kwargs):
     """
@@ -180,7 +202,7 @@ def create_relationships_tasks(
             source_operation_name=source_operation_name,
             target_operation_name=target_operation_name,
             **kwargs)
-        sub_tasks.append(relationship_operations)
+        sub_tasks.append(r for r in relationship_operations)
     return sub_tasks
 
 
@@ -197,7 +219,7 @@ def create_relationship_tasks(relationship, interface_name, source_operation_nam
     operations = []
     if source_operation_name:
         operations.append(
-            OperationTask(
+            create_task(
                 relationship,
                 interface_name=interface_name,
                 operation_name=source_operation_name,
@@ -206,7 +228,7 @@ def create_relationship_tasks(relationship, interface_name, source_operation_nam
         )
     if target_operation_name:
         operations.append(
-            OperationTask(
+            create_task(
                 relationship,
                 interface_name=interface_name,
                 operation_name=target_operation_name,

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/1303f092/aria/orchestrator/workflows/builtin/workflows.py
----------------------------------------------------------------------
diff --git a/aria/orchestrator/workflows/builtin/workflows.py b/aria/orchestrator/workflows/builtin/workflows.py
index 1fc9eed..b286e98 100644
--- a/aria/orchestrator/workflows/builtin/workflows.py
+++ b/aria/orchestrator/workflows/builtin/workflows.py
@@ -69,14 +69,14 @@ __all__ = (
 @workflow(suffix_template='{node.name}')
 def install_node(graph, node, **kwargs):
     # Create
-    sequence = [task.OperationTask(node, NORMATIVE_STANDARD_INTERFACE, NORMATIVE_CREATE)]
+    sequence = [task.create_task(node, NORMATIVE_STANDARD_INTERFACE, NORMATIVE_CREATE)]
 
     # Configure
     sequence += task.create_relationships_tasks(node,
                                                 NORMATIVE_CONFIGURE_INTERFACE,
                                                 NORMATIVE_PRE_CONFIGURE_SOURCE,
                                                 NORMATIVE_PRE_CONFIGURE_TARGET)
-    sequence.append(task.OperationTask(node, NORMATIVE_STANDARD_INTERFACE, NORMATIVE_CONFIGURE))
+    sequence.append(task.create_task(node, NORMATIVE_STANDARD_INTERFACE, NORMATIVE_CONFIGURE))
     sequence += task.create_relationships_tasks(node,
                                                 NORMATIVE_CONFIGURE_INTERFACE,
                                                 NORMATIVE_POST_CONFIGURE_SOURCE,
@@ -93,7 +93,7 @@ def uninstall_node(graph, node, **kwargs):
     sequence = _create_stop_tasks(node)
 
     # Delete
-    sequence.append(task.OperationTask(node, NORMATIVE_STANDARD_INTERFACE, NORMATIVE_DELETE))
+    sequence.append(task.create_task(node, NORMATIVE_STANDARD_INTERFACE, NORMATIVE_DELETE))
 
     graph.sequence(*sequence)
 
@@ -109,7 +109,7 @@ def stop_node(graph, node, **kwargs):
 
 
 def _create_start_tasks(node):
-    sequence = [task.OperationTask(node, NORMATIVE_STANDARD_INTERFACE, NORMATIVE_START)]
+    sequence = [task.create_task(node, NORMATIVE_STANDARD_INTERFACE, NORMATIVE_START)]
     sequence += task.create_relationships_tasks(node,
                                                 NORMATIVE_CONFIGURE_INTERFACE,
                                                 NORMATIVE_ADD_SOURCE, NORMATIVE_ADD_TARGET)
@@ -117,7 +117,7 @@ def _create_start_tasks(node):
 
 
 def _create_stop_tasks(node):
-    sequence = [task.OperationTask(node, NORMATIVE_STANDARD_INTERFACE, NORMATIVE_STOP)]
+    sequence = [task.create_task(node, NORMATIVE_STANDARD_INTERFACE, NORMATIVE_STOP)]
     sequence += task.create_relationships_tasks(node,
                                                 NORMATIVE_CONFIGURE_INTERFACE,
                                                 NORMATIVE_REMOVE_SOURCE, NORMATIVE_REMOVE_TARGET)

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/1303f092/aria/orchestrator/workflows/core/translation.py
----------------------------------------------------------------------
diff --git a/aria/orchestrator/workflows/core/translation.py b/aria/orchestrator/workflows/core/translation.py
index d764024..7362d5a 100644
--- a/aria/orchestrator/workflows/core/translation.py
+++ b/aria/orchestrator/workflows/core/translation.py
@@ -49,7 +49,7 @@ def build_execution_graph(
             default=[start_task])
 
         if isinstance(api_task, api.task.OperationTask):
-            if api_task.is_empty:
+            if api_task.has_implementation:
                 operation_task = core_task.OperationTask(api_task)
             else:
                 operation_task = core_task.OperationTask(api_task, executor=default_executor)

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/1303f092/aria/orchestrator/workflows/events_logging.py
----------------------------------------------------------------------
diff --git a/aria/orchestrator/workflows/events_logging.py b/aria/orchestrator/workflows/events_logging.py
index b031146..9913012 100644
--- a/aria/orchestrator/workflows/events_logging.py
+++ b/aria/orchestrator/workflows/events_logging.py
@@ -36,12 +36,9 @@ def _get_task_name(task):
 @events.start_task_signal.connect
 def _start_task_handler(task, **kwargs):
     # If the task has not implementation this is an empty task.
-    if task.implementation:
-        task.context.logger.debug('{name} {task.interface_name}.{task.operation_name} has
no '
-                                  'implementation'.format(name=_get_task_name(task), task=task))
-    else:
-        task.context.logger.info('{name} {task.interface_name}.{task.operation_name} started...'
-                                 .format(name=_get_task_name(task), task=task))
+    suffix = 'started...' if task.implementation else 'has no implementation'
+    task.context.logger.debug('{name} {task.interface_name}.{task.operation_name} {suffix}'
+                              .format(name=_get_task_name(task), task=task, suffix=suffix))
 
 
 @events.on_success_task_signal.connect

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/1303f092/tests/orchestrator/workflows/core/test_engine.py
----------------------------------------------------------------------
diff --git a/tests/orchestrator/workflows/core/test_engine.py b/tests/orchestrator/workflows/core/test_engine.py
index c9911dc..2a5dd8c 100644
--- a/tests/orchestrator/workflows/core/test_engine.py
+++ b/tests/orchestrator/workflows/core/test_engine.py
@@ -60,36 +60,34 @@ class BaseTest(object):
             inputs=None,
             max_attempts=None,
             retry_interval=None,
-            ignore_failure=None,
-            is_stub=False):
+            ignore_failure=None):
         node = ctx.model.node.get_by_name(mock.models.DEPENDENCY_NODE_NAME)
+        interface_name = 'aria.interfaces.lifecycle'
 
-        if not is_stub:
+        if func:
             operation_kwargs = dict(implementation='{name}.{func.__name__}'.format(
                 name=__name__, func=func))
             if inputs:
                 # the operation has to declare the inputs before those may be passed
                 operation_kwargs['inputs'] = inputs
 
-            interface = mock.models.create_interface(
-                node.service,
-                'aria.interfaces.lifecycle',
-                'create',
-                operation_kwargs=operation_kwargs
-            )
+            operation_name = 'create'
+            interface = mock.models.create_interface(node.service, interface_name, operation_name,
+                                                     operation_kwargs=operation_kwargs)
         else:
-            interface = mock.models.create_interface(
-                node.service,
-                'aria.interfaces.lifecycle',
-                'create',
-            )
+            operation_name = 'configure'
+            interface = mock.models.create_interface(node.service, interface_name, operation_name)
 
-        node.interfaces[interface.name] = interface
+        if interface.name not in node.interfaces:
+            node.interfaces[interface.name] = interface
+        else:
+            node.interfaces[interface.name].operations[operation_name] = \
+                interface.operations[operation_name]
 
         return api.task.OperationTask(
             node,
             interface_name='aria.interfaces.lifecycle',
-            operation_name='create',
+            operation_name=operation_name,
             inputs=inputs or {},
             max_attempts=max_attempts,
             retry_interval=retry_interval,
@@ -218,7 +216,7 @@ class TestEngine(BaseTest):
         @workflow
         def sub_workflow(ctx, graph):
             op1 = self._op(ctx, func=mock_ordered_task, inputs={'counter': 1})
-            op2 = self._op(ctx, is_stub=True)
+            op2 = self._op(ctx)
             op3 = self._op(ctx, func=mock_ordered_task, inputs={'counter': 2})
             graph.sequence(op1, op2, op3)
 


Mime
View raw message