|
|
|
@ -56,12 +56,14 @@ 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.repository.ProcessTaskRelationLogDao; |
|
|
|
|
import org.apache.dolphinscheduler.plugin.task.api.TaskPluginManager; |
|
|
|
|
import org.apache.dolphinscheduler.service.process.ProcessService; |
|
|
|
|
import org.apache.dolphinscheduler.service.process.ProcessServiceImpl; |
|
|
|
|
|
|
|
|
|
import java.text.MessageFormat; |
|
|
|
|
import java.util.ArrayList; |
|
|
|
|
import java.util.Arrays; |
|
|
|
|
import java.util.Collections; |
|
|
|
|
import java.util.HashMap; |
|
|
|
|
import java.util.List; |
|
|
|
@ -124,11 +126,15 @@ public class TaskDefinitionServiceImplTest {
|
|
|
|
|
@Mock |
|
|
|
|
private ProcessDefinitionService processDefinitionService; |
|
|
|
|
|
|
|
|
|
@Mock |
|
|
|
|
private ProcessTaskRelationLogDao processTaskRelationLogDao; |
|
|
|
|
|
|
|
|
|
private static final String TASK_PARAMETER = |
|
|
|
|
"{\"resourceList\":[],\"localParams\":[],\"rawScript\":\"echo 1\",\"conditionResult\":{\"successNode\":[\"\"],\"failedNode\":[\"\"]},\"dependence\":{}}";; |
|
|
|
|
private static final long PROJECT_CODE = 1L; |
|
|
|
|
private static final long PROCESS_DEFINITION_CODE = 2L; |
|
|
|
|
private static final long TASK_CODE = 3L; |
|
|
|
|
private static final String UPSTREAM_CODE = "3,5"; |
|
|
|
|
private static final int VERSION = 1; |
|
|
|
|
private static final int RESOURCE_RATE = -1; |
|
|
|
|
protected User user; |
|
|
|
@ -169,14 +175,7 @@ public class TaskDefinitionServiceImplTest {
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void updateTaskDefinition() { |
|
|
|
|
String taskDefinitionJson = |
|
|
|
|
"{\"name\":\"detail_up\",\"description\":\"\",\"taskType\":\"SHELL\",\"taskParams\":" |
|
|
|
|
+ "\"{\\\"resourceList\\\":[],\\\"localParams\\\":[{\\\"prop\\\":\\\"datetime\\\",\\\"direct\\\":\\\"IN\\\"," |
|
|
|
|
+ "\\\"type\\\":\\\"VARCHAR\\\",\\\"value\\\":\\\"${system.datetime}\\\"}],\\\"rawScript\\\":" |
|
|
|
|
+ "\\\"echo ${datetime}\\\",\\\"conditionResult\\\":\\\"{\\\\\\\"successNode\\\\\\\":[\\\\\\\"\\\\\\\"]," |
|
|
|
|
+ "\\\\\\\"failedNode\\\\\\\":[\\\\\\\"\\\\\\\"]}\\\",\\\"dependence\\\":{}}\",\"flag\":0,\"taskPriority\":0," |
|
|
|
|
+ "\"workerGroup\":\"default\",\"failRetryTimes\":0,\"failRetryInterval\":0,\"timeoutFlag\":0," |
|
|
|
|
+ "\"timeoutNotifyStrategy\":0,\"timeout\":0,\"delayTime\":0,\"resourceIds\":\"\"}"; |
|
|
|
|
String taskDefinitionJson = getTaskDefinitionJson();; |
|
|
|
|
|
|
|
|
|
Project project = getProject(); |
|
|
|
|
Mockito.when(projectMapper.queryByCode(PROJECT_CODE)).thenReturn(project); |
|
|
|
@ -591,6 +590,52 @@ public class TaskDefinitionServiceImplTest {
|
|
|
|
|
Assertions.assertDoesNotThrow(() -> taskDefinitionService.getTaskDefinition(user, TASK_CODE)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testUpdateTaskWithUpstream() { |
|
|
|
|
|
|
|
|
|
String taskDefinitionJson = getTaskDefinitionJson(); |
|
|
|
|
TaskDefinition taskDefinition = getTaskDefinition(); |
|
|
|
|
taskDefinition.setFlag(Flag.NO); |
|
|
|
|
TaskDefinition taskDefinitionSecond = getTaskDefinition(); |
|
|
|
|
taskDefinitionSecond.setCode(5); |
|
|
|
|
|
|
|
|
|
user.setUserType(UserType.ADMIN_USER); |
|
|
|
|
Mockito.when(projectMapper.queryByCode(PROJECT_CODE)).thenReturn(getProject()); |
|
|
|
|
Mockito.when(projectService.hasProjectAndWritePerm(user, getProject(), new HashMap<>())).thenReturn(true); |
|
|
|
|
Mockito.when(taskDefinitionMapper.queryByCode(TASK_CODE)).thenReturn(taskDefinition); |
|
|
|
|
Mockito.when(taskPluginManager.checkTaskParameters(Mockito.any())).thenReturn(true); |
|
|
|
|
Mockito.when(taskDefinitionLogMapper.queryMaxVersionForDefinition(TASK_CODE)).thenReturn(1); |
|
|
|
|
Mockito.when(taskDefinitionMapper.updateById(Mockito.any())).thenReturn(1); |
|
|
|
|
Mockito.when(taskDefinitionLogMapper.insert(Mockito.any())).thenReturn(1); |
|
|
|
|
|
|
|
|
|
Mockito.when(taskDefinitionMapper.queryByCodeList(Mockito.anySet())) |
|
|
|
|
.thenReturn(Arrays.asList(taskDefinition, taskDefinitionSecond)); |
|
|
|
|
|
|
|
|
|
Mockito.when(processTaskRelationMapper.queryUpstreamByCode(PROJECT_CODE, TASK_CODE)) |
|
|
|
|
.thenReturn(getProcessTaskRelationListV2()); |
|
|
|
|
Mockito.when(processDefinitionMapper.queryByCode(PROCESS_DEFINITION_CODE)).thenReturn(getProcessDefinition()); |
|
|
|
|
Mockito.when(processTaskRelationMapper.batchInsert(Mockito.anyList())).thenReturn(1); |
|
|
|
|
Mockito.when(processTaskRelationMapper.updateById(Mockito.any())).thenReturn(1); |
|
|
|
|
Mockito.when(processTaskRelationLogDao.batchInsert(Mockito.anyList())).thenReturn(2); |
|
|
|
|
// success
|
|
|
|
|
Map<String, Object> successMap = taskDefinitionService.updateTaskWithUpstream(user, PROJECT_CODE, TASK_CODE, |
|
|
|
|
taskDefinitionJson, UPSTREAM_CODE); |
|
|
|
|
Assertions.assertEquals(Status.SUCCESS, successMap.get(Constants.STATUS)); |
|
|
|
|
user.setUserType(UserType.GENERAL_USER); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private String getTaskDefinitionJson() { |
|
|
|
|
return "{\"name\":\"detail_up\",\"description\":\"\",\"taskType\":\"SHELL\",\"taskParams\":" |
|
|
|
|
+ "\"{\\\"resourceList\\\":[],\\\"localParams\\\":[{\\\"prop\\\":\\\"datetime\\\"," |
|
|
|
|
+ "\\\"direct\\\":\\\"IN\\\",\\\"type\\\":\\\"VARCHAR\\\"," |
|
|
|
|
+ "\\\"value\\\":\\\"${system.datetime}\\\"}],\\\"rawScript\\\":\\\"echo ${datetime}\\\"," |
|
|
|
|
+ "\\\"conditionResult\\\":\\\"{\\\\\\\"successNode\\\\\\\":[\\\\\\\"\\\\\\\"]," |
|
|
|
|
+ "\\\\\\\"failedNode\\\\\\\":[\\\\\\\"\\\\\\\"]}\\\",\\\"dependence\\\":{}}\"," |
|
|
|
|
+ "\"flag\":0,\"taskPriority\":0,\"workerGroup\":\"default\",\"failRetryTimes\":0," |
|
|
|
|
+ "\"failRetryInterval\":0,\"timeoutFlag\":0,\"timeoutNotifyStrategy\":0,\"timeout\":0," |
|
|
|
|
+ "\"delayTime\":0,\"resourceIds\":\"\"}"; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* create admin user |
|
|
|
|
*/ |
|
|
|
@ -663,6 +708,27 @@ public class TaskDefinitionServiceImplTest {
|
|
|
|
|
return processTaskRelationList; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private List<ProcessTaskRelation> getProcessTaskRelationListV2() { |
|
|
|
|
List<ProcessTaskRelation> processTaskRelationList = new ArrayList<>(); |
|
|
|
|
|
|
|
|
|
ProcessTaskRelation processTaskRelation = new ProcessTaskRelation(); |
|
|
|
|
fillProcessTaskRelation(processTaskRelation); |
|
|
|
|
|
|
|
|
|
processTaskRelationList.add(processTaskRelation); |
|
|
|
|
processTaskRelation = new ProcessTaskRelation(); |
|
|
|
|
fillProcessTaskRelation(processTaskRelation); |
|
|
|
|
processTaskRelation.setPreTaskCode(4L); |
|
|
|
|
processTaskRelationList.add(processTaskRelation); |
|
|
|
|
return processTaskRelationList; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void fillProcessTaskRelation(ProcessTaskRelation processTaskRelation) { |
|
|
|
|
processTaskRelation.setProjectCode(PROJECT_CODE); |
|
|
|
|
processTaskRelation.setProcessDefinitionCode(PROCESS_DEFINITION_CODE); |
|
|
|
|
processTaskRelation.setPreTaskCode(TASK_CODE); |
|
|
|
|
processTaskRelation.setPostTaskCode(TASK_CODE + 1L); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private List<ProcessTaskRelationLog> getProcessTaskRelationLogList() { |
|
|
|
|
List<ProcessTaskRelationLog> processTaskRelationLogList = new ArrayList<>(); |
|
|
|
|
|
|
|
|
|