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 12:05:25 UTC

incubator-ariatosca git commit: Add status-related methods to the Execution, Task and Node models [Forced Update!]

Repository: incubator-ariatosca
Updated Branches:
  refs/heads/ARIA-133-Add-status-related-methods-to-Execution-Task-and-Node-models 8ccb67aa7 -> a08f6d657 (forced update)


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

Branch: refs/heads/ARIA-133-Add-status-related-methods-to-Execution-Task-and-Node-models
Commit: a08f6d6578a855a88a54c8c97a8a3ca28dd7c56c
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 15:03:43 2017 +0300

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


http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/a08f6d65/aria/modeling/orchestration.py
----------------------------------------------------------------------
diff --git a/aria/modeling/orchestration.py b/aria/modeling/orchestration.py
index 2d58671..a2bb7a6 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 has_ended(self):
+        return self.status in [self.SUCCESS, self.FAILED]
+
+    def is_waiting(self):
+        return not self.has_ended()
+
     @property
     def runs_on(self):
         if self._runs_on == self.RUNS_ON_NODE:

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/a08f6d65/aria/modeling/service_instance.py
----------------------------------------------------------------------
diff --git a/aria/modeling/service_instance.py b/aria/modeling/service_instance.py
index 1e18db0..1b17ffd 100644
--- a/aria/modeling/service_instance.py
+++ b/aria/modeling/service_instance.py
@@ -391,6 +391,9 @@ class NodeBase(InstanceModelMixin): # pylint: disable=too-many-public-methods
         except KeyError:
             return None
 
+    def not_deleted_or_errored(self):
+        return self.state not in [self.DELETED, self.ERROR]
+
     @declared_attr
     def node_template(cls):
         return relationship.many_to_one(cls, 'node_template')

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