|
|
|
@ -23,6 +23,7 @@ import org.apache.dolphinscheduler.api.service.impl.TaskDefinitionServiceImpl;
|
|
|
|
|
import org.apache.dolphinscheduler.common.Constants; |
|
|
|
|
import org.apache.dolphinscheduler.common.enums.UserType; |
|
|
|
|
import org.apache.dolphinscheduler.common.model.TaskNode; |
|
|
|
|
import org.apache.dolphinscheduler.common.task.shell.ShellParameters; |
|
|
|
|
import org.apache.dolphinscheduler.common.utils.JSONUtils; |
|
|
|
|
import org.apache.dolphinscheduler.dao.entity.Project; |
|
|
|
|
import org.apache.dolphinscheduler.dao.entity.TaskDefinition; |
|
|
|
@ -132,29 +133,13 @@ public class TaskDefinitionServiceImplTest {
|
|
|
|
|
putMsg(result, Status.SUCCESS, projectCode); |
|
|
|
|
Mockito.when(projectService.checkProjectAndAuth(loginUser, project, projectCode)).thenReturn(result); |
|
|
|
|
|
|
|
|
|
String createTaskDefinitionJson = "[{\n" |
|
|
|
|
+ "\"name\": \"test12111\",\n" |
|
|
|
|
+ "\"description\": \"test\",\n" |
|
|
|
|
+ "\"taskType\": \"SHELL\",\n" |
|
|
|
|
+ "\"flag\": 0,\n" |
|
|
|
|
+ "\"taskParams\": \n" |
|
|
|
|
+ "\"{\\\"resourceList\\\":[],\n" |
|
|
|
|
+ "\\\"localParams\\\":[],\n" |
|
|
|
|
+ "\\\"rawScript\\\":\\\"echo 11\\\",\n" |
|
|
|
|
+ "\\\"conditionResult\\\":\n" |
|
|
|
|
+ "{\\\"successNode\\\":[\\\"\\\"],\n" |
|
|
|
|
+ "\\\"failedNode\\\":[\\\"\\\"]},\n" |
|
|
|
|
+ "\\\"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" |
|
|
|
|
+ "}] "; |
|
|
|
|
String createTaskDefinitionJson = "[{\"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\":\"\"}]"; |
|
|
|
|
List<TaskDefinition> taskDefinitions = JSONUtils.toList(createTaskDefinitionJson, TaskDefinition.class); |
|
|
|
|
Mockito.when(taskDefinitionMapper.batchInsert(Mockito.anyList())).thenReturn(1); |
|
|
|
|
Mockito.when(taskDefinitionLogMapper.batchInsert(Mockito.anyList())).thenReturn(1); |
|
|
|
@ -314,4 +299,30 @@ public class TaskDefinitionServiceImplTest {
|
|
|
|
|
return project; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
@Test |
|
|
|
|
public void checkJson() { |
|
|
|
|
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\":\"\"}]"; |
|
|
|
|
List<TaskDefinitionLog> taskDefinitionLogs = JSONUtils.toList(taskDefinitionJson, TaskDefinitionLog.class); |
|
|
|
|
Assert.assertFalse(taskDefinitionLogs.isEmpty()); |
|
|
|
|
String taskParams = "{\"resourceList\":[],\"localParams\":[{\"prop\":\"datetime\",\"direct\":\"IN\",\"type\":\"VARCHAR\"," |
|
|
|
|
+ "\"value\":\"${system.datetime}\"}],\"rawScript\":\"echo ${datetime}\",\"conditionResult\":\"{\\\"successNode\\\":[\\\"\\\"]," |
|
|
|
|
+ "\\\"failedNode\\\":[\\\"\\\"]}\",\"dependence\":{}}"; |
|
|
|
|
ShellParameters parameters = JSONUtils.parseObject(taskParams, ShellParameters.class); |
|
|
|
|
Assert.assertNotNull(parameters); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void genTaskCodeList() { |
|
|
|
|
User loginUser = new User(); |
|
|
|
|
loginUser.setId(-1); |
|
|
|
|
loginUser.setUserType(UserType.GENERAL_USER); |
|
|
|
|
Map<String, Object> genTaskCodeList = taskDefinitionService.genTaskCodeList(loginUser, 10); |
|
|
|
|
Assert.assertEquals(Status.SUCCESS, genTaskCodeList.get(Constants.STATUS)); |
|
|
|
|
} |
|
|
|
|
} |