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 14:35:02 UTC
incubator-ariatosca git commit: ARIA-133 Add status-related
properties 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 77e35d02b -> 9cfc094d5 (forced update)
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/9cfc094d
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/9cfc094d
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/9cfc094d
Branch: refs/heads/ARIA-133-Add-status-related-methods-to-Execution-Task-and-Node-models
Commit: 9cfc094d533cb8ce410faeccad32dfed8670445f
Parents: 2de0497
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 17:30:36 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 | 9 +++++++++
4 files changed, 32 insertions(+), 7 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/9cfc094d/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/9cfc094d/aria/modeling/service_instance.py
----------------------------------------------------------------------
diff --git a/aria/modeling/service_instance.py b/aria/modeling/service_instance.py
index e2e5ae0..3a5495a 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 not_deleted_or_errored(self):
+ return self.state not in [self.DELETED, self.ERROR]
+
# region foreign_keys
@declared_attr
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/9cfc094d/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/9cfc094d/aria/orchestrator/workflows/core/task.py
----------------------------------------------------------------------
diff --git a/aria/orchestrator/workflows/core/task.py b/aria/orchestrator/workflows/core/task.py
index 1e13588..cccb752 100644
--- a/aria/orchestrator/workflows/core/task.py
+++ b/aria/orchestrator/workflows/core/task.py
@@ -69,6 +69,15 @@ 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):
"""