|
|
|
@ -14,22 +14,51 @@
|
|
|
|
|
* See the License for the specific language governing permissions and |
|
|
|
|
* limitations under the License. |
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
package org.apache.dolphinscheduler.api.service; |
|
|
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSONArray; |
|
|
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
|
|
import org.apache.dolphinscheduler.api.ApiApplicationServer; |
|
|
|
|
import org.apache.dolphinscheduler.api.dto.ProcessMeta; |
|
|
|
|
import org.apache.dolphinscheduler.api.enums.Status; |
|
|
|
|
import org.apache.dolphinscheduler.common.Constants; |
|
|
|
|
import org.apache.dolphinscheduler.common.enums.*; |
|
|
|
|
import org.apache.dolphinscheduler.common.enums.ExecutionStatus; |
|
|
|
|
import org.apache.dolphinscheduler.common.enums.FailureStrategy; |
|
|
|
|
import org.apache.dolphinscheduler.common.enums.Priority; |
|
|
|
|
import org.apache.dolphinscheduler.common.enums.ReleaseState; |
|
|
|
|
import org.apache.dolphinscheduler.common.enums.UserType; |
|
|
|
|
import org.apache.dolphinscheduler.common.enums.WarningType; |
|
|
|
|
import org.apache.dolphinscheduler.common.utils.DateUtils; |
|
|
|
|
import org.apache.dolphinscheduler.common.utils.FileUtils; |
|
|
|
|
import org.apache.dolphinscheduler.common.utils.JSONUtils; |
|
|
|
|
import org.apache.dolphinscheduler.dao.entity.*; |
|
|
|
|
import org.apache.dolphinscheduler.dao.mapper.*; |
|
|
|
|
import org.apache.dolphinscheduler.dao.entity.DataSource; |
|
|
|
|
import org.apache.dolphinscheduler.dao.entity.ProcessData; |
|
|
|
|
import org.apache.dolphinscheduler.dao.entity.ProcessDefinition; |
|
|
|
|
import org.apache.dolphinscheduler.dao.entity.ProcessInstance; |
|
|
|
|
import org.apache.dolphinscheduler.dao.entity.Project; |
|
|
|
|
import org.apache.dolphinscheduler.dao.entity.Schedule; |
|
|
|
|
import org.apache.dolphinscheduler.dao.entity.TaskInstance; |
|
|
|
|
import org.apache.dolphinscheduler.dao.entity.User; |
|
|
|
|
import org.apache.dolphinscheduler.dao.entity.WorkerGroup; |
|
|
|
|
import org.apache.dolphinscheduler.dao.mapper.DataSourceMapper; |
|
|
|
|
import org.apache.dolphinscheduler.dao.mapper.ProcessDefinitionMapper; |
|
|
|
|
import org.apache.dolphinscheduler.dao.mapper.ProcessInstanceMapper; |
|
|
|
|
import org.apache.dolphinscheduler.dao.mapper.ProjectMapper; |
|
|
|
|
import org.apache.dolphinscheduler.dao.mapper.ScheduleMapper; |
|
|
|
|
import org.apache.dolphinscheduler.dao.mapper.TaskInstanceMapper; |
|
|
|
|
import org.apache.dolphinscheduler.service.process.ProcessService; |
|
|
|
|
|
|
|
|
|
import org.apache.http.entity.ContentType; |
|
|
|
|
|
|
|
|
|
import java.io.File; |
|
|
|
|
import java.io.FileInputStream; |
|
|
|
|
import java.io.IOException; |
|
|
|
|
import java.text.MessageFormat; |
|
|
|
|
import java.util.ArrayList; |
|
|
|
|
import java.util.Date; |
|
|
|
|
import java.util.HashMap; |
|
|
|
|
import java.util.List; |
|
|
|
|
import java.util.Map; |
|
|
|
|
|
|
|
|
|
import org.json.JSONException; |
|
|
|
|
import org.junit.Assert; |
|
|
|
|
import org.junit.Test; |
|
|
|
@ -43,11 +72,8 @@ import org.springframework.boot.test.context.SpringBootTest;
|
|
|
|
|
import org.springframework.mock.web.MockMultipartFile; |
|
|
|
|
import org.springframework.web.multipart.MultipartFile; |
|
|
|
|
|
|
|
|
|
import java.io.File; |
|
|
|
|
import java.io.FileInputStream; |
|
|
|
|
import java.io.IOException; |
|
|
|
|
import java.text.MessageFormat; |
|
|
|
|
import java.util.*; |
|
|
|
|
import com.alibaba.fastjson.JSONArray; |
|
|
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
|
|
|
|
|
|
|
@RunWith(MockitoJUnitRunner.Silent.class) |
|
|
|
|
@SpringBootTest(classes = ApiApplicationServer.class) |
|
|
|
@ -82,28 +108,28 @@ public class ProcessDefinitionServiceTest {
|
|
|
|
|
@Mock |
|
|
|
|
private TaskInstanceMapper taskInstanceMapper; |
|
|
|
|
|
|
|
|
|
private String sqlDependentJson = "{\"globalParams\":[]," + |
|
|
|
|
"\"tasks\":[{\"type\":\"SQL\",\"id\":\"tasks-27297\",\"name\":\"sql\"," + |
|
|
|
|
"\"params\":{\"type\":\"MYSQL\",\"datasource\":1,\"sql\":\"select * from test\"," + |
|
|
|
|
"\"udfs\":\"\",\"sqlType\":\"1\",\"title\":\"\",\"receivers\":\"\",\"receiversCc\":\"\",\"showType\":\"TABLE\"" + |
|
|
|
|
",\"localParams\":[],\"connParams\":\"\"," + |
|
|
|
|
"\"preStatements\":[],\"postStatements\":[]}," + |
|
|
|
|
"\"description\":\"\",\"runFlag\":\"NORMAL\",\"dependence\":{},\"maxRetryTimes\":\"0\"," + |
|
|
|
|
"\"retryInterval\":\"1\",\"timeout\":{\"strategy\":\"\"," + |
|
|
|
|
"\"enable\":false},\"taskInstancePriority\":\"MEDIUM\",\"workerGroupId\":-1," + |
|
|
|
|
"\"preTasks\":[\"dependent\"]},{\"type\":\"DEPENDENT\",\"id\":\"tasks-33787\"," + |
|
|
|
|
"\"name\":\"dependent\",\"params\":{},\"description\":\"\",\"runFlag\":\"NORMAL\"," + |
|
|
|
|
"\"dependence\":{\"relation\":\"AND\",\"dependTaskList\":[{\"relation\":\"AND\"," + |
|
|
|
|
"\"dependItemList\":[{\"projectId\":2,\"definitionId\":46,\"depTasks\":\"ALL\"," + |
|
|
|
|
"\"cycle\":\"day\",\"dateValue\":\"today\"}]}]},\"maxRetryTimes\":\"0\",\"retryInterval\":\"1\"," + |
|
|
|
|
"\"timeout\":{\"strategy\":\"\",\"enable\":false},\"taskInstancePriority\":\"MEDIUM\"," + |
|
|
|
|
"\"workerGroupId\":-1,\"preTasks\":[]}],\"tenantId\":1,\"timeout\":0}"; |
|
|
|
|
|
|
|
|
|
private String shellJson = "{\"globalParams\":[],\"tasks\":[{\"type\":\"SHELL\",\"id\":\"tasks-9527\",\"name\":\"shell-1\"," + |
|
|
|
|
"\"params\":{\"resourceList\":[],\"localParams\":[],\"rawScript\":\"#!/bin/bash\\necho \\\"shell-1\\\"\"}," + |
|
|
|
|
"\"description\":\"\",\"runFlag\":\"NORMAL\",\"dependence\":{},\"maxRetryTimes\":\"0\",\"retryInterval\":\"1\"," + |
|
|
|
|
"\"timeout\":{\"strategy\":\"\",\"interval\":1,\"enable\":false},\"taskInstancePriority\":\"MEDIUM\"," + |
|
|
|
|
"\"workerGroupId\":-1,\"preTasks\":[]}],\"tenantId\":1,\"timeout\":0}"; |
|
|
|
|
private String sqlDependentJson = "{\"globalParams\":[]," |
|
|
|
|
+ "\"tasks\":[{\"type\":\"SQL\",\"id\":\"tasks-27297\",\"name\":\"sql\"," |
|
|
|
|
+ "\"params\":{\"type\":\"MYSQL\",\"datasource\":1,\"sql\":\"select * from test\"," |
|
|
|
|
+ "\"udfs\":\"\",\"sqlType\":\"1\",\"title\":\"\",\"receivers\":\"\",\"receiversCc\":\"\",\"showType\":\"TABLE\"" |
|
|
|
|
+ ",\"localParams\":[],\"connParams\":\"\"," |
|
|
|
|
+ "\"preStatements\":[],\"postStatements\":[]}," |
|
|
|
|
+ "\"description\":\"\",\"runFlag\":\"NORMAL\",\"dependence\":{},\"maxRetryTimes\":\"0\"," |
|
|
|
|
+ "\"retryInterval\":\"1\",\"timeout\":{\"strategy\":\"\"," |
|
|
|
|
+ "\"enable\":false},\"taskInstancePriority\":\"MEDIUM\",\"workerGroupId\":-1," |
|
|
|
|
+ "\"preTasks\":[\"dependent\"]},{\"type\":\"DEPENDENT\",\"id\":\"tasks-33787\"," |
|
|
|
|
+ "\"name\":\"dependent\",\"params\":{},\"description\":\"\",\"runFlag\":\"NORMAL\"," |
|
|
|
|
+ "\"dependence\":{\"relation\":\"AND\",\"dependTaskList\":[{\"relation\":\"AND\"," |
|
|
|
|
+ "\"dependItemList\":[{\"projectId\":2,\"definitionId\":46,\"depTasks\":\"ALL\"," |
|
|
|
|
+ "\"cycle\":\"day\",\"dateValue\":\"today\"}]}]},\"maxRetryTimes\":\"0\",\"retryInterval\":\"1\"," |
|
|
|
|
+ "\"timeout\":{\"strategy\":\"\",\"enable\":false},\"taskInstancePriority\":\"MEDIUM\"," |
|
|
|
|
+ "\"workerGroupId\":-1,\"preTasks\":[]}],\"tenantId\":1,\"timeout\":0}"; |
|
|
|
|
|
|
|
|
|
private String shellJson = "{\"globalParams\":[],\"tasks\":[{\"type\":\"SHELL\",\"id\":\"tasks-9527\",\"name\":\"shell-1\"," |
|
|
|
|
+ "\"params\":{\"resourceList\":[],\"localParams\":[],\"rawScript\":\"#!/bin/bash\\necho \\\"shell-1\\\"\"}," |
|
|
|
|
+ "\"description\":\"\",\"runFlag\":\"NORMAL\",\"dependence\":{},\"maxRetryTimes\":\"0\",\"retryInterval\":\"1\"," |
|
|
|
|
+ "\"timeout\":{\"strategy\":\"\",\"interval\":1,\"enable\":false},\"taskInstancePriority\":\"MEDIUM\"," |
|
|
|
|
+ "\"workerGroupId\":-1,\"preTasks\":[]}],\"tenantId\":1,\"timeout\":0}"; |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testQueryProcessDefinitionList() { |
|
|
|
@ -190,7 +216,7 @@ public class ProcessDefinitionServiceTest {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testCopyProcessDefinition() throws Exception{ |
|
|
|
|
public void testCopyProcessDefinition() throws Exception { |
|
|
|
|
String projectName = "project_test1"; |
|
|
|
|
Mockito.when(projectMapper.queryByName(projectName)).thenReturn(getProject(projectName)); |
|
|
|
|
|
|
|
|
@ -207,7 +233,11 @@ public class ProcessDefinitionServiceTest {
|
|
|
|
|
|
|
|
|
|
ProcessDefinition definition = getProcessDefinition(); |
|
|
|
|
definition.setLocations("{\"tasks-36196\":{\"name\":\"ssh_test1\",\"targetarr\":\"\",\"x\":141,\"y\":70}}"); |
|
|
|
|
definition.setProcessDefinitionJson("{\"globalParams\":[],\"tasks\":[{\"type\":\"SHELL\",\"id\":\"tasks-36196\",\"name\":\"ssh_test1\",\"params\":{\"resourceList\":[],\"localParams\":[],\"rawScript\":\"aa=\\\"1234\\\"\\necho ${aa}\"},\"desc\":\"\",\"runFlag\":\"NORMAL\",\"dependence\":{},\"maxRetryTimes\":\"0\",\"retryInterval\":\"1\",\"timeout\":{\"strategy\":\"\",\"interval\":null,\"enable\":false},\"taskInstancePriority\":\"MEDIUM\",\"workerGroupId\":-1,\"preTasks\":[]}],\"tenantId\":-1,\"timeout\":0}"); |
|
|
|
|
definition.setProcessDefinitionJson("{\"globalParams\":[]," |
|
|
|
|
+ "\"tasks\":[{\"type\":\"SHELL\",\"id\":\"tasks-36196\",\"name\":\"ssh_test1\"," |
|
|
|
|
+ "\"params\":{\"resourceList\":[],\"localParams\":[],\"rawScript\":\"aa=\\\"1234\\\"\\necho ${aa}\"},\"desc\":\"\",\"runFlag\":\"NORMAL\",\"dependence\":{}," |
|
|
|
|
+ "\"maxRetryTimes\":\"0\",\"retryInterval\":\"1\",\"timeout\":{\"strategy\":\"\",\"interval\":null,\"enable\":false}," |
|
|
|
|
+ "\"taskInstancePriority\":\"MEDIUM\",\"workerGroupId\":-1,\"preTasks\":[]}],\"tenantId\":-1,\"timeout\":0}"); |
|
|
|
|
definition.setConnects("[]"); |
|
|
|
|
//instance exit
|
|
|
|
|
Mockito.when(processDefineMapper.selectById(46)).thenReturn(definition); |
|
|
|
@ -341,16 +371,6 @@ public class ProcessDefinitionServiceTest {
|
|
|
|
|
46, 2); |
|
|
|
|
Assert.assertEquals(Status.REQUEST_PARAMS_NOT_VALID_ERROR, failRes.get(Constants.STATUS)); |
|
|
|
|
|
|
|
|
|
//FIXME has function exit code 1 when exception
|
|
|
|
|
//process definition offline
|
|
|
|
|
// List<Schedule> schedules = new ArrayList<>();
|
|
|
|
|
// Schedule schedule = getSchedule();
|
|
|
|
|
// schedules.add(schedule);
|
|
|
|
|
// Mockito.when(scheduleMapper.selectAllByProcessDefineArray(new int[]{46})).thenReturn(schedules);
|
|
|
|
|
// Mockito.when(scheduleMapper.updateById(schedule)).thenReturn(1);
|
|
|
|
|
// Map<String, Object> offlineRes = processDefinitionService.releaseProcessDefinition(loginUser, "project_test1",
|
|
|
|
|
// 46, ReleaseState.OFFLINE.getCode());
|
|
|
|
|
// Assert.assertEquals(Status.SUCCESS, offlineRes.get(Constants.STATUS));
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@ -382,7 +402,7 @@ public class ProcessDefinitionServiceTest {
|
|
|
|
|
Mockito.when(processDefineMapper.verifyByDefineName(project.getId(),"test_pdf")).thenReturn(getProcessDefinition()); |
|
|
|
|
Map<String, Object> processExistRes = processDefinitionService.verifyProcessDefinitionName(loginUser, |
|
|
|
|
"project_test1", "test_pdf"); |
|
|
|
|
Assert.assertEquals(Status.PROCESS_INSTANCE_EXIST, processExistRes.get(Constants.STATUS)); |
|
|
|
|
Assert.assertEquals(Status.VERIFY_PROCESS_DEFINITION_NAME_UNIQUE_ERROR, processExistRes.get(Constants.STATUS)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@ -575,7 +595,6 @@ public class ProcessDefinitionServiceTest {
|
|
|
|
|
processDefinitionName, processDefinitionId); |
|
|
|
|
Assert.assertEquals(0, workerNullFlag); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
@ -591,35 +610,34 @@ public class ProcessDefinitionServiceTest {
|
|
|
|
|
Project testProject = getProject("test"); |
|
|
|
|
|
|
|
|
|
//Recursive subprocess sub2 process in sub1 process and sub1process in top process
|
|
|
|
|
String topProcessJson = "{\"globalParams\":[]," + |
|
|
|
|
"\"tasks\":[{\"type\":\"SHELL\",\"id\":\"tasks-38634\",\"name\":\"shell1\"," + |
|
|
|
|
"\"params\":{\"resourceList\":[],\"localParams\":[],\"rawScript\":\"#!/bin/bash\\necho \\\"shell-1\\\"\"}," + |
|
|
|
|
"\"description\":\"\",\"runFlag\":\"NORMAL\",\"dependence\":{},\"maxRetryTimes\":\"0\"," + |
|
|
|
|
"\"retryInterval\":\"1\",\"timeout\":{\"strategy\":\"\",\"interval\":null,\"enable\":false}," + |
|
|
|
|
"\"taskInstancePriority\":\"MEDIUM\",\"workerGroupId\":-1,\"preTasks\":[]}," + |
|
|
|
|
"{\"type\":\"SUB_PROCESS\",\"id\":\"tasks-44207\",\"name\":\"shell-4\"," + |
|
|
|
|
"\"params\":{\"processDefinitionId\":39},\"description\":\"\",\"runFlag\":\"NORMAL\"," + |
|
|
|
|
"\"dependence\":{},\"timeout\":{\"strategy\":\"\",\"interval\":null,\"enable\":false}," + |
|
|
|
|
"\"taskInstancePriority\":\"MEDIUM\",\"workerGroupId\":-1," + |
|
|
|
|
"\"preTasks\":[\"shell1\"]}],\"tenantId\":1,\"timeout\":0}"; |
|
|
|
|
|
|
|
|
|
String sub1ProcessJson = "{\"globalParams\":[],\"tasks\":[{\"type\":\"SHELL\",\"id\":\"tasks-84090\"," + |
|
|
|
|
"\"name\":\"shell-4\",\"params\":{\"resourceList\":[],\"localParams\":[],\"rawScript\":\"#!/bin/bash\\necho \\\"shell-4\\\"\"}," + |
|
|
|
|
"\"description\":\"\",\"runFlag\":\"NORMAL\",\"dependence\":{},\"maxRetryTimes\":\"0\"," + |
|
|
|
|
"\"retryInterval\":\"1\",\"timeout\":{\"strategy\":\"\",\"interval\":null,\"enable\":false}," + |
|
|
|
|
"\"taskInstancePriority\":\"MEDIUM\",\"workerGroupId\":-1,\"preTasks\":[]},{\"type\":\"SUB_PROCESS\"," + |
|
|
|
|
"\"id\":\"tasks-87364\",\"name\":\"shell-5\"," + |
|
|
|
|
"\"params\":{\"processDefinitionId\":46},\"description\":\"\",\"runFlag\":\"NORMAL\",\"dependence\":{}," + |
|
|
|
|
"\"timeout\":{\"strategy\":\"\",\"interval\":null,\"enable\":false},\"taskInstancePriority\":\"MEDIUM\"," + |
|
|
|
|
"\"workerGroupId\":-1,\"preTasks\":[\"shell-4\"]}],\"tenantId\":1,\"timeout\":0}"; |
|
|
|
|
|
|
|
|
|
String sub2ProcessJson = "{\"globalParams\":[]," + |
|
|
|
|
"\"tasks\":[{\"type\":\"SHELL\",\"id\":\"tasks-52423\",\"name\":\"shell-5\"," + |
|
|
|
|
"\"params\":{\"resourceList\":[],\"localParams\":[],\"rawScript\":\"echo \\\"shell-5\\\"\"},\"description\":\"\"," + |
|
|
|
|
"\"runFlag\":\"NORMAL\",\"dependence\":{},\"maxRetryTimes\":\"0\",\"retryInterval\":\"1\"," + |
|
|
|
|
"\"timeout\":{\"strategy\":\"\",\"interval\":null,\"enable\":false},\"taskInstancePriority\":\"MEDIUM\",\"workerGroupId\":-1," + |
|
|
|
|
"\"preTasks\":[]}],\"tenantId\":1,\"timeout\":0}"; |
|
|
|
|
|
|
|
|
|
String topProcessJson = "{\"globalParams\":[]," |
|
|
|
|
+ "\"tasks\":[{\"type\":\"SHELL\",\"id\":\"tasks-38634\",\"name\":\"shell1\"," |
|
|
|
|
+ "\"params\":{\"resourceList\":[],\"localParams\":[],\"rawScript\":\"#!/bin/bash\\necho \\\"shell-1\\\"\"}," |
|
|
|
|
+ "\"description\":\"\",\"runFlag\":\"NORMAL\",\"dependence\":{},\"maxRetryTimes\":\"0\"," |
|
|
|
|
+ "\"retryInterval\":\"1\",\"timeout\":{\"strategy\":\"\",\"interval\":null,\"enable\":false}," |
|
|
|
|
+ "\"taskInstancePriority\":\"MEDIUM\",\"workerGroupId\":-1,\"preTasks\":[]}," |
|
|
|
|
+ "{\"type\":\"SUB_PROCESS\",\"id\":\"tasks-44207\",\"name\":\"shell-4\"," |
|
|
|
|
+ "\"params\":{\"processDefinitionId\":39},\"description\":\"\",\"runFlag\":\"NORMAL\"," |
|
|
|
|
+ "\"dependence\":{},\"timeout\":{\"strategy\":\"\",\"interval\":null,\"enable\":false}," |
|
|
|
|
+ "\"taskInstancePriority\":\"MEDIUM\",\"workerGroupId\":-1," |
|
|
|
|
+ "\"preTasks\":[\"shell1\"]}],\"tenantId\":1,\"timeout\":0}"; |
|
|
|
|
|
|
|
|
|
String sub1ProcessJson = "{\"globalParams\":[],\"tasks\":[{\"type\":\"SHELL\",\"id\":\"tasks-84090\"," |
|
|
|
|
+ "\"name\":\"shell-4\",\"params\":{\"resourceList\":[],\"localParams\":[],\"rawScript\":\"#!/bin/bash\\necho \\\"shell-4\\\"\"}," |
|
|
|
|
+ "\"description\":\"\",\"runFlag\":\"NORMAL\",\"dependence\":{},\"maxRetryTimes\":\"0\"," |
|
|
|
|
+ "\"retryInterval\":\"1\",\"timeout\":{\"strategy\":\"\",\"interval\":null,\"enable\":false}," |
|
|
|
|
+ "\"taskInstancePriority\":\"MEDIUM\",\"workerGroupId\":-1,\"preTasks\":[]},{\"type\":\"SUB_PROCESS\"," |
|
|
|
|
+ "\"id\":\"tasks-87364\",\"name\":\"shell-5\"," |
|
|
|
|
+ "\"params\":{\"processDefinitionId\":46},\"description\":\"\",\"runFlag\":\"NORMAL\",\"dependence\":{}," |
|
|
|
|
+ "\"timeout\":{\"strategy\":\"\",\"interval\":null,\"enable\":false},\"taskInstancePriority\":\"MEDIUM\"," |
|
|
|
|
+ "\"workerGroupId\":-1,\"preTasks\":[\"shell-4\"]}],\"tenantId\":1,\"timeout\":0}"; |
|
|
|
|
|
|
|
|
|
String sub2ProcessJson = "{\"globalParams\":[]," |
|
|
|
|
+ "\"tasks\":[{\"type\":\"SHELL\",\"id\":\"tasks-52423\",\"name\":\"shell-5\"," |
|
|
|
|
+ "\"params\":{\"resourceList\":[],\"localParams\":[],\"rawScript\":\"echo \\\"shell-5\\\"\"},\"description\":\"\"," |
|
|
|
|
+ "\"runFlag\":\"NORMAL\",\"dependence\":{},\"maxRetryTimes\":\"0\",\"retryInterval\":\"1\"," |
|
|
|
|
+ "\"timeout\":{\"strategy\":\"\",\"interval\":null,\"enable\":false},\"taskInstancePriority\":\"MEDIUM\",\"workerGroupId\":-1," |
|
|
|
|
+ "\"preTasks\":[]}],\"tenantId\":1,\"timeout\":0}"; |
|
|
|
|
|
|
|
|
|
JSONObject jsonObject = JSONUtils.parseObject(topProcessJson); |
|
|
|
|
JSONArray jsonArray = (JSONArray) jsonObject.get("tasks"); |
|
|
|
@ -657,29 +675,29 @@ public class ProcessDefinitionServiceTest {
|
|
|
|
|
@Test |
|
|
|
|
public void testImportProcessDefinitionById() throws IOException { |
|
|
|
|
|
|
|
|
|
String processJson = "[{\"projectName\":\"testProject\",\"processDefinitionName\":\"shell-4\"," + |
|
|
|
|
"\"processDefinitionJson\":\"{\\\"tenantId\\\":1,\\\"globalParams\\\":[]," + |
|
|
|
|
"\\\"tasks\\\":[{\\\"workerGroupId\\\":\\\"default\\\",\\\"description\\\":\\\"\\\",\\\"runFlag\\\":\\\"NORMAL\\\"," + |
|
|
|
|
"\\\"type\\\":\\\"SHELL\\\",\\\"params\\\":{\\\"rawScript\\\":\\\"#!/bin/bash\\\\necho \\\\\\\"shell-4\\\\\\\"\\\"," + |
|
|
|
|
"\\\"localParams\\\":[],\\\"resourceList\\\":[]},\\\"timeout\\\":{\\\"enable\\\":false,\\\"strategy\\\":\\\"\\\"}," + |
|
|
|
|
"\\\"maxRetryTimes\\\":\\\"0\\\",\\\"taskInstancePriority\\\":\\\"MEDIUM\\\",\\\"name\\\":\\\"shell-4\\\"," + |
|
|
|
|
"\\\"dependence\\\":{},\\\"retryInterval\\\":\\\"1\\\",\\\"preTasks\\\":[],\\\"id\\\":\\\"tasks-84090\\\"}," + |
|
|
|
|
"{\\\"taskInstancePriority\\\":\\\"MEDIUM\\\",\\\"name\\\":\\\"shell-5\\\",\\\"workerGroupId\\\":\\\"default\\\\," + |
|
|
|
|
"\\\"description\\\":\\\"\\\",\\\"dependence\\\":{},\\\"preTasks\\\":[\\\"shell-4\\\"],\\\"id\\\":\\\"tasks-87364\\\"," + |
|
|
|
|
"\\\"runFlag\\\":\\\"NORMAL\\\",\\\"type\\\":\\\"SUB_PROCESS\\\",\\\"params\\\":{\\\"processDefinitionId\\\":46}," + |
|
|
|
|
"\\\"timeout\\\":{\\\"enable\\\":false,\\\"strategy\\\":\\\"\\\"}}],\\\"timeout\\\":0}\"," + |
|
|
|
|
"\"processDefinitionDescription\":\"\",\"processDefinitionLocations\":\"{\\\"tasks-84090\\\":{\\\"name\\\":\\\"shell-4\\\"," + |
|
|
|
|
"\\\"targetarr\\\":\\\"\\\",\\\"x\\\":128,\\\"y\\\":114},\\\"tasks-87364\\\":{\\\"name\\\":\\\"shell-5\\\"," + |
|
|
|
|
"\\\"targetarr\\\":\\\"tasks-84090\\\",\\\"x\\\":266,\\\"y\\\":115}}\"," + |
|
|
|
|
"\"processDefinitionConnects\":\"[{\\\"endPointSourceId\\\":\\\"tasks-84090\\\"," + |
|
|
|
|
"\\\"endPointTargetId\\\":\\\"tasks-87364\\\"}]\"}]"; |
|
|
|
|
|
|
|
|
|
String subProcessJson = "{\"globalParams\":[]," + |
|
|
|
|
"\"tasks\":[{\"type\":\"SHELL\",\"id\":\"tasks-52423\",\"name\":\"shell-5\"," + |
|
|
|
|
"\"params\":{\"resourceList\":[],\"localParams\":[],\"rawScript\":\"echo \\\"shell-5\\\"\"},\"description\":\"\"," + |
|
|
|
|
"\"runFlag\":\"NORMAL\",\"dependence\":{},\"maxRetryTimes\":\"0\",\"retryInterval\":\"1\"," + |
|
|
|
|
"\"timeout\":{\"strategy\":\"\",\"interval\":null,\"enable\":false},\"taskInstancePriority\":\"MEDIUM\",\"workerGroupId\":\\\"default\\\\," + |
|
|
|
|
"\"preTasks\":[]}],\"tenantId\":1,\"timeout\":0}"; |
|
|
|
|
String processJson = "[{\"projectName\":\"testProject\",\"processDefinitionName\":\"shell-4\"," |
|
|
|
|
+ "\"processDefinitionJson\":\"{\\\"tenantId\\\":1,\\\"globalParams\\\":[]," |
|
|
|
|
+ "\\\"tasks\\\":[{\\\"workerGroupId\\\":\\\"default\\\",\\\"description\\\":\\\"\\\",\\\"runFlag\\\":\\\"NORMAL\\\"," |
|
|
|
|
+ "\\\"type\\\":\\\"SHELL\\\",\\\"params\\\":{\\\"rawScript\\\":\\\"#!/bin/bash\\\\necho \\\\\\\"shell-4\\\\\\\"\\\"," |
|
|
|
|
+ "\\\"localParams\\\":[],\\\"resourceList\\\":[]},\\\"timeout\\\":{\\\"enable\\\":false,\\\"strategy\\\":\\\"\\\"}," |
|
|
|
|
+ "\\\"maxRetryTimes\\\":\\\"0\\\",\\\"taskInstancePriority\\\":\\\"MEDIUM\\\",\\\"name\\\":\\\"shell-4\\\"," |
|
|
|
|
+ "\\\"dependence\\\":{},\\\"retryInterval\\\":\\\"1\\\",\\\"preTasks\\\":[],\\\"id\\\":\\\"tasks-84090\\\"}," |
|
|
|
|
+ "{\\\"taskInstancePriority\\\":\\\"MEDIUM\\\",\\\"name\\\":\\\"shell-5\\\",\\\"workerGroupId\\\":\\\"default\\\\," |
|
|
|
|
+ "\\\"description\\\":\\\"\\\",\\\"dependence\\\":{},\\\"preTasks\\\":[\\\"shell-4\\\"],\\\"id\\\":\\\"tasks-87364\\\"," |
|
|
|
|
+ "\\\"runFlag\\\":\\\"NORMAL\\\",\\\"type\\\":\\\"SUB_PROCESS\\\",\\\"params\\\":{\\\"processDefinitionId\\\":46}," |
|
|
|
|
+ "\\\"timeout\\\":{\\\"enable\\\":false,\\\"strategy\\\":\\\"\\\"}}],\\\"timeout\\\":0}\"," |
|
|
|
|
+ "\"processDefinitionDescription\":\"\",\"processDefinitionLocations\":\"{\\\"tasks-84090\\\":{\\\"name\\\":\\\"shell-4\\\"," |
|
|
|
|
+ "\\\"targetarr\\\":\\\"\\\",\\\"x\\\":128,\\\"y\\\":114},\\\"tasks-87364\\\":{\\\"name\\\":\\\"shell-5\\\"," |
|
|
|
|
+ "\\\"targetarr\\\":\\\"tasks-84090\\\",\\\"x\\\":266,\\\"y\\\":115}}\"," |
|
|
|
|
+ "\"processDefinitionConnects\":\"[{\\\"endPointSourceId\\\":\\\"tasks-84090\\\"," |
|
|
|
|
+ "\\\"endPointTargetId\\\":\\\"tasks-87364\\\"}]\"}]"; |
|
|
|
|
|
|
|
|
|
String subProcessJson = "{\"globalParams\":[]," |
|
|
|
|
+ "\"tasks\":[{\"type\":\"SHELL\",\"id\":\"tasks-52423\",\"name\":\"shell-5\"," |
|
|
|
|
+ "\"params\":{\"resourceList\":[],\"localParams\":[],\"rawScript\":\"echo \\\"shell-5\\\"\"},\"description\":\"\"," |
|
|
|
|
+ "\"runFlag\":\"NORMAL\",\"dependence\":{},\"maxRetryTimes\":\"0\",\"retryInterval\":\"1\"," |
|
|
|
|
+ "\"timeout\":{\"strategy\":\"\",\"interval\":null,\"enable\":false},\"taskInstancePriority\":\"MEDIUM\",\"workerGroupId\":\\\"default\\\\," |
|
|
|
|
+ "\"preTasks\":[]}],\"tenantId\":1,\"timeout\":0}"; |
|
|
|
|
|
|
|
|
|
FileUtils.writeStringToFile(new File("/tmp/task.json"),processJson); |
|
|
|
|
|
|
|
|
@ -708,28 +726,6 @@ public class ProcessDefinitionServiceTest {
|
|
|
|
|
Mockito.when(projectService.checkProjectAndAuth(loginUser, getProject(currentProjectName), currentProjectName)).thenReturn(result); |
|
|
|
|
Mockito.when(processDefineMapper.queryByDefineId(46)).thenReturn(shellDefinition2); |
|
|
|
|
|
|
|
|
|
//import process
|
|
|
|
|
// Map<String, Object> importProcessResult = processDefinitionService.importProcessDefinition(loginUser, multipartFile, currentProjectName);
|
|
|
|
|
//
|
|
|
|
|
// Assert.assertEquals(Status.SUCCESS, importProcessResult.get(Constants.STATUS));
|
|
|
|
|
//
|
|
|
|
|
// boolean delete = file.delete();
|
|
|
|
|
//
|
|
|
|
|
// Assert.assertTrue(delete);
|
|
|
|
|
|
|
|
|
|
// String processMetaJson = "";
|
|
|
|
|
// improssProcessCheckData(file, loginUser, currentProjectName, processMetaJson);
|
|
|
|
|
//
|
|
|
|
|
// processMetaJson = "{\"scheduleWorkerGroupId\":-1}";
|
|
|
|
|
// improssProcessCheckData(file, loginUser, currentProjectName, processMetaJson);
|
|
|
|
|
//
|
|
|
|
|
// processMetaJson = "{\"scheduleWorkerGroupId\":-1,\"projectName\":\"test\"}";
|
|
|
|
|
// improssProcessCheckData(file, loginUser, currentProjectName, processMetaJson);
|
|
|
|
|
//
|
|
|
|
|
// processMetaJson = "{\"scheduleWorkerGroupId\":-1,\"projectName\":\"test\",\"processDefinitionName\":\"test_definition\"}";
|
|
|
|
|
// improssProcessCheckData(file, loginUser, currentProjectName, processMetaJson);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
@ -786,7 +782,7 @@ public class ProcessDefinitionServiceTest {
|
|
|
|
|
* get mock datasource |
|
|
|
|
* @return DataSource |
|
|
|
|
*/ |
|
|
|
|
private DataSource getDataSource(){ |
|
|
|
|
private DataSource getDataSource() { |
|
|
|
|
DataSource dataSource = new DataSource(); |
|
|
|
|
dataSource.setId(2); |
|
|
|
|
dataSource.setName("test"); |
|
|
|
@ -797,7 +793,7 @@ public class ProcessDefinitionServiceTest {
|
|
|
|
|
* get mock processDefinition |
|
|
|
|
* @return ProcessDefinition |
|
|
|
|
*/ |
|
|
|
|
private ProcessDefinition getProcessDefinition(){ |
|
|
|
|
private ProcessDefinition getProcessDefinition() { |
|
|
|
|
|
|
|
|
|
ProcessDefinition processDefinition = new ProcessDefinition(); |
|
|
|
|
processDefinition.setId(46); |
|
|
|
@ -814,7 +810,7 @@ public class ProcessDefinitionServiceTest {
|
|
|
|
|
* @param projectName projectName |
|
|
|
|
* @return Project |
|
|
|
|
*/ |
|
|
|
|
private Project getProject(String projectName){ |
|
|
|
|
private Project getProject(String projectName) { |
|
|
|
|
Project project = new Project(); |
|
|
|
|
project.setId(1); |
|
|
|
|
project.setName(projectName); |
|
|
|
|