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:22:25 UTC

[1/8] incubator-ariatosca git commit: Initial version of node state changes

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 <av...@gigaspaces.com>
Authored: Wed Mar 22 17:19:58 2017 +0200
Committer: Avia Efrat <av...@gigaspaces.com>
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=[]
     )
 


[4/8] incubator-ariatosca git commit: Add tests

Posted by av...@apache.org.
Add tests


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

Branch: refs/heads/ARIA-126-update-node-statuses
Commit: c248108870614f374410a959ac727646089e25b3
Parents: 2fa8466
Author: Avia Efrat <av...@gigaspaces.com>
Authored: Fri Mar 24 16:44:00 2017 +0300
Committer: Avia Efrat <av...@gigaspaces.com>
Committed: Sun Mar 26 11:31:09 2017 +0300

----------------------------------------------------------------------
 .../orchestrator/workflows/core/test_events.py  | 130 +++++++++++++++++++
 1 file changed, 130 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/c2481088/tests/orchestrator/workflows/core/test_events.py
----------------------------------------------------------------------
diff --git a/tests/orchestrator/workflows/core/test_events.py b/tests/orchestrator/workflows/core/test_events.py
new file mode 100644
index 0000000..5e717e7
--- /dev/null
+++ b/tests/orchestrator/workflows/core/test_events.py
@@ -0,0 +1,130 @@
+import pytest
+from tests import mock, storage
+from aria.modeling.service_instance import NodeBase
+from aria.orchestrator.decorators import operation, workflow
+from aria.orchestrator.workflows.core import engine
+from aria.orchestrator.workflows.executor.thread import ThreadExecutor
+from aria.orchestrator.workflows import api
+
+global_test_dict = {}  # used the capture transitional node state changes
+
+
+@pytest.fixture
+def ctx(tmpdir):
+    context = mock.context.simple(str(tmpdir))
+    yield context
+    storage.release_sqlite_storage(context.model)
+
+# TODO another possible approach of writing these tests:
+# Don't create a ctx for every test.
+# Problem is, that if for every test we create a workflow that contains just one standard
+# lifecycle operation, then by the time we try to run the second test, the workflow failes since
+# the execution tries to go from 'terminated' to 'pending'.
+# And if we write a workflow that contains all the lifecycle operations, then first we need to
+# change the api of `mock.models.create_interface`, which a lot of other tests use, and second how
+# do we check all the state transition during the workflow execution in a convenient way.
+
+TYPE_URI_NAME = 'tosca.interfaces.node.lifecycle.Standard'
+SHORTHAND_NAME = 'Standard'
+
+def test_node_state_changes_as_a_result_of_standard_lifecycle_create(ctx):
+    node = run_operation_on_node(ctx, interface_name=TYPE_URI_NAME, op_name='create')
+    _assert_node_state_changed_as_a_result_of_standard_lifecycle_operation(node, 'create')
+
+
+def test_node_state_changes_as_a_result_of_standard_lifecycle_configure(ctx):
+    node = run_operation_on_node(ctx, interface_name=TYPE_URI_NAME, op_name='configure')
+    _assert_node_state_changed_as_a_result_of_standard_lifecycle_operation(node, 'configure')
+
+
+def test_node_state_changes_as_a_result_of_standard_lifecycle_start(ctx):
+    node = run_operation_on_node(ctx, interface_name=TYPE_URI_NAME, op_name='start')
+    _assert_node_state_changed_as_a_result_of_standard_lifecycle_operation(node, 'start')
+
+
+def test_node_state_changes_as_a_result_of_standard_lifecycle_stop(ctx):
+    node = run_operation_on_node(ctx, interface_name=TYPE_URI_NAME, op_name='stop')
+    _assert_node_state_changed_as_a_result_of_standard_lifecycle_operation(node, 'stop')
+
+
+def test_node_state_changes_as_a_result_of_standard_lifecycle_delete(ctx):
+    node = run_operation_on_node(ctx, interface_name=TYPE_URI_NAME, op_name='delete')
+    _assert_node_state_changed_as_a_result_of_standard_lifecycle_operation(node, 'delete')
+
+
+def test_node_state_changes_as_a_result_of_standard_lifecycle_create_shorthand_name(ctx):
+    node = run_operation_on_node(ctx, interface_name=SHORTHAND_NAME, op_name='create')
+    _assert_node_state_changed_as_a_result_of_standard_lifecycle_operation(node, 'create')
+
+
+def test_node_state_changes_as_a_result_of_standard_lifecycle_configure_shorthand_name(ctx):
+    node = run_operation_on_node(ctx, interface_name=SHORTHAND_NAME, op_name='configure')
+    _assert_node_state_changed_as_a_result_of_standard_lifecycle_operation(node, 'configure')
+
+
+def test_node_state_changes_as_a_result_of_standard_lifecycle_start_shorthand_name(ctx):
+    node = run_operation_on_node(ctx, interface_name=SHORTHAND_NAME, op_name='start')
+    _assert_node_state_changed_as_a_result_of_standard_lifecycle_operation(node, 'start')
+
+
+def test_node_state_changes_as_a_result_of_standard_lifecycle_stop_shorthand_name(ctx):
+    node = run_operation_on_node(ctx, interface_name=SHORTHAND_NAME, op_name='stop')
+    _assert_node_state_changed_as_a_result_of_standard_lifecycle_operation(node, 'stop')
+
+
+def test_node_state_changes_as_a_result_of_standard_lifecycle_delete_shorthand_name(ctx):
+    node = run_operation_on_node(ctx, interface_name=SHORTHAND_NAME, op_name='delete')
+    _assert_node_state_changed_as_a_result_of_standard_lifecycle_operation(node, 'delete')
+
+
+def test_node_state_doesnt_change_as_a_result_of_an_operation_that_is_not_standard_lifecycle1(ctx):
+    node = run_operation_on_node(ctx, interface_name='interface_name', op_name='op_name')
+    assert node.state == node.INITIAL
+
+
+def test_node_state_doesnt_change_as_a_result_of_an_operation_that_is_not_standard_lifecycle2(ctx):
+    node = run_operation_on_node(ctx, interface_name='interface_name', op_name='create')
+    assert node.state == node.INITIAL
+
+
+def run_operation_on_node(ctx, op_name, interface_name):
+    node = ctx.model.node.get_by_name(mock.models.DEPENDENCY_NODE_NAME)
+    interface = mock.models.create_interface(
+        service=node.service,
+        interface_name=interface_name,
+        operation_name=op_name,
+        operation_kwargs=dict(implementation='{name}.{func.__name__}'.format(name=__name__,
+                                                                             func=func)))
+    node.interfaces[interface.name] = interface
+
+    eng = engine.Engine(executor=ThreadExecutor(),
+                        workflow_context=ctx,
+                        tasks_graph=single_operation_workflow(ctx=ctx,
+                                                              node=node,
+                                                              interface_name=interface_name,
+                                                              op_name=op_name))
+    eng.execute()
+    return node
+
+
+def run_standard_lifecycle_operation_on_node(ctx, op_name):
+    return run_operation_on_node(ctx, interface_name='aria.interfaces.lifecycle.Standard',
+                                 op_name=op_name)
+
+
+def _assert_node_state_changed_as_a_result_of_standard_lifecycle_operation(node, op_name):
+    assert global_test_dict['transitional_state'] == NodeBase._op_to_state[op_name]['transitional']
+    assert node.state == NodeBase._op_to_state[op_name]['finished']
+
+
+@workflow
+def single_operation_workflow(ctx, graph, node, interface_name, op_name):
+    graph.add_tasks(api.task.OperationTask.for_node(
+        node=node,
+        interface_name=interface_name,
+        operation_name=op_name))
+
+
+@operation
+def func(ctx):
+    global_test_dict['transitional_state'] = ctx.node.state


[5/8] incubator-ariatosca git commit: Include both type uri and shorthand name for standard interface regex

Posted by av...@apache.org.
Include both type uri and shorthand name for standard interface regex


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

Branch: refs/heads/ARIA-126-update-node-statuses
Commit: 0ee98a6b88306b086f96fde9c67bff487d283814
Parents: c248108
Author: Avia Efrat <av...@gigaspaces.com>
Authored: Sun Mar 26 11:41:05 2017 +0300
Committer: Avia Efrat <av...@gigaspaces.com>
Committed: Sun Mar 26 11:41:05 2017 +0300

----------------------------------------------------------------------
 aria/orchestrator/workflows/core/events_handler.py | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/0ee98a6b/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 814f6a2..16563e1 100644
--- a/aria/orchestrator/workflows/core/events_handler.py
+++ b/aria/orchestrator/workflows/core/events_handler.py
@@ -128,8 +128,11 @@ def _workflow_cancelling(workflow_context, *args, **kwargs):
 
 
 def _update_node_state(task, transitional=False):
-        match = re.search('^Standard:(\S+)@node', task.context.name)
+        match = re.search('(?:tosca.interfaces.node.lifecycle.Standard|Standard):(\S+)@node',
+                          task.context.name)
         if match:
-            state = task.runs_on.determine_state(match.group(1), transitional)
+            node = task.runs_on
+            state = node.determine_state(match.group(1), transitional)
             if state:
-                task.runs_on.state = state
+                node.state = state
+                task.context.model.node.update(node)


[8/8] incubator-ariatosca git commit: And condition for updating the node states

Posted by av...@apache.org.
And condition for updating the node states


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

Branch: refs/heads/ARIA-126-update-node-statuses
Commit: c3abcc87074c7a0a6c7ddecb66a0c47e65d884bb
Parents: 44ac15f
Author: Avia Efrat <av...@gigaspaces.com>
Authored: Sun Mar 26 12:21:41 2017 +0300
Committer: Avia Efrat <av...@gigaspaces.com>
Committed: Sun Mar 26 12:21:41 2017 +0300

----------------------------------------------------------------------
 aria/orchestrator/workflows/core/events_handler.py | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/c3abcc87/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 7191674..80d1266 100644
--- a/aria/orchestrator/workflows/core/events_handler.py
+++ b/aria/orchestrator/workflows/core/events_handler.py
@@ -27,8 +27,12 @@ from datetime import (
     timedelta,
 )
 
+from aria.orchestrator.workflows.core.task import OperationTask
+
 from ... import events
 from ... import exceptions
+from ... context.operation import NodeOperationContext
+
 
 @events.sent_task_signal.connect
 def _task_sent(task, *args, **kwargs):
@@ -43,7 +47,8 @@ def _task_started(task, *args, **kwargs):
         task.status = task.STARTED
 
         # update node state if necessary
-        _update_node_state(task, transitional=True)
+        if type(task) is OperationTask and type(task.context) is NodeOperationContext:
+            _update_node_state(task, transitional=True)
 
 
 @events.on_failure_task_signal.connect
@@ -78,7 +83,8 @@ def _task_succeeded(task, *args, **kwargs):
         task.status = task.SUCCESS
 
         # update node state if necessary
-        _update_node_state(task)
+        if type(task) is OperationTask and type(task.context) is NodeOperationContext:
+            _update_node_state(task)
 
 
 @events.start_workflow_signal.connect


[7/8] incubator-ariatosca git commit: Update the standard interface regex

Posted by av...@apache.org.
Update the standard interface regex


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

Branch: refs/heads/ARIA-126-update-node-statuses
Commit: 44ac15f3969179c4907400f743293a4c2fabaf1d
Parents: 137b91e
Author: Avia Efrat <av...@gigaspaces.com>
Authored: Sun Mar 26 12:19:27 2017 +0300
Committer: Avia Efrat <av...@gigaspaces.com>
Committed: Sun Mar 26 12:19:27 2017 +0300

----------------------------------------------------------------------
 aria/orchestrator/workflows/core/events_handler.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/44ac15f3/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 16563e1..7191674 100644
--- a/aria/orchestrator/workflows/core/events_handler.py
+++ b/aria/orchestrator/workflows/core/events_handler.py
@@ -128,7 +128,7 @@ def _workflow_cancelling(workflow_context, *args, **kwargs):
 
 
 def _update_node_state(task, transitional=False):
-        match = re.search('(?:tosca.interfaces.node.lifecycle.Standard|Standard):(\S+)@node',
+        match = re.search('^(?:tosca.interfaces.node.lifecycle.Standard|Standard):(\S+)@node',
                           task.context.name)
         if match:
             node = task.runs_on


[3/8] incubator-ariatosca git commit: Remove drafts for node states transitions validation

Posted by av...@apache.org.
Remove drafts for node states transitions validation


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

Branch: refs/heads/ARIA-126-update-node-statuses
Commit: 2fa8466f01a6507de7f627da788b101ea6f152da
Parents: 3fe8b06
Author: Avia Efrat <av...@gigaspaces.com>
Authored: Thu Mar 23 12:10:41 2017 +0200
Committer: Avia Efrat <av...@gigaspaces.com>
Committed: Thu Mar 23 12:10:41 2017 +0200

----------------------------------------------------------------------
 aria/modeling/service_instance.py | 24 ------------------------
 1 file changed, 24 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/2fa8466f/aria/modeling/service_instance.py
----------------------------------------------------------------------
diff --git a/aria/modeling/service_instance.py b/aria/modeling/service_instance.py
index f9e8d7b..a1c264e 100644
--- a/aria/modeling/service_instance.py
+++ b/aria/modeling/service_instance.py
@@ -366,13 +366,6 @@ class NodeBase(InstanceModelMixin): # pylint: disable=too-many-public-methods
 
     STATES = {INITIAL, CREATING, CREATED, CONFIGURING, CONFIGURED, STARTING, STARTED, STOPPING,
               DELETING, ERROR}
-    
-    # TODO implement validation method
-    # VALID_TRANSITIONS = {
-    #     INITIALIZED: [CREATING],
-    #     STARTED: END_STATES + [CANCELLING],
-    #     CANCELLING: END_STATES + [FORCE_CANCELLING]
-    # }
 
     _op_to_state = {'create': {'transitional': CREATING, 'finished': CREATED},
                     'configure': {'transitional': CONFIGURING, 'finished': CONFIGURED},
@@ -388,23 +381,6 @@ class NodeBase(InstanceModelMixin): # pylint: disable=too-many-public-methods
         except AttributeError:
             return None
 
-    # # TODO implement validation method
-    # @orm.validates('state')
-    # def validate_status(self, key, value):
-    #     """Validation function that verifies node state transitions are OK"""
-    #     try:
-    #         current_status = getattr(self, key)
-    #     except AttributeError:
-    #         return
-    #     valid_transitions = self.VALID_TRANSITIONS.get(current_status, [])
-    #     if all([current_status is not None,
-    #             current_status != value,
-    #             value not in valid_transitions]):
-    #         raise ValueError('Cannot change execution status from {current} to {new}'.format(
-    #             current=current_status,
-    #             new=value))
-    #     return value
-
     @declared_attr
     def node_template(cls):
         return relationship.many_to_one(cls, 'node_template')


[2/8] incubator-ariatosca git commit: Add 'stopped' and 'deleted' states

Posted by av...@apache.org.
Add 'stopped' and 'deleted' states


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

Branch: refs/heads/ARIA-126-update-node-statuses
Commit: 3fe8b06d7ff49e9f8f7e6a954d8dcf7626a235a0
Parents: 5a6d3d8
Author: Avia Efrat <av...@gigaspaces.com>
Authored: Wed Mar 22 18:01:57 2017 +0200
Committer: Avia Efrat <av...@gigaspaces.com>
Committed: Thu Mar 23 11:16:12 2017 +0200

----------------------------------------------------------------------
 aria/modeling/service_instance.py | 30 ++++++++++++++++++++++++++++--
 tests/mock/models.py              |  2 +-
 2 files changed, 29 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/3fe8b06d/aria/modeling/service_instance.py
----------------------------------------------------------------------
diff --git a/aria/modeling/service_instance.py b/aria/modeling/service_instance.py
index 7b82341..f9e8d7b 100644
--- a/aria/modeling/service_instance.py
+++ b/aria/modeling/service_instance.py
@@ -359,17 +359,26 @@ class NodeBase(InstanceModelMixin): # pylint: disable=too-many-public-methods
     STARTING = 'starting'
     STARTED = 'started'
     STOPPING = 'stopping'
+    STOPPED = 'stopped'
     DELETING = 'deleting'
+    DELETED = 'deleted'
     ERROR = 'error'
 
     STATES = {INITIAL, CREATING, CREATED, CONFIGURING, CONFIGURED, STARTING, STARTED, STOPPING,
               DELETING, ERROR}
+    
+    # TODO implement validation method
+    # VALID_TRANSITIONS = {
+    #     INITIALIZED: [CREATING],
+    #     STARTED: END_STATES + [CANCELLING],
+    #     CANCELLING: END_STATES + [FORCE_CANCELLING]
+    # }
 
     _op_to_state = {'create': {'transitional': CREATING, 'finished': CREATED},
                     'configure': {'transitional': CONFIGURING, 'finished': CONFIGURED},
                     'start': {'transitional': STARTING, 'finished': STARTED},
-                    'stop': {'transitional': STOPPING},
-                    'delete': {'transitional': DELETING}}
+                    'stop': {'transitional': STOPPING, 'finished': STOPPED},
+                    'delete': {'transitional': DELETING, 'finished': DELETED}}
 
     @classmethod
     def determine_state(cls, op_name, transitional):
@@ -379,6 +388,23 @@ class NodeBase(InstanceModelMixin): # pylint: disable=too-many-public-methods
         except AttributeError:
             return None
 
+    # # TODO implement validation method
+    # @orm.validates('state')
+    # def validate_status(self, key, value):
+    #     """Validation function that verifies node state transitions are OK"""
+    #     try:
+    #         current_status = getattr(self, key)
+    #     except AttributeError:
+    #         return
+    #     valid_transitions = self.VALID_TRANSITIONS.get(current_status, [])
+    #     if all([current_status is not None,
+    #             current_status != value,
+    #             value not in valid_transitions]):
+    #         raise ValueError('Cannot change execution status from {current} to {new}'.format(
+    #             current=current_status,
+    #             new=value))
+    #     return value
+
     @declared_attr
     def node_template(cls):
         return relationship.many_to_one(cls, 'node_template')

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/3fe8b06d/tests/mock/models.py
----------------------------------------------------------------------
diff --git a/tests/mock/models.py b/tests/mock/models.py
index 3695898..9b75aec 100644
--- a/tests/mock/models.py
+++ b/tests/mock/models.py
@@ -121,7 +121,7 @@ def create_dependency_node(dependency_node_template, service):
         runtime_properties={'ip': '1.1.1.1'},
         version=None,
         node_template=dependency_node_template,
-        state='',
+        state=models.Node.INITIAL,
         scaling_groups=[],
         service=service
     )


[6/8] incubator-ariatosca git commit: The 'stopped' and 'deleted' states aren't actually defined in the spec

Posted by av...@apache.org.
The 'stopped' and 'deleted' states aren't actually defined in the spec


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

Branch: refs/heads/ARIA-126-update-node-statuses
Commit: 137b91e359a8bdca5e23cc62724309a6f59b339c
Parents: 0ee98a6
Author: Avia Efrat <av...@gigaspaces.com>
Authored: Sun Mar 26 11:45:15 2017 +0300
Committer: Avia Efrat <av...@gigaspaces.com>
Committed: Sun Mar 26 11:45:15 2017 +0300

----------------------------------------------------------------------
 aria/modeling/service_instance.py | 18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/137b91e3/aria/modeling/service_instance.py
----------------------------------------------------------------------
diff --git a/aria/modeling/service_instance.py b/aria/modeling/service_instance.py
index a1c264e..810cf0e 100644
--- a/aria/modeling/service_instance.py
+++ b/aria/modeling/service_instance.py
@@ -359,26 +359,36 @@ class NodeBase(InstanceModelMixin): # pylint: disable=too-many-public-methods
     STARTING = 'starting'
     STARTED = 'started'
     STOPPING = 'stopping'
-    STOPPED = 'stopped'
     DELETING = 'deleting'
     DELETED = 'deleted'
+    # TODO decide what happens to a node's state after its 'deleting' state, as
+    # this is not defined as part of the tosca spec.
     ERROR = 'error'
 
     STATES = {INITIAL, CREATING, CREATED, CONFIGURING, CONFIGURED, STARTING, STARTED, STOPPING,
-              DELETING, ERROR}
+              DELETING, DELETED, ERROR}
 
     _op_to_state = {'create': {'transitional': CREATING, 'finished': CREATED},
                     'configure': {'transitional': CONFIGURING, 'finished': CONFIGURED},
                     'start': {'transitional': STARTING, 'finished': STARTED},
-                    'stop': {'transitional': STOPPING, 'finished': STOPPED},
+                    'stop': {'transitional': STOPPING, 'finished': CONFIGURED},
                     'delete': {'transitional': DELETING, 'finished': DELETED}}
 
     @classmethod
     def determine_state(cls, op_name, transitional):
+        """ :returns the state the node should be in as a result of running the
+            operation on this node.
+
+            e.g. if we are running tosca.interfaces.node.lifecycle.Standard.create, then
+            the resulting state should either 'creating' (if the task just started) or 'created'
+            (if the task ended).
+
+            If the operation is not a standard tosca lifecycle operation, then we return None"""
+
         state_type = 'transitional' if transitional else 'finished'
         try:
             return cls._op_to_state[op_name][state_type]
-        except AttributeError:
+        except KeyError:
             return None
 
     @declared_attr