# 扩展编排节点
遵循 serverless workflow 规范,提供了扩展编排节点的能力,可以通过多种方式,将业务封装到编排节点里面,形成可复用的模块。
# 节点协议
以下是一个操作节点的 schema 定义示例。
{
"label": "节点调用", // 节点标题
"name": "GeneralOperationsImpl#linkFunction", // 节点名,唯一
"operation": "custom:linkFunction", // 节点表达式
"type": "custom", // 节点类型,custom为自定义
"orderNo": 0, // 分组内排序
"parameters": { // 参数组
"function": {
"label": "标题", // 参数标题
"name": "function", // 参数名,唯一,作为参数组的key
"type": "string", // 参数数据类型
"defaultValue": null, // 参数默认值
"description": "", // 参数描述
"required": true, // 参数是否必填
"inputType": "SelectOrch" // 参数输入控件类型,一般可不填,自动根据参数数据类型判断
}
},
"output": { // 输出结果
"label": "调用结果", // 输出结果标题
"name": "result", // 输出结果名
"type": "object", // 输出结果数据类型
"description": "" // 输出结果描述
},
"group": "" // 所属分组,为空时归属到默认分组[其他]
}
# 节点定义
# 定义注解说明
在后续实现节点的部分小节中,会使用到注解来定义节点,这里对注解参数作简要解释:
@FunctionModule - 节点定义
| 属性 | 说明 | 默认值 |
|---|---|---|
| name | 节点名,全局唯一 | 类名#方法名 |
| label | 节点操作标题 | - |
| type | 节点操作类型 | CUSTOM |
| operation | 必填,节点操作映射的表达式 | - |
| orderNo | 排序 | 0 |
| description | 描述 | - |
| group | 所属分组 | - |
@FunctionParameter - 节点参数定义
| 属性 | 说明 | 默认值 |
|---|---|---|
| label | 参数标题 | - |
| type | 参数数据类型 | OBJECT |
| defaultValue | 默认值 | - |
| description | 描述 | - |
| required | 是否必填 | true |
@FunctionOutput - 节点输出结果定义
| 属性 | 说明 | 默认值 |
|---|---|---|
| name | 输出结果名 | - |
| label | 输出结果标题 | - |
| type | 输出结果类型 | OBJECT |
| description | 描述 | - |
# Bean方法转操作节点
在Configuraion类或启动类上添加@FunctionScan注解扫描节点定义,使之生效;注册的bean需要添加@ExpressionModule注解并指定name:
import openfuse.serverlessworkflow.api.expression.ExpressionModule;
import openfuse.serverlessworkflow.web.schema.anno.FunctionScan;
@Configuration(proxyBeanMethods = false)
// 可指定其他package(默认为当前package),为减少不必要的扫描,建议缩小范围,需要包含到DemoBean的package
@FunctionScan(basePackages = {"xxx.xxx"})
public class CustomConfiguration {
@Bean
@ExpressionModule("demo")
DemoBean demo() {
return new DemoBean();
}
}
进入DemoBean中,每个方法相当于一个操作节点,在方法上添加注解定义节点的名称、参数名称及类型等:
import openfuse.serverlessworkflow.web.schema.DataType;
import openfuse.serverlessworkflow.web.schema.anno.FunctionModule;
import openfuse.serverlessworkflow.web.schema.anno.FunctionOutput;
import openfuse.serverlessworkflow.web.schema.anno.FunctionParameter;
public class DemoBean {
/**
* 当操作节点在编排中被使用,@FunctionModule中的operation以及name不能随意修改删除,但可以挪动位置映射到其他方法。
*
* 注解解释:
* @FunctionModule
* 1. operation类似spel表达式,@demo来源于@ExpressionModule中定义的name,.find(id)为调用的方法名以及参数
* 2. name全局唯一,命名建议带上特定前缀
*/
@FunctionModule(label = "查询操作", operation = "@demo.find(id)", name = "DemoFind", group = "示例")
@FunctionOutput(name = "result", label = "结果")
public Map<String, Object> find(
@FunctionParameter(label = "唯一键ID", required = false, type = DataType.STRING)
String id) {
return New.hashMap("id", id);
}
}
# 静态方法转操作节点
在api工程 /resources/schema.yml 文件中添加定义:
- label: 获取两数中最大值
name: Math.min
type: custom
operation: T(java.lang.Math).max(intVal1, intVal2)
orderNo: 1
parameters:
- label: 数值1
name: intVal1
type: integer
defaultValue: 0
description: 参数描述
requred: true
- label: 数值2
name: intVal2
type: integer
defaultValue: 0
description: 参数描述
requred: true
output:
label: 最大值
name: maximum
type: integer
className: java.lang.Integer
description: 输出结果描述
# 定义属性覆盖
针对通过注解生成定义的方式,注解中缺少一些针对界面展示的配置属性,如IDE需要的inputType属性等,可以在api工程/resources/schema.yml文件中进行添加或覆盖,该文件属性优先级高于注解属性:
- name: "CustomOperations#operation1" # 根据name查找对应的编排操作,必填
parameter:
param1:
inputType: xxx