This is an automated email from the ASF dual-hosted git repository.
wenhemin pushed a commit to branch json_split_two
in repository https://gitbox.apache.org/repos/asf/dolphinscheduler.git
The following commit(s) were added to refs/heads/json_split_two by this push:
new 4e3bedd [Feature][JsonSplit-api]taskDefinition update interface
(#5869)
4e3bedd is described below
commit 4e3bedd2b9e2d448fda2d5c955dbc0ee9b794db6
Author: sky <[email protected]>
AuthorDate: Thu Jul 22 19:46:27 2021 +0800
[Feature][JsonSplit-api]taskDefinition update interface (#5869)
* create task definition api
create task definition api
create task definition api
* fix code smell
* use taskdefinitionlogs not taskdefinition
* fix code smell
* trigger GitHub actions
* fix unit test question
* fix unit test question
* fix unit test question
* task definition update api
* fix code smell
* fix code smell
* update taskdefinition api
* keep taskdefinition creator stable
---
.../api/controller/TaskDefinitionController.java | 10 +++---
.../service/impl/TaskDefinitionServiceImpl.java | 24 +++++++++++--
.../api/service/TaskDefinitionServiceImplTest.java | 42 +++++++++++++++++++++-
3 files changed, 67 insertions(+), 9 deletions(-)
diff --git
a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/TaskDefinitionController.java
b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/TaskDefinitionController.java
index 9a25cc2..a31da46 100644
---
a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/TaskDefinitionController.java
+++
b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/TaskDefinitionController.java
@@ -78,8 +78,8 @@ public class TaskDefinitionController extends BaseController {
*/
@ApiOperation(value = "save", notes = "CREATE_TASK_DEFINITION_NOTES")
@ApiImplicitParams({
- @ApiImplicitParam(name = "projectName", value = "PROJECT_NAME",
required = true, type = "String"),
- @ApiImplicitParam(name = "taskDefinitionJson", value =
"TASK_DEFINITION_JSON", required = true, type = "String")
+ @ApiImplicitParam(name = "projectCode", value = "PROJECT_CODE",
required = true, type = "Long"),
+ @ApiImplicitParam(name = "taskDefinitionJson", value =
"TASK_DEFINITION_JSON", required = true, type = "String")
})
@PostMapping(value = "/save")
@ResponseStatus(HttpStatus.CREATED)
@@ -103,9 +103,9 @@ public class TaskDefinitionController extends
BaseController {
*/
@ApiOperation(value = "update", notes = "UPDATE_TASK_DEFINITION_NOTES")
@ApiImplicitParams({
- @ApiImplicitParam(name = "projectName", value = "PROJECT_NAME",
required = true, type = "String"),
- @ApiImplicitParam(name = "code", value = "TASK_DEFINITION_CODE",
required = true, dataType = "Long", example = "1"),
- @ApiImplicitParam(name = "taskDefinitionJson", value =
"TASK_DEFINITION_JSON", required = true, type = "String")
+ @ApiImplicitParam(name = "projectCode", value = "PROJECT_CODE",
required = true, type = "Long"),
+ @ApiImplicitParam(name = "code", value = "TASK_DEFINITION_CODE",
required = true, dataType = "Long", example = "1"),
+ @ApiImplicitParam(name = "taskDefinitionJson", value =
"TASK_DEFINITION_JSON", required = true, type = "String")
})
@PostMapping(value = "/update")
@ResponseStatus(HttpStatus.OK)
diff --git
a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/TaskDefinitionServiceImpl.java
b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/TaskDefinitionServiceImpl.java
index 4b2a963..2f8ec20 100644
---
a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/TaskDefinitionServiceImpl.java
+++
b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/TaskDefinitionServiceImpl.java
@@ -231,13 +231,31 @@ public class TaskDefinitionServiceImpl extends
BaseServiceImpl implements TaskDe
putMsg(result, Status.TASK_DEFINE_NOT_EXIST, taskCode);
return result;
}
- TaskNode taskNode = JSONUtils.parseObject(taskDefinitionJson,
TaskNode.class);
- checkTaskNode(result, taskNode, taskDefinitionJson);
+ TaskDefinitionLog taskDefinitionToUpdate =
JSONUtils.parseObject(taskDefinitionJson, TaskDefinitionLog.class);
+ checkTaskDefinition(result, taskDefinitionToUpdate);
if (result.get(Constants.STATUS) == DATA_IS_NOT_VALID
|| result.get(Constants.STATUS) ==
Status.PROCESS_NODE_S_PARAMETER_INVALID) {
return result;
}
- int update = processService.updateTaskDefinition(loginUser,
project.getCode(), taskNode, taskDefinition);
+ Integer version =
taskDefinitionLogMapper.queryMaxVersionForDefinition(taskCode);
+ Date now = new Date();
+ taskDefinitionToUpdate.setCode(taskDefinition.getCode());
+ taskDefinitionToUpdate.setId(taskDefinition.getId());
+ taskDefinitionToUpdate.setProjectCode(projectCode);
+ taskDefinitionToUpdate.setUserId(taskDefinition.getUserId());
+ taskDefinitionToUpdate.setVersion(version == null || version == 0 ? 1
: version + 1);
+
taskDefinitionToUpdate.setTaskType(taskDefinitionToUpdate.getTaskType().toUpperCase());
+
taskDefinitionToUpdate.setResourceIds(processService.getResourceIds(taskDefinitionToUpdate));
+ taskDefinitionToUpdate.setUpdateTime(now);
+ int update = taskDefinitionMapper.updateById(taskDefinitionToUpdate);
+ taskDefinitionToUpdate.setOperator(loginUser.getId());
+ taskDefinitionToUpdate.setOperateTime(now);
+ taskDefinitionToUpdate.setCreateTime(now);
+ int insert = taskDefinitionLogMapper.insert(taskDefinitionToUpdate);
+ if ((update & insert) != 1) {
+ putMsg(result, Status.CREATE_TASK_DEFINITION_ERROR);
+ return result;
+ }
result.put(Constants.DATA_LIST, taskCode);
putMsg(result, Status.SUCCESS, update);
return result;
diff --git
a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/TaskDefinitionServiceImplTest.java
b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/TaskDefinitionServiceImplTest.java
index d58c509..9f51ab7 100644
---
a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/TaskDefinitionServiceImplTest.java
+++
b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/TaskDefinitionServiceImplTest.java
@@ -160,12 +160,52 @@ public class TaskDefinitionServiceImplTest {
Mockito.when(taskDefinitionLogMapper.batchInsert(Mockito.anyList())).thenReturn(1);
Map<String, Object> relation = taskDefinitionService
.createTaskDefinition(loginUser, projectCode,
createTaskDefinitionJson);
-
Assert.assertEquals(Status.SUCCESS, relation.get(Constants.STATUS));
}
@Test
+ public void updateTaskDefinition () {
+ String updateTaskDefinitionJson = "{\n"
+ + "\"name\": \"test12111\",\n"
+ + "\"description\": \"test\",\n"
+ + "\"taskType\": \"SHELL\",\n"
+ + "\"flag\": 0,\n"
+ + "\"taskParams\":
\"{\\\"resourceList\\\":[],\\\"localParams\\\":[],\\\"rawScript\\\":\\\"echo
11\\\",\\\"conditionResult\\\": "
+ +
"{\\\"successNode\\\":[\\\"\\\"],\\\"failedNode\\\":[\\\"\\\"]},\\\"dependence\\\":{}}\",\n"
+ + "\"taskPriority\": 0,\n"
+ + "\"workerGroup\": \"default\",\n"
+ + "\"failRetryTimes\": 0,\n"
+ + "\"failRetryInterval\": 1,\n"
+ + "\"timeoutFlag\": 1,\n"
+ + "\"timeoutNotifyStrategy\": 0,\n"
+ + "\"timeout\": 0,\n"
+ + "\"delayTime\": 0,\n"
+ + "\"resourceIds\": \"\"\n"
+ + "}";
+ long projectCode = 1L;
+ long taskCode = 1L;
+
+ Project project = getProject(projectCode);
+
Mockito.when(projectMapper.queryByCode(projectCode)).thenReturn(project);
+
+ User loginUser = new User();
+ loginUser.setId(-1);
+ loginUser.setUserType(UserType.GENERAL_USER);
+
+ Map<String, Object> result = new HashMap<>();
+ putMsg(result, Status.SUCCESS, projectCode);
+ Mockito.when(projectService.checkProjectAndAuth(loginUser, project,
project.getName())).thenReturn(result);
+
+
Mockito.when(processService.isTaskOnline(taskCode)).thenReturn(Boolean.FALSE);
+
Mockito.when(taskDefinitionMapper.queryByDefinitionCode(taskCode)).thenReturn(new
TaskDefinition());
+
Mockito.when(taskDefinitionMapper.updateById(Mockito.any(TaskDefinitionLog.class))).thenReturn(1);
+
Mockito.when(taskDefinitionLogMapper.insert(Mockito.any(TaskDefinitionLog.class))).thenReturn(1);
+ result = taskDefinitionService.updateTaskDefinition(loginUser,
projectCode, taskCode, updateTaskDefinitionJson);
+ Assert.assertEquals(Status.SUCCESS, result.get(Constants.STATUS));
+ }
+
+ @Test
public void queryTaskDefinitionByName() {
String taskName = "task";
long projectCode = 1L;