def replace_all_id(pipeline_data): flows = pipeline_data['flows'] node_map = {} flow_map = {} # step.1 replace nodes id # replace events id start_event_id = node_uniqid() end_event_id = node_uniqid() node_map[pipeline_data[PE.start_event][ID]] = start_event_id node_map[pipeline_data[PE.end_event][ID]] = end_event_id _replace_event_id(flows, pipeline_data[PE.start_event], start_event_id) _replace_event_id(flows, pipeline_data[PE.end_event], end_event_id) # replace activities id activities = pipeline_data[PE.activities] keys = activities.keys() for old_id in keys: substituted_id = node_uniqid() node_map[old_id] = substituted_id _replace_activity_id(flows, activities, old_id, substituted_id) # replace gateways id gateways = pipeline_data[PE.gateways] keys = gateways.keys() for old_id in keys: substituted_id = node_uniqid() node_map[old_id] = substituted_id _replace_gateway_id(flows, gateways, old_id, substituted_id) # step.2 replace flows id keys = flows.keys() for old_id in keys: substituted_id = line_uniqid() flow_map[old_id] = substituted_id _replace_flow_id(flows, old_id, substituted_id, pipeline_data) # step.3 replace front end data _replace_front_end_data_id(pipeline_data, node_map, flow_map)
def convert_stage_and_params_from_v2_to_v3(stage_data, params, biz_cc_id): step_2_tag = get_step_tagcode(stage_data) constants = convert_params_from_v2_to_v3(params, step_2_tag) pipeline_tree = { 'start_event': { 'id': node_uniqid(), 'incoming': '', 'outgoing': '', 'type': 'EmptyStartEvent', 'name': '', }, 'end_event': { 'id': node_uniqid(), 'incoming': '', 'outgoing': '', 'type': 'EmptyEndEvent', 'name': '', }, 'activities': {}, 'gateways': {}, 'flows': {}, 'constants': constants, 'outputs': [] } last_node = pipeline_tree['start_event'] for stage in stage_data: is_parallel = stage.get('is_parallel') step_data = stage['steps'] stage_name = stage['stage_name'] if is_parallel: flow = { 'id': line_uniqid(), 'source': last_node['id'], 'target': '', 'is_default': False, } last_node['outgoing'] = flow['id'] parallel_gateway = { 'id': node_uniqid(), 'incoming': flow['id'], 'outgoing': [], 'type': 'ParallelGateway', 'name': '', } flow['target'] = parallel_gateway['id'] converge_gateway = { 'id': node_uniqid(), 'incoming': [], 'outgoing': '', 'type': 'ConvergeGateway', 'name': '', } pipeline_tree['gateways'].update({ parallel_gateway['id']: parallel_gateway, converge_gateway['id']: converge_gateway, }) pipeline_tree['flows'].update({ flow['id']: flow }) last_node = parallel_gateway for step in step_data: activity = convert_atom_from_v2_step_to_v3_act(step, constants, biz_cc_id, stage_name) flow = { 'id': line_uniqid(), 'source': last_node['id'], 'target': activity['id'], 'is_default': False, } activity['incoming'] = flow['id'] if is_parallel: parallel_gateway['outgoing'].append(flow['id']) flow2 = { 'id': line_uniqid(), 'source': activity['id'], 'target': converge_gateway['id'], 'is_default': False, } converge_gateway['incoming'].append(flow2['id']) activity['outgoing'] = flow2['id'] pipeline_tree['flows'].update({ flow['id']: flow, flow2['id']: flow2, }) else: last_node['outgoing'] = flow['id'] last_node = activity pipeline_tree['flows'].update({ flow['id']: flow }) pipeline_tree['activities'].update({ activity['id']: activity }) if is_parallel: last_node = converge_gateway flow = { 'id': line_uniqid(), 'source': last_node['id'], 'target': pipeline_tree['end_event']['id'], 'is_default': False, } pipeline_tree['flows'].update({ flow['id']: flow }) last_node['outgoing'] = flow['id'] pipeline_tree['end_event']['incoming'] = flow['id'] return draw_pipeline_automatic(pipeline_tree)
def replace_long_path_with_dummy(pipeline, ranks): """ @summary: 使用虚拟节点和虚拟边替换长边 @param pipeline: @param ranks: @return: real_flows_chain: 被替换掉的长边 """ real_flows_chain = {} for flow_id, flow in list(pipeline[PWE.flows].items()): flow_slack = slack(ranks, flow) if flow_slack > 0: real_flows_chain[flow_id] = flow dummy_nodes_ranks = range(ranks[flow[PWE.source]] + MIN_LEN, ranks[flow[PWE.target]], MIN_LEN) incoming_flow_id = line_uniqid() dummy_node_id = node_uniqid() dummy_flow = { PWE.id: incoming_flow_id, PWE.type: DUMMY_FLOW_TYPE, PWE.source: flow[PWE.source], PWE.target: dummy_node_id } # change outgoing of flow.source node delete_flow_id_from_node_io( pipeline['all_nodes'][flow[PWE.source]], flow_id, PWE.outgoing) add_flow_id_to_node_io(pipeline['all_nodes'][flow[PWE.source]], incoming_flow_id, PWE.outgoing) # delete long path flow from pipeline pipeline[PWE.flows].pop(flow_id) for node_rank in dummy_nodes_ranks: # 生成当前 dummy node 的 outgoing flow outgoing_flow_id = line_uniqid() dummy_node = { PWE.id: dummy_node_id, PWE.type: DUMMY_NODE_TYPE, PWE.name: DUMMY_NODE_TYPE, PWE.incoming: incoming_flow_id, PWE.outgoing: outgoing_flow_id } # add dummy to pipeline pipeline['all_nodes'].update({dummy_node_id: dummy_node}) pipeline[PWE.flows].update({incoming_flow_id: dummy_flow}) # add dummy to ranks ranks.update({dummy_node_id: node_rank}) # next loop init data incoming_flow_id = outgoing_flow_id dummy_node_id = node_uniqid() dummy_flow = { PWE.id: incoming_flow_id, PWE.type: DUMMY_FLOW_TYPE, PWE.source: dummy_node[PWE.id], PWE.target: dummy_node_id } # add last dummy flow to pipeline dummy_flow[PWE.target] = flow[PWE.target] pipeline[PWE.flows].update({incoming_flow_id: dummy_flow}) # change incoming of flow.target node delete_flow_id_from_node_io( pipeline['all_nodes'][flow[PWE.target]], flow_id, PWE.incoming) add_flow_id_to_node_io(pipeline['all_nodes'][flow[PWE.target]], incoming_flow_id, PWE.incoming) return real_flows_chain
def replace_all_id(pipeline_data): flows = pipeline_data[PE.flows] node_map = {} flow_map = {} # step.1 replace nodes id # replace events id start_event_id = node_uniqid() end_event_id = node_uniqid() node_map[pipeline_data[PE.start_event][PE.id]] = start_event_id node_map[pipeline_data[PE.end_event][PE.id]] = end_event_id start_event_id_maps = _replace_event_id(flows, pipeline_data[PE.start_event], start_event_id) end_event_id_maps = _replace_event_id(flows, pipeline_data[PE.end_event], end_event_id) # replace activities id activity_id_maps = {} activities = pipeline_data[PE.activities] keys = activities.keys() for old_id in keys: substituted_id = node_uniqid() node_map[old_id] = substituted_id _replace_activity_id(flows, activities, old_id, substituted_id) activity_id_maps[old_id] = substituted_id # replace gateways id gateway_id_maps = {} gateways = pipeline_data[PE.gateways] keys = gateways.keys() for old_id in keys: substituted_id = node_uniqid() node_map[old_id] = substituted_id _replace_gateway_id(flows, gateways, old_id, substituted_id) gateway_id_maps[old_id] = substituted_id # step.2 replace flows id flow_id_maps = {} keys = flows.keys() for old_id in keys: substituted_id = line_uniqid() flow_map[old_id] = substituted_id _replace_flow_id(flows, old_id, substituted_id, pipeline_data) flow_id_maps[old_id] = substituted_id # step.3 replace id in data _replace_id_in_data(pipeline_data, node_map) # step.4 try to replace front end data _replace_front_end_data_id(pipeline_data, node_map, flow_map) return { 'start_event': start_event_id_maps, 'end_event': end_event_id_maps, 'activity': activity_id_maps, 'gateway': gateway_id_maps, 'flow': flow_id_maps }