Exemple #1
0
    def test_find_workflow_tasks(self):
        tasks = workflow.find_workflow_tasks(self.parser, "attach-volumes")

        self.assertEqual(2, len(tasks))

        self._assert_single_item(tasks, name='create-vms')
        self._assert_single_item(tasks, name='attach-volumes')
Exemple #2
0
    def start_workflow_execution(cls, workbook_name, task_name, context):
        db_api.start_tx()

        workbook = cls._get_workbook(workbook_name)
        # Persist execution and tasks in DB.
        try:
            execution = cls._create_execution(workbook_name,
                                              task_name,
                                              context)

            tasks = cls._create_tasks(
                workflow.find_workflow_tasks(workbook, task_name),
                workbook,
                workbook_name, execution['id']
            )

            tasks_to_start = workflow.find_resolved_tasks(tasks)

            data_flow.prepare_tasks(tasks_to_start, context)

            db_api.commit_tx()
        except Exception as e:
            raise exc.EngineException("Failed to create necessary DB objects:"
                                      " %s" % e)
        finally:
            db_api.end_tx()

        cls._run_tasks(tasks_to_start)

        return execution
Exemple #3
0
    def test_find_workflow_tasks(self):
        tasks = workflow.find_workflow_tasks(self.parser, "attach-volumes")

        self.assertEqual(2, len(tasks))

        self._assert_single_item(tasks, name='create-vms')
        self._assert_single_item(tasks, name='attach-volumes')
Exemple #4
0
    def start_workflow_execution(self, cntx, **kwargs):
        """Starts a workflow execution based on the specified workbook name
        and target task.

        :param cntx: a request context dict
        :type cntx: MistralContext
        :param kwargs: a dict of method arguments
        :type kwargs: dict
        :return: Workflow execution.
        """
        workbook_name = kwargs.get('workbook_name')
        task_name = kwargs.get('task_name')
        context = kwargs.get('context', None)

        context = copy.copy(context) if context else {}

        WORKFLOW_TRACE.info("New execution started - [workbook_name = '%s', "
                            "task_name = '%s']" % (workbook_name, task_name))

        db_api.start_tx()

        # Persist execution and tasks in DB.
        try:
            workbook = self._get_workbook(workbook_name)
            execution = self._create_execution(workbook_name,
                                               task_name,
                                               context)

            tasks = self._create_tasks(
                workflow.find_workflow_tasks(workbook, task_name),
                workbook,
                workbook_name, execution['id']
            )

            tasks_to_start, delayed_tasks = workflow.find_resolved_tasks(tasks)

            self._add_variables_to_data_flow_context(context, execution)

            data_flow.prepare_tasks(tasks_to_start, context)

            db_api.commit_tx()
        except Exception as e:
            msg = "Failed to create necessary DB objects: %s" % e
            LOG.exception(msg)
            raise exc.EngineException(msg)
        finally:
            db_api.end_tx()

        for task in delayed_tasks:
            self._schedule_run(workbook, task, context)

        self._run_tasks(tasks_to_start)

        return execution
    def start_workflow_execution(cls, workbook_name, task_name, context):
        context = copy.copy(context) if context else {}

        db_api.start_tx()

        WORKFLOW_TRACE.info("New execution started - [workbook_name = '%s', "
                            "task_name = '%s']" % (workbook_name, task_name))

        # Persist execution and tasks in DB.
        try:
            workbook = cls._get_workbook(workbook_name)
            execution = cls._create_execution(workbook_name,
                                              task_name,
                                              context)

            tasks = cls._create_tasks(
                workflow.find_workflow_tasks(workbook, task_name),
                workbook,
                workbook_name, execution['id']
            )

            tasks_to_start, delayed_tasks = workflow.find_resolved_tasks(tasks)

            cls._add_variables_to_data_flow_context(context, execution)

            data_flow.prepare_tasks(tasks_to_start, context)

            db_api.commit_tx()
        except Exception as e:
            LOG.exception("Failed to create necessary DB objects.")
            raise exc.EngineException("Failed to create necessary DB objects:"
                                      " %s" % e)
        finally:
            db_api.end_tx()

        for task in delayed_tasks:
            cls._schedule_run(workbook, task, context)

        cls._run_tasks(tasks_to_start)

        return execution
Exemple #6
0
    def start_workflow_execution(cls, workbook_name, task_name, context):
        context = copy.copy(context) if context else {}

        db_api.start_tx()

        WORKFLOW_TRACE.info("New execution started - [workbook_name = '%s', "
                            "task_name = '%s']" % (workbook_name, task_name))

        # Persist execution and tasks in DB.
        try:
            workbook = cls._get_workbook(workbook_name)
            execution = cls._create_execution(workbook_name, task_name,
                                              context)

            tasks = cls._create_tasks(
                workflow.find_workflow_tasks(workbook, task_name), workbook,
                workbook_name, execution['id'])

            tasks_to_start, delayed_tasks = workflow.find_resolved_tasks(tasks)

            cls._add_variables_to_data_flow_context(context, execution)

            data_flow.prepare_tasks(tasks_to_start, context)

            db_api.commit_tx()
        except Exception as e:
            LOG.exception("Failed to create necessary DB objects.")
            raise exc.EngineException("Failed to create necessary DB objects:"
                                      " %s" % e)
        finally:
            db_api.end_tx()

        for task in delayed_tasks:
            cls._schedule_run(workbook, task, context)

        cls._run_tasks(tasks_to_start)

        return execution
Exemple #7
0
    def start_workflow_execution(self, cntx, **kwargs):
        """Starts a workflow execution based on the specified workbook name
        and target task.

        :param cntx: a request context dict
        :type cntx: MistralContext
        :param kwargs: a dict of method arguments
        :type kwargs: dict
        :return: Workflow execution.
        """
        workbook_name = kwargs.get('workbook_name')
        task_name = kwargs.get('task_name')
        context = kwargs.get('context', None)

        context = copy.copy(context) if context else {}

        WORKFLOW_TRACE.info("New execution started - [workbook_name = '%s', "
                            "task_name = '%s']" % (workbook_name, task_name))

        db_api.start_tx()

        # Persist execution and tasks in DB.
        try:
            workbook = self._get_workbook(workbook_name)
            execution = self._create_execution(workbook_name, task_name,
                                               context)

            # Create the whole tree of tasks required by target task, including
            # target task itself.
            tasks = self._create_tasks(
                workflow.find_workflow_tasks(workbook, task_name),
                workbook,
                workbook_name, execution['id']
            )

            # Create a list of tasks that can be executed immediately (have
            # their requirements satisfied, or, at that point, rather don't
            # have them at all) along with the list of tasks that require some
            # delay before they'll be executed.
            tasks_to_start, delayed_tasks = workflow.find_resolved_tasks(tasks)

            # Populate context with special variables such as `openstack` and
            # `__execution`.
            self._add_variables_to_data_flow_context(context, execution)

            # Update task with new context and params.
            executables = data_flow.prepare_tasks(tasks_to_start,
                                                  context,
                                                  workbook)

            db_api.commit_tx()
        except Exception as e:
            msg = "Failed to create necessary DB objects: %s" % e
            LOG.exception(msg)
            raise exc.EngineException(msg)
        finally:
            db_api.end_tx()

        for task in delayed_tasks:
            self._schedule_run(workbook, task, context)

        for task_id, action_name, action_params in executables:
            self._run_task(task_id, action_name, action_params)

        return execution