ariatosca-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From emblempar...@apache.org
Subject [05/14] incubator-ariatosca git commit: ARIA-133 Add status-related properties to the Execution, Task and Node models
Date Fri, 07 Apr 2017 00:54:58 GMT
ARIA-133 Add status-related properties to the Execution, Task and Node models

We are adding these properties 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.

It should be noted, since we currently have the concept of `StubTasks`
(that are not part of the model), we had to implement the same logic for
them, although they don't direct access to the state constants of the
task model. We did this since they are treated as 'regular' model tasks
in some parts of the code.


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

Branch: refs/heads/ARIA-92-plugin-in-implementation-string
Commit: 941d85c0ed622b6b233f38f853145c6a55120dec
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 18:41:19 2017 +0300

----------------------------------------------------------------------
 aria/modeling/orchestration.py             | 20 ++++++++++++++++----
 aria/modeling/service_instance.py          |  4 ++++
 aria/orchestrator/workflows/core/engine.py |  6 +++---
 aria/orchestrator/workflows/core/task.py   |  8 ++++++++
 4 files changed, 31 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/941d85c0/aria/modeling/orchestration.py
----------------------------------------------------------------------
diff --git a/aria/modeling/orchestration.py b/aria/modeling/orchestration.py
index a13ae87..f0bd4b2 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,14 @@ class ExecutionBase(ModelMixin):
     status = Column(Enum(*STATES, name='execution_status'), default=PENDING)
     workflow_name = Column(Text)
 
+    @property
+    def has_ended(self):
+        return self.status in self.END_STATES
+
+    @property
+    def is_active(self):
+        return not self.has_ended
+
     @declared_attr
     def logs(cls):
         return relationship.one_to_many(cls, 'log')
@@ -240,9 +247,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'
@@ -289,6 +293,14 @@ class TaskBase(ModelMixin):
     _runs_on = Column(Enum(*RUNS_ON, name='runs_on'), name='runs_on')
 
     @property
+    def has_ended(self):
+        return self.status in [self.SUCCESS, self.FAILED]
+
+    @property
+    def is_waiting(self):
+        return self.status in [self.PENDING, self.RETRYING]
+
+    @property
     def runs_on(self):
         if self._runs_on == self.RUNS_ON_NODE:
             return self.node

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/941d85c0/aria/modeling/service_instance.py
----------------------------------------------------------------------
diff --git a/aria/modeling/service_instance.py b/aria/modeling/service_instance.py
index e2e5ae0..e6c2b12 100644
--- a/aria/modeling/service_instance.py
+++ b/aria/modeling/service_instance.py
@@ -417,6 +417,10 @@ class NodeBase(InstanceModelMixin):
         except KeyError:
             return None
 
+    @property
+    def is_available(self):
+        return self.state not in [self.INITIAL, self.DELETED, self.ERROR]
+
     # region foreign_keys
 
     @declared_attr

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/941d85c0/aria/orchestrator/workflows/core/engine.py
----------------------------------------------------------------------
diff --git a/aria/orchestrator/workflows/core/engine.py b/aria/orchestrator/workflows/core/engine.py
index fa4550d..d32abb8 100644
--- a/aria/orchestrator/workflows/core/engine.py
+++ b/aria/orchestrator/workflows/core/engine.py
@@ -88,12 +88,12 @@ 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
+                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 +105,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
 

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/941d85c0/aria/orchestrator/workflows/core/task.py
----------------------------------------------------------------------
diff --git a/aria/orchestrator/workflows/core/task.py b/aria/orchestrator/workflows/core/task.py
index 1e13588..aa8963f 100644
--- a/aria/orchestrator/workflows/core/task.py
+++ b/aria/orchestrator/workflows/core/task.py
@@ -69,6 +69,14 @@ class StubTask(BaseTask):
         self.status = models.Task.PENDING
         self.due_at = datetime.utcnow()
 
+    @property
+    def has_ended(self):
+        return self.status in [models.Task.SUCCESS, models.Task.FAILED]
+
+    @property
+    def is_waiting(self):
+        return self.status in [models.Task.PENDING, models.Task.RETRYING]
+
 
 class StartWorkflowTask(StubTask):
     """


Mime
View raw message