diff --git a/lib/server/controller/flow.js b/lib/server/controller/flow.js index 7cccbc834..d76988b5d 100644 --- a/lib/server/controller/flow.js +++ b/lib/server/controller/flow.js @@ -33,8 +33,9 @@ import { LCDataService, TABLE_FILE_NAME } from '../service/common/data-service' import httpConf from '../conf/http' import v3Conf from '../conf/v3' import { transFlowTplToBkFlowPipelineTree } from '../utils/flow' -import { getTaskList } from '../service/business/flow' +import { getLesscodeBkFlowSpaceId, getTaskList } from '../service/business/flow' +const bkflowApiGatewayName = global.BKFLOW_API_GATEWAY_NAME const authorization = { bk_app_code: v3Conf.APP_ID, bk_app_secret: v3Conf.APP_SECRET @@ -69,7 +70,7 @@ export const createAppBkFlowSpace = async ({ projectId, name, appCode, superuser if (!spaceData) { try { const response = await execApiGateWay({ - apiName: 'bkflow-eng-svc', + apiName: bkflowApiGatewayName, path: `/create_space/`, method: 'post', authorization: { @@ -538,10 +539,10 @@ export default class FlowController { const taskName = `${flowDetail.name}_${dayjs().format('YYYYMMDDHHmmss')}` const notifyConfig = JSON.parse(flowDetail.notifyConfig) - const { bkFlowSpaceId } = await LCDataService.findOne(TABLE_FILE_NAME.PROJECT_BKFLOW_SPACE, { projectId: 0 }) + const bkFlowSpaceId = await getLesscodeBkFlowSpaceId() const bkFlowTaskDetail = await execApiGateWay({ - apiName: 'bkflow-eng-svc', + apiName: bkflowApiGatewayName, path: `/space/${bkFlowSpaceId}/create_task_without_template`, method: 'post', authorization: { @@ -575,7 +576,7 @@ export default class FlowController { edges: flowDetail.edges }) await execApiGateWay({ - apiName: 'bkflow-eng-svc', + apiName: bkflowApiGatewayName, path: `/space/${bkFlowSpaceId}/task/${bkFlowTaskDetail.data.id}/operate_task/start/`, method: 'post', authorization: { @@ -623,11 +624,11 @@ export default class FlowController { const taskIds = list.map(item => item.bkFlowTaskId) - const { bkFlowSpaceId } = await LCDataService.findOne(TABLE_FILE_NAME.PROJECT_BKFLOW_SPACE, { projectId: 0 }) + const bkFlowSpaceId = await getLesscodeBkFlowSpaceId() // 调用BkFlow接口查询任务的执行状态 const tasksStatusRes = await execApiGateWay({ - apiName: 'bkflow-eng-svc', + apiName: bkflowApiGatewayName, path: `/space/${bkFlowSpaceId}/get_tasks_states/`, method: 'post', authorization: { @@ -687,11 +688,11 @@ export default class FlowController { const taskIds = list.map(item => item.bkFlowTaskId) - const { bkFlowSpaceId } = await LCDataService.findOne(TABLE_FILE_NAME.PROJECT_BKFLOW_SPACE, { projectId: 0 }) + const bkFlowSpaceId = await getLesscodeBkFlowSpaceId() // 调用BkFlow接口查询任务的执行状态 const tasksStatusRes = await execApiGateWay({ - apiName: 'bkflow-eng-svc', + apiName: bkflowApiGatewayName, path: `/space/${bkFlowSpaceId}/get_tasks_states/`, method: 'post', authorization: { @@ -741,10 +742,12 @@ export default class FlowController { console.log('准备请求 =====') const pipelineTree = transFlowTplToBkFlowPipelineTree(projectId, nodes, edges) - const { bkFlowSpaceId } = await LCDataService.findOne(TABLE_FILE_NAME.PROJECT_BKFLOW_SPACE, { projectId: 0 }) + + const bkFlowSpaceId = await getLesscodeBkFlowSpaceId() + try { const res = await execApiGateWay({ - apiName: 'bkflow-eng-svc', + apiName: bkflowApiGatewayName, path: `/space/${bkFlowSpaceId}/validate_pipeline_tree`, method: 'post', authorization: { @@ -785,11 +788,11 @@ export default class FlowController { ) { const runningNodeIds = [] const taskItem = await LCDataService.findOne(TABLE_FILE_NAME.FLOW_TASK, { id: taskId }) - const { bkFlowSpaceId } = await LCDataService.findOne(TABLE_FILE_NAME.PROJECT_BKFLOW_SPACE, { projectId: 0 }) + const bkFlowSpaceId = await getLesscodeBkFlowSpaceId() // 任务执行详情数据 const taskExecDetail = await execApiGateWay({ - apiName: 'bkflow-eng-svc', + apiName: bkflowApiGatewayName, path: `/space/${bkFlowSpaceId}/task/${taskItem.bkFlowTaskId}/get_task_states/`, method: 'get', authorization: { @@ -826,7 +829,7 @@ export default class FlowController { if (runningStateNodes.length > 0) { // 任务模板详情数据,比较节点id const taskTplDetail = await execApiGateWay({ - apiName: 'bkflow-eng-svc', + apiName: bkflowApiGatewayName, path: `/space/${bkFlowSpaceId}/task/${taskItem.bkFlowTaskId}/get_task_detail/`, method: 'get', authorization: { @@ -862,11 +865,11 @@ export default class FlowController { @PathParams({ name: 'taskId', require: true }) taskId, ) { const taskItem = await LCDataService.findOne(TABLE_FILE_NAME.FLOW_TASK, { id: taskId }) - const { bkFlowSpaceId } = await LCDataService.findOne(TABLE_FILE_NAME.PROJECT_BKFLOW_SPACE, { projectId: 0 }) + const bkFlowSpaceId = await getLesscodeBkFlowSpaceId() // 任务执行详情数据 const taskExecDetail = await execApiGateWay({ - apiName: 'bkflow-eng-svc', + apiName: bkflowApiGatewayName, path: `/space/${bkFlowSpaceId}/task/${taskItem.bkFlowTaskId}/get_task_states/`, method: 'get', authorization: { @@ -879,7 +882,7 @@ export default class FlowController { // 任务模板详情数据 const taskTplDetail = await execApiGateWay({ - apiName: 'bkflow-eng-svc', + apiName: bkflowApiGatewayName, path: `/space/${bkFlowSpaceId}/task/${taskItem.bkFlowTaskId}/get_task_detail/`, method: 'get', authorization: { @@ -955,10 +958,10 @@ export default class FlowController { }) const taskItem = await LCDataService.findOne(TABLE_FILE_NAME.FLOW_TASK, { id: taskId }) - const { bkFlowSpaceId } = await LCDataService.findOne(TABLE_FILE_NAME.PROJECT_BKFLOW_SPACE, { projectId: 0 }) + const bkFlowSpaceId = await getLesscodeBkFlowSpaceId() const taskTplDetail = await execApiGateWay({ - apiName: 'bkflow-eng-svc', + apiName: bkflowApiGatewayName, path: `/space/${bkFlowSpaceId}/task/${taskItem.bkFlowTaskId}/get_task_detail/`, method: 'get', authorization: { @@ -979,7 +982,7 @@ export default class FlowController { if (bkFlowNodeId) { const res = await execApiGateWay({ - apiName: 'bkflow-eng-svc', + apiName: bkflowApiGatewayName, path: `/space/${bkFlowSpaceId}/task/${taskItem.bkFlowTaskId}/node/${bkFlowNodeId}/operate_node/callback/`, method: 'post', authorization: { diff --git a/lib/server/controller/release.js b/lib/server/controller/release.js index 1f2897990..97dc0ba8d 100644 --- a/lib/server/controller/release.js +++ b/lib/server/controller/release.js @@ -298,7 +298,7 @@ const Realease = { // bkflow给部署的应用授权 await execApiGateWay({ - apiName: 'bkflow-eng-svc', + apiName: global.BKFLOW_API_GATEWAY_NAME, apiUrlTemp: httpConf.apiGateWayUrlTmpl, path: '/grant_apigw_permissions_to_app/', method: 'post', diff --git a/lib/server/custom-global.js b/lib/server/custom-global.js index c0a9f7012..c924bcd50 100644 --- a/lib/server/custom-global.js +++ b/lib/server/custom-global.js @@ -49,6 +49,8 @@ global.IAM_ENABLE = process.env.NODE_ENV !== 'development' global.NOTICE_CENTER_ENABLE = process.env.NOTICE_CENTER_ENABLE ?? true // lesscode网关名称 global.LESSCODE_API_GATEWAY_NAME = process.env.API_GATEWAY_NAME || 'bk-lesscode' +// bkflow网关名称 +global.BKFLOW_API_GATEWAY_NAME = process.env.BKFLOW_API_GATEWAY_NAME || (global.AUTH_NAME === 'bk_token' ? 'bk-flow-engine' : 'bkflow-eng-svc') const loadEnv = (filePath) => { if (fs.existsSync(filePath)) { diff --git a/lib/server/project-template/vue2/project-init-code/lib/server/controller/flow.js b/lib/server/project-template/vue2/project-init-code/lib/server/controller/flow.js index c2dd1f7e7..3872e7c0c 100644 --- a/lib/server/project-template/vue2/project-init-code/lib/server/controller/flow.js +++ b/lib/server/project-template/vue2/project-init-code/lib/server/controller/flow.js @@ -32,6 +32,7 @@ import { transFlowTplToBkFlowPipelineTree } from '../util/flow/index' const spaceId = '${spaceId}' +const bkflowGwName = global.BKFLOW_API_GATEWAY_NAME // bkflow的预发布环境名称为stage const bkflowGwStage = apiGateWayConfig.stageName === 'stag' ? 'stage' : apiGateWayConfig.stageName @@ -51,7 +52,7 @@ export default class FlowController { const taskName = `${flowDetail.name}_${dayjs().format('YYYYMMDDHHmmss')}` const bkFlowTaskDetail = await execApiGateWay({ - apiName: 'bkflow-eng-svc', + apiName: bkflowGwName, path: `/space/${spaceId}/create_task_without_template`, method: 'post', authorization: { @@ -86,7 +87,7 @@ export default class FlowController { } ) await execApiGateWay({ - apiName: 'bkflow-eng-svc', + apiName: bkflowGwName, path: `/space/${spaceId}/task/${bkFlowTaskDetail.data.id}/operate_task/start/`, method: 'post', authorization: { @@ -143,7 +144,7 @@ export default class FlowController { // 调用BkFlow接口查询任务的执行状态 const tasksStatusRes = await execApiGateWay({ - apiName: 'bkflow-eng-svc', + apiName: bkflowGwName, path: `/space/${spaceId}/get_tasks_states/`, method: 'post', authorization: { @@ -202,7 +203,7 @@ export default class FlowController { // 调用BkFlow接口查询任务的执行状态 const tasksStatusRes = await execApiGateWay({ - apiName: 'bkflow-eng-svc', + apiName: bkflowGwName, path: `/space/${spaceId}/get_tasks_states/`, method: 'post', authorization: { @@ -234,7 +235,7 @@ export default class FlowController { // 任务执行详情数据 const taskExecDetail = await execApiGateWay({ - apiName: 'bkflow-eng-svc', + apiName: bkflowGwName, path: `/space/${spaceId}/task/${taskItem.bkFlowTaskId}/get_task_states/`, method: 'get', authorization: { @@ -270,7 +271,7 @@ export default class FlowController { if (runningStateNodes.length > 0) { // 任务模板详情数据,比较节点id const taskTplDetail = await execApiGateWay({ - apiName: 'bkflow-eng-svc', + apiName: bkflowGwName, path: `/space/${spaceId}/task/${taskItem.bkFlowTaskId}/get_task_detail/`, method: 'get', authorization: { @@ -306,7 +307,7 @@ export default class FlowController { // 任务执行详情数据 const taskExecDetail = await execApiGateWay({ - apiName: 'bkflow-eng-svc', + apiName: bkflowGwName, path: `/space/${spaceId}/task/${taskItem.bkFlowTaskId}/get_task_states/`, method: 'get', authorization: { @@ -318,7 +319,7 @@ export default class FlowController { // 任务模板详情数据 const taskTplDetail = await execApiGateWay({ - apiName: 'bkflow-eng-svc', + apiName: bkflowGwName, path: `/space/${spaceId}/task/${taskItem.bkFlowTaskId}/get_task_detail/`, method: 'get', authorization: { @@ -394,7 +395,7 @@ export default class FlowController { const taskItem = await dataService.findOne('flow-task', { id: taskId }) const taskTplDetail = await execApiGateWay({ - apiName: 'bkflow-eng-svc', + apiName: bkflowGwName, path: `/space/${spaceId}/task/${taskItem.bkFlowTaskId}/get_task_detail/`, method: 'get', authorization: { @@ -414,7 +415,7 @@ export default class FlowController { if (bkFlowNodeId) { const res = await execApiGateWay({ - apiName: 'bkflow-eng-svc', + apiName: bkflowGwName, path: `/space/${spaceId}/task/${taskItem.bkFlowTaskId}/node/${bkFlowNodeId}/operate_node/callback/`, method: 'post', authorization: { diff --git a/lib/server/project-template/vue2/project-init-code/lib/server/custom-global.js b/lib/server/project-template/vue2/project-init-code/lib/server/custom-global.js index 57230fc43..0f6b22d21 100644 --- a/lib/server/project-template/vue2/project-init-code/lib/server/custom-global.js +++ b/lib/server/project-template/vue2/project-init-code/lib/server/custom-global.js @@ -38,6 +38,8 @@ global.ITSM_APP_CODE = process.env.BKPAAS_ENGINE_REGION === 'ieod' ? 'bkc-itsm' global.BKPAAS_ENGINE_REGION = process.env.BKPAAS_ENGINE_REGION === 'ieod' ? 'ieod' : 'default' // 是否对接权限中心 global.IAM_ENABLE = process.env.NODE_ENV !== 'development' +// bkflow网关名称 +global.BKFLOW_API_GATEWAY_NAME = process.env.BKFLOW_API_GATEWAY_NAME || (global.AUTH_NAME === 'bk_token' ? 'bk-flow-engine' : 'bkflow-eng-svc') const loadEnv = (filePath) => { if (fs.existsSync(filePath)) { diff --git a/lib/server/project-template/vue3/project-init-code/lib/server/controller/flow.js b/lib/server/project-template/vue3/project-init-code/lib/server/controller/flow.js index 163c44b5e..4713eff34 100644 --- a/lib/server/project-template/vue3/project-init-code/lib/server/controller/flow.js +++ b/lib/server/project-template/vue3/project-init-code/lib/server/controller/flow.js @@ -32,6 +32,7 @@ import { transFlowTplToBkFlowPipelineTree } from '../util/flow/index' const spaceId = '${spaceId}' +const bkflowGwName = global.BKFLOW_API_GATEWAY_NAME // bkflow的预发布环境名称为stage const bkflowGwStage = apiGateWayConfig.stageName === 'stag' ? 'stage' : apiGateWayConfig.stageName @@ -51,7 +52,7 @@ export default class FlowController { const taskName = `${flowDetail.name}_${dayjs().format('YYYYMMDDHHmmss')}` const bkFlowTaskDetail = await execApiGateWay({ - apiName: 'bkflow-eng-svc', + apiName: bkflowGwName, path: `/space/${spaceId}/create_task_without_template`, method: 'post', authorization: { @@ -86,7 +87,7 @@ export default class FlowController { } ) await execApiGateWay({ - apiName: 'bkflow-eng-svc', + apiName: bkflowGwName, path: `/space/${spaceId}/task/${bkFlowTaskDetail.data.id}/operate_task/start/`, method: 'post', authorization: { @@ -143,7 +144,7 @@ export default class FlowController { // 调用BkFlow接口查询任务的执行状态 const tasksStatusRes = await execApiGateWay({ - apiName: 'bkflow-eng-svc', + apiName: bkflowGwName, path: `/space/${spaceId}/get_tasks_states/`, method: 'post', authorization: { @@ -202,7 +203,7 @@ export default class FlowController { // 调用BkFlow接口查询任务的执行状态 const tasksStatusRes = await execApiGateWay({ - apiName: 'bkflow-eng-svc', + apiName: bkflowGwName, path: `/space/${spaceId}/get_tasks_states/`, method: 'post', authorization: { @@ -234,7 +235,7 @@ export default class FlowController { // 任务执行详情数据 const taskExecDetail = await execApiGateWay({ - apiName: 'bkflow-eng-svc', + apiName: bkflowGwName, path: `/space/${spaceId}/task/${taskItem.bkFlowTaskId}/get_task_states/`, method: 'get', authorization: { @@ -270,7 +271,7 @@ export default class FlowController { if (runningStateNodes.length > 0) { // 任务模板详情数据,比较节点id const taskTplDetail = await execApiGateWay({ - apiName: 'bkflow-eng-svc', + apiName: bkflowGwName, path: `/space/${spaceId}/task/${taskItem.bkFlowTaskId}/get_task_detail/`, method: 'get', authorization: { @@ -306,7 +307,7 @@ export default class FlowController { // 任务执行详情数据 const taskExecDetail = await execApiGateWay({ - apiName: 'bkflow-eng-svc', + apiName: bkflowGwName, path: `/space/${spaceId}/task/${taskItem.bkFlowTaskId}/get_task_states/`, method: 'get', authorization: { @@ -318,7 +319,7 @@ export default class FlowController { // 任务模板详情数据 const taskTplDetail = await execApiGateWay({ - apiName: 'bkflow-eng-svc', + apiName: bkflowGwName, path: `/space/${spaceId}/task/${taskItem.bkFlowTaskId}/get_task_detail/`, method: 'get', authorization: { @@ -394,7 +395,7 @@ export default class FlowController { const taskItem = await dataService.findOne('flow-task', { id: taskId }) const taskTplDetail = await execApiGateWay({ - apiName: 'bkflow-eng-svc', + apiName: bkflowGwName, path: `/space/${spaceId}/task/${taskItem.bkFlowTaskId}/get_task_detail/`, method: 'get', authorization: { @@ -414,7 +415,7 @@ export default class FlowController { if (bkFlowNodeId) { const res = await execApiGateWay({ - apiName: 'bkflow-eng-svc', + apiName: bkflowGwName, path: `/space/${spaceId}/task/${taskItem.bkFlowTaskId}/node/${bkFlowNodeId}/operate_node/callback/`, method: 'post', authorization: { diff --git a/lib/server/project-template/vue3/project-init-code/lib/server/custom-global.js b/lib/server/project-template/vue3/project-init-code/lib/server/custom-global.js index 57230fc43..0f6b22d21 100644 --- a/lib/server/project-template/vue3/project-init-code/lib/server/custom-global.js +++ b/lib/server/project-template/vue3/project-init-code/lib/server/custom-global.js @@ -38,6 +38,8 @@ global.ITSM_APP_CODE = process.env.BKPAAS_ENGINE_REGION === 'ieod' ? 'bkc-itsm' global.BKPAAS_ENGINE_REGION = process.env.BKPAAS_ENGINE_REGION === 'ieod' ? 'ieod' : 'default' // 是否对接权限中心 global.IAM_ENABLE = process.env.NODE_ENV !== 'development' +// bkflow网关名称 +global.BKFLOW_API_GATEWAY_NAME = process.env.BKFLOW_API_GATEWAY_NAME || (global.AUTH_NAME === 'bk_token' ? 'bk-flow-engine' : 'bkflow-eng-svc') const loadEnv = (filePath) => { if (fs.existsSync(filePath)) { diff --git a/lib/server/service/business/flow.js b/lib/server/service/business/flow.js index 7feecbf48..435935dc2 100644 --- a/lib/server/service/business/flow.js +++ b/lib/server/service/business/flow.js @@ -28,7 +28,7 @@ export const createBkFlowSpace = async () => { } const response = await execApiGateWay({ - apiName: 'bkflow-eng-svc', + apiName: global.BKFLOW_API_GATEWAY_NAME, path: `/create_space/`, method: 'post', authorization: { @@ -55,6 +55,7 @@ export const createBkFlowSpace = async () => { projectId: 0, bkFlowSpaceId: response.data.space.id }) + return response.data.space.id } } catch (err) { console.error('create bkflow space error:\n', err) @@ -62,7 +63,16 @@ export const createBkFlowSpace = async () => { } } - return spaceData + return spaceData.bkFlowSpaceId +} + +// 获取lesscode平台在bkflow的空间id,如果不存在则创建一个 +export const getLesscodeBkFlowSpaceId = async () => { + const spaceData = await LCDataService.findOne(TABLE_FILE_NAME.PROJECT_BKFLOW_SPACE, { projectId: 0 }) + if (spaceData) { + return spaceData.bkFlowSpaceId + } + return await createBkFlowSpace() } export const getTaskList = (parmas) => {