From fd63e816d9974433721f4e5c0156703af61c4b62 Mon Sep 17 00:00:00 2001 From: aiwenmo <32723967+aiwenmo@users.noreply.github.com> Date: Sun, 16 Apr 2023 21:44:52 +0800 Subject: [PATCH] [Fix-1887] [admin] Fix DolphinScheduler can not generate task code in createTaskDefinition (#1888) Co-authored-by: wenmo <32723967+wenmo@users.noreply.github.com> --- .../dlink/controller/SchedulerController.java | 32 ++++++++++++------- 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/dlink-admin/src/main/java/com/dlink/controller/SchedulerController.java b/dlink-admin/src/main/java/com/dlink/controller/SchedulerController.java index 094ac9309c..033bd12fa2 100644 --- a/dlink-admin/src/main/java/com/dlink/controller/SchedulerController.java +++ b/dlink-admin/src/main/java/com/dlink/controller/SchedulerController.java @@ -92,7 +92,8 @@ public Result getTaskDefinition(@ApiParam(value = "dinky任务id TaskDefinition taskDefinition = null; Project dinkyProject = SystemInit.getProject(); - Catalogue catalogue = catalogueService.getOne(new LambdaQueryWrapper().eq(Catalogue::getTaskId, dinkyTaskId)); + Catalogue catalogue = catalogueService + .getOne(new LambdaQueryWrapper().eq(Catalogue::getTaskId, dinkyTaskId)); if (catalogue == null) { return Result.failed("节点获取失败"); } @@ -130,7 +131,8 @@ public Result> getTaskMainInfos(@ApiParam(value = "dinky任 Project dinkyProject = SystemInit.getProject(); - Catalogue catalogue = catalogueService.getOne(new LambdaQueryWrapper().eq(Catalogue::getTaskId, dinkyTaskId)); + Catalogue catalogue = catalogueService + .getOne(new LambdaQueryWrapper().eq(Catalogue::getTaskId, dinkyTaskId)); if (catalogue == null) { return Result.failed("节点获取失败"); } @@ -143,8 +145,9 @@ public Result> getTaskMainInfos(@ApiParam(value = "dinky任 long projectCode = dinkyProject.getCode(); List 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); } @@ -154,9 +157,10 @@ public Result> getTaskMainInfos(@ApiParam(value = "dinky任 */ @PostMapping("/task") @ApiOperation(value = "创建任务定义", notes = "创建任务定义") - public Result createTaskDefinition(@ApiParam(value = "前置任务编号 逗号隔开") @RequestParam(required = false) String upstreamCodes, - @ApiParam(value = "dinky任务id") @RequestParam Long dinkyTaskId, - @Valid @RequestBody TaskRequest taskRequest) { + public Result 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()); @@ -165,7 +169,8 @@ public Result createTaskDefinition(@ApiParam(value = "前置任务编号 Project dinkyProject = SystemInit.getProject(); - Catalogue catalogue = catalogueService.getOne(new LambdaQueryWrapper().eq(Catalogue::getTaskId, dinkyTaskId)); + Catalogue catalogue = catalogueService + .getOne(new LambdaQueryWrapper().eq(Catalogue::getTaskId, dinkyTaskId)); if (catalogue == null) { return Result.failed("节点获取失败"); } @@ -198,6 +203,9 @@ public Result 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); @@ -212,10 +220,10 @@ public Result createTaskDefinition(@ApiParam(value = "前置任务编号 @PutMapping("/task") @ApiOperation(value = "更新任务定义", notes = "更新任务定义") public Result 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) {