Example #1
0
 def test_pipeline_get_act_inputs(self):
     parser_obj = WebPipelineAdapter(WEB_PIPELINE_WITH_SUB_PROCESS2)
     act_inputs = parser_obj.get_act_inputs(id_list2[3], [id_list2[10]])
     self.assertEqual(act_inputs, {
         'input_test': 'custom2',
         'radio_test': '1',
     })
Example #2
0
    def _prerender_node_data(
        self, pipeline_instance: PipelineInstance, subprocess_stack: List[str], username: str
    ) -> (bool, str, dict, dict):
        try:
            inputs = WebPipelineAdapter(pipeline_instance.execution_data).get_act_inputs(
                act_id=self.node_id,
                subprocess_stack=subprocess_stack,
                root_pipeline_data=get_pipeline_context(
                    pipeline_instance, obj_type="instance", data_type="data", username=username
                ),
                root_pipeline_context=get_pipeline_context(
                    pipeline_instance, obj_type="instance", data_type="context", username=username
                ),
            )
            outputs = {}
        except Exception:
            logger.exception(
                "_prerender_node_data(node_id:{}, subprocess_stack:{}, username: {}) fail".format(
                    self.node_id, subprocess_stack, username
                )
            )
            return False, "_prerender_node_data fail", {}, {}

        if not isinstance(inputs, dict):
            inputs = {}

        return True, "", inputs, outputs
Example #3
0
 def test_web_pipeline_parser2(self):
     parser_obj = WebPipelineAdapter(WEB_PIPELINE_WITH_SUB_PROCESS2)
     self.assertIsInstance(parser_obj.parse(), Pipeline)
Example #4
0
 def test_web_pipeline_parser(self):
     parser_obj = WebPipelineAdapter(WEB_PIPELINE_DATA)
     self.assertIsInstance(parser_obj.parse(), Pipeline)
Example #5
0
    def get_node_data(self,
                      node_id,
                      component_code=None,
                      subprocess_stack=None):
        if not self.has_node(node_id):
            message = 'node[node_id={node_id}] not found in task[task_id={task_id}]'.format(
                node_id=node_id, task_id=self.id)
            return {'result': False, 'message': message, 'data': {}}

        act_started = True
        result = True
        inputs = {}
        outputs = {}
        try:
            inputs = pipeline_api.get_inputs(node_id)
            outputs = pipeline_api.get_outputs(node_id)
        except Data.DoesNotExist:
            act_started = False

        instance_data = self.pipeline_instance.execution_data
        if not act_started:
            try:
                inputs = WebPipelineAdapter(instance_data).get_act_inputs(
                    act_id=node_id,
                    subprocess_stack=subprocess_stack,
                    root_pipeline_data=get_pipeline_context(
                        self.pipeline_instance, 'instance'))
                outputs = {}
            except Exception as e:
                inputs = {}
                result = False
                message = 'parser pipeline tree error: %s' % e
                logger.exception(message)
                outputs = {'ex_data': message}

        if component_code:
            outputs_table = []
            try:
                component = library.ComponentLibrary.get_component_class(
                    component_code)
                outputs_format = component.outputs_format()
            except Exception as e:
                result = False
                message = 'get component[component_code=%s] format error: %s' % (
                    component_code, e)
                logger.exception(message)
                outputs = {'ex_data': message}
            else:
                outputs_data = outputs.get('outputs', {})
                # 在原子定义中的预设输出参数
                archived_keys = []
                for outputs_item in outputs_format:
                    value = outputs_data.get(outputs_item['key'], '')
                    outputs_table.append({
                        'name': outputs_item['name'],
                        'key': outputs_item['key'],
                        'value': value,
                        'preset': True,
                    })
                    archived_keys.append(outputs_item['key'])
                # 其他输出参数
                for out_key, out_value in outputs_data.items():
                    if out_key not in archived_keys:
                        outputs_table.append({
                            'name': out_key,
                            'key': out_key,
                            'value': out_value,
                            'preset': False,
                        })

        else:
            outputs_table = [{
                'key': key,
                'value': val,
                'preset': False
            } for key, val in outputs.get('outputs', {}).items()]

        if not isinstance(inputs, dict):
            inputs = {}
        if not isinstance(outputs, dict):
            outputs = {}

        data = {
            'inputs': inputs,
            'outputs': outputs_table,
            'ex_data': outputs.pop('ex_data', '')
        }
        return {
            'result': result,
            'data': data,
            'message': '' if result else data['ex_data']
        }