Repository: incubator-ariatosca Updated Branches: refs/heads/ARIA-155-clean-models-from-usused-fields [created] 18a50ba5b
ARIA-155 Clean models from unused fields Project: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/commit/18a50ba5 Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/18a50ba5 Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/18a50ba5 Branch: refs/heads/ARIA-155-clean-models-from-usused-fields Commit: 18a50ba5b4236acbdb039e2d39cb76642fc5dcc4 Parents: 1f3e7ff Author: Ran Ziv <[email protected]> Authored: Sun Apr 30 15:15:37 2017 +0300 Committer: Ran Ziv <[email protected]> Committed: Sun Apr 30 15:15:37 2017 +0300 ---------------------------------------------------------------------- aria/modeling/orchestration.py | 7 +- aria/modeling/service_instance.py | 28 ++--- aria/modeling/service_template.py | 16 +-- .../workflows/core/events_handler.py | 4 +- aria/orchestrator/workflows/core/task.py | 14 +-- tests/mock/models.py | 3 - tests/modeling/test_mixins.py | 3 - tests/modeling/test_models.py | 106 +++++++++---------- tests/orchestrator/workflows/core/test_task.py | 8 +- .../orchestrator/workflows/executor/__init__.py | 2 +- 10 files changed, 80 insertions(+), 111 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/18a50ba5/aria/modeling/orchestration.py ---------------------------------------------------------------------- diff --git a/aria/modeling/orchestration.py b/aria/modeling/orchestration.py index f163903..ab9d34d 100644 --- a/aria/modeling/orchestration.py +++ b/aria/modeling/orchestration.py @@ -92,7 +92,6 @@ class ExecutionBase(ModelMixin): started_at = Column(DateTime, nullable=True, index=True) ended_at = Column(DateTime, nullable=True, index=True) error = Column(Text, nullable=True) - is_system_workflow = Column(Boolean, nullable=False, default=False) status = Column(Enum(*STATES, name='execution_status'), default=PENDING) workflow_name = Column(Text) @@ -252,8 +251,8 @@ class TaskBase(ModelMixin): :vartype started_at: datetime :ivar ended_at: Timestamp for when task ended :vartype ended_at: datetime - :ivar retry_count: How many retries occurred - :vartype retry_count: int + :ivar attempts_count: How many attempts occurred + :vartype attempts_count: int """ __tablename__ = 'task' @@ -314,7 +313,7 @@ class TaskBase(ModelMixin): due_at = Column(DateTime, nullable=False, index=True, default=datetime.utcnow()) started_at = Column(DateTime, default=None) ended_at = Column(DateTime, default=None) - retry_count = Column(Integer, default=0) + attempts_count = Column(Integer, default=1) def has_ended(self): return self.status in (self.SUCCESS, self.FAILED) http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/18a50ba5/aria/modeling/service_instance.py ---------------------------------------------------------------------- diff --git a/aria/modeling/service_instance.py b/aria/modeling/service_instance.py index d5391ef..ad8e7ed 100644 --- a/aria/modeling/service_instance.py +++ b/aria/modeling/service_instance.py @@ -74,10 +74,6 @@ class ServiceBase(InstanceModelMixin): :vartype created_at: :class:`datetime.datetime` :ivar updated_at: Update timestamp :vartype updated_at: :class:`datetime.datetime` - :ivar permalink: ?? - :vartype permalink: basestring - :ivar scaling_groups: ?? - :vartype scaling_groups: {} :ivar modifications: Modifications of this service :vartype modifications: [:class:`ServiceModification`] :ivar updates: Updates of this service @@ -187,13 +183,6 @@ class ServiceBase(InstanceModelMixin): created_at = Column(DateTime, nullable=False, index=True) updated_at = Column(DateTime) - # region orchestration - - permalink = Column(Text) - scaling_groups = Column(modeling_types.Dict) - - # endregion - def satisfy_requirements(self): satisfied = True for node in self.nodes.itervalues(): @@ -346,8 +335,6 @@ class NodeBase(InstanceModelMixin): :vartype host: :class:`Node` :ivar runtime_properties: TODO: should be replaced with attributes :vartype runtime_properties: {} - :ivar scaling_groups: ?? - :vartype scaling_groups: [] :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` @@ -530,7 +517,6 @@ class NodeBase(InstanceModelMixin): description = Column(Text) runtime_properties = Column(modeling_types.Dict) - scaling_groups = Column(modeling_types.List) state = Column(Enum(*STATES, name='node_state'), nullable=False, default=INITIAL) version = Column(Integer, default=1) @@ -1653,10 +1639,10 @@ class OperationBase(InstanceModelMixin): :vartype dependencies: [basestring] :ivar inputs: Parameters that can be used by this operation :vartype inputs: {basestring: :class:`Parameter`} - :ivar executor: Executor name + :ivar executor: Name of executor to run the operation with :vartype executor: basestring - :ivar max_retries: Maximum number of retries allowed in case of failure - :vartype max_retries: int + :ivar max_attempts: Maximum number of attempts allowed in case of failure + :vartype max_attempts: int :ivar retry_interval: Interval between retries (in seconds) :vartype retry_interval: int :ivar interface: Containing interface @@ -1742,7 +1728,7 @@ class OperationBase(InstanceModelMixin): configuration = Column(modeling_types.StrictDict(key_cls=basestring)) dependencies = Column(modeling_types.StrictList(item_cls=basestring)) executor = Column(Text) - max_retries = Column(Integer) + max_attempts = Column(Integer) retry_interval = Column(Integer) def configure(self): @@ -1771,7 +1757,7 @@ class OperationBase(InstanceModelMixin): ('implementation', self.implementation), ('dependencies', self.dependencies), ('executor', self.executor), - ('max_retries', self.max_retries), + ('max_attempts', self.max_attempts), ('retry_interval', self.retry_interval), ('inputs', formatting.as_raw_dict(self.inputs)))) @@ -1805,8 +1791,8 @@ class OperationBase(InstanceModelMixin): ', '.join((str(context.style.literal(v)) for v in self.dependencies)))) if self.executor is not None: console.puts('Executor: {0}'.format(context.style.literal(self.executor))) - if self.max_retries is not None: - console.puts('Max retries: {0}'.format(context.style.literal(self.max_retries))) + if self.max_attempts is not None: + console.puts('Max attempts: {0}'.format(context.style.literal(self.max_attempts))) if self.retry_interval is not None: console.puts('Retry interval: {0}'.format( context.style.literal(self.retry_interval))) http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/18a50ba5/aria/modeling/service_template.py ---------------------------------------------------------------------- diff --git a/aria/modeling/service_template.py b/aria/modeling/service_template.py index f1c2bcb..7fab4fc 100644 --- a/aria/modeling/service_template.py +++ b/aria/modeling/service_template.py @@ -1762,10 +1762,10 @@ class OperationTemplateBase(TemplateModelMixin): :vartype dependencies: [basestring] :ivar inputs: Parameters that can be used by this operation :vartype inputs: {basestring: :class:`Parameter`} - :ivar executor: Executor name + :ivar executor: Name of executor to run the operation with :vartype executor: basestring - :ivar max_retries: Maximum number of retries allowed in case of failure - :vartype max_retries: int + :ivar max_attempts: Maximum number of attempts allowed in case of failure + :vartype max_attempts: int :ivar retry_interval: Interval between retries (in seconds) :vartype retry_interval: int :ivar interface_template: Containing interface template @@ -1848,7 +1848,7 @@ class OperationTemplateBase(TemplateModelMixin): configuration = Column(modeling_types.StrictDict(key_cls=basestring)) dependencies = Column(modeling_types.StrictList(item_cls=basestring)) executor = Column(Text) - max_retries = Column(Integer) + max_attempts = Column(Integer) retry_interval = Column(Integer) @property @@ -1859,7 +1859,7 @@ class OperationTemplateBase(TemplateModelMixin): ('implementation', self.implementation), ('dependencies', self.dependencies), ('executor', self.executor), - ('max_retries', self.max_retries), + ('max_attempts', self.max_attempts), ('retry_interval', self.retry_interval), ('inputs', formatting.as_raw_dict(self.inputs)))) @@ -1889,7 +1889,7 @@ class OperationTemplateBase(TemplateModelMixin): configuration=self.configuration, dependencies=self.dependencies, executor=self.executor, - max_retries=self.max_retries, + max_attempts=self.max_attempts, retry_interval=self.retry_interval, operation_template=self) utils.instantiate_dict(container, operation.inputs, self.inputs) @@ -1923,8 +1923,8 @@ class OperationTemplateBase(TemplateModelMixin): ', '.join((str(context.style.literal(v)) for v in self.dependencies)))) if self.executor is not None: console.puts('Executor: {0}'.format(context.style.literal(self.executor))) - if self.max_retries is not None: - console.puts('Max retries: {0}'.format(context.style.literal(self.max_retries))) + if self.max_attempts is not None: + console.puts('Max attempts: {0}'.format(context.style.literal(self.max_attempts))) if self.retry_interval is not None: console.puts('Retry interval: {0}'.format( context.style.literal(self.retry_interval))) http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/18a50ba5/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 b43082b..88c24bd 100644 --- a/aria/orchestrator/workflows/core/events_handler.py +++ b/aria/orchestrator/workflows/core/events_handler.py @@ -49,7 +49,7 @@ def _task_failed(task, exception, *args, **kwargs): with task._update(): should_retry = all([ not isinstance(exception, exceptions.TaskAbortException), - task.retry_count < task.max_attempts - 1 or task.max_attempts == task.INFINITE_RETRIES, + task.attempts_count < task.max_attempts or task.max_attempts == task.INFINITE_RETRIES, # ignore_failure check here means the task will not be retries and it will be marked # as failed. The engine will also look at ignore_failure so it won't fail the # workflow. @@ -62,7 +62,7 @@ def _task_failed(task, exception, *args, **kwargs): if retry_interval is None: retry_interval = task.retry_interval task.status = task.RETRYING - task.retry_count += 1 + task.attempts_count += 1 task.due_at = datetime.utcnow() + timedelta(seconds=retry_interval) else: task.ended_at = datetime.utcnow() http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/18a50ba5/aria/orchestrator/workflows/core/task.py ---------------------------------------------------------------------- diff --git a/aria/orchestrator/workflows/core/task.py b/aria/orchestrator/workflows/core/task.py index 2b26152..8adeb7e 100644 --- a/aria/orchestrator/workflows/core/task.py +++ b/aria/orchestrator/workflows/core/task.py @@ -229,17 +229,17 @@ class OperationTask(BaseTask): self._update_fields['ended_at'] = value @property - def retry_count(self): + def attempts_count(self): """ - Returns the retry count for the task - :return: retry count + Returns the attempts count for the task + :return: attempts count """ - return self.model_task.retry_count + return self.model_task.attempts_count - @retry_count.setter + @attempts_count.setter @_locked - def retry_count(self, value): - self._update_fields['retry_count'] = value + def attempts_count(self, value): + self._update_fields['attempts_count'] = value @property def due_at(self): http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/18a50ba5/tests/mock/models.py ---------------------------------------------------------------------- diff --git a/tests/mock/models.py b/tests/mock/models.py index cdedea9..f066551 100644 --- a/tests/mock/models.py +++ b/tests/mock/models.py @@ -81,8 +81,6 @@ def create_service(service_template, name=SERVICE_NAME, inputs=None): description='', created_at=now, updated_at=now, - permalink='', - scaling_groups={}, ) @@ -196,7 +194,6 @@ def create_node(dependency_node_template, service, name=NODE_NAME, state=models. version=None, node_template=dependency_node_template, state=state, - scaling_groups=[], service=service, interfaces=get_standard_interface(service), ) http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/18a50ba5/tests/modeling/test_mixins.py ---------------------------------------------------------------------- diff --git a/tests/modeling/test_mixins.py b/tests/modeling/test_mixins.py index cd7cadf..a18a04e 100644 --- a/tests/modeling/test_mixins.py +++ b/tests/modeling/test_mixins.py @@ -97,8 +97,6 @@ def test_model_to_dict(context): expected_keys = [ 'description', 'created_at', - 'permalink', - 'scaling_groups', 'updated_at' ] @@ -128,7 +126,6 @@ def test_relationship_model_ordering(context): version=None, node_template=new_node_template, state=modeling.models.Node.INITIAL, - scaling_groups=[] ) source_node.outbound_relationships.append(modeling.models.Relationship( http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/18a50ba5/tests/modeling/test_models.py ---------------------------------------------------------------------- diff --git a/tests/modeling/test_models.py b/tests/modeling/test_models.py index 2da2154..4d1557c 100644 --- a/tests/modeling/test_models.py +++ b/tests/modeling/test_models.py @@ -41,7 +41,7 @@ from aria.modeling.models import ( ) from tests import mock -from ..storage import release_sqlite_storage, init_inmemory_model_storage +from tests.storage import release_sqlite_storage, init_inmemory_model_storage @contextmanager @@ -206,31 +206,26 @@ class TestServiceTemplate(object): class TestService(object): @pytest.mark.parametrize( - 'is_valid, name, created_at, description, inputs, permalink, ' - 'outputs, scaling_groups, updated_at', + 'is_valid, name, created_at, description, inputs, ' + 'outputs, updated_at', [ - (False, m_cls, now, 'desc', {}, 'perlnk', {}, {}, now), - (False, 'name', m_cls, 'desc', {}, 'perlnk', {}, {}, now), - (False, 'name', now, m_cls, {}, 'perlnk', {}, {}, now), - (False, 'name', now, 'desc', {}, m_cls, {}, {}, now), - (False, 'name', now, 'desc', {}, 'perlnk', m_cls, {}, now), - (False, 'name', now, 'desc', {}, 'perlnk', {}, m_cls, now), - (False, 'name', now, 'desc', {}, 'perlnk', {}, {}, m_cls), - - (True, 'name', now, 'desc', {}, 'perlnk', {}, {}, now), - (True, None, now, 'desc', {}, 'perlnk', {}, {}, now), - (True, 'name', now, 'desc', {}, 'perlnk', {}, {}, now), - (True, 'name', now, None, {}, 'perlnk', {}, {}, now), - (True, 'name', now, 'desc', {}, 'perlnk', {}, {}, now), - (True, 'name', now, 'desc', {}, None, {}, {}, now), - (True, 'name', now, 'desc', {}, 'perlnk', {}, {}, now), - (True, 'name', now, 'desc', {}, 'perlnk', {}, None, now), - (True, 'name', now, 'desc', {}, 'perlnk', {}, {}, None), - (True, 'name', now, 'desc', {}, 'perlnk', {}, {}, now), + (False, m_cls, now, 'desc', {}, {}, now), + (False, 'name', m_cls, 'desc', {}, {}, now), + (False, 'name', now, m_cls, {}, {}, now), + (False, 'name', now, 'desc', m_cls, {}, now), + (False, 'name', now, 'desc', {}, m_cls, now), + (False, 'name', now, 'desc', {}, {}, m_cls), + + (True, 'name', now, 'desc', {}, {}, now), + (True, None, now, 'desc', {}, {}, now), + (True, 'name', now, None, {}, {}, now), + (True, 'name', now, 'desc', {}, {}, now), + (True, 'name', now, 'desc', {}, {}, None), + (True, 'name', now, 'desc', {}, {}, now), ] ) def test_service_model_creation(self, service_storage, is_valid, name, created_at, description, - inputs, permalink, outputs, scaling_groups, updated_at): + inputs, outputs, updated_at): service = _test_model( is_valid=is_valid, storage=service_storage, @@ -241,9 +236,7 @@ class TestService(object): created_at=created_at, description=description, inputs=inputs, - permalink=permalink, outputs=outputs, - scaling_groups=scaling_groups, updated_at=updated_at )) if is_valid: @@ -254,27 +247,26 @@ class TestService(object): class TestExecution(object): @pytest.mark.parametrize( - 'is_valid, created_at, started_at, ended_at, error, is_system_workflow, inputs, ' + 'is_valid, created_at, started_at, ended_at, error, inputs, ' 'status, workflow_name', [ - (False, m_cls, now, now, 'error', False, {}, Execution.STARTED, 'wf_name'), - (False, now, m_cls, now, 'error', False, {}, Execution.STARTED, 'wf_name'), - (False, now, now, m_cls, 'error', False, {}, Execution.STARTED, 'wf_name'), - (False, now, now, now, m_cls, False, {}, Execution.STARTED, 'wf_name'), - (False, now, now, now, 'error', False, m_cls, Execution.STARTED, 'wf_name'), - (False, now, now, now, 'error', False, {}, m_cls, 'wf_name'), - (False, now, now, now, 'error', False, {}, Execution.STARTED, m_cls), - - (True, now, now, now, 'error', False, {}, Execution.STARTED, 'wf_name'), - (True, now, None, now, 'error', False, {}, Execution.STARTED, 'wf_name'), - (True, now, now, None, 'error', False, {}, Execution.STARTED, 'wf_name'), - (True, now, now, now, None, False, {}, Execution.STARTED, 'wf_name'), - (True, now, now, now, 'error', False, {}, Execution.STARTED, 'wf_name'), + (False, m_cls, now, now, 'error', {}, Execution.STARTED, 'wf_name'), + (False, now, m_cls, now, 'error', {}, Execution.STARTED, 'wf_name'), + (False, now, now, m_cls, 'error', {}, Execution.STARTED, 'wf_name'), + (False, now, now, now, m_cls, {}, Execution.STARTED, 'wf_name'), + (False, now, now, now, 'error', m_cls, Execution.STARTED, 'wf_name'), + (False, now, now, now, 'error', {}, m_cls, 'wf_name'), + (False, now, now, now, 'error', {}, Execution.STARTED, m_cls), + + (True, now, now, now, 'error', {}, Execution.STARTED, 'wf_name'), + (True, now, None, now, 'error', {}, Execution.STARTED, 'wf_name'), + (True, now, now, None, 'error', {}, Execution.STARTED, 'wf_name'), + (True, now, now, now, None, {}, Execution.STARTED, 'wf_name'), + (True, now, now, now, 'error', {}, Execution.STARTED, 'wf_name'), ] ) def test_execution_model_creation(self, service_storage, is_valid, created_at, started_at, - ended_at, error, is_system_workflow, inputs, status, - workflow_name): + ended_at, error, inputs, status, workflow_name): execution = _test_model( is_valid=is_valid, storage=service_storage, @@ -285,7 +277,6 @@ class TestExecution(object): started_at=started_at, ended_at=ended_at, error=error, - is_system_workflow=is_system_workflow, inputs=inputs, status=status, workflow_name=workflow_name, @@ -549,23 +540,23 @@ class TestNodeTemplate(object): class TestNode(object): @pytest.mark.parametrize( - 'is_valid, name, runtime_properties, scaling_groups, state, version', + 'is_valid, name, runtime_properties, state, version', [ - (False, m_cls, {}, [], 'state', 1), - (False, 'name', m_cls, [], 'state', 1), - (False, 'name', {}, m_cls, 'state', 1), - (False, 'name', {}, [], m_cls, 1), - (False, m_cls, {}, [], 'state', m_cls), - - (True, 'name', {}, [], 'initial', 1), - (True, None, {}, [], 'initial', 1), - (True, 'name', None, [], 'initial', 1), - (True, 'name', {}, None, 'initial', 1), - (True, 'name', {}, [], 'initial', None), + (False, m_cls, {}, 'state', 1), + (False, 'name', m_cls, 'state', 1), + (False, 'name', {}, 'state', 1), + (False, 'name', {}, m_cls, 1), + (False, m_cls, {}, 'state', m_cls), + + (True, 'name', {}, 'initial', 1), + (True, None, {}, 'initial', 1), + (True, 'name', None, 'initial', 1), + (True, 'name', {}, 'initial', 1), + (True, 'name', {}, 'initial', None), ] ) def test_node_model_creation(self, node_template_storage, is_valid, name, runtime_properties, - scaling_groups, state, version): + state, version): node = _test_model( is_valid=is_valid, storage=node_template_storage, @@ -575,7 +566,6 @@ class TestNode(object): type=node_template_storage.type.list()[0], name=name, runtime_properties=runtime_properties, - scaling_groups=scaling_groups, state=state, version=version, service=node_template_storage.service.list()[0] @@ -771,7 +761,7 @@ class TestPlugin(object): class TestTask(object): @pytest.mark.parametrize( - 'is_valid, status, due_at, started_at, ended_at, max_attempts, retry_count, ' + 'is_valid, status, due_at, started_at, ended_at, max_attempts, attempts_count, ' 'retry_interval, ignore_failure, name, operation_mapping, inputs, plugin_id', [ (False, m_cls, now, now, now, 1, 1, 1, True, 'name', 'map', {}, '1'), @@ -800,7 +790,7 @@ class TestTask(object): ] ) def test_task_model_creation(self, execution_storage, is_valid, status, due_at, started_at, - ended_at, max_attempts, retry_count, retry_interval, + ended_at, max_attempts, attempts_count, retry_interval, ignore_failure, name, operation_mapping, inputs, plugin_id): task = _test_model( is_valid=is_valid, @@ -813,7 +803,7 @@ class TestTask(object): started_at=started_at, ended_at=ended_at, max_attempts=max_attempts, - retry_count=retry_count, + attempts_count=attempts_count, retry_interval=retry_interval, ignore_failure=ignore_failure, name=name, http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/18a50ba5/tests/orchestrator/workflows/core/test_task.py ---------------------------------------------------------------------- diff --git a/tests/orchestrator/workflows/core/test_task.py b/tests/orchestrator/workflows/core/test_task.py index 8dda209..0765350 100644 --- a/tests/orchestrator/workflows/core/test_task.py +++ b/tests/orchestrator/workflows/core/test_task.py @@ -127,7 +127,7 @@ class TestOperationTask(object): with pytest.raises(exceptions.TaskException): core_task.ended_at = now with pytest.raises(exceptions.TaskException): - core_task.retry_count = 2 + core_task.attempts_count = 2 with pytest.raises(exceptions.TaskException): core_task.due_at = now @@ -141,16 +141,16 @@ class TestOperationTask(object): core_task.status = core_task.STARTED core_task.started_at = future_time core_task.ended_at = future_time - core_task.retry_count = 2 + core_task.attempts_count = 2 core_task.due_at = future_time assert core_task.status != core_task.STARTED assert core_task.started_at != future_time assert core_task.ended_at != future_time - assert core_task.retry_count != 2 + assert core_task.attempts_count != 2 assert core_task.due_at != future_time assert core_task.status == core_task.STARTED assert core_task.started_at == future_time assert core_task.ended_at == future_time - assert core_task.retry_count == 2 + assert core_task.attempts_count == 2 assert core_task.due_at == future_time http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/18a50ba5/tests/orchestrator/workflows/executor/__init__.py ---------------------------------------------------------------------- diff --git a/tests/orchestrator/workflows/executor/__init__.py b/tests/orchestrator/workflows/executor/__init__.py index c05831a..cedcc5f 100644 --- a/tests/orchestrator/workflows/executor/__init__.py +++ b/tests/orchestrator/workflows/executor/__init__.py @@ -34,7 +34,7 @@ class MockTask(object): self.id = str(uuid.uuid4()) self.logger = logging.getLogger() self.context = MockContext() - self.retry_count = 0 + self.attempts_count = 1 self.max_attempts = 1 self.ignore_failure = False self.interface_name = 'interface_name'
