Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
apache
DolphinScheduler
提交
c9717085
DolphinScheduler
项目概览
apache
/
DolphinScheduler
上一次同步 1 年多
通知
707
Star
9572
Fork
3514
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
DolphinScheduler
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
c9717085
编写于
1月 04, 2022
作者:
J
JinYong Li
提交者:
GitHub
1月 04, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add task save and binds workflow (#7772)
上级
70ab2b88
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
158 addition
and
3 deletion
+158
-3
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/TaskDefinitionController.java
...hinscheduler/api/controller/TaskDefinitionController.java
+30
-0
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/TaskDefinitionService.java
...e/dolphinscheduler/api/service/TaskDefinitionService.java
+16
-0
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/TaskDefinitionServiceImpl.java
...scheduler/api/service/impl/TaskDefinitionServiceImpl.java
+91
-3
dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/TaskDefinitionMapper.java
...che/dolphinscheduler/dao/mapper/TaskDefinitionMapper.java
+9
-0
dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/TaskDefinitionMapper.xml
...ache/dolphinscheduler/dao/mapper/TaskDefinitionMapper.xml
+12
-0
未找到文件。
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/TaskDefinitionController.java
浏览文件 @
c9717085
...
...
@@ -95,6 +95,36 @@ public class TaskDefinitionController extends BaseController {
return
returnDataList
(
result
);
}
/**
* create single task definition that binds the workflow
*
* @param loginUser login user
* @param projectCode project code
* @param processDefinitionCode process definition code
* @param taskDefinitionJsonObj task definition json object
* @param upstreamCodes upstream task codes, sep comma
* @return create result code
*/
@ApiOperation
(
value
=
"saveSingle"
,
notes
=
"CREATE_SINGLE_TASK_DEFINITION_NOTES"
)
@ApiImplicitParams
({
@ApiImplicitParam
(
name
=
"projectCode"
,
value
=
"PROJECT_CODE"
,
required
=
true
,
type
=
"Long"
),
@ApiImplicitParam
(
name
=
"processDefinitionCode"
,
value
=
"PROCESS_DEFINITION_CODE"
,
required
=
true
,
type
=
"processDefinitionCode"
),
@ApiImplicitParam
(
name
=
"taskDefinitionJsonObj"
,
value
=
"TASK_DEFINITION_JSON"
,
required
=
true
,
type
=
"String"
),
@ApiImplicitParam
(
name
=
"upstreamCodes"
,
value
=
"UPSTREAM_CODES"
,
required
=
false
,
type
=
"String"
)
})
@PostMapping
(
"/save-single"
)
@ResponseStatus
(
HttpStatus
.
CREATED
)
@ApiException
(
CREATE_TASK_DEFINITION_ERROR
)
@AccessLogAnnotation
(
ignoreRequestArgs
=
"loginUser"
)
public
Result
createTaskBindsWorkFlow
(
@ApiIgnore
@RequestAttribute
(
value
=
Constants
.
SESSION_USER
)
User
loginUser
,
@ApiParam
(
name
=
"projectCode"
,
value
=
"PROJECT_CODE"
,
required
=
true
)
@PathVariable
long
projectCode
,
@RequestParam
(
value
=
"processDefinitionCode"
,
required
=
true
)
long
processDefinitionCode
,
@RequestParam
(
value
=
"taskDefinitionJsonObj"
,
required
=
true
)
String
taskDefinitionJsonObj
,
@RequestParam
(
value
=
"upstreamCodes"
,
required
=
false
)
String
upstreamCodes
)
{
Map
<
String
,
Object
>
result
=
taskDefinitionService
.
createTaskBindsWorkFlow
(
loginUser
,
projectCode
,
processDefinitionCode
,
taskDefinitionJsonObj
,
upstreamCodes
);
return
returnDataList
(
result
);
}
/**
* update task definition
*
...
...
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/TaskDefinitionService.java
浏览文件 @
c9717085
...
...
@@ -40,6 +40,22 @@ public interface TaskDefinitionService {
long
projectCode
,
String
taskDefinitionJson
);
/**
* create single task definition that binds the workflow
*
* @param loginUser login user
* @param projectCode project code
* @param processDefinitionCode process definition code
* @param taskDefinitionJsonObj task definition json object
* @param upstreamCodes upstream task codes, sep comma
* @return create result code
*/
Map
<
String
,
Object
>
createTaskBindsWorkFlow
(
User
loginUser
,
long
projectCode
,
long
processDefinitionCode
,
String
taskDefinitionJsonObj
,
String
upstreamCodes
);
/**
* query task definition
*
...
...
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/TaskDefinitionServiceImpl.java
浏览文件 @
c9717085
...
...
@@ -32,6 +32,7 @@ import org.apache.dolphinscheduler.common.enums.TaskType;
import
org.apache.dolphinscheduler.common.utils.CodeGenerateUtils
;
import
org.apache.dolphinscheduler.common.utils.CodeGenerateUtils.CodeGenerateException
;
import
org.apache.dolphinscheduler.common.utils.JSONUtils
;
import
org.apache.dolphinscheduler.dao.entity.ProcessDefinition
;
import
org.apache.dolphinscheduler.dao.entity.ProcessTaskRelation
;
import
org.apache.dolphinscheduler.dao.entity.ProcessTaskRelationLog
;
import
org.apache.dolphinscheduler.dao.entity.Project
;
...
...
@@ -39,16 +40,16 @@ import org.apache.dolphinscheduler.dao.entity.TaskDefinition;
import
org.apache.dolphinscheduler.dao.entity.TaskDefinitionLog
;
import
org.apache.dolphinscheduler.dao.entity.TaskMainInfo
;
import
org.apache.dolphinscheduler.dao.entity.User
;
import
org.apache.dolphinscheduler.dao.mapper.ProcessDefinitionMapper
;
import
org.apache.dolphinscheduler.dao.mapper.ProcessTaskRelationLogMapper
;
import
org.apache.dolphinscheduler.dao.mapper.ProcessTaskRelationMapper
;
import
org.apache.dolphinscheduler.dao.mapper.ProjectMapper
;
import
org.apache.dolphinscheduler.dao.mapper.TaskDefinitionLogMapper
;
import
org.apache.dolphinscheduler.dao.mapper.TaskDefinitionMapper
;
import
org.apache.dolphinscheduler.dao.mapper.UserMapper
;
import
org.apache.dolphinscheduler.service.permission.PermissionCheck
;
import
org.apache.dolphinscheduler.service.process.ProcessService
;
import
org.apache.commons.lang.StringUtils
;
import
org.apache.commons.lang
3
.StringUtils
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
...
...
@@ -101,7 +102,7 @@ public class TaskDefinitionServiceImpl extends BaseServiceImpl implements TaskDe
private
ProcessService
processService
;
@Autowired
private
UserMapper
user
Mapper
;
private
ProcessDefinitionMapper
processDefinition
Mapper
;
/**
* create task definition
...
...
@@ -148,6 +149,93 @@ public class TaskDefinitionServiceImpl extends BaseServiceImpl implements TaskDe
return
result
;
}
/**
* create single task definition that binds the workflow
*
* @param loginUser login user
* @param projectCode project code
* @param processDefinitionCode process definition code
* @param taskDefinitionJsonObj task definition json object
* @param upstreamCodes upstream task codes, sep comma
* @return create result code
*/
@Transactional
(
rollbackFor
=
RuntimeException
.
class
)
@Override
public
Map
<
String
,
Object
>
createTaskBindsWorkFlow
(
User
loginUser
,
long
projectCode
,
long
processDefinitionCode
,
String
taskDefinitionJsonObj
,
String
upstreamCodes
)
{
Project
project
=
projectMapper
.
queryByCode
(
projectCode
);
//check user access for project
Map
<
String
,
Object
>
result
=
projectService
.
checkProjectAndAuth
(
loginUser
,
project
,
projectCode
);
if
(
result
.
get
(
Constants
.
STATUS
)
!=
Status
.
SUCCESS
)
{
return
result
;
}
ProcessDefinition
processDefinition
=
processDefinitionMapper
.
queryByCode
(
processDefinitionCode
);
if
(
processDefinition
==
null
)
{
putMsg
(
result
,
Status
.
PROCESS_DEFINE_NOT_EXIST
,
processDefinitionCode
);
return
result
;
}
TaskDefinitionLog
taskDefinition
=
JSONUtils
.
parseObject
(
taskDefinitionJsonObj
,
TaskDefinitionLog
.
class
);
if
(
taskDefinition
==
null
)
{
logger
.
error
(
"taskDefinitionJsonObj is not valid json"
);
putMsg
(
result
,
Status
.
DATA_IS_NOT_VALID
,
taskDefinitionJsonObj
);
return
result
;
}
if
(!
CheckUtils
.
checkTaskDefinitionParameters
(
taskDefinition
))
{
logger
.
error
(
"task definition {} parameter invalid"
,
taskDefinition
.
getName
());
putMsg
(
result
,
Status
.
PROCESS_NODE_S_PARAMETER_INVALID
,
taskDefinition
.
getName
());
return
result
;
}
long
taskCode
=
taskDefinition
.
getCode
();
if
(
taskCode
==
0
)
{
try
{
taskCode
=
CodeGenerateUtils
.
getInstance
().
genCode
();
taskDefinition
.
setCode
(
taskCode
);
}
catch
(
CodeGenerateException
e
)
{
logger
.
error
(
"Task code get error, "
,
e
);
putMsg
(
result
,
Status
.
INTERNAL_SERVER_ERROR_ARGS
,
taskDefinitionJsonObj
);
return
result
;
}
}
if
(
StringUtils
.
isNotBlank
(
upstreamCodes
))
{
Set
<
Long
>
upstreamTaskCodes
=
Arrays
.
stream
(
upstreamCodes
.
split
(
Constants
.
COMMA
)).
map
(
Long:
:
parseLong
).
collect
(
Collectors
.
toSet
());
List
<
TaskDefinition
>
upstreamTaskDefinitionList
=
taskDefinitionMapper
.
queryByCodeList
(
upstreamTaskCodes
);
Set
<
Long
>
queryUpStreamTaskCodes
=
upstreamTaskDefinitionList
.
stream
().
map
(
TaskDefinition:
:
getCode
).
collect
(
Collectors
.
toSet
());
// upstreamTaskCodes - queryUpStreamTaskCodes
Set
<
Long
>
diffCode
=
upstreamTaskCodes
.
stream
().
filter
(
code
->
!
queryUpStreamTaskCodes
.
contains
(
code
)).
collect
(
Collectors
.
toSet
());
if
(!
diffCode
.
isEmpty
())
{
putMsg
(
result
,
Status
.
TASK_DEFINE_NOT_EXIST
,
StringUtils
.
join
(
diffCode
,
Constants
.
COMMA
));
return
result
;
}
List
<
ProcessTaskRelationLog
>
processTaskRelationLogList
=
Lists
.
newArrayList
();
for
(
TaskDefinition
upstreamTask
:
upstreamTaskDefinitionList
)
{
ProcessTaskRelationLog
processTaskRelationLog
=
new
ProcessTaskRelationLog
();
processTaskRelationLog
.
setPreTaskCode
(
upstreamTask
.
getCode
());
processTaskRelationLog
.
setPreTaskVersion
(
upstreamTask
.
getVersion
());
processTaskRelationLog
.
setPostTaskCode
(
taskCode
);
processTaskRelationLog
.
setPostTaskVersion
(
Constants
.
VERSION_FIRST
);
processTaskRelationLogList
.
add
(
processTaskRelationLog
);
}
int
insertResult
=
processService
.
saveTaskRelation
(
loginUser
,
projectCode
,
processDefinition
.
getCode
(),
processDefinition
.
getVersion
(),
processTaskRelationLogList
,
null
);
if
(
insertResult
==
Constants
.
EXIT_CODE_SUCCESS
)
{
putMsg
(
result
,
Status
.
SUCCESS
);
result
.
put
(
Constants
.
DATA_LIST
,
processDefinition
);
}
else
{
putMsg
(
result
,
Status
.
CREATE_PROCESS_TASK_RELATION_ERROR
);
throw
new
ServiceException
(
Status
.
CREATE_PROCESS_TASK_RELATION_ERROR
);
}
}
int
saveTaskResult
=
processService
.
saveTaskDefine
(
loginUser
,
projectCode
,
Lists
.
newArrayList
(
taskDefinition
));
if
(
saveTaskResult
==
Constants
.
DEFINITION_FAILURE
)
{
putMsg
(
result
,
Status
.
CREATE_TASK_DEFINITION_ERROR
);
throw
new
ServiceException
(
Status
.
CREATE_TASK_DEFINITION_ERROR
);
}
return
result
;
}
/**
* query task definition
*
...
...
dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/TaskDefinitionMapper.java
浏览文件 @
c9717085
...
...
@@ -25,6 +25,7 @@ import org.apache.dolphinscheduler.dao.entity.TaskMainInfo;
import
org.apache.ibatis.annotations.MapKey
;
import
org.apache.ibatis.annotations.Param
;
import
java.util.Collection
;
import
java.util.List
;
import
java.util.Map
;
...
...
@@ -117,4 +118,12 @@ public interface TaskDefinitionMapper extends BaseMapper<TaskDefinition> {
@Param
(
"searchWorkflowName"
)
String
searchWorkflowName
,
@Param
(
"searchTaskName"
)
String
searchTaskName
,
@Param
(
"taskType"
)
String
taskType
);
/**
* query task definition by code list
*
* @param codes taskDefinitionCode list
* @return task definition list
*/
List
<
TaskDefinition
>
queryByCodeList
(
@Param
(
"codes"
)
Collection
<
Long
>
codes
);
}
dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/TaskDefinitionMapper.xml
浏览文件 @
c9717085
...
...
@@ -106,4 +106,16 @@
</if>
order by td.update_time desc
</select>
<select
id=
"queryByCodeList"
resultType=
"org.apache.dolphinscheduler.dao.entity.TaskDefinition"
>
select
<include
refid=
"baseSql"
/>
from t_ds_task_definition
where 1 = 1
<if
test=
"codes != null and codes.size != 0"
>
and code in
<foreach
collection=
"codes"
index=
"index"
item=
"i"
open=
"("
separator=
","
close=
")"
>
#{i}
</foreach>
</if>
</select>
</mapper>
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录