Repository: incubator-ariatosca Updated Branches: refs/heads/ARIA-126-update-node-statuses [created] c3abcc870
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/5a6d3d86 Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/5a6d3d86 Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/5a6d3d86 Branch: refs/heads/ARIA-126-update-node-statuses Commit: 5a6d3d86b82c4a625d8117ac68aa4060ee61a784 Parents: 9841ca4 Author: Avia Efrat <[email protected]> Authored: Wed Mar 22 17:19:58 2017 +0200 Committer: Avia Efrat <[email protected]> Committed: Wed Mar 22 17:26:35 2017 +0200 ---------------------------------------------------------------------- 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/5a6d3d86/aria/modeling/service_instance.py ---------------------------------------------------------------------- diff --git a/aria/modeling/service_instance.py b/aria/modeling/service_instance.py index b97c148..7b82341 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 @@ -324,8 +326,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 @@ -349,6 +351,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') @@ -397,7 +427,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/5a6d3d86/aria/modeling/service_template.py ---------------------------------------------------------------------- diff --git a/aria/modeling/service_template.py b/aria/modeling/service_template.py index 5d667e3..8bb03e5 100644 --- a/aria/modeling/service_template.py +++ b/aria/modeling/service_template.py @@ -504,7 +504,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/5a6d3d86/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/5a6d3d86/tests/mock/models.py ---------------------------------------------------------------------- diff --git a/tests/mock/models.py b/tests/mock/models.py index bf43a75..3695898 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/5a6d3d86/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=[] )
