ariatosca-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject [3/3] incubator-ariatosca git commit: Add status-related methods to the Execution, Task and Node models
Date Tue, 28 Mar 2017 12:08:44 GMT
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/02fedd92
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/02fedd92
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/02fedd92

Branch: refs/heads/ARIA-133-Add-status-related-methods-to-Execution-Task-and-Node-models
Commit: 02fedd928367d85b589b10c6c62a91f124b917d5
Parents: 2de0497
Author: Avia Efrat <avia@gigaspaces.com>
Authored: Tue Mar 28 12:51:42 2017 +0300
Committer: Avia Efrat <avia@gigaspaces.com>
Committed: Tue Mar 28 15:08:33 2017 +0300

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


http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/02fedd92/aria/modeling/orchestration.py
----------------------------------------------------------------------
diff --git a/aria/modeling/orchestration.py b/aria/modeling/orchestration.py
index a13ae87..b35b293 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 logs(cls):
         return relationship.one_to_many(cls, 'log')
@@ -240,9 +245,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'
@@ -288,6 +290,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/02fedd92/aria/modeling/service_instance.py
----------------------------------------------------------------------
diff --git a/aria/modeling/service_instance.py b/aria/modeling/service_instance.py
index e2e5ae0..80828b1 100644
--- a/aria/modeling/service_instance.py
+++ b/aria/modeling/service_instance.py
@@ -417,7 +417,8 @@ class NodeBase(InstanceModelMixin):
         except KeyError:
             return None
 
-    # region foreign_keys
+    def not_deleted_or_errored(self):
+        return self.state not in [self.DELETED, self.ERROR]
 
     @declared_attr
     def type_fk(cls):

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


Mime
View raw message