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/26 09:25:59 UTC
[09/12] incubator-ariatosca git commit: Initial version of node state
changes
Initial version of node state changes
No validation of transitions.
Without addressing the 'error' state.
Project: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/commit/e8e760ab
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/e8e760ab
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/e8e760ab
Branch: refs/heads/ARIA-126-update-node-statuses
Commit: e8e760aba4038d24c7aaa46168d924db3833b9a6
Parents: b3cf69a
Author: Avia Efrat <av...@gigaspaces.com>
Authored: Wed Mar 22 17:19:58 2017 +0200
Committer: Avia Efrat <av...@gigaspaces.com>
Committed: Sun Mar 26 12:25:33 2017 +0300
----------------------------------------------------------------------
aria/modeling/service_instance.py | 38 +++++++++++++++++---
aria/modeling/service_template.py | 2 +-
.../workflows/core/events_handler.py | 15 ++++++++
tests/mock/models.py | 2 +-
tests/modeling/test_mixins.py | 2 +-
5 files changed, 52 insertions(+), 7 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/e8e760ab/aria/modeling/service_instance.py
----------------------------------------------------------------------
diff --git a/aria/modeling/service_instance.py b/aria/modeling/service_instance.py
index f120734..b38d214 100644
--- a/aria/modeling/service_instance.py
+++ b/aria/modeling/service_instance.py
@@ -18,7 +18,9 @@
from sqlalchemy import (
Column,
Text,
- Integer
+ Integer,
+ Enum,
+ orm
)
from sqlalchemy import DateTime
from sqlalchemy.ext.associationproxy import association_proxy
@@ -322,8 +324,8 @@ class NodeBase(InstanceModelMixin): # pylint: disable=too-many-public-methods
:vartype runtime_properties: {}
:ivar scaling_groups: ??
:vartype scaling_groups: []
- :ivar state: ??
- :vartype state: basestring
+ :ivar state: The state of the node, according to to the TOSCA-defined node states
+ :vartype state: string
:ivar version: Used by `aria.storage.instrumentation`
:vartype version: int
@@ -347,6 +349,34 @@ class NodeBase(InstanceModelMixin): # pylint: disable=too-many-public-methods
'node_template_fk',
'service_name']
+ INITIAL = 'initial'
+ CREATING = 'creating'
+ CREATED = 'created'
+ CONFIGURING = 'configuring'
+ CONFIGURED = 'configured'
+ STARTING = 'starting'
+ STARTED = 'started'
+ STOPPING = 'stopping'
+ DELETING = 'deleting'
+ ERROR = 'error'
+
+ STATES = {INITIAL, CREATING, CREATED, CONFIGURING, CONFIGURED, STARTING, STARTED, STOPPING,
+ DELETING, ERROR}
+
+ _op_to_state = {'create': {'transitional': CREATING, 'finished': CREATED},
+ 'configure': {'transitional': CONFIGURING, 'finished': CONFIGURED},
+ 'start': {'transitional': STARTING, 'finished': STARTED},
+ 'stop': {'transitional': STOPPING},
+ 'delete': {'transitional': DELETING}}
+
+ @classmethod
+ def determine_state(cls, op_name, transitional):
+ state_type = 'transitional' if transitional else 'finished'
+ try:
+ return cls._op_to_state[op_name][state_type]
+ except AttributeError:
+ return None
+
@declared_attr
def node_template(cls):
return relationship.many_to_one(cls, 'node_template')
@@ -391,7 +421,7 @@ class NodeBase(InstanceModelMixin): # pylint: disable=too-many-public-methods
runtime_properties = Column(modeling_types.Dict)
scaling_groups = Column(modeling_types.List)
- state = Column(Text, nullable=False)
+ state = Column(Enum(*STATES, name='node_state'), nullable=False, default=INITIAL)
version = Column(Integer, default=1)
__mapper_args__ = {'version_id_col': version} # Enable SQLAlchemy automatic version counting
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/e8e760ab/aria/modeling/service_template.py
----------------------------------------------------------------------
diff --git a/aria/modeling/service_template.py b/aria/modeling/service_template.py
index 7246ff1..8b619bf 100644
--- a/aria/modeling/service_template.py
+++ b/aria/modeling/service_template.py
@@ -497,7 +497,7 @@ class NodeTemplateBase(TemplateModelMixin):
node = models.Node(name=name,
type=self.type,
description=deepcopy_with_locators(self.description),
- state='',
+ state=models.Node.INITIAL,
node_template=self)
utils.instantiate_dict(node, node.properties, self.properties)
utils.instantiate_dict(node, node.interfaces, self.interface_templates)
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/e8e760ab/aria/orchestrator/workflows/core/events_handler.py
----------------------------------------------------------------------
diff --git a/aria/orchestrator/workflows/core/events_handler.py b/aria/orchestrator/workflows/core/events_handler.py
index a420d2b..814f6a2 100644
--- a/aria/orchestrator/workflows/core/events_handler.py
+++ b/aria/orchestrator/workflows/core/events_handler.py
@@ -20,6 +20,7 @@ Path: aria.events.storage_event_handler
Implementation of storage handlers for workflow and operation events.
"""
+import re
from datetime import (
datetime,
@@ -41,6 +42,9 @@ def _task_started(task, *args, **kwargs):
task.started_at = datetime.utcnow()
task.status = task.STARTED
+ # update node state if necessary
+ _update_node_state(task, transitional=True)
+
@events.on_failure_task_signal.connect
def _task_failed(task, exception, *args, **kwargs):
@@ -73,6 +77,9 @@ def _task_succeeded(task, *args, **kwargs):
task.ended_at = datetime.utcnow()
task.status = task.SUCCESS
+ # update node state if necessary
+ _update_node_state(task)
+
@events.start_workflow_signal.connect
def _workflow_started(workflow_context, *args, **kwargs):
@@ -118,3 +125,11 @@ def _workflow_cancelling(workflow_context, *args, **kwargs):
return _workflow_cancelled(workflow_context=workflow_context)
execution.status = execution.CANCELLING
workflow_context.execution = execution
+
+
+def _update_node_state(task, transitional=False):
+ match = re.search('^Standard:(\S+)@node', task.context.name)
+ if match:
+ state = task.runs_on.determine_state(match.group(1), transitional)
+ if state:
+ task.runs_on.state = state
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/e8e760ab/tests/mock/models.py
----------------------------------------------------------------------
diff --git a/tests/mock/models.py b/tests/mock/models.py
index a60b35e..6e8eae4 100644
--- a/tests/mock/models.py
+++ b/tests/mock/models.py
@@ -136,7 +136,7 @@ def create_dependent_node(dependent_node_template, service):
runtime_properties={},
version=None,
node_template=dependent_node_template,
- state='',
+ state=models.Node.INITIAL,
scaling_groups=[],
service=service
)
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/e8e760ab/tests/modeling/test_mixins.py
----------------------------------------------------------------------
diff --git a/tests/modeling/test_mixins.py b/tests/modeling/test_mixins.py
index 7795b57..6a59102 100644
--- a/tests/modeling/test_mixins.py
+++ b/tests/modeling/test_mixins.py
@@ -127,7 +127,7 @@ def test_relationship_model_ordering(context):
service=service,
version=None,
node_template=new_node_template,
- state='',
+ state=models.Node.INITIAL,
scaling_groups=[]
)