Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 45224200CD2 for ; Wed, 21 Jun 2017 15:58:35 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 43B22160BD0; Wed, 21 Jun 2017 13:58:35 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 353DF160BF9 for ; Wed, 21 Jun 2017 15:58:34 +0200 (CEST) Received: (qmail 32755 invoked by uid 500); 21 Jun 2017 13:58:33 -0000 Mailing-List: contact commits-help@ariatosca.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@ariatosca.incubator.apache.org Delivered-To: mailing list commits@ariatosca.incubator.apache.org Received: (qmail 32700 invoked by uid 99); 21 Jun 2017 13:58:33 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 21 Jun 2017 13:58:33 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 544A2E0A38; Wed, 21 Jun 2017 13:58:33 +0000 (UTC) From: mxmrlv To: commits@ariatosca.apache.org Reply-To: commits@ariatosca.apache.org References: In-Reply-To: Subject: [GitHub] incubator-ariatosca pull request #158: ARIA-236 Resumable workflow execution... Content-Type: text/plain Message-Id: <20170621135833.544A2E0A38@git1-us-west.apache.org> Date: Wed, 21 Jun 2017 13:58:33 +0000 (UTC) archived-at: Wed, 21 Jun 2017 13:58:35 -0000 Github user mxmrlv commented on a diff in the pull request: https://github.com/apache/incubator-ariatosca/pull/158#discussion_r123253556 --- Diff: tests/orchestrator/test_workflow_runner.py --- @@ -293,3 +304,129 @@ def _create_workflow_runner(request, workflow_name, inputs=None, executor=None, resource_storage=resource, plugin_manager=plugin_manager, **task_configuration_kwargs) + + +class TestResumableWorkflows(object): + + def test_resume_workflow(self, workflow_context, executor): + self._create_interface(workflow_context, mock_success_task) + + service = workflow_context.service + service.workflows['custom_workflow'] = tests_mock.models.create_operation( + 'custom_workflow', + operation_kwargs={'function': '{0}.{1}'.format(__name__, mock_workflow.__name__)} + ) + workflow_context.model.service.update(service) + + wf_runner = WorkflowRunner( + service_id=workflow_context.service.id, + inputs={}, + model_storage=workflow_context.model, + resource_storage=workflow_context.resource, + plugin_manager=None, + workflow_name='custom_workflow', + executor=executor) + wf_thread = Thread(target=wf_runner.execute) + try: + wf_thread.start() + + # Wait for the execution to start + while global_test_holder.get('state') != 'active': + pass + global_test_holder['state'] = 'terminated' + wf_runner.cancel() + + # Make sure the execution was canceled and the task has not ended + while wf_runner.execution.status != workflow_context.execution.CANCELLED: + pass + task = workflow_context.model.task.list(filters={'_stub_type': None})[0] + assert task.status in (task.FAILED, task.RETRYING) + assert global_test_holder['state'] == 'idle' + + # Create a new workflow runner, with an existing execution id. This would cause + # the old execution to restart. + new_wf_runner = WorkflowRunner( + service_id=wf_runner.service.id, + inputs={}, + model_storage=workflow_context.model, + resource_storage=workflow_context.resource, + plugin_manager=None, + execution_id=wf_runner.execution.id, + executor=executor) + + # Set the resumed to True, for the execution to succeed. + global_test_holder['resumed'] = True + new_wf_runner.execute() + + # Wait for it to finish and assert changes. + while global_test_holder.get('state') != 'ended': + pass + assert task.status == task.SUCCESS + assert wf_runner.execution.status == wf_runner.execution.SUCCEEDED + + except: + global_test_holder['state'] = 'terminated' + wf_thread.join(0.5) + raise + + @staticmethod + @pytest.fixture + def executor(): + result = thread.ThreadExecutor() + try: + yield result + finally: + result.close() + + @staticmethod + @pytest.fixture + def workflow_context(tmpdir): + workflow_context = tests_mock.context.simple(str(tmpdir)) + yield workflow_context + storage.release_sqlite_storage(workflow_context.model) + + @staticmethod + def _create_interface(ctx, func, arguments=None): + node = ctx.model.node.get_by_name(tests_mock.models.DEPENDENCY_NODE_NAME) + interface_name = 'aria.interfaces.lifecycle' + operation_kwargs = dict(function='{name}.{func.__name__}'.format( + name=__name__, func=func)) + if arguments: + # the operation has to declare the arguments before those may be passed + operation_kwargs['arguments'] = arguments + operation_name = 'create' + interface = tests_mock.models.create_interface(node.service, interface_name, operation_name, + operation_kwargs=operation_kwargs) + node.interfaces[interface.name] = interface + ctx.model.node.update(node) + + return node, interface_name, operation_name + + @staticmethod + def _engine(workflow_func, workflow_context, executor): + graph = workflow_func(ctx=workflow_context) + execution = workflow_context.execution + compile.create_execution_tasks(execution, graph, executor.__class__) + workflow_context.execution = execution + + return engine.Engine(executors={executor.__class__: executor}) + + +@workflow +def mock_workflow(ctx, graph): + node = ctx.model.node.get_by_name(tests_mock.models.DEPENDENCY_NODE_NAME) + graph.add_tasks( + api.task.OperationTask( + node, interface_name='aria.interfaces.lifecycle', operation_name='create') + ) + + +@operation +def mock_success_task(**_): --- End diff -- rename --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastructure@apache.org or file a JIRA ticket with INFRA. ---