Пример #1
0
    def _get_workflow_result(self, st2_exec_id, mistral_exec_id):
        """
        Returns the workflow status and output. Mistral workflow status will be converted
        to st2 action status.
        :param st2_exec_id: st2 execution ID
        :type st2_exec_id: ``str``
        :param mistral_exec_id: Mistral execution ID
        :type mistral_exec_id: ``str``
        :rtype: (``str``, ``dict``)
        """
        try:
            jitter = random.uniform(0, self._jitter)
            eventlet.sleep(jitter)
            execution = self._client.executions.get(mistral_exec_id)
        except mistralclient_base.APIException as mistral_exc:
            if 'not found' in mistral_exc.message:
                raise exceptions.ReferenceNotFoundError(mistral_exc.message)
            raise mistral_exc

        result = jsonify.try_loads(
            execution.output) if execution.state in DONE_STATES else {}

        result['extra'] = {
            'state': execution.state,
            'state_info': execution.state_info
        }

        LOG.info('[%s] Query returned status "%s" for mistral execution %s.',
                 st2_exec_id, execution.state, mistral_exec_id)

        return result
Пример #2
0
    def _get_workflow_result(self, exec_id):
        """
        Returns the workflow status and output. Mistral workflow status will be converted
        to st2 action status.
        :param exec_id: Mistral execution ID
        :type exec_id: ``str``
        :rtype: (``str``, ``dict``)
        """
        try:
            execution = self._client.executions.get(exec_id)
        except mistralclient_base.APIException as mistral_exc:
            if 'not found' in mistral_exc.message:
                raise exceptions.ReferenceNotFoundError(mistral_exc.message)
            raise mistral_exc

        params = json.loads(execution.params)

        result = jsonify.try_loads(
            execution.output) if execution.state in DONE_STATES else {}

        result['extra'] = {
            'params': params,
            'state': execution.state,
            'state_info': execution.state_info
        }

        return result
Пример #3
0
    def _get_workflow_tasks(self,
                            st2_exec_id,
                            mistral_exec_id,
                            recorded_tasks=None):
        """
        Returns the list of tasks for a workflow execution.
        :param st2_exec_id: st2 execution ID
        :type st2_exec_id: ``str``
        :param mistral_exec_id: Mistral execution ID
        :type mistral_exec_id: ``str``
        :param recorded_tasks: The list of tasks recorded in the liveaction result.
        :rtype: ``list``
        """
        result = []
        queries = []

        if recorded_tasks is None:
            recorded_tasks = []

        try:
            wf_tasks = self._client.tasks.list(
                workflow_execution_id=mistral_exec_id)

            for wf_task in wf_tasks:
                recorded = list(
                    filter(lambda x: x['id'] == wf_task.id, recorded_tasks))

                if (not recorded or recorded[0].get('state') != wf_task.state
                        or str(recorded[0].get('created_at')) !=
                        wf_task.created_at
                        or str(recorded[0].get('updated_at')) !=
                        wf_task.updated_at):
                    queries.append(wf_task)

            target_task_names = [wf_task.name for wf_task in queries]

            LOG.info(
                '[%s] Querying the following tasks for mistral execution %s: %s',
                st2_exec_id, mistral_exec_id,
                ', '.join(target_task_names) if target_task_names else 'None')

            for wf_task in queries:
                result.append(self._client.tasks.get(wf_task.id))

                # Lets not blast requests but just space it out for better CPU profile
                jitter = random.uniform(0, self._jitter)
                eventlet.sleep(jitter)
        except mistralclient_base.APIException as mistral_exc:
            if 'not found' in mistral_exc.message:
                raise exceptions.ReferenceNotFoundError(mistral_exc.message)
            raise mistral_exc

        return [
            self._format_task_result(task=entry.to_dict()) for entry in result
        ]
Пример #4
0
    def _get_workflow_tasks(self, exec_id):
        """
        Returns the list of tasks for a workflow execution.
        :param exec_id: Mistral execution ID
        :type exec_id: ``str``
        :rtype: ``list``
        """
        wf_tasks = []

        try:
            for task in self._client.tasks.list(workflow_execution_id=exec_id):
                wf_tasks.append(self._client.tasks.get(task.id))
        except mistralclient_base.APIException as mistral_exc:
            if 'not found' in mistral_exc.message:
                raise exceptions.ReferenceNotFoundError(mistral_exc.message)
            raise mistral_exc

        return [self._format_task_result(task=wf_task.to_dict()) for wf_task in wf_tasks]