Skip to content

Commit

Permalink
[Fix-1887] [admin] Fix DolphinScheduler can not generate task code in…
Browse files Browse the repository at this point in the history
… createTaskDefinition (#1888)

Co-authored-by: wenmo <[email protected]>
  • Loading branch information
aiwenmo and aiwenmo authored Apr 16, 2023
1 parent 803cab1 commit fd63e81
Showing 1 changed file with 20 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ public Result<TaskDefinition> getTaskDefinition(@ApiParam(value = "dinky任务id
TaskDefinition taskDefinition = null;
Project dinkyProject = SystemInit.getProject();

Catalogue catalogue = catalogueService.getOne(new LambdaQueryWrapper<Catalogue>().eq(Catalogue::getTaskId, dinkyTaskId));
Catalogue catalogue = catalogueService
.getOne(new LambdaQueryWrapper<Catalogue>().eq(Catalogue::getTaskId, dinkyTaskId));
if (catalogue == null) {
return Result.failed("节点获取失败");
}
Expand Down Expand Up @@ -130,7 +131,8 @@ public Result<List<TaskMainInfo>> getTaskMainInfos(@ApiParam(value = "dinky任

Project dinkyProject = SystemInit.getProject();

Catalogue catalogue = catalogueService.getOne(new LambdaQueryWrapper<Catalogue>().eq(Catalogue::getTaskId, dinkyTaskId));
Catalogue catalogue = catalogueService
.getOne(new LambdaQueryWrapper<Catalogue>().eq(Catalogue::getTaskId, dinkyTaskId));
if (catalogue == null) {
return Result.failed("节点获取失败");
}
Expand All @@ -143,8 +145,9 @@ public Result<List<TaskMainInfo>> getTaskMainInfos(@ApiParam(value = "dinky任
long projectCode = dinkyProject.getCode();

List<TaskMainInfo> taskMainInfos = taskClient.getTaskMainInfos(projectCode, processName, "");
//去掉本身
taskMainInfos.removeIf(taskMainInfo -> (catalogue.getName() + ":" + catalogue.getId()).equalsIgnoreCase(taskMainInfo.getTaskName()));
// 去掉本身
taskMainInfos.removeIf(taskMainInfo -> (catalogue.getName() + ":" + catalogue.getId())
.equalsIgnoreCase(taskMainInfo.getTaskName()));

return Result.succeed(taskMainInfos);
}
Expand All @@ -154,9 +157,10 @@ public Result<List<TaskMainInfo>> getTaskMainInfos(@ApiParam(value = "dinky任
*/
@PostMapping("/task")
@ApiOperation(value = "创建任务定义", notes = "创建任务定义")
public Result<String> createTaskDefinition(@ApiParam(value = "前置任务编号 逗号隔开") @RequestParam(required = false) String upstreamCodes,
@ApiParam(value = "dinky任务id") @RequestParam Long dinkyTaskId,
@Valid @RequestBody TaskRequest taskRequest) {
public Result<String> createTaskDefinition(
@ApiParam(value = "前置任务编号 逗号隔开") @RequestParam(required = false) String upstreamCodes,
@ApiParam(value = "dinky任务id") @RequestParam Long dinkyTaskId,
@Valid @RequestBody TaskRequest taskRequest) {
DlinkTaskParams dlinkTaskParams = new DlinkTaskParams();
dlinkTaskParams.setTaskId(dinkyTaskId.toString());
dlinkTaskParams.setAddress(dolphinSchedulerProperties.getAddress());
Expand All @@ -165,7 +169,8 @@ public Result<String> createTaskDefinition(@ApiParam(value = "前置任务编号

Project dinkyProject = SystemInit.getProject();

Catalogue catalogue = catalogueService.getOne(new LambdaQueryWrapper<Catalogue>().eq(Catalogue::getTaskId, dinkyTaskId));
Catalogue catalogue = catalogueService
.getOne(new LambdaQueryWrapper<Catalogue>().eq(Catalogue::getTaskId, dinkyTaskId));
if (catalogue == null) {
return Result.failed("节点获取失败");
}
Expand Down Expand Up @@ -198,6 +203,9 @@ public Result<String> createTaskDefinition(@ApiParam(value = "前置任务编号
return Result.failed("添加失败,工作流定义[" + processName + "]已存在任务定义[" + taskName + "] 请刷新");
}

Long taskCode = taskClient.genTaskCode(projectCode);
taskRequest.setCode(taskCode);

String taskDefinitionJsonObj = JSONUtil.toJsonStr(taskRequest);
taskClient.createTaskDefinition(projectCode, processCode, upstreamCodes, taskDefinitionJsonObj);

Expand All @@ -212,10 +220,10 @@ public Result<String> createTaskDefinition(@ApiParam(value = "前置任务编号
@PutMapping("/task")
@ApiOperation(value = "更新任务定义", notes = "更新任务定义")
public Result<String> updateTaskDefinition(@ApiParam(value = "项目编号") @RequestParam long projectCode,
@ApiParam(value = "工作流定义编号") @RequestParam long processCode,
@ApiParam(value = "任务定义编号") @RequestParam long taskCode,
@ApiParam(value = "前置任务编号 逗号隔开") @RequestParam(required = false) String upstreamCodes,
@Valid @RequestBody TaskRequest taskRequest) {
@ApiParam(value = "工作流定义编号") @RequestParam long processCode,
@ApiParam(value = "任务定义编号") @RequestParam long taskCode,
@ApiParam(value = "前置任务编号 逗号隔开") @RequestParam(required = false) String upstreamCodes,
@Valid @RequestBody TaskRequest taskRequest) {

TaskDefinition taskDefinition = taskClient.getTaskDefinition(projectCode, taskCode);
if (taskDefinition == null) {
Expand Down

0 comments on commit fd63e81

Please sign in to comment.