ariatosca-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dankil...@apache.org
Subject incubator-ariatosca git commit: ARIA-17 Change task max-retries to max-attempts [Forced Update!]
Date Mon, 14 Nov 2016 08:53:50 GMT
Repository: incubator-ariatosca
Updated Branches:
  refs/heads/ARIA-17-change-retries-to-attempts 7b36aacbd -> eb3dd5d72 (forced update)


ARIA-17 Change task max-retries to max-attempts


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

Branch: refs/heads/ARIA-17-change-retries-to-attempts
Commit: eb3dd5d726050e38d92d02bbebddbdf6d0ffafad
Parents: 4807626
Author: Dan Kilman <dank@gigaspaces.com>
Authored: Mon Nov 14 10:44:22 2016 +0200
Committer: Dan Kilman <dank@gigaspaces.com>
Committed: Mon Nov 14 10:53:45 2016 +0200

----------------------------------------------------------------------
 aria/context/workflow.py                  |  4 ++--
 aria/events/builtin_event_handler.py      |  2 +-
 aria/storage/models.py                    | 12 +++++++++++-
 aria/workflows/api/task.py                |  6 +++---
 aria/workflows/core/task.py               |  2 +-
 tests/context/test_workflow.py            |  2 +-
 tests/mock/context.py                     |  2 +-
 tests/mock/models.py                      |  2 +-
 tests/storage/test_models.py              | 22 +++++++++++++++++++++-
 tests/workflows/api/test_task.py          |  8 ++++----
 tests/workflows/core/test_engine.py       | 24 ++++++++++++------------
 tests/workflows/executor/test_executor.py |  2 +-
 12 files changed, 59 insertions(+), 29 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/eb3dd5d7/aria/context/workflow.py
----------------------------------------------------------------------
diff --git a/aria/context/workflow.py b/aria/context/workflow.py
index 329757a..fb9c8ee 100644
--- a/aria/context/workflow.py
+++ b/aria/context/workflow.py
@@ -47,7 +47,7 @@ class WorkflowContext(logger.LoggerMixin):
             workflow_id,
             execution_id=None,
             parameters=None,
-            task_max_retries=0,
+            task_max_attempts=1,
             task_retry_interval=0,
             **kwargs):
         super(WorkflowContext, self).__init__(**kwargs)
@@ -59,7 +59,7 @@ class WorkflowContext(logger.LoggerMixin):
         self.workflow_id = workflow_id
         self.execution_id = execution_id or str(uuid4())
         self.parameters = parameters or {}
-        self.task_max_retries = task_max_retries
+        self.task_max_attempts = task_max_attempts
         self.task_retry_interval = task_retry_interval
         # TODO: execution creation should happen somewhere else
         # should be moved there, when such logical place exists

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/eb3dd5d7/aria/events/builtin_event_handler.py
----------------------------------------------------------------------
diff --git a/aria/events/builtin_event_handler.py b/aria/events/builtin_event_handler.py
index ac65978..cba3180 100644
--- a/aria/events/builtin_event_handler.py
+++ b/aria/events/builtin_event_handler.py
@@ -55,7 +55,7 @@ def _task_started(task, *args, **kwargs):
 @on_failure_task_signal.connect
 def _task_failed(task, *args, **kwargs):
     with task.update():
-        if task.retry_count < task.max_retries or task.max_retries == task.INFINITE_RETRIES:
+        if task.retry_count < task.max_attempts - 1 or task.max_attempts == task.INFINITE_RETRIES:
             task.status = task.RETRYING
             task.retry_count += 1
             task.due_at = datetime.utcnow() + timedelta(seconds=task.retry_interval)

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/eb3dd5d7/aria/storage/models.py
----------------------------------------------------------------------
diff --git a/aria/storage/models.py b/aria/storage/models.py
index c0f8c28..23f2408 100644
--- a/aria/storage/models.py
+++ b/aria/storage/models.py
@@ -395,6 +395,16 @@ class Task(Model):
     """
     A Model which represents an task
     """
+
+    class _Validation(object):
+
+        @staticmethod
+        def validate_max_attempts(_, value, *args):
+            """Validates that max attempts is either -1 or a positive number"""
+            if value < 1 and value != Task.INFINITE_RETRIES:
+                raise ValueError('Max attempts can be either -1 (infinite) or any positive
number. '
+                                 'Got {value}'.format(value=value))
+
     PENDING = 'pending'
     RETRYING = 'retrying'
     SENT = 'sent'
@@ -419,7 +429,7 @@ class Task(Model):
     due_at = Field(type=datetime, default=datetime.utcnow)
     started_at = Field(type=datetime, default=None)
     ended_at = Field(type=datetime, default=None)
-    max_retries = Field(type=int, default=1)
+    max_attempts = Field(type=int, default=1, validation_func=_Validation.validate_max_attempts)
     retry_count = Field(type=int, default=0)
     retry_interval = Field(type=(int, float), default=0)
 

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/eb3dd5d7/aria/workflows/api/task.py
----------------------------------------------------------------------
diff --git a/aria/workflows/api/task.py b/aria/workflows/api/task.py
index ca62cf7..bb8e045 100644
--- a/aria/workflows/api/task.py
+++ b/aria/workflows/api/task.py
@@ -58,7 +58,7 @@ class OperationTask(BaseTask):
                  name,
                  operation_details,
                  node_instance,
-                 max_retries=None,
+                 max_attempts=None,
                  retry_interval=None,
                  inputs=None):
         """
@@ -73,8 +73,8 @@ class OperationTask(BaseTask):
         self.operation_details = operation_details
         self.node_instance = node_instance
         self.inputs = inputs or {}
-        self.max_retries = (self.workflow_context.task_max_retries
-                            if max_retries is None else max_retries)
+        self.max_attempts = (self.workflow_context.task_max_attempts
+                             if max_attempts is None else max_attempts)
         self.retry_interval = (self.workflow_context.task_retry_interval
                                if retry_interval is None else retry_interval)
 

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/eb3dd5d7/aria/workflows/core/task.py
----------------------------------------------------------------------
diff --git a/aria/workflows/core/task.py b/aria/workflows/core/task.py
index 267c091..b90306a 100644
--- a/aria/workflows/core/task.py
+++ b/aria/workflows/core/task.py
@@ -96,7 +96,7 @@ class OperationTask(BaseTask, logger.LoggerMixin):
             inputs=api_task.inputs,
             status=task_model.PENDING,
             execution_id=self.workflow_context.execution_id,
-            max_retries=api_task.max_retries,
+            max_attempts=api_task.max_attempts,
             retry_interval=api_task.retry_interval,
         )
         self.workflow_context.model.task.store(task)

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/eb3dd5d7/tests/context/test_workflow.py
----------------------------------------------------------------------
diff --git a/tests/context/test_workflow.py b/tests/context/test_workflow.py
index b40a66d..4b71855 100644
--- a/tests/context/test_workflow.py
+++ b/tests/context/test_workflow.py
@@ -49,7 +49,7 @@ class TestWorkflowContext(object):
             deployment_id=models.DEPLOYMENT_ID,
             workflow_id=models.WORKFLOW_ID,
             execution_id=models.EXECUTION_ID,
-            task_max_retries=models.TASK_MAX_RETRIES,
+            task_max_attempts=models.TASK_MAX_ATTEMPTS,
             task_retry_interval=models.TASK_RETRY_INTERVAL
         )
 

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/eb3dd5d7/tests/mock/context.py
----------------------------------------------------------------------
diff --git a/tests/mock/context.py b/tests/mock/context.py
index bef2437..4d218b5 100644
--- a/tests/mock/context.py
+++ b/tests/mock/context.py
@@ -30,6 +30,6 @@ def simple():
         deployment_id=models.DEPLOYMENT_ID,
         workflow_id=models.WORKFLOW_ID,
         execution_id=models.EXECUTION_ID,
-        task_max_retries=models.TASK_MAX_RETRIES,
+        task_max_attempts=models.TASK_MAX_ATTEMPTS,
         task_retry_interval=models.TASK_RETRY_INTERVAL
     )

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/eb3dd5d7/tests/mock/models.py
----------------------------------------------------------------------
diff --git a/tests/mock/models.py b/tests/mock/models.py
index 5547321..295149e 100644
--- a/tests/mock/models.py
+++ b/tests/mock/models.py
@@ -24,7 +24,7 @@ BLUEPRINT_ID = 'test_blueprint_id'
 WORKFLOW_ID = 'test_workflow_id'
 EXECUTION_ID = 'test_execution_id'
 TASK_RETRY_INTERVAL = 1
-TASK_MAX_RETRIES = 1
+TASK_MAX_ATTEMPTS = 1
 
 
 def get_dependency_node():

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/eb3dd5d7/tests/storage/test_models.py
----------------------------------------------------------------------
diff --git a/tests/storage/test_models.py b/tests/storage/test_models.py
index 5c9abe3..6a879fe 100644
--- a/tests/storage/test_models.py
+++ b/tests/storage/test_models.py
@@ -27,7 +27,10 @@ from aria.storage.models import (
     Node,
     NodeInstance,
     Blueprint,
-    Execution)
+    Execution,
+    Task
+)
+from tests.mock import models
 
 # TODO: add tests per model
 
@@ -339,3 +342,20 @@ def test_execution_status_transition():
             execution = create_execution(current_status)
             with pytest.raises(ValueError):
                 execution.status = transitioned_status
+
+
+def test_task_max_attempts_validation():
+    def create_task(max_attempts):
+        Task(execution_id='eid',
+             name='name',
+             operation_details={},
+             inputs={},
+             node_instance=models.get_dependency_node_instance(),
+             max_attempts=max_attempts)
+    create_task(max_attempts=1)
+    create_task(max_attempts=2)
+    create_task(max_attempts=Task.INFINITE_RETRIES)
+    with pytest.raises(ValueError):
+        create_task(max_attempts=0)
+    with pytest.raises(ValueError):
+        create_task(max_attempts=-2)

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/eb3dd5d7/tests/workflows/api/test_task.py
----------------------------------------------------------------------
diff --git a/tests/workflows/api/test_task.py b/tests/workflows/api/test_task.py
index 7ecd28c..857f3bf 100644
--- a/tests/workflows/api/test_task.py
+++ b/tests/workflows/api/test_task.py
@@ -67,7 +67,7 @@ class TestOperationTask(object):
         op_details = {'operation_details': True}
         node_instance = mock.models.get_dependency_node_instance()
         inputs = {'inputs': True}
-        max_retries = 10
+        max_attempts = 10
         retry_interval = 10
 
         with context.workflow.current.push(workflow_context):
@@ -75,7 +75,7 @@ class TestOperationTask(object):
                                                 operation_details=op_details,
                                                 node_instance=node_instance,
                                                 inputs=inputs,
-                                                max_retries=max_retries,
+                                                max_attempts=max_attempts,
                                                 retry_interval=retry_interval)
 
         assert model_task.name == name
@@ -83,7 +83,7 @@ class TestOperationTask(object):
         assert model_task.node_instance == node_instance
         assert model_task.inputs == inputs
         assert model_task.retry_interval == retry_interval
-        assert model_task.max_retries == max_retries
+        assert model_task.max_attempts == max_attempts
 
     def test_operation_task_default_values(self):
         workflow_context = mock.context.simple()
@@ -95,7 +95,7 @@ class TestOperationTask(object):
 
         assert model_task.inputs == {}
         assert model_task.retry_interval == workflow_context.task_retry_interval
-        assert model_task.max_retries == workflow_context.task_max_retries
+        assert model_task.max_attempts == workflow_context.task_max_attempts
 
 
 class TestWorkflowTask(object):

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/eb3dd5d7/tests/workflows/core/test_engine.py
----------------------------------------------------------------------
diff --git a/tests/workflows/core/test_engine.py b/tests/workflows/core/test_engine.py
index 984d5da..744e155 100644
--- a/tests/workflows/core/test_engine.py
+++ b/tests/workflows/core/test_engine.py
@@ -54,14 +54,14 @@ class BaseTest(object):
                              tasks_graph=graph)
 
     @staticmethod
-    def _op(func, ctx, inputs=None, max_retries=None, retry_interval=None):
+    def _op(func, ctx, inputs=None, max_attempts=None, retry_interval=None):
         return api.task.OperationTask(
             name='task',
             operation_details={'operation': 'tests.workflows.core.test_engine.{name}'.format(
                 name=func.__name__)},
             node_instance=ctx.model.node_instance.get('dependency_node_instance'),
             inputs=inputs,
-            max_retries=max_retries,
+            max_attempts=max_attempts,
             retry_interval=retry_interval
         )
 
@@ -261,12 +261,12 @@ class TestCancel(BaseTest):
 
 class TestRetries(BaseTest):
 
-    def test_one_max_retries_and_success_on_retry(self, workflow_context, executor):
+    def test_two_max_attempts_and_success_on_retry(self, workflow_context, executor):
         @workflow
         def mock_workflow(ctx, graph):
             op = self._op(mock_conditional_failure_task, ctx,
                           inputs={'failure_count': 1},
-                          max_retries=1)
+                          max_attempts=2)
             graph.add_tasks(op)
         self._execute(
             workflow_func=mock_workflow,
@@ -277,12 +277,12 @@ class TestRetries(BaseTest):
         assert len(global_test_holder.get('invocations', [])) == 2
         assert global_test_holder.get('sent_task_signal_calls') == 2
 
-    def test_one_max_retries_and_failure_on_retry(self, workflow_context, executor):
+    def test_two_max_attempts_and_failure_on_retry(self, workflow_context, executor):
         @workflow
         def mock_workflow(ctx, graph):
             op = self._op(mock_conditional_failure_task, ctx,
                           inputs={'failure_count': 2},
-                          max_retries=1)
+                          max_attempts=2)
             graph.add_tasks(op)
         with pytest.raises(exceptions.ExecutorException):
             self._execute(
@@ -294,12 +294,12 @@ class TestRetries(BaseTest):
         assert len(global_test_holder.get('invocations', [])) == 2
         assert global_test_holder.get('sent_task_signal_calls') == 2
 
-    def test_two_max_retries_and_success_on_first_retry(self, workflow_context, executor):
+    def test_three_max_attempts_and_success_on_first_retry(self, workflow_context, executor):
         @workflow
         def mock_workflow(ctx, graph):
             op = self._op(mock_conditional_failure_task, ctx,
                           inputs={'failure_count': 1},
-                          max_retries=2)
+                          max_attempts=3)
             graph.add_tasks(op)
         self._execute(
             workflow_func=mock_workflow,
@@ -310,12 +310,12 @@ class TestRetries(BaseTest):
         assert len(global_test_holder.get('invocations', [])) == 2
         assert global_test_holder.get('sent_task_signal_calls') == 2
 
-    def test_two_max_retries_and_success_on_second_retry(self, workflow_context, executor):
+    def test_three_max_attempts_and_success_on_second_retry(self, workflow_context, executor):
         @workflow
         def mock_workflow(ctx, graph):
             op = self._op(mock_conditional_failure_task, ctx,
                           inputs={'failure_count': 2},
-                          max_retries=2)
+                          max_attempts=3)
             graph.add_tasks(op)
         self._execute(
             workflow_func=mock_workflow,
@@ -331,7 +331,7 @@ class TestRetries(BaseTest):
         def mock_workflow(ctx, graph):
             op = self._op(mock_conditional_failure_task, ctx,
                           inputs={'failure_count': 1},
-                          max_retries=-1)
+                          max_attempts=-1)
             graph.add_tasks(op)
         self._execute(
             workflow_func=mock_workflow,
@@ -357,7 +357,7 @@ class TestRetries(BaseTest):
         def mock_workflow(ctx, graph):
             op = self._op(mock_conditional_failure_task, ctx,
                           inputs={'failure_count': 1},
-                          max_retries=1,
+                          max_attempts=2,
                           retry_interval=retry_interval)
             graph.add_tasks(op)
         self._execute(

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/eb3dd5d7/tests/workflows/executor/test_executor.py
----------------------------------------------------------------------
diff --git a/tests/workflows/executor/test_executor.py b/tests/workflows/executor/test_executor.py
index 1318485..0faa753 100644
--- a/tests/workflows/executor/test_executor.py
+++ b/tests/workflows/executor/test_executor.py
@@ -117,7 +117,7 @@ class MockTask(object):
         self.name = name
         self.inputs = inputs or {}
         self.retry_count = 0
-        self.max_retries = 0
+        self.max_attempts = 1
 
         for state in models.Task.STATES:
             setattr(self, state.upper(), state)


Mime
View raw message