Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 23 additions & 20 deletions lib/server/controller/flow.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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: {
Expand Down Expand Up @@ -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: {
Expand Down Expand Up @@ -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: {
Expand Down Expand Up @@ -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: {
Expand Down Expand Up @@ -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: {
Expand Down Expand Up @@ -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: {
Expand Down Expand Up @@ -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: {
Expand Down Expand Up @@ -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: {
Expand Down Expand Up @@ -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: {
Expand All @@ -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: {
Expand Down Expand Up @@ -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: {
Expand All @@ -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: {
Expand Down
2 changes: 1 addition & 1 deletion lib/server/controller/release.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
2 changes: 2 additions & 0 deletions lib/server/custom-global.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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: {
Expand Down Expand Up @@ -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: {
Expand Down Expand Up @@ -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: {
Expand Down Expand Up @@ -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: {
Expand Down Expand Up @@ -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: {
Expand Down Expand Up @@ -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: {
Expand Down Expand Up @@ -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: {
Expand All @@ -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: {
Expand Down Expand Up @@ -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: {
Expand All @@ -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: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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: {
Expand Down Expand Up @@ -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: {
Expand Down Expand Up @@ -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: {
Expand Down Expand Up @@ -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: {
Expand Down Expand Up @@ -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: {
Expand Down Expand Up @@ -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: {
Expand Down Expand Up @@ -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: {
Expand All @@ -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: {
Expand Down Expand Up @@ -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: {
Expand All @@ -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: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
Loading