You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ariatosca.apache.org by av...@apache.org on 2017/03/28 11:58:46 UTC

incubator-ariatosca git commit: Add status-related methods to the Execution, Task and Node models

Repository: incubator-ariatosca
Updated Branches:
  refs/heads/ARIA-133-Add-status-related-methods-to-Execution-Task-and-Node-models [created] 8ccb67aa7


Add status-related methods to the Execution, Task and Node models

We are adding these methods so it will be easier to filter those models
from storage according to their status, and to not make use of the their
`status` constants outside of the models themselves.


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

Branch: refs/heads/ARIA-133-Add-status-related-methods-to-Execution-Task-and-Node-models
Commit: 8ccb67aa7ce9ff38279be6a58d021d386961a086
Parents: 07cbfcd
Author: Avia Efrat <av...@gigaspaces.com>
Authored: Tue Mar 28 12:51:42 2017 +0300
Committer: Avia Efrat <av...@gigaspaces.com>
Committed: Tue Mar 28 14:55:09 2017 +0300

----------------------------------------------------------------------
 aria/modeling/orchestration.py             | 16 ++++++++++++----
 aria/orchestrator/workflows/core/engine.py |  7 +++----
 2 files changed, 15 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/8ccb67aa/aria/modeling/orchestration.py
----------------------------------------------------------------------
diff --git a/aria/modeling/orchestration.py b/aria/modeling/orchestration.py
index 2d58671..e6f6c7f 100644
--- a/aria/modeling/orchestration.py
+++ b/aria/modeling/orchestration.py
@@ -69,7 +69,6 @@ class ExecutionBase(ModelMixin):
 
     STATES = [TERMINATED, FAILED, CANCELLED, PENDING, STARTED, CANCELLING, FORCE_CANCELLING]
     END_STATES = [TERMINATED, FAILED, CANCELLED]
-    ACTIVE_STATES = [state for state in STATES if state not in END_STATES]
 
     VALID_TRANSITIONS = {
         PENDING: [STARTED, CANCELLED],
@@ -102,6 +101,12 @@ class ExecutionBase(ModelMixin):
     status = Column(Enum(*STATES, name='execution_status'), default=PENDING)
     workflow_name = Column(Text)
 
+    def has_ended(self):
+        return self.status in self.END_STATES
+
+    def is_active(self):
+        return not self.has_ended()
+
     @declared_attr
     def service(cls):
         return relationship.many_to_one(cls, 'service')
@@ -228,9 +233,6 @@ class TaskBase(ModelMixin):
         FAILED,
     )
 
-    WAIT_STATES = [PENDING, RETRYING]
-    END_STATES = [SUCCESS, FAILED]
-
     RUNS_ON_SOURCE = 'source'
     RUNS_ON_TARGET = 'target'
     RUNS_ON_NODE = 'node'
@@ -272,6 +274,12 @@ class TaskBase(ModelMixin):
     implementation = Column(String)
     _runs_on = Column(Enum(*RUNS_ON, name='runs_on'), name='runs_on')
 
+    def is_waiting(self):
+        return self.status in [self.PENDING, self.RETRYING]
+
+    def has_ended(self):
+        return not self.is_waiting()
+
     @property
     def runs_on(self):
         if self._runs_on == self.RUNS_ON_NODE:

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/8ccb67aa/aria/orchestrator/workflows/core/engine.py
----------------------------------------------------------------------
diff --git a/aria/orchestrator/workflows/core/engine.py b/aria/orchestrator/workflows/core/engine.py
index fa4550d..3228934 100644
--- a/aria/orchestrator/workflows/core/engine.py
+++ b/aria/orchestrator/workflows/core/engine.py
@@ -88,12 +88,11 @@ class Engine(logger.LoggerMixin):
     def _executable_tasks(self):
         now = datetime.utcnow()
         return (task for task in self._tasks_iter()
-                if task.status in models.Task.WAIT_STATES and
-                task.due_at <= now and
+                if task.is_waiting() and task.due_at <= now and
                 not self._task_has_dependencies(task))
 
     def _ended_tasks(self):
-        return (task for task in self._tasks_iter() if task.status in models.Task.END_STATES)
+        return (task for task in self._tasks_iter() if task.has_ended)
 
     def _task_has_dependencies(self, task):
         return len(self._execution_graph.pred.get(task.id, {})) > 0
@@ -105,7 +104,7 @@ class Engine(logger.LoggerMixin):
         for _, data in self._execution_graph.nodes_iter(data=True):
             task = data['task']
             if isinstance(task, engine_task.OperationTask):
-                if task.model_task.status not in models.Task.END_STATES:
+                if not task.model_task.has_ended():
                     self._workflow_context.model.task.refresh(task.model_task)
             yield task