dolphinscheduler-ui/public/images/task-icons/
目录下新增两个节点的logo图片,一个为激活状态的一个为非激活状态的,如下。修改文件dolphinscheduler-ui/src/views/projects/task/constants/task-type.ts
给TASK_TYPES_MAP增加新节点的映射信息,如下
修改完成之后,新节点的名字就会在dolphin组件的侧边栏显示出来啦。
修改文件dolphinscheduler-ui/src/views/projects/workflow/components/dag/dag.module.scss
.draggable
样式下的.sidebar-icon
样式中分别添加图标激活和没激活的路径。取名规范必须为.icon-
后面接先前在TASK_TYPES_MAP中新增的内容的小写。修改完成之后,新节点的logo就会在dolphin组件的侧边栏显示出来啦。
在目录dolphinscheduler-ui/src/views/projects/task/components/node/fields
下新增节点字段的ts文件
如下所示:期间需要新增国际化文件中的字段信息。
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import {useI18n} from 'vue-i18n'
import {useCustomParams, useResources} from '.'
import type {IJsonItem} from '../types'
import { ref, onMounted, watch } from 'vue'
export function useEmailSender(model: { [field: string]: any }): IJsonItem[] {
const otherStatementSpan = ref(22)
const {t} = useI18n()
return [
{
type: 'input',
field: 'subject',
name: t('project.node.email_sender_subject')
},
{
type: 'editor',
field: 'messageTemplate',
name: t('project.node.email_sender_message_template'),
},
{
type: 'multi-input',
field: 'emails',
name: t('project.node.email_sender_emails'),
span: otherStatementSpan,
props: {
placeholder: t('project.node.email_sender_emails'),
type: 'textarea',
autosize: { minRows: 1 }
}
},
useResources(),
...useCustomParams({model, field: 'localParams', isSimple: false})
]
}
在目录dolphinscheduler-ui/src/views/projects/task/components/node/tasks
下新增节点字段的ts文件
如下所示:
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { reactive } from 'vue'
import * as Fields from '../fields/index'
import type { IJsonItem, INodeData } from '../types'
import { ITaskData } from '../types'
export function useEmailSender({
projectCode,
from = 0,
readonly,
data
}: {
projectCode: number
from?: number
readonly?: boolean
data?: ITaskData
}) {
const model = reactive({
name: '',
taskType: 'EMAIL_SENDER',
flag: 'YES',
description: '',
timeoutFlag: false,
timeoutNotifyStrategy: ['WARN'],
localParams: [],
environmentCode: null,
failRetryInterval: 1,
failRetryTimes: 0,
workerGroup: 'default',
delayTime: 0,
timeout: 30,
messageTemplate: '',
emails: [],
subject: ''
} as INodeData)
return {
json: [
Fields.useName(from),
...Fields.useTaskDefinition({ projectCode, from, readonly, data, model }),
Fields.useRunFlag(),
Fields.useDescription(),
Fields.useTaskPriority(),
Fields.useWorkerGroup(),
Fields.useEnvironmentName(model, !data?.id),
...Fields.useTaskGroup(model, projectCode),
...Fields.useFailed(),
Fields.useDelayTime(model),
...Fields.useTimeoutAlarm(model),
...Fields.useEmailSender(model),
Fields.usePreTasks()
] as IJsonItem[],
model
}
}
ps: 这里存在不容易察觉到的细节,尤其注意。
这个地方一定要跟着改,不然页面上显示的字段,还是之前复制的那个节点的字段。
修改文件dolphinscheduler-ui/src/views/projects/task/components/node/fields/index.ts
新增一个export导出就好了
修改文件dolphinscheduler-ui/src/views/projects/task/components/node/tasks/index.ts
新增一个映射关系,如下:
前面这个部分必须和第二步时候的TASK_TYPES_MAP
这个map中的alias一致。
?
修改文件dolphinscheduler-ui/src/views/projects/task/components/node/format-data.ts
在formatParams
方法中增加新增节点的表单赋值代码,不加的话,页面上填的值,提交执行的时候,后端是拿不到的。
如下所示:
?
修改文件dolphinscheduler-ui/src/views/projects/task/components/node/types.ts
在这个文件中添加,我们在5步时候新增的字段在interface ITaskParams
这个实体里面添加就好了。
至此,前端基本上改的就差不多了,下面是后端。
在目录dolphinscheduler-task-plugin/dolphinscheduler-task-patsnap/src/main/java/org/apache/dolphinscheduler/plugin/task
下新增节点对应的文件夹。
新增类XXXParameters继承CustomBaseParameters
注意点如下:
@ReplacePlaceholders
这个注解,目前这个注解支持String类型和List类型的字段的占位符自动替换。checkParameters
这个方法,不然到时候填完表单信息保存的时候会报错,节点信息无效的。新增类XXXChannel继承 CustomBaseChannel
重写一下createTask和parseParameters方法。
新增类XXXChannelFactory,需要继承CustomBaseChannelFactory
重写getName
和create
方法。
getName的内容必须和前端第二步中改的TASK_TYPES_MAP
中的alias的名字一致。
新增类XXXTask继承CustomBaseTask
类
需要重写方法handlePatsnapTask
,这个节点想做什么事情,都在这个方法里面实现。
注意点如下:
setExitStatusCode(TaskConstants.EXIT_CODE_SUCCESS);
这行代码,告知节点运行successsetExitStatusCode(TaskConstants.EXIT_CODE_FAILURE);
这行代码。releaseResource();
来释放资源。cancel
,前端点击取消的时候,会执行到这个方法里面。