mirror of
https://gitee.com/dolphinscheduler/DolphinScheduler.git
synced 2024-12-04 05:09:48 +08:00
[FIX-3836][1.3.3-release-API] process definition validation name interface prompt information error (#3899)
* fix bug : error message * fix code smell * fix code smell
This commit is contained in:
parent
301d728c7b
commit
e740dc7645
@ -14,14 +14,11 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.apache.dolphinscheduler.api.service;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import static org.apache.dolphinscheduler.common.Constants.CMDPARAM_SUB_PROCESS_DEFINE_ID;
|
||||
|
||||
import org.apache.dolphinscheduler.api.dto.ProcessMeta;
|
||||
import org.apache.dolphinscheduler.api.dto.treeview.Instance;
|
||||
import org.apache.dolphinscheduler.api.dto.treeview.TreeViewDto;
|
||||
@ -32,7 +29,14 @@ import org.apache.dolphinscheduler.api.utils.PageInfo;
|
||||
import org.apache.dolphinscheduler.api.utils.exportprocess.ProcessAddTaskParam;
|
||||
import org.apache.dolphinscheduler.api.utils.exportprocess.TaskNodeParamFactory;
|
||||
import org.apache.dolphinscheduler.common.Constants;
|
||||
import org.apache.dolphinscheduler.common.enums.*;
|
||||
import org.apache.dolphinscheduler.common.enums.AuthorizationType;
|
||||
import org.apache.dolphinscheduler.common.enums.FailureStrategy;
|
||||
import org.apache.dolphinscheduler.common.enums.Flag;
|
||||
import org.apache.dolphinscheduler.common.enums.Priority;
|
||||
import org.apache.dolphinscheduler.common.enums.ReleaseState;
|
||||
import org.apache.dolphinscheduler.common.enums.TaskType;
|
||||
import org.apache.dolphinscheduler.common.enums.UserType;
|
||||
import org.apache.dolphinscheduler.common.enums.WarningType;
|
||||
import org.apache.dolphinscheduler.common.graph.DAG;
|
||||
import org.apache.dolphinscheduler.common.model.TaskNode;
|
||||
import org.apache.dolphinscheduler.common.model.TaskNodeRelation;
|
||||
@ -41,12 +45,46 @@ import org.apache.dolphinscheduler.common.process.Property;
|
||||
import org.apache.dolphinscheduler.common.process.ResourceInfo;
|
||||
import org.apache.dolphinscheduler.common.task.AbstractParameters;
|
||||
import org.apache.dolphinscheduler.common.thread.Stopper;
|
||||
import org.apache.dolphinscheduler.common.utils.*;
|
||||
import org.apache.dolphinscheduler.dao.entity.*;
|
||||
import org.apache.dolphinscheduler.dao.mapper.*;
|
||||
import org.apache.dolphinscheduler.common.utils.CollectionUtils;
|
||||
import org.apache.dolphinscheduler.common.utils.DateUtils;
|
||||
import org.apache.dolphinscheduler.common.utils.JSONUtils;
|
||||
import org.apache.dolphinscheduler.common.utils.StringUtils;
|
||||
import org.apache.dolphinscheduler.common.utils.TaskParametersUtils;
|
||||
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.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.dao.utils.DagHelper;
|
||||
import org.apache.dolphinscheduler.service.permission.PermissionCheck;
|
||||
import org.apache.dolphinscheduler.service.process.ProcessService;
|
||||
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.servlet.ServletOutputStream;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@ -55,16 +93,12 @@ import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.servlet.ServletOutputStream;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static org.apache.dolphinscheduler.common.Constants.CMDPARAM_SUB_PROCESS_DEFINE_ID;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
|
||||
/**
|
||||
* process definition service
|
||||
@ -74,6 +108,7 @@ public class ProcessDefinitionService extends BaseDAGService {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(ProcessDefinitionService.class);
|
||||
|
||||
private static final String PROCESSDEFINITIONID = "processDefinitionId";
|
||||
|
||||
@Autowired
|
||||
private ProjectMapper projectMapper;
|
||||
@ -161,7 +196,7 @@ public class ProcessDefinitionService extends BaseDAGService {
|
||||
processDefine.setFlag(Flag.YES);
|
||||
processDefineMapper.insert(processDefine);
|
||||
putMsg(result, Status.SUCCESS);
|
||||
result.put("processDefinitionId",processDefine.getId());
|
||||
result.put(PROCESSDEFINITIONID,processDefine.getId());
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -173,17 +208,17 @@ public class ProcessDefinitionService extends BaseDAGService {
|
||||
private String getResourceIds(ProcessData processData) {
|
||||
List<TaskNode> tasks = processData.getTasks();
|
||||
Set<Integer> resourceIds = new HashSet<>();
|
||||
for(TaskNode taskNode : tasks){
|
||||
for (TaskNode taskNode : tasks) {
|
||||
String taskParameter = taskNode.getParams();
|
||||
AbstractParameters params = TaskParametersUtils.getParameters(taskNode.getType(),taskParameter);
|
||||
AbstractParameters params = TaskParametersUtils.getParameters(taskNode.getType(), taskParameter);
|
||||
if (CollectionUtils.isNotEmpty(params.getResourceFilesList())) {
|
||||
Set<Integer> tempSet = params.getResourceFilesList().stream().filter(t->t.getId()!=0).map(ResourceInfo::getId).collect(Collectors.toSet());
|
||||
Set<Integer> tempSet = params.getResourceFilesList().stream().filter(t -> t.getId() != 0).map(ResourceInfo::getId).collect(Collectors.toSet());
|
||||
resourceIds.addAll(tempSet);
|
||||
}
|
||||
}
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for(int i : resourceIds) {
|
||||
for (int i : resourceIds) {
|
||||
if (sb.length() > 0) {
|
||||
sb.append(",");
|
||||
}
|
||||
@ -192,7 +227,6 @@ public class ProcessDefinitionService extends BaseDAGService {
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* query process definition list
|
||||
*
|
||||
@ -218,7 +252,6 @@ public class ProcessDefinitionService extends BaseDAGService {
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* query process definition list paging
|
||||
*
|
||||
@ -264,7 +297,6 @@ public class ProcessDefinitionService extends BaseDAGService {
|
||||
*/
|
||||
public Map<String, Object> queryProcessDefinitionById(User loginUser, String projectName, Integer processId) {
|
||||
|
||||
|
||||
Map<String, Object> result = new HashMap<>(5);
|
||||
Project project = projectMapper.queryByName(projectName);
|
||||
|
||||
@ -292,7 +324,7 @@ public class ProcessDefinitionService extends BaseDAGService {
|
||||
* @param processId process definition id
|
||||
* @return copy result code
|
||||
*/
|
||||
public Map<String, Object> copyProcessDefinition(User loginUser, String projectName, Integer processId) throws JsonProcessingException{
|
||||
public Map<String, Object> copyProcessDefinition(User loginUser, String projectName, Integer processId) throws JsonProcessingException {
|
||||
|
||||
Map<String, Object> result = new HashMap<>(5);
|
||||
Project project = projectMapper.queryByName(projectName);
|
||||
@ -311,7 +343,7 @@ public class ProcessDefinitionService extends BaseDAGService {
|
||||
return createProcessDefinition(
|
||||
loginUser,
|
||||
projectName,
|
||||
processDefinition.getName()+"_copy_"+System.currentTimeMillis(),
|
||||
processDefinition.getName() + "_copy_" + System.currentTimeMillis(),
|
||||
processDefinition.getProcessDefinitionJson(),
|
||||
processDefinition.getDescription(),
|
||||
processDefinition.getLocations(),
|
||||
@ -417,7 +449,7 @@ public class ProcessDefinitionService extends BaseDAGService {
|
||||
if (processDefinition == null) {
|
||||
putMsg(result, Status.SUCCESS);
|
||||
} else {
|
||||
putMsg(result, Status.PROCESS_INSTANCE_EXIST, name);
|
||||
putMsg(result, Status.VERIFY_PROCESS_DEFINITION_NAME_UNIQUE_ERROR, name);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@ -464,15 +496,15 @@ public class ProcessDefinitionService extends BaseDAGService {
|
||||
// get the timing according to the process definition
|
||||
List<Schedule> schedules = scheduleMapper.queryByProcessDefinitionId(processDefinitionId);
|
||||
if (!schedules.isEmpty() && schedules.size() > 1) {
|
||||
logger.warn("scheduler num is {},Greater than 1",schedules.size());
|
||||
logger.warn("scheduler num is {},Greater than 1", schedules.size());
|
||||
putMsg(result, Status.DELETE_PROCESS_DEFINE_BY_ID_ERROR);
|
||||
return result;
|
||||
}else if(schedules.size() == 1){
|
||||
} else if (schedules.size() == 1) {
|
||||
Schedule schedule = schedules.get(0);
|
||||
if(schedule.getReleaseState() == ReleaseState.OFFLINE){
|
||||
if (schedule.getReleaseState() == ReleaseState.OFFLINE) {
|
||||
scheduleMapper.deleteById(schedule.getId());
|
||||
}else if(schedule.getReleaseState() == ReleaseState.ONLINE){
|
||||
putMsg(result, Status.SCHEDULE_CRON_STATE_ONLINE,schedule.getId());
|
||||
} else if (schedule.getReleaseState() == ReleaseState.ONLINE) {
|
||||
putMsg(result, Status.SCHEDULE_CRON_STATE_ONLINE, schedule.getId());
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@ -543,7 +575,7 @@ public class ProcessDefinitionService extends BaseDAGService {
|
||||
new int[]{processDefinition.getId()}
|
||||
);
|
||||
|
||||
for(Schedule schedule:scheduleList){
|
||||
for (Schedule schedule:scheduleList) {
|
||||
logger.info("set schedule offline, project id: {}, schedule id: {}, process definition id: {}", project.getId(), schedule.getId(), id);
|
||||
// set status
|
||||
schedule.setReleaseState(ReleaseState.OFFLINE);
|
||||
@ -567,9 +599,9 @@ public class ProcessDefinitionService extends BaseDAGService {
|
||||
* @param processDefinitionIds
|
||||
* @param response
|
||||
*/
|
||||
public void batchExportProcessDefinitionByIds(User loginUser, String projectName, String processDefinitionIds, HttpServletResponse response){
|
||||
public void batchExportProcessDefinitionByIds(User loginUser, String projectName, String processDefinitionIds, HttpServletResponse response) {
|
||||
|
||||
if(StringUtils.isEmpty(processDefinitionIds)){
|
||||
if (StringUtils.isEmpty(processDefinitionIds)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -580,14 +612,14 @@ public class ProcessDefinitionService extends BaseDAGService {
|
||||
Map<String, Object> checkResult = projectService.checkProjectAndAuth(loginUser, project, projectName);
|
||||
Status resultStatus = (Status) checkResult.get(Constants.STATUS);
|
||||
|
||||
if(resultStatus != Status.SUCCESS){
|
||||
if (resultStatus != Status.SUCCESS) {
|
||||
return;
|
||||
}
|
||||
|
||||
List<ProcessMeta> processDefinitionList =
|
||||
getProcessDefinitionList(processDefinitionIds);
|
||||
|
||||
if(CollectionUtils.isNotEmpty(processDefinitionList)){
|
||||
if (CollectionUtils.isNotEmpty(processDefinitionList)) {
|
||||
downloadProcessDefinitionFile(response, processDefinitionList);
|
||||
}
|
||||
}
|
||||
@ -597,7 +629,7 @@ public class ProcessDefinitionService extends BaseDAGService {
|
||||
* @param processDefinitionIds
|
||||
* @return
|
||||
*/
|
||||
private List<ProcessMeta> getProcessDefinitionList(String processDefinitionIds){
|
||||
private List<ProcessMeta> getProcessDefinitionList(String processDefinitionIds) {
|
||||
List<ProcessMeta> processDefinitionList = new ArrayList<>();
|
||||
String[] processDefinitionIdArray = processDefinitionIds.split(",");
|
||||
for (String strProcessDefinitionId : processDefinitionIdArray) {
|
||||
@ -629,7 +661,7 @@ public class ProcessDefinitionService extends BaseDAGService {
|
||||
buff.close();
|
||||
} catch (IOException e) {
|
||||
logger.warn("export process fail", e);
|
||||
}finally {
|
||||
} finally {
|
||||
if (null != buff) {
|
||||
try {
|
||||
buff.close();
|
||||
@ -747,9 +779,9 @@ public class ProcessDefinitionService extends BaseDAGService {
|
||||
return result;
|
||||
}
|
||||
|
||||
for(ProcessMeta processMeta:processMetaList){
|
||||
for (ProcessMeta processMeta:processMetaList) {
|
||||
|
||||
if (!checkAndImportProcessDefinition(loginUser, currentProjectName, result, processMeta)){
|
||||
if (!checkAndImportProcessDefinition(loginUser, currentProjectName, result, processMeta)) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@ -767,7 +799,7 @@ public class ProcessDefinitionService extends BaseDAGService {
|
||||
*/
|
||||
private boolean checkAndImportProcessDefinition(User loginUser, String currentProjectName, Map<String, Object> result, ProcessMeta processMeta) {
|
||||
|
||||
if(!checkImportanceParams(processMeta,result)){
|
||||
if (!checkImportanceParams(processMeta,result)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -775,7 +807,7 @@ public class ProcessDefinitionService extends BaseDAGService {
|
||||
String processDefinitionName = processMeta.getProcessDefinitionName();
|
||||
//use currentProjectName to query
|
||||
Project targetProject = projectMapper.queryByName(currentProjectName);
|
||||
if(null != targetProject){
|
||||
if (null != targetProject) {
|
||||
processDefinitionName = recursionProcessDefinitionName(targetProject.getId(),
|
||||
processDefinitionName, 1);
|
||||
}
|
||||
@ -799,14 +831,13 @@ public class ProcessDefinitionService extends BaseDAGService {
|
||||
processDefinitionName,
|
||||
addImportTaskNodeParam(loginUser, processMeta.getProcessDefinitionJson(), targetProject));
|
||||
|
||||
if(createProcessResult == null){
|
||||
if (createProcessResult == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
//create process definition
|
||||
Integer processDefinitionId =
|
||||
Objects.isNull(createProcessResult.get("processDefinitionId"))?
|
||||
null:Integer.parseInt(createProcessResult.get("processDefinitionId").toString());
|
||||
Objects.isNull(createProcessResult.get(PROCESSDEFINITIONID)) ? null : Integer.parseInt(createProcessResult.get(PROCESSDEFINITIONID).toString());
|
||||
|
||||
//scheduler param
|
||||
return getImportProcessScheduleResult(loginUser,
|
||||
@ -833,12 +864,12 @@ public class ProcessDefinitionService extends BaseDAGService {
|
||||
Map<String, Object> result,
|
||||
ProcessMeta processMeta,
|
||||
String processDefinitionName,
|
||||
String importProcessParam){
|
||||
String importProcessParam) {
|
||||
Map<String, Object> createProcessResult = null;
|
||||
try {
|
||||
createProcessResult = createProcessDefinition(loginUser
|
||||
,currentProjectName,
|
||||
processDefinitionName+"_import_"+System.currentTimeMillis(),
|
||||
processDefinitionName + "_import_" + System.currentTimeMillis(),
|
||||
importProcessParam,
|
||||
processMeta.getProcessDefinitionDescription(),
|
||||
processMeta.getProcessDefinitionLocations(),
|
||||
@ -889,7 +920,7 @@ public class ProcessDefinitionService extends BaseDAGService {
|
||||
* @param result
|
||||
* @return
|
||||
*/
|
||||
private boolean checkImportanceParams(ProcessMeta processMeta,Map<String, Object> result){
|
||||
private boolean checkImportanceParams(ProcessMeta processMeta,Map<String, Object> result) {
|
||||
if (StringUtils.isEmpty(processMeta.getProjectName())) {
|
||||
putMsg(result, Status.DATA_IS_NULL, "projectName");
|
||||
return false;
|
||||
@ -1009,7 +1040,7 @@ public class ProcessDefinitionService extends BaseDAGService {
|
||||
if (checkTaskHasSubProcess(taskType)) {
|
||||
//get sub process info
|
||||
JSONObject subParams = JSONUtils.parseObject(taskNode.getString("params"));
|
||||
Integer subProcessId = subParams.getInteger("processDefinitionId");
|
||||
Integer subProcessId = subParams.getInteger(PROCESSDEFINITIONID);
|
||||
ProcessDefinition subProcess = processDefineMapper.queryByDefineId(subProcessId);
|
||||
//check is sub process exist in db
|
||||
if (null != subProcess) {
|
||||
@ -1069,7 +1100,7 @@ public class ProcessDefinitionService extends BaseDAGService {
|
||||
|
||||
if (null != newSubProcessDefine) {
|
||||
subProcessIdMap.put(subProcessId, newSubProcessDefine.getId());
|
||||
subParams.put("processDefinitionId", newSubProcessDefine.getId());
|
||||
subParams.put(PROCESSDEFINITIONID, newSubProcessDefine.getId());
|
||||
taskNode.put("params", subParams);
|
||||
}
|
||||
}
|
||||
@ -1078,7 +1109,6 @@ public class ProcessDefinitionService extends BaseDAGService {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* check the process definition node meets the specifications
|
||||
*
|
||||
@ -1148,7 +1178,6 @@ public class ProcessDefinitionService extends BaseDAGService {
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
String processDefinitionJson = processDefinition.getProcessDefinitionJson();
|
||||
|
||||
ProcessData processData = JSONUtils.parseObject(processDefinitionJson, ProcessData.class);
|
||||
@ -1182,7 +1211,7 @@ public class ProcessDefinitionService extends BaseDAGService {
|
||||
Map<Integer, List<TaskNode>> taskNodeMap = new HashMap<>();
|
||||
String[] idList = defineIdList.split(",");
|
||||
List<Integer> idIntList = new ArrayList<>();
|
||||
for(String definitionId : idList) {
|
||||
for (String definitionId : idList) {
|
||||
idIntList.add(Integer.parseInt(definitionId));
|
||||
}
|
||||
Integer[] idArray = idIntList.toArray(new Integer[idIntList.size()]);
|
||||
@ -1193,7 +1222,7 @@ public class ProcessDefinitionService extends BaseDAGService {
|
||||
return result;
|
||||
}
|
||||
|
||||
for(ProcessDefinition processDefinition : processDefinitionList){
|
||||
for (ProcessDefinition processDefinition : processDefinitionList) {
|
||||
String processDefinitionJson = processDefinition.getProcessDefinitionJson();
|
||||
ProcessData processData = JSONUtils.parseObject(processDefinitionJson, ProcessData.class);
|
||||
List<TaskNode> taskNodeList = (processData.getTasks() == null) ? new ArrayList<>() : processData.getTasks();
|
||||
@ -1207,7 +1236,6 @@ public class ProcessDefinitionService extends BaseDAGService {
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* query process definition all by project id
|
||||
*
|
||||
@ -1258,7 +1286,7 @@ public class ProcessDefinitionService extends BaseDAGService {
|
||||
*/
|
||||
List<ProcessInstance> processInstanceList = processInstanceMapper.queryByProcessDefineId(processId, limit);
|
||||
|
||||
for(ProcessInstance processInstance:processInstanceList){
|
||||
for (ProcessInstance processInstance:processInstanceList) {
|
||||
processInstance.setDuration(DateUtils.differSec(processInstance.getStartTime(),processInstance.getEndTime()));
|
||||
}
|
||||
|
||||
@ -1299,7 +1327,6 @@ public class ProcessDefinitionService extends BaseDAGService {
|
||||
TaskNode taskNode = dag.getNode(nodeName);
|
||||
treeViewDto.setType(taskNode.getType());
|
||||
|
||||
|
||||
//set treeViewDto instances
|
||||
for (int i = limit - 1; i >= 0; i--) {
|
||||
ProcessInstance processInstance = processInstanceList.get(i);
|
||||
@ -1356,7 +1383,6 @@ public class ProcessDefinitionService extends BaseDAGService {
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Generate the DAG Graph based on the process definition id
|
||||
*
|
||||
@ -1383,9 +1409,6 @@ public class ProcessDefinitionService extends BaseDAGService {
|
||||
return new DAG<>();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* whether the graph has a ring
|
||||
*
|
||||
@ -1416,16 +1439,16 @@ public class ProcessDefinitionService extends BaseDAGService {
|
||||
return graph.hasCycle();
|
||||
}
|
||||
|
||||
private String recursionProcessDefinitionName(Integer projectId,String processDefinitionName,int num){
|
||||
private String recursionProcessDefinitionName(Integer projectId,String processDefinitionName,int num) {
|
||||
ProcessDefinition processDefinition = processDefineMapper.queryByDefineName(projectId, processDefinitionName);
|
||||
if (processDefinition != null) {
|
||||
if(num > 1){
|
||||
if (num > 1) {
|
||||
String str = processDefinitionName.substring(0,processDefinitionName.length() - 3);
|
||||
processDefinitionName = str + "("+num+")";
|
||||
}else{
|
||||
processDefinitionName = processDefinition.getName() + "("+num+")";
|
||||
processDefinitionName = str + "(" + num + ")";
|
||||
} else {
|
||||
processDefinitionName = processDefinition.getName() + "(" + num + ")";
|
||||
}
|
||||
}else{
|
||||
} else {
|
||||
return processDefinitionName;
|
||||
}
|
||||
return recursionProcessDefinitionName(projectId,processDefinitionName,num + 1);
|
||||
|
@ -14,6 +14,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.apache.dolphinscheduler.api.controller;
|
||||
|
||||
import org.apache.dolphinscheduler.api.enums.Status;
|
||||
@ -23,11 +24,21 @@ import org.apache.dolphinscheduler.api.utils.Result;
|
||||
import org.apache.dolphinscheduler.common.Constants;
|
||||
import org.apache.dolphinscheduler.common.enums.ReleaseState;
|
||||
import org.apache.dolphinscheduler.common.enums.UserType;
|
||||
import org.apache.dolphinscheduler.common.model.TaskNode;
|
||||
import org.apache.dolphinscheduler.dao.entity.ProcessDefinition;
|
||||
import org.apache.dolphinscheduler.dao.entity.Resource;
|
||||
import org.apache.dolphinscheduler.dao.entity.User;
|
||||
import org.junit.*;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
@ -36,18 +47,12 @@ import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.mock.web.MockHttpServletResponse;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.text.MessageFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* process definition controller test
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.Silent.class)
|
||||
public class ProcessDefinitionControllerTest{
|
||||
public class ProcessDefinitionControllerTest {
|
||||
|
||||
private static Logger logger = LoggerFactory.getLogger(ProcessDefinitionControllerTest.class);
|
||||
|
||||
@ -60,7 +65,7 @@ public class ProcessDefinitionControllerTest{
|
||||
protected User user;
|
||||
|
||||
@Before
|
||||
public void before(){
|
||||
public void before() {
|
||||
User loginUser = new User();
|
||||
loginUser.setId(1);
|
||||
loginUser.setUserType(UserType.GENERAL_USER);
|
||||
@ -71,7 +76,13 @@ public class ProcessDefinitionControllerTest{
|
||||
|
||||
@Test
|
||||
public void testCreateProcessDefinition() throws Exception {
|
||||
String json = "{\"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}";
|
||||
String json = "{\"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}";
|
||||
String locations = "{\"tasks-36196\":{\"name\":\"ssh_test1\",\"targetarr\":\"\",\"x\":141,\"y\":70}}";
|
||||
|
||||
String projectName = "test";
|
||||
@ -103,21 +114,27 @@ public class ProcessDefinitionControllerTest{
|
||||
public void testVerifyProcessDefinitionName() throws Exception {
|
||||
|
||||
Map<String, Object> result = new HashMap<>(5);
|
||||
putMsg(result, Status.PROCESS_INSTANCE_EXIST);
|
||||
putMsg(result, Status.VERIFY_PROCESS_DEFINITION_NAME_UNIQUE_ERROR);
|
||||
String projectName = "test";
|
||||
String name = "dag_test";
|
||||
|
||||
Mockito.when(processDefinitionService.verifyProcessDefinitionName(user,projectName,name)).thenReturn(result);
|
||||
|
||||
Result response = processDefinitionController.verifyProcessDefinitionName(user,projectName,name);
|
||||
Assert.assertEquals(Status.PROCESS_INSTANCE_EXIST.getCode(),response.getCode().intValue());
|
||||
Assert.assertEquals(Status.VERIFY_PROCESS_DEFINITION_NAME_UNIQUE_ERROR.getCode(), response.getCode().intValue());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateProcessDefinition() throws Exception {
|
||||
|
||||
String json = "{\"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}";
|
||||
String json = "{\"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}";
|
||||
String locations = "{\"tasks-36196\":{\"name\":\"ssh_test1\",\"targetarr\":\"\",\"x\":141,\"y\":70}}";
|
||||
String projectName = "test";
|
||||
String name = "dag_test";
|
||||
@ -151,7 +168,13 @@ public class ProcessDefinitionControllerTest{
|
||||
@Test
|
||||
public void testQueryProcessDefinitionById() throws Exception {
|
||||
|
||||
String json = "{\"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}";
|
||||
String json = "{\"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}";
|
||||
String locations = "{\"tasks-36196\":{\"name\":\"ssh_test1\",\"targetarr\":\"\",\"x\":141,\"y\":70}}";
|
||||
String projectName = "test";
|
||||
String name = "dag_test";
|
||||
@ -193,7 +216,6 @@ public class ProcessDefinitionControllerTest{
|
||||
Assert.assertEquals(Status.SUCCESS.getCode(),response.getCode().intValue());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testQueryProcessDefinitionList() throws Exception {
|
||||
|
||||
@ -204,18 +226,24 @@ public class ProcessDefinitionControllerTest{
|
||||
putMsg(result, Status.SUCCESS);
|
||||
result.put(Constants.DATA_LIST, resourceList);
|
||||
|
||||
|
||||
Mockito.when(processDefinitionService.queryProcessDefinitionList(user, projectName)).thenReturn(result);
|
||||
Result response = processDefinitionController.queryProcessDefinitionList(user, projectName);
|
||||
|
||||
Assert.assertEquals(Status.SUCCESS.getCode(),response.getCode().intValue());
|
||||
}
|
||||
|
||||
public List<ProcessDefinition> getDefinitionList(){
|
||||
public List<ProcessDefinition> getDefinitionList() {
|
||||
|
||||
List<ProcessDefinition> resourceList = new ArrayList<>();
|
||||
|
||||
String json = "{\"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}";
|
||||
String json = "{\"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}";
|
||||
String locations = "{\"tasks-36196\":{\"name\":\"ssh_test1\",\"targetarr\":\"\",\"x\":141,\"y\":70}}";
|
||||
String projectName = "test";
|
||||
String name = "dag_test";
|
||||
@ -293,7 +321,7 @@ public class ProcessDefinitionControllerTest{
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testQueryProcessDefinitionAllByProjectId() throws Exception{
|
||||
public void testQueryProcessDefinitionAllByProjectId() throws Exception {
|
||||
int projectId = 1;
|
||||
Map<String,Object> result = new HashMap<>();
|
||||
putMsg(result,Status.SUCCESS);
|
||||
@ -305,7 +333,7 @@ public class ProcessDefinitionControllerTest{
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testViewTree() throws Exception{
|
||||
public void testViewTree() throws Exception {
|
||||
String projectName = "test";
|
||||
int processId = 1;
|
||||
int limit = 2;
|
||||
@ -319,7 +347,7 @@ public class ProcessDefinitionControllerTest{
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testQueryProcessDefinitionListPaging() throws Exception{
|
||||
public void testQueryProcessDefinitionListPaging() throws Exception {
|
||||
String projectName = "test";
|
||||
int pageNo = 1;
|
||||
int pageSize = 10;
|
||||
@ -337,7 +365,7 @@ public class ProcessDefinitionControllerTest{
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBatchExportProcessDefinitionByIds() throws Exception{
|
||||
public void testBatchExportProcessDefinitionByIds() throws Exception {
|
||||
|
||||
String processDefinitionIds = "1,2";
|
||||
String projectName = "test";
|
||||
|
@ -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 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 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 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 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 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 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);
|
||||
|
Loading…
Reference in New Issue
Block a user