def get_act_data(self, act_id, component_code=None, subprocess_stack=None): act_started = True result = True try: inputs = pipeline_api.get_inputs(act_id) outputs = pipeline_api.get_outputs(act_id) except Data.DoesNotExist: act_started = False if component_code: if not act_started: try: instance_data = self.pipeline_instance.execution_data inputs = pipeline_parser.WebPipelineAdapter( instance_data).get_act_inputs( act_id=act_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} 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: for outputs_item in outputs_format: value = outputs.get('outputs', {}).get(outputs_item['key'], '') outputs_table.append({ 'name': outputs_item['name'], 'value': value }) else: outputs_table = [] data = { 'inputs': inputs, 'outputs': outputs_table, 'ex_data': outputs.pop('ex_data', '') } return {'result': result, 'data': data, 'message': data['ex_data']}
def get_inputs(act_id): return api.get_inputs(act_id)
def test_get_inputs(self): data = MockData(get_inputs_return=uniqid()) with patch(PIPELINE_DATA_GET, MagicMock(return_value=data)): inputs = api.get_inputs(self.node_id) self.assertEqual(inputs, data.inputs)
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'] }
def get_node_data_v1( self, username: str, subprocess_stack: List[str], component_code: Optional[str] = None, loop: Optional[int] = None, **kwargs, ) -> dict: node_started = True inputs = {} outputs = {} try: detail = pipeline_api.get_status_tree(self.node_id) except pipeline_exceptions.InvalidOperationException: node_started = False else: # 最新 loop 执行记录,直接通过接口获取 if loop is None or int(loop) >= detail["loop"]: try: inputs = pipeline_api.get_inputs(self.node_id) except pipeline_engine_models.Data.DoesNotExist: logger.exception("shield DoesNotExist in pipeline engine layer") inputs = {} try: outputs = pipeline_api.get_outputs(self.node_id) except pipeline_engine_models.Data.DoesNotExist: logger.exception("shield DoesNotExist in pipeline engine layer") outputs = {} # 历史 loop 记录,需要从 histories 获取,并取最新一次操作数据(如手动重试时重新填参) else: his_data = pipeline_api.get_activity_histories(node_id=self.node_id, loop=loop) inputs = his_data[-1]["inputs"] outputs = {"outputs": his_data[-1]["outputs"], "ex_data": his_data[-1]["ex_data"]} pipeline_instance = kwargs["pipeline_instance"] if not node_started: node_info = self._get_node_info( node_id=self.node_id, pipeline=pipeline_instance.execution_data, subprocess_stack=subprocess_stack ) if node_info["type"] != "ServiceActivity": return { "result": True, "data": {"inputs": {}, "outputs": [], "ex_data": ""}, "message": "", "code": err_code.SUCCESS.code, } success, err, inputs, outputs = self._prerender_node_data( pipeline_instance=pipeline_instance, subprocess_stack=subprocess_stack, username=username ) if not success: return { "result": False, "data": {}, "message": err, "code": err_code.UNKNOWN_ERROR.code, } # 根据传入的 component_code 对输出进行格式化 success, err, outputs_table = self._format_outputs( outputs=outputs, component_code=component_code, pipeline_instance=pipeline_instance, subprocess_stack=subprocess_stack, ) if not success: return { "result": False, "data": {}, "message": err, "code": err_code.UNKNOWN_ERROR.code, } data = {"inputs": inputs, "outputs": outputs_table, "ex_data": outputs.pop("ex_data", "")} return {"result": True, "data": data, "message": "", "code": err_code.SUCCESS.code}