Browse Source

update ut for mybatisplus (#950)

* update english documents

* refactor zk client

* update documents

* update zkclient

* update zkclient

* update documents

* add architecture-design

* change i18n

* update i18n

* update english documents

* add architecture-design

* update english documents

* update en-US documents

* add architecture-design

* update demo site

* add mybatis plus model

* modify mybatisplus

* modify mybatisplus

* change interface by mybatisplus

* add unit test

* refactor dao interface.

* add unit test for dao...

* add unit test for dao...

* add unit test for dao...

* Merge remote-tracking branch 'upstream/dev-db' into dev-db

# Conflicts:
#	dolphinscheduler-dao/src/main/resources/cn.escheduler.dao.mapper/ProjectMapper.xml
#	dolphinscheduler-dao/src/main/resources/cn.escheduler.dao.mapper/ScheduleMapper.xml
#	escheduler-dao/src/main/resources/cn.escheduler.dao.mapper/ProcessInstanceMapper.xml
#	escheduler-dao/src/main/resources/cn.escheduler.dao.mapper/ProjectUserMapper.xml
#	escheduler-dao/src/main/resources/cn.escheduler.dao.mapper/QueueMapper.xml
#	escheduler-dao/src/test/java/cn/escheduler/dao/mapper/ProcessInstanceMapperTest.java
#	escheduler-dao/src/test/java/cn/escheduler/dao/mapper/ProjectUserMapperTest.java
#	escheduler-dao/src/test/java/cn/escheduler/dao/mapper/QueueMapperTest.java
#	escheduler-dao/src/test/java/cn/escheduler/dao/mapper/ResourceUserMapperTest.java
#	escheduler-dao/src/test/java/cn/escheduler/dao/mapper/ScheduleMapperTest.java
#	escheduler-dao/src/test/java/cn/escheduler/dao/mapper/SessionMapperTest.java
#	escheduler-dao/src/test/java/cn/escheduler/dao/mapper/TenantMapperTest.java

* Merge remote-tracking branch 'upstream/dev-db' into dev-db

# Conflicts:
#	dolphinscheduler-dao/src/main/resources/cn.escheduler.dao.mapper/ProjectMapper.xml
#	dolphinscheduler-dao/src/main/resources/cn.escheduler.dao.mapper/ScheduleMapper.xml
#	escheduler-dao/src/main/resources/cn.escheduler.dao.mapper/ProcessInstanceMapper.xml
#	escheduler-dao/src/main/resources/cn.escheduler.dao.mapper/ProjectUserMapper.xml
#	escheduler-dao/src/main/resources/cn.escheduler.dao.mapper/QueueMapper.xml
#	escheduler-dao/src/test/java/cn/escheduler/dao/mapper/ProcessInstanceMapperTest.java
#	escheduler-dao/src/test/java/cn/escheduler/dao/mapper/ProjectUserMapperTest.java
#	escheduler-dao/src/test/java/cn/escheduler/dao/mapper/QueueMapperTest.java
#	escheduler-dao/src/test/java/cn/escheduler/dao/mapper/ResourceUserMapperTest.java
#	escheduler-dao/src/test/java/cn/escheduler/dao/mapper/ScheduleMapperTest.java
#	escheduler-dao/src/test/java/cn/escheduler/dao/mapper/SessionMapperTest.java
#	escheduler-dao/src/test/java/cn/escheduler/dao/mapper/TenantMapperTest.java
pull/2/head
bao liang 5 years ago committed by qiaozhanwei
parent
commit
b5636b043f
  1. 46
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/DataAnalysisService.java
  2. 4
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/ProjectService.java
  3. 4
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/ResourcesService.java
  4. 7
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/TaskInstanceService.java
  5. 33
      dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/ProcessDao.java
  6. 24
      dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/Project.java
  7. 20
      dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/Resource.java
  8. 3
      dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/ProjectMapper.java
  9. 4
      dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/ResourceMapper.java
  10. 19
      dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/TaskInstanceMapper.java
  11. 50
      dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/ProjectMapper.xml
  12. 26
      dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/ResourceMapper.xml
  13. 78
      dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/TaskInstanceMapper.xml
  14. 2
      dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/ErrorCommandMapperTest.java
  15. 9
      dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/ProcessInstanceMapperTest.java
  16. 127
      dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/ProjectMapperTest.java
  17. 2
      dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/ProjectUserMapperTest.java
  18. 1
      dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/QueueMapperTest.java
  19. 150
      dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/ResourceMapperTest.java
  20. 198
      dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/TaskInstanceMapperTest.java
  21. 8
      dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/TenantMapperTest.java
  22. 2
      dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/worker/task/AbstractCommandExecutor.java
  23. 8
      dolphinscheduler-server/src/test/java/org/apache/dolphinscheduler/server/master/AlertManagerTest.java

46
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/DataAnalysisService.java

@ -108,9 +108,9 @@ public class DataAnalysisService {
return result;
}
Integer[] projectIds = getProjectIdsArrays(loginUser, projectId);
List<ExecuteStatusCount> taskInstanceStateCounts =
taskInstanceMapper.countTaskInstanceStateByUser(loginUser.getId(),
loginUser.getUserType(), start, end, String.valueOf(projectId));
taskInstanceMapper.countTaskInstanceStateByUser(start, end, projectIds);
TaskCountDto taskCountResult = new TaskCountDto(taskInstanceStateCounts);
if (taskInstanceStateCounts != null) {
@ -158,16 +158,7 @@ public class DataAnalysisService {
putErrorRequestParamsMsg(result);
return result;
}
List<Integer> projectIds = new ArrayList<>();
if(projectId !=0){
projectIds.add(projectId);
}else if(loginUser.getUserType() == UserType.GENERAL_USER){
projectIds = processDao.getProjectIdListHavePerm(loginUser.getId());
}
Integer[] projectIdArray = projectIds.toArray(new Integer[projectIds.size()]);
Integer[] projectIdArray = getProjectIdsArrays(loginUser, projectId);
List<ExecuteStatusCount> processInstanceStateCounts =
processInstanceMapper.countInstanceStateByUser(start, end,
projectIdArray);
@ -194,8 +185,7 @@ public class DataAnalysisService {
Map<String, Object> result = new HashMap<>();
Integer[] projectIdArray = new Integer[1];
projectIdArray[0] = projectId;
Integer[] projectIdArray = getProjectIdsArrays(loginUser, projectId);
List<DefinitionGroupByUser> defineGroupByUsers = processDefinitionMapper.countDefinitionGroupByUser(
loginUser.getId(), projectIdArray);
@ -265,14 +255,7 @@ public class DataAnalysisService {
return result;
}
List<Integer> projectIds = new ArrayList<>();
if(projectId !=0){
projectIds.add(projectId);
}else if(loginUser.getUserType() == UserType.GENERAL_USER){
projectIds = processDao.getProjectIdListHavePerm(loginUser.getId());
}
Integer[] projectIdArray = projectIds.toArray(new Integer[projectIds.size()]);
Integer[] projectIdArray = getProjectIdsArrays(loginUser, projectId);
// count command state
List<CommandCount> commandStateCounts =
commandMapper.countCommandState(
@ -336,6 +319,16 @@ public class DataAnalysisService {
return result;
}
private Integer[] getProjectIdsArrays(User loginUser, int projectId) {
List<Integer> projectIds = new ArrayList<>();
if(projectId !=0){
projectIds.add(projectId);
}else if(loginUser.getUserType() == UserType.GENERAL_USER){
projectIds = processDao.getProjectIdListHavePerm(loginUser.getId());
}
return projectIds.toArray(new Integer[projectIds.size()]);
}
/**
* count queue state
* @param loginUser
@ -391,21 +384,18 @@ public class DataAnalysisService {
}
Integer taskQueueCount = 0;
Integer taskKillCount = 0;
int[] projectIds = new int[1];
projectIds[0] = projectId;
Integer[] projectIds = getProjectIdsArrays(loginUser, projectId);
if (tasksQueueIds.length != 0){
taskQueueCount = taskInstanceMapper.countTask(
loginUser.getId(),loginUser.getUserType(),projectIds,
projectIds,
tasksQueueIds);
}
if (tasksKillIds.length != 0){
taskKillCount = taskInstanceMapper.countTask(loginUser.getId(),loginUser.getUserType(), projectIds, tasksKillIds);
taskKillCount = taskInstanceMapper.countTask(projectIds, tasksKillIds);
}
dataMap.put("taskQueue",taskQueueCount);
dataMap.put("taskKill",taskKillCount);

4
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/ProjectService.java

@ -81,7 +81,7 @@ public class ProjectService extends BaseService{
Date now = new Date();
project.setName(name);
project.setDesc(desc);
project.setDescription(desc);
project.setUserId(loginUser.getId());
project.setUserName(loginUser.getUserName());
project.setCreateTime(now);
@ -244,7 +244,7 @@ public class ProjectService extends BaseService{
return result;
}
project.setName(projectName);
project.setDesc(desc);
project.setDescription(desc);
project.setUpdateTime(new Date());
int update = projectMapper.updateById(project);

4
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/ResourcesService.java

@ -214,7 +214,7 @@ public class ResourcesService extends BaseService {
}
if (name.equals(resource.getAlias()) && desc.equals(resource.getDesc())) {
if (name.equals(resource.getAlias()) && desc.equals(resource.getDescription())) {
putMsg(result, Status.SUCCESS);
return result;
}
@ -231,7 +231,7 @@ public class ResourcesService extends BaseService {
// updateProcessInstance data
Date now = new Date();
resource.setAlias(name);
resource.setDesc(desc);
resource.setDescription(desc);
resource.setUpdateTime(now);
try {

7
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/TaskInstanceService.java

@ -91,14 +91,9 @@ public class TaskInstanceService extends BaseService {
}
int[] statusArray = null;
String statesStr = null;
// filter by status
if(stateType != null){
statusArray = new int[]{stateType.ordinal()};
}
if(statusArray != null){
statesStr = Arrays.toString(statusArray).replace("[", "").replace("]","");
}
Date start = null;
Date end = null;
@ -117,7 +112,7 @@ public class TaskInstanceService extends BaseService {
Page<TaskInstance> page = new Page(pageNo, pageSize);
IPage<TaskInstance> taskInstanceIPage = taskInstanceMapper.queryTaskInstanceListPaging(
page, project.getId(), processInstanceId, searchVal, taskName, statesStr, host, start, end
page, project.getId(), processInstanceId, searchVal, taskName, statusArray, host, start, end
);
PageInfo pageInfo = new PageInfo<ProcessInstance>(pageNo, pageSize);
Set<String> exclusionSet = new HashSet<String>(){{

33
dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/ProcessDao.java

@ -1204,7 +1204,7 @@ public class ProcessDao extends AbstractBaseDao {
}
public TaskInstance findTaskInstanceById(Integer taskId){
return taskInstanceMapper.queryById(taskId);
return taskInstanceMapper.selectById(taskId);
}
@ -1331,7 +1331,7 @@ public class ProcessDao extends AbstractBaseDao {
String executePath,
String logPath,
int taskInstId) {
TaskInstance taskInstance = taskInstanceMapper.queryById(taskInstId);
TaskInstance taskInstance = taskInstanceMapper.selectById(taskInstId);
taskInstance.setState(state);
taskInstance.setStartTime(startTime);
taskInstance.setHost(host);
@ -1384,7 +1384,7 @@ public class ProcessDao extends AbstractBaseDao {
public void changeTaskState(ExecutionStatus state,
Date endTime,
int taskInstId) {
TaskInstance taskInstance = taskInstanceMapper.queryById(taskInstId);
TaskInstance taskInstance = taskInstanceMapper.selectById(taskInstId);
taskInstance.setState(state);
taskInstance.setEndTime(endTime);
saveTaskInstance(taskInstance);
@ -1406,19 +1406,6 @@ public class ProcessDao extends AbstractBaseDao {
return result;
}
/**
* set task
* 根据任务实例id设置pid
* @param taskInstId
* @param pid
*/
public void updatePidByTaskInstId(int taskInstId, int pid) {
TaskInstance taskInstance = taskInstanceMapper.queryById(taskInstId);
taskInstance.setPid(pid);
taskInstance.setAppLink("");
saveTaskInstance(taskInstance);
}
/**
* update pid and app links field by task instance id
* @param taskInstId
@ -1426,22 +1413,12 @@ public class ProcessDao extends AbstractBaseDao {
*/
public void updatePidByTaskInstId(int taskInstId, int pid,String appLinks) {
TaskInstance taskInstance = taskInstanceMapper.queryById(taskInstId);
TaskInstance taskInstance = taskInstanceMapper.selectById(taskInstId);
taskInstance.setPid(pid);
taskInstance.setAppLink(appLinks);
saveTaskInstance(taskInstance);
}
/**
* query ProcessDefinition by name
*
* @see ProcessDefinition
*/
public ProcessDefinition findProcessDefineByName(int projectId, String name) {
ProcessDefinition projectFlow = processDefineMapper.queryByDefineName(projectId, name);
return projectFlow;
}
/**
* query Schedule <p>
*
@ -1488,7 +1465,7 @@ public class ProcessDao extends AbstractBaseDao {
*/
public List<TaskInstance> queryNeedFailoverTaskInstances(String host){
return taskInstanceMapper.queryByHostAndStatus(host,
StringUtils.join(stateArray, ","));
stateArray);
}
/**

24
dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/Project.java

@ -52,25 +52,21 @@ public class Project {
/**
* project name
*/
@TableField("name")
private String name;
/**
* project description
*/
@TableField("`desc`")
private String desc;
private String description;
/**
* create time
*/
@TableField("`create_time`")
private Date createTime;
/**
* update time
*/
@TableField("`update_time`")
private Date updateTime;
/**
@ -123,14 +119,6 @@ public class Project {
this.name = name;
}
public String getDesc() {
return desc;
}
public void setDesc(String desc) {
this.desc = desc;
}
public Date getCreateTime() {
return createTime;
}
@ -147,6 +135,13 @@ public class Project {
this.updateTime = updateTime;
}
public void setDescription(String description) {
this.description = description;
}
public String getDescription() {
return description;
}
public int getUserId() {
return userId;
}
@ -177,7 +172,7 @@ public class Project {
", userId=" + userId +
", userName='" + userName + '\'' +
", name='" + name + '\'' +
", desc='" + desc + '\'' +
", description='" + description + '\'' +
", createTime=" + createTime +
", updateTime=" + updateTime +
'}';
@ -208,4 +203,5 @@ public class Project {
result = 31 * result + name.hashCode();
return result;
}
}

20
dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/Resource.java

@ -42,7 +42,7 @@ public class Resource {
/**
* description
*/
private String desc;
private String description;
/**
* file alias
@ -77,13 +77,13 @@ public class Resource {
public Resource() {
}
public Resource(int id, String alias, String fileName, String desc, int userId,
public Resource(int id, String alias, String fileName, String description, int userId,
ResourceType type, long size,
Date createTime, Date updateTime) {
this.id = id;
this.alias = alias;
this.fileName = fileName;
this.desc = desc;
this.description = description;
this.userId = userId;
this.type = type;
this.size = size;
@ -91,10 +91,10 @@ public class Resource {
this.updateTime = updateTime;
}
public Resource(String alias, String fileName, String desc, int userId, ResourceType type, long size, Date createTime, Date updateTime) {
public Resource(String alias, String fileName, String description, int userId, ResourceType type, long size, Date createTime, Date updateTime) {
this.alias = alias;
this.fileName = fileName;
this.desc = desc;
this.description = description;
this.userId = userId;
this.type = type;
this.size = size;
@ -126,12 +126,12 @@ public class Resource {
this.fileName = fileName;
}
public String getDesc() {
return desc;
public String getDescription() {
return description;
}
public void setDesc(String desc) {
this.desc = desc;
public void setDescription(String description) {
this.description = description;
}
public int getUserId() {
@ -181,7 +181,7 @@ public class Resource {
"id=" + id +
", alias='" + alias + '\'' +
", fileName='" + fileName + '\'' +
", desc='" + desc + '\'' +
", description='" + description + '\'' +
", userId=" + userId +
", type=" + type +
", size=" + size +

3
dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/ProjectMapper.java

@ -33,9 +33,6 @@ public interface ProjectMapper extends BaseMapper<Project> {
@Param("userId") int userId,
@Param("searchName") String searchName);
IPage<Project> queryAllProjectListPaging(IPage<Project> page,
@Param("searchName") String searchName);
List<Project> queryProjectCreatedByUser(@Param("userId") int userId);
List<Project> queryAuthedProjectListByUserId(@Param("userId") int userId);

4
dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/ResourceMapper.java

@ -40,7 +40,7 @@ public interface ResourceMapper extends BaseMapper<Resource> {
/**
*
* @param page
* @param userId query all if -1, then query the authed resources
* @param userId query all if 0, then query the authed resources
* @param type
* @param searchVal
* @return
@ -53,7 +53,7 @@ public interface ResourceMapper extends BaseMapper<Resource> {
/**
*
* @param userId
* @param type
* @param type query all if -1
* @return
*/
List<Resource> queryResourceListAuthored(@Param("userId") int userId, @Param("type") int type);

19
dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/TaskInstanceMapper.java

@ -34,39 +34,34 @@ public interface TaskInstanceMapper extends BaseMapper<TaskInstance> {
List<Integer> queryTaskByProcessIdAndState(@Param("processInstanceId") Integer processInstanceId,
@Param("state") Integer state);
TaskInstance queryById(@Param("taskInstanceId") int taskInstanceId);
List<TaskInstance> findValidTaskListByProcessId(@Param("processInstanceId") Integer processInstanceId,
@Param("flag") Flag flag);
List<TaskInstance> queryByHostAndStatus(@Param("host") String host,
@Param("states") String stateArray);
@Param("states") int[] stateArray);
int setFailoverByHostAndStateArray(@Param("host") String host,
@Param("states") String stateArray,
@Param("states") int[] stateArray,
@Param("destStatus") ExecutionStatus destStatus);
TaskInstance queryByInstanceIdAndName(@Param("processInstanceId") int processInstanceId,
@Param("name") String name);
Integer countTask(@Param("userId") int userId,
@Param("userType") UserType userType,
@Param("projectIds") int[] projectIds,
Integer countTask(
@Param("projectIds") Integer[] projectIds,
@Param("taskIds") int[] taskIds);
List<ExecuteStatusCount> countTaskInstanceStateByUser(@Param("userId") int userId,
@Param("userType") UserType userType,
List<ExecuteStatusCount> countTaskInstanceStateByUser(
@Param("startTime") Date startTime,
@Param("endTime") Date endTime,
@Param("projectIds") String projectIds);
@Param("projectIds") Integer[] projectIds);
IPage<TaskInstance> queryTaskInstanceListPaging(IPage<TaskInstance> page,
@Param("projectId") int projectId,
@Param("processInstanceId") Integer processInstanceId,
@Param("searchVal") String searchVal,
@Param("taskName") String taskName,
@Param("states") String statusArray,
@Param("states") int[] statusArray,
@Param("host") String host,
@Param("startTime") Date startTime,
@Param("endTime") Date endTime

50
dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/ProjectMapper.xml

@ -3,62 +3,48 @@
<mapper namespace="org.apache.dolphinscheduler.dao.mapper.ProjectMapper">
<select id="queryDetailById" resultType="org.apache.dolphinscheduler.dao.entity.Project">
select p.*,u.user_name as user_name
from t_ds_project
join t_ds_user u on p.user_id = u.id
from t_escheduler_project p
join t_escheduler_user u on p.user_id = u.id
where p.id = #{projectId}
</select>
<select id="queryByName" resultType="org.apache.dolphinscheduler.dao.entity.Project">
select p.* u.user_name as user_name
from t_ds_project
join t_ds_user u on p.user_id = u.id
select p.*,u.user_name as user_name
from t_escheduler_project p
join t_escheduler_user u on p.user_id = u.id
where p.name = #{projectName}
and p.flag = 1
limit 1
</select>
<select id="queryProjectListPaging" resultType="org.apache.dolphinscheduler.dao.entity.Project">
select p.*, u.user_name as user_name,
(SELECT COUNT(*) FROM t_ds_process_definition AS def WHERE def.project_id = p.id) AS def_count,
(SELECT COUNT(*) FROM t_ds_process_definition def, t_ds_process_instance inst WHERE def.id = inst.process_definition_id AND def.project_id = p.id AND inst.state=1 ) as inst_running_count,
from t_ds_project p
join t_ds_user u on u.id=p.user_id
select p.*,u.user_name as user_name,
(SELECT COUNT(*) FROM t_escheduler_process_definition AS def WHERE def.project_id = p.id) AS def_count,
(SELECT COUNT(*) FROM t_escheduler_process_definition def, t_escheduler_process_instance inst WHERE def.id = inst.process_definition_id AND def.project_id = p.id AND inst.state=1 ) as inst_running_count
from t_escheduler_project p
join t_escheduler_user u on u.id=p.user_id
where 1=1
<if test="userId != 0">
and p.id in
(select project_id from t_ds_relation_project_user where user_id=#{userId}
union select id as project_id from t_ds_project where user_id=#{userId})
(select project_id from t_escheduler_relation_project_user where user_id=#{userId}
union select id as project_id from t_escheduler_project where user_id=#{userId})
)
</if>
<if test="searchName!=null and searchName != ''">
and p.name like concat('%', #{searchName}, '%')
</if>
and p.flag=1
order by p.create_time desc
</select>
<select id="queryAllProjectListPaging" resultType="org.apache.dolphinscheduler.dao.entity.Project">
select p.*, u.user_name as user_name,
(SELECT COUNT(*) FROM t_ds_process_definition AS def WHERE def.project_id = p.id) AS def_count,
(SELECT COUNT(*) FROM t_ds_process_definition def, t_ds_process_instance inst WHERE def.id = inst.process_definition_id AND def.project_id = p.id AND inst.state=1 ) as inst_running_count,
from t_ds_project p
join t_ds_user u on u.id=p.user_id
where p.flag=1
<if test="searchName!=null and searchName != ''">
and p.name like concat('%', #{searchName}, '%')
</if>
order by p.create_time desc
</select>
<select id="queryAuthedProjectListByUserId" resultType="org.apache.dolphinscheduler.dao.entity.Project">
select p.*
from t_ds_project p,t_ds_relation_project_user rel
where p.id = rel.project_id and p.flag=1 and rel.user_id= #{userId}
from t_escheduler_project p,t_escheduler_relation_project_user rel
where p.id = rel.project_id and rel.user_id= #{userId}
</select>
<select id="queryProjectExceptUserId" resultType="org.apache.dolphinscheduler.dao.entity.Project">
select *
from t_ds_project
where flag=1 and user_id <![CDATA[ <> ]]> #{userId}
from t_escheduler_project
where user_id <![CDATA[ <> ]]> #{userId}
</select>
<select id="queryProjectCreatedByUser" resultType="org.apache.dolphinscheduler.dao.entity.Project">
select *
from t_ds_project
from t_escheduler_project
where user_id = #{userId}
</select>

26
dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/ResourceMapper.xml

@ -3,13 +3,13 @@
<mapper namespace="org.apache.dolphinscheduler.dao.mapper.ResourceMapper">
<select id="queryResourceList" resultType="org.apache.dolphinscheduler.dao.entity.Resource">
select *
from t_ds_resources
from t_escheduler_resources
where 1= 1
<if test="alias != null and alias != ''">
and alias = #{alias}
</if>
<if test="type != -1">
and `type` = #{type}
and type = #{type}
</if>
<if test="userId != 0">
and user_id = #{userId}
@ -17,21 +17,21 @@
</select>
<select id="queryResourceListAuthored" resultType="org.apache.dolphinscheduler.dao.entity.Resource">
select *
from t_ds_resources
from t_escheduler_resources
where 1 = 1
<if test="type != -1">
and `type`=#{type}
and type=#{type}
</if>
and id in (select resources_id from t_ds_relation_resources_user where user_id=#{userId}
union select id as resources_id from t_ds_resources where user_id=#{userId})
and id in (select resources_id from t_escheduler_relation_resources_user where user_id=#{userId}
union select id as resources_id from t_escheduler_resources where user_id=#{userId})
</select>
<select id="queryResourcePaging" resultType="org.apache.dolphinscheduler.dao.entity.Resource">
select *
from t_ds_resources
where `type`=#{type}
from t_escheduler_resources
where type=#{type}
<if test="userId != 0">
and id in (select resources_id from t_ds_relation_resources_user where user_id=#{userId}
union select id as resources_id from t_ds_resources where user_id=#{userId})
and id in (select resources_id from t_escheduler_relation_resources_user where user_id=#{userId}
union select id as resources_id from t_escheduler_resources where user_id=#{userId})
</if>
<if test="searchVal != null and searchVal != ''">
and alias like concat('%', #{searchVal}, '%')
@ -40,17 +40,17 @@
</select>
<select id="queryAuthorizedResourceList" resultType="org.apache.dolphinscheduler.dao.entity.Resource">
select r.*
from t_ds_resources r,t_ds_relation_resources_user rel
from t_escheduler_resources r,t_escheduler_relation_resources_user rel
where r.id = rel.resources_id AND rel.user_id = #{userId}
</select>
<select id="queryResourceExceptUserId" resultType="org.apache.dolphinscheduler.dao.entity.Resource">
select *
from t_ds_resources
from t_escheduler_resources
where user_id <![CDATA[ <> ]]> #{userId}
</select>
<select id="queryTenantCodeByResourceName" resultType="java.lang.String">
select tenant_code
from t_ds_tenant t, t_ds_user u, t_ds_resources res
from t_escheduler_tenant t, t_escheduler_user u, t_escheduler_resources res
where t.id = u.tenant_id and u.id = res.user_id and res.type=0
and res.alias= #{resName}
</select>

78
dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/TaskInstanceMapper.xml

@ -2,63 +2,76 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="org.apache.dolphinscheduler.dao.mapper.TaskInstanceMapper">
<update id="setFailoverByHostAndStateArray">
update t_ds_task_instance
update t_escheduler_task_instance
set state = #{destStatus}
where host = #{host} and state in (#{states})
where host = #{host}
and state in
<foreach collection="states" index="index" item="i" open="(" separator="," close=")">
#{i}
</foreach>
</update>
<select id="queryById" resultType="org.apache.dolphinscheduler.dao.entity.TaskInstance">
select *, UNIX_TIMESTAMP(end_time)-UNIX_TIMESTAMP(start_time) as duration
from t_ds_task_instance
where id=#{taskInstanceId}
</select>
<select id="queryTaskByProcessIdAndState" resultType="java.lang.Integer">
select *, UNIX_TIMESTAMP(end_time)-UNIX_TIMESTAMP(start_time) as duration
from t_ds_task_instance
select id
from t_escheduler_task_instance
WHERE process_instance_id = #{processInstanceId}
and state = #{state}
and flag = 1
</select>
<select id="findValidTaskListByProcessId" resultType="org.apache.dolphinscheduler.dao.entity.TaskInstance">
select *, UNIX_TIMESTAMP(end_time)-UNIX_TIMESTAMP(start_time) as duration
from t_ds_task_instance
select *
from t_escheduler_task_instance
WHERE process_instance_id = #{processInstanceId}
and flag = #{flag}
order by start_time desc
</select>
<select id="queryByHostAndStatus" resultType="org.apache.dolphinscheduler.dao.entity.TaskInstance">
select *
from t_ds_task_instance
from t_escheduler_task_instance
where 1 = 1
<if test="host != null and host != ''">
and host = #{host}
</if>
and state in (#{states})
<if test="states != null and states.length != 0">
and state in
<foreach collection="states" index="index" item="i" open="(" separator="," close=")">
#{i}
</foreach>
</if>
</select>
<select id="countTaskInstanceStateByUser" resultType="org.apache.dolphinscheduler.dao.entity.ExecuteStatusCount">
select state, count(0) as count
from t_ds_task_instance t
left join t_ds_process_definition d on d.id=t.process_definition_id
left join t_ds_project p on p.id=d.project_id
from t_escheduler_task_instance t
left join t_escheduler_process_definition d on d.id=t.process_definition_id
left join t_escheduler_project p on p.id=d.project_id
where 1=1
<if test="projectIds != null and projectIds != ''">
and d.project_id in (#{projectIds})
and d.project_id in
<foreach collection="projectIds" index="index" item="i" open="(" separator="," close=")">
#{i}
</foreach>
</if>
and t.flag = 1
<if test="startTime != null and endTime != null">
and t.start_time > #{startTime} and t.start_time <![CDATA[ <= ]]> #{endTime}
</if>
and t.flag = 1 and t.start_time > #{startTime} and t.start_time <![CDATA[ <= ]]> #{endTime}
group by t.state
</select>
<select id="queryByInstanceIdAndName" resultType="org.apache.dolphinscheduler.dao.entity.TaskInstance">
select *
from t_ds_task_instance
from t_escheduler_task_instance
where process_instance_id = #{processInstanceId}
and `name` = #{name}
and `flag` = 1
and name = #{name}
and flag = 1
</select>
<select id="countTask" resultType="java.lang.Integer">
select count(1) as `count`
from t_ds_task_instance task,t_ds_process_definition process
select count(1) as count
from t_escheduler_task_instance task,t_escheduler_process_definition process
where task.process_definition_id=process.id
<if test="projectIds != null and projectIds != ''">
and process.project_id in (#{projectIds})
<if test="projectIds != null and projectIds.length != 0">
and process.project_id in
<foreach collection="projectIds" index="index" item="i" open="(" separator="," close=")">
#{i}
</foreach>
</if>
<if test="taskIds != null and taskIds.length != 0">
and task.id in
@ -68,10 +81,10 @@
</if>
</select>
<select id="queryTaskInstanceListPaging" resultType="org.apache.dolphinscheduler.dao.entity.TaskInstance">
select instance.*,process.name as process_instance_name, UNIX_TIMESTAMP(instance.end_time)-UNIX_TIMESTAMP(instance.start_time) as duration
from t_ds_task_instance instance
join t_ds_process_definition define ON instance.process_definition_id = define.id
join process on process.id=instance.process_instance_id
select instance.*,process.name as process_instance_name
from t_escheduler_task_instance instance
join t_escheduler_process_definition define ON instance.process_definition_id = define.id
join t_escheduler_process_instance process on process.id=instance.process_instance_id
where define.project_id = #{projectId}
<if test="startTime != null">
and instance.start_time > #{startTime} and instance.start_time <![CDATA[ <=]]> #{endTime}
@ -85,8 +98,11 @@
<if test="taskName != null and taskName != ''">
and instance.name=#{taskName}
</if>
<if test="states != null and states != ''">
and instance.state in ( "+ stateStr + " )
<if test="states != null and states.length != 0">
and instance.state in
<foreach collection="states" index="index" item="i" open="(" separator="," close=")">
#{i}
</foreach>
</if>
<if test="host != null and host != ''">
and instance.host like concat('%', #{host}, '%')

2
dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/ErrorCommandMapperTest.java

@ -74,8 +74,6 @@ public class ErrorCommandMapperTest {
@Test
public void testQuery() {
errorCommandMapper.delete(null);
ErrorCommand errorCommand = insertOne();
ProcessDefinition processDefinition = new ProcessDefinition();

9
dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/ProcessInstanceMapperTest.java

@ -20,15 +20,13 @@ package org.apache.dolphinscheduler.dao.mapper;
import org.apache.dolphinscheduler.common.enums.ExecutionStatus;
import org.apache.dolphinscheduler.common.enums.Flag;
import org.apache.dolphinscheduler.common.enums.ReleaseState;
import org.apache.dolphinscheduler.dao.entity.*;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.dolphinscheduler.dao.entity.ExecuteStatusCount;
import org.apache.dolphinscheduler.dao.entity.ProcessDefinition;
import org.apache.dolphinscheduler.dao.entity.ProcessInstance;
import org.apache.dolphinscheduler.dao.entity.Project;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mortbay.jetty.servlet.AbstractSessionIdManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
@ -197,9 +195,6 @@ public class ProcessInstanceMapperTest {
@Test
public void testCountInstanceStateByUser() {
processDefinitionMapper.delete(null);
processInstanceMapper.delete(null);
Project project = new Project();
project.setName("testProject");
projectMapper.insert(project);

127
dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/ProjectMapperTest.java

@ -17,40 +17,161 @@
package org.apache.dolphinscheduler.dao.mapper;
import org.apache.dolphinscheduler.dao.entity.Project;
import org.apache.dolphinscheduler.dao.entity.User;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import java.util.Date;
import java.util.List;
@RunWith(SpringRunner.class)
@SpringBootTest
public class ProjectMapperTest {
@Autowired
ProjectMapper projectMapper;
@Autowired
UserMapper userMapper;
private Project insertOne(){
//insertOne
Project project = new Project();
project.setName("ut project");
project.setUserId(111);
projectMapper.insert(project);
return project;
}
@Test
public void testUpdate(){
//insertOne
Project project = insertOne();
project.setCreateTime(new Date());
//update
int update = projectMapper.updateById(project);
Assert.assertEquals(update, 1);
projectMapper.deleteById(project.getId());
}
@Test
public void testDelete(){
Project projectMap = insertOne();
int delete = projectMapper.deleteById(projectMap.getId());
Assert.assertEquals(delete, 1);
}
@Test
public void testQuery() {
Project project = insertOne();
//query
List<Project> projects = projectMapper.selectList(null);
Assert.assertNotEquals(projects.size(), 0);
projectMapper.deleteById(project.getId());
}
@Test
public void testQueryDetailById() {
User user = new User();
user.setUserName("ut user");
userMapper.insert(user);
Project project = insertOne();
project.setUserId(user.getId());
projectMapper.updateById(project);
Project project1 = projectMapper.queryDetailById(project.getId());
userMapper.deleteById(user.getId());
projectMapper.deleteById(project.getId());
Assert.assertNotEquals(project1, null);
Assert.assertEquals(project1.getUserName(), user.getUserName());
}
@Test
public void testQueryProjectByName() {
User user = new User();
user.setUserName("ut user");
userMapper.insert(user);
Project project = insertOne();
project.setUserId(user.getId());
projectMapper.updateById(project);
Project project1 = projectMapper.queryByName(project.getName());
userMapper.deleteById(user.getId());
projectMapper.deleteById(project.getId());
Assert.assertNotEquals(project1, null);
Assert.assertEquals(project1.getUserName(), user.getUserName());
}
@Test
public void testQueryProjectListPaging() {
}
Project project = insertOne();
Project project1 = insertOne();
@Test
public void testQueryAllProjectListPaging() {
User user = new User();
user.setUserName("ut user");
userMapper.insert(user);
project.setUserId(user.getId());
projectMapper.updateById(project);
Page<Project> page = new Page(1,3);
IPage<Project> projectIPage = projectMapper.queryProjectListPaging(
page,
project.getUserId(),
null
);
IPage<Project> projectIPage1 = projectMapper.queryProjectListPaging(
page,
project.getUserId(),
project.getName()
);
projectMapper.deleteById(project.getId());
projectMapper.deleteById(project1.getId());
userMapper.deleteById(user.getId());
Assert.assertNotEquals(projectIPage.getTotal(), 0);
Assert.assertNotEquals(projectIPage1.getTotal(), 0);
}
@Test
public void testQueryProjectCreatedByUser() {
Project project = insertOne();
List<Project> projects = projectMapper.queryProjectCreatedByUser(project.getUserId());
projectMapper.deleteById(project.getId());
Assert.assertNotEquals(projects.size(), 0);
}
@Test
public void testQueryAuthedProjectListByUserId() {
Project project = insertOne();
List<Project> projects = projectMapper.queryProjectCreatedByUser(project.getUserId());
projectMapper.deleteById(project.getId());
Assert.assertNotEquals(projects.size(), 0);
}
@Test
public void testQueryProjectExceptUserId() {
Project project = insertOne();
List<Project> projects = projectMapper.queryProjectExceptUserId(
100000
);
projectMapper.deleteById(project.getId());
Assert.assertNotEquals(projects.size(), 0);
}
}

2
dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/ProjectUserMapperTest.java

@ -17,6 +17,8 @@
package org.apache.dolphinscheduler.dao.mapper;
import org.apache.dolphinscheduler.common.enums.ExecutionStatus;
import org.apache.dolphinscheduler.dao.entity.ProjectUser;
import org.apache.dolphinscheduler.dao.entity.ProjectUser;
import org.junit.Assert;
import org.junit.Test;

1
dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/QueueMapperTest.java

@ -17,6 +17,7 @@
package org.apache.dolphinscheduler.dao.mapper;
import org.apache.dolphinscheduler.dao.entity.Queue;
import org.apache.dolphinscheduler.dao.entity.Queue;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

150
dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/ResourceMapperTest.java

@ -17,36 +17,186 @@
package org.apache.dolphinscheduler.dao.mapper;
import org.apache.dolphinscheduler.common.enums.ResourceType;
import org.apache.dolphinscheduler.dao.entity.*;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import java.util.Date;
import java.util.List;
@RunWith(SpringRunner.class)
@SpringBootTest
public class ResourceMapperTest {
@Autowired
ResourceMapper resourceMapper;
@Autowired
ResourceUserMapper resourceUserMapper;
@Autowired
TenantMapper tenantMapper;
@Autowired
UserMapper userMapper;
private Resource insertOne(){
//insertOne
Resource resource = new Resource();
resource.setAlias("ut resource");
resource.setType(ResourceType.FILE);
resource.setUserId(111);
resourceMapper.insert(resource);
return resource;
}
@Test
public void testUpdate(){
//insertOne
Resource resource = insertOne();
resource.setCreateTime(new Date());
//update
int update = resourceMapper.updateById(resource);
Assert.assertEquals(update, 1);
resourceMapper.deleteById(resource.getId());
}
@Test
public void testDelete(){
Resource resourceMap = insertOne();
int delete = resourceMapper.deleteById(resourceMap.getId());
Assert.assertEquals(delete, 1);
}
@Test
public void testQuery() {
Resource resource = insertOne();
//query
List<Resource> resources = resourceMapper.selectList(null);
Assert.assertNotEquals(resources.size(), 0);
resourceMapper.deleteById(resource.getId());
}
@Test
public void testQueryResourceList() {
Resource resource = insertOne();
String alias = "";
int userId = resource.getUserId();
int type = resource.getType().ordinal();
List<Resource> resources = resourceMapper.queryResourceList(
alias,
userId,
type
);
Assert.assertNotEquals(resources.size(), 0);
resourceMapper.deleteById(resource.getId());
}
@Test
public void testQueryResourcePaging() {
Resource resource = insertOne();
ResourcesUser resourcesUser = new ResourcesUser();
resourcesUser.setResourcesId(resource.getId());
resourcesUser.setUserId(1110);
resourceUserMapper.insert(resourcesUser);
Page<Resource> page = new Page(1, 3);
IPage<Resource> resourceIPage = resourceMapper.queryResourcePaging(
page,
resource.getUserId(),
resource.getType().ordinal(),
""
);
IPage<Resource> resourceIPage1 = resourceMapper.queryResourcePaging(
page,
1110,
resource.getType().ordinal(),
""
);
resourceMapper.deleteById(resource.getId());
resourceUserMapper.deleteById(resourcesUser.getId());
Assert.assertNotEquals(resourceIPage.getTotal(), 0);
Assert.assertNotEquals(resourceIPage1.getTotal(), 0);
}
@Test
public void testQueryResourceListAuthored() {
Resource resource = insertOne();
List<Resource> resources = resourceMapper.queryAuthorizedResourceList(resource.getUserId());
ResourcesUser resourcesUser = new ResourcesUser();
resourcesUser.setResourcesId(resource.getId());
resourcesUser.setUserId(1110);
resourceUserMapper.insert(resourcesUser);
List<Resource> resources1 = resourceMapper.queryAuthorizedResourceList(1110);
resourceUserMapper.deleteById(resourcesUser.getId());
resourceMapper.deleteById(resource.getId());
Assert.assertEquals(resources.size(), 0);
Assert.assertNotEquals(resources1.size(), 0);
}
@Test
public void testQueryAuthorizedResourceList() {
Resource resource = insertOne();
List<Resource> resources = resourceMapper.queryAuthorizedResourceList(resource.getUserId());
resourceMapper.deleteById(resource.getId());
Assert.assertEquals(resources.size(), 0);
}
@Test
public void testQueryResourceExceptUserId() {
Resource resource = insertOne();
List<Resource> resources = resourceMapper.queryResourceExceptUserId(
11111
);
Assert.assertNotEquals(resources.size(), 0);
resourceMapper.deleteById(resource.getId());
}
@Test
public void testQueryTenantCodeByResourceName() {
Tenant tenant = new Tenant();
tenant.setTenantName("ut tenant ");
tenant.setTenantCode("ut tenant code for resource");
tenantMapper.insert(tenant);
User user = new User();
user.setTenantId(tenant.getId());
user.setUserName("ut user");
userMapper.insert(user);
Resource resource = insertOne();
resource.setUserId(user.getId());
resourceMapper.updateById(resource);
String resource1 = resourceMapper.queryTenantCodeByResourceName(
resource.getAlias()
);
Assert.assertEquals(resource1, "ut tenant code for resource");
resourceMapper.deleteById(resource.getId());
}
}

198
dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/TaskInstanceMapperTest.java

@ -17,48 +17,242 @@
package org.apache.dolphinscheduler.dao.mapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.dolphinscheduler.common.enums.CommandType;
import org.apache.dolphinscheduler.common.enums.ExecutionStatus;
import org.apache.dolphinscheduler.common.enums.Flag;
import org.apache.dolphinscheduler.common.enums.TaskType;
import org.apache.dolphinscheduler.dao.entity.ExecuteStatusCount;
import org.apache.dolphinscheduler.dao.entity.ProcessDefinition;
import org.apache.dolphinscheduler.dao.entity.ProcessInstance;
import org.apache.dolphinscheduler.dao.entity.TaskInstance;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import java.util.Date;
import java.util.List;
@RunWith(SpringRunner.class)
@SpringBootTest
public class TaskInstanceMapperTest {
@Autowired
TaskInstanceMapper taskInstanceMapper;
@Autowired
ProcessDefinitionMapper processDefinitionMapper;
@Autowired
ProcessInstanceMapper processInstanceMapper;
private TaskInstance insertOne(){
//insertOne
TaskInstance taskInstance = new TaskInstance();
taskInstance.setFlag(Flag.YES);
taskInstance.setName("ut task");
taskInstance.setState(ExecutionStatus.RUNNING_EXEUTION);
taskInstance.setStartTime(new Date());
taskInstance.setEndTime(new Date());
taskInstance.setTaskJson("{}");
taskInstance.setTaskType(TaskType.SHELL.toString());
taskInstanceMapper.insert(taskInstance);
return taskInstance;
}
@Test
public void testQueryTaskByProcessIdAndState() {
public void testUpdate(){
//insertOne
TaskInstance taskInstance = insertOne();
//update
int update = taskInstanceMapper.updateById(taskInstance);
Assert.assertEquals(update, 1);
taskInstanceMapper.deleteById(taskInstance.getId());
}
@Test
public void testQueryById() {
public void testDelete(){
TaskInstance taskInstance = insertOne();
int delete = taskInstanceMapper.deleteById(taskInstance.getId());
Assert.assertEquals(delete, 1);
}
@Test
public void testQuery() {
TaskInstance taskInstance = insertOne();
//query
List<TaskInstance> taskInstances = taskInstanceMapper.selectList(null);
taskInstanceMapper.deleteById(taskInstance.getId());
Assert.assertNotEquals(taskInstances.size(), 0);
}
@Test
public void testQueryTaskByProcessIdAndState() {
TaskInstance task = insertOne();
task.setProcessInstanceId(110);
taskInstanceMapper.updateById(task);
List<Integer> taskInstances = taskInstanceMapper.queryTaskByProcessIdAndState(
task.getProcessInstanceId(),
ExecutionStatus.RUNNING_EXEUTION.ordinal()
);
taskInstanceMapper.deleteById(task.getId());
Assert.assertNotEquals(taskInstances.size(), 0);
}
@Test
public void testFindValidTaskListByProcessId() {
TaskInstance task = insertOne();
TaskInstance task2 = insertOne();
task.setProcessInstanceId(110);
task2.setProcessInstanceId(110);
taskInstanceMapper.updateById(task);
taskInstanceMapper.updateById(task2);
List<TaskInstance> taskInstances = taskInstanceMapper.findValidTaskListByProcessId(
task.getProcessInstanceId(),
Flag.YES
);
task2.setFlag(Flag.NO);
taskInstanceMapper.updateById(task2);
List<TaskInstance> taskInstances1 = taskInstanceMapper.findValidTaskListByProcessId(task.getProcessInstanceId(),
Flag.NO);
taskInstanceMapper.deleteById(task2.getId());
taskInstanceMapper.deleteById(task.getId());
Assert.assertNotEquals(taskInstances.size(), 0);
Assert.assertNotEquals(taskInstances1.size(), 0 );
}
@Test
public void testQueryByHostAndStatus() {
TaskInstance task = insertOne();
task.setHost("111.111.11.11");
taskInstanceMapper.updateById(task);
List<TaskInstance> taskInstances = taskInstanceMapper.queryByHostAndStatus(
task.getHost(), new int[]{ExecutionStatus.RUNNING_EXEUTION.ordinal()}
);
taskInstanceMapper.deleteById(task.getId());
Assert.assertNotEquals(taskInstances.size(), 0);
}
@Test
public void testSetFailoverByHostAndStateArray() {
TaskInstance task = insertOne();
task.setHost("111.111.11.11");
taskInstanceMapper.updateById(task);
int setResult = taskInstanceMapper.setFailoverByHostAndStateArray(
task.getHost(),
new int[]{ExecutionStatus.RUNNING_EXEUTION.ordinal()},
ExecutionStatus.NEED_FAULT_TOLERANCE
);
taskInstanceMapper.deleteById(task.getId());
Assert.assertNotEquals(setResult, 0);
}
@Test
public void testQueryByInstanceIdAndName() {
TaskInstance task = insertOne();
task.setHost("111.111.11.11");
taskInstanceMapper.updateById(task);
TaskInstance taskInstance = taskInstanceMapper.queryByInstanceIdAndName(
task.getProcessInstanceId(),
task.getName()
);
taskInstanceMapper.deleteById(task.getId());
Assert.assertNotEquals(taskInstance, null);
}
@Test
public void testCountTask() {
TaskInstance task = insertOne();
ProcessDefinition definition = new ProcessDefinition();
definition.setProjectId(1111);
processDefinitionMapper.insert(definition);
task.setProcessDefinitionId(definition.getId());
taskInstanceMapper.updateById(task);
int countTask = taskInstanceMapper.countTask(
new Integer[0],
new int[0]
);
int countTask2 = taskInstanceMapper.countTask(
new Integer[]{definition.getProjectId()},
new int[]{task.getId()}
);
taskInstanceMapper.deleteById(task.getId());
processDefinitionMapper.deleteById(definition.getId());
Assert.assertNotEquals(countTask, 0);
Assert.assertNotEquals(countTask2, 0);
}
@Test
public void testCountTaskInstanceStateByUser() {
TaskInstance task = insertOne();
ProcessDefinition definition = new ProcessDefinition();
definition.setProjectId(1111);
processDefinitionMapper.insert(definition);
task.setProcessDefinitionId(definition.getId());
taskInstanceMapper.updateById(task);
List<ExecuteStatusCount> count = taskInstanceMapper.countTaskInstanceStateByUser(
null, null,
new Integer[]{definition.getProjectId()}
);
processDefinitionMapper.deleteById(definition.getId());
taskInstanceMapper.deleteById(task.getId());
}
@Test
public void testQueryTaskInstanceListPaging() {
TaskInstance task = insertOne();
ProcessDefinition definition = new ProcessDefinition();
definition.setProjectId(1111);
processDefinitionMapper.insert(definition);
ProcessInstance processInstance = new ProcessInstance();
processInstance.setProcessDefinitionId(definition.getId());
processInstance.setState(ExecutionStatus.RUNNING_EXEUTION);
processInstance.setName("ut process");
processInstance.setStartTime(new Date());
processInstance.setEndTime(new Date());
processInstance.setCommandType(CommandType.START_PROCESS);
processInstanceMapper.insert(processInstance);
task.setProcessDefinitionId(definition.getId());
task.setProcessInstanceId(processInstance.getId());
taskInstanceMapper.updateById(task);
Page<TaskInstance> page = new Page(1,3);
IPage<TaskInstance> taskInstanceIPage = taskInstanceMapper.queryTaskInstanceListPaging(
page,
definition.getProjectId(),
task.getProcessInstanceId(),
"",
"",
new int[0],
"",
null,null
);
processInstanceMapper.deleteById(processInstance.getId());
taskInstanceMapper.deleteById(task.getId());
processDefinitionMapper.deleteById(definition.getId());
Assert.assertNotEquals(taskInstanceIPage.getTotal(), 0);
}
}

8
dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/TenantMapperTest.java

@ -111,14 +111,22 @@ public class TenantMapperTest {
@Test
public void testQueryTenantPaging() {
Queue queue = new Queue();
queue.setQueue("ut queue");
queue.setQueueName("ut queue name");
queueMapper.insert(queue);
Tenant tenant = insertOne();
tenant.setTenantCode("ut code");
tenant.setTenantName("ut name");
tenant.setQueueId(queue.getId());
tenantMapper.updateById(tenant);
Page<Tenant> page = new Page(1,3);
IPage<Tenant> tenantIPage = tenantMapper.queryTenantPaging(page, tenant.getTenantName());
queueMapper.deleteById(queue.getId());
tenantMapper.deleteById(tenant.getId());
Assert.assertNotEquals(tenantIPage.getTotal(), 0);
}

2
dolphinscheduler-server/src/main/java/org/apache/dolphinscheduler/server/worker/task/AbstractCommandExecutor.java

@ -153,7 +153,7 @@ public abstract class AbstractCommandExecutor {
// task instance id
int taskInstId = Integer.parseInt(taskAppId.split("_")[2]);
processDao.updatePidByTaskInstId(taskInstId, pid);
processDao.updatePidByTaskInstId(taskInstId, pid, "");
logger.info("process start, process id is: {}", pid);

8
dolphinscheduler-server/src/test/java/org/apache/dolphinscheduler/server/master/AlertManagerTest.java

@ -67,8 +67,8 @@ public class AlertManagerTest {
// fault task instance
TaskInstance toleranceTask1 = taskInstanceMapper.queryById(5038);
TaskInstance toleranceTask2 = taskInstanceMapper.queryById(5039);
TaskInstance toleranceTask1 = taskInstanceMapper.selectById(5038);
TaskInstance toleranceTask2 = taskInstanceMapper.selectById(5039);
List<TaskInstance> toleranceTaskList = new ArrayList<>(2);
toleranceTaskList.add(toleranceTask1);
@ -92,9 +92,9 @@ public class AlertManagerTest {
// fault task instance
TaskInstance toleranceTask1 = taskInstanceMapper.queryById(5038);
TaskInstance toleranceTask1 = taskInstanceMapper.selectById(5038);
toleranceTask1.setState(ExecutionStatus.FAILURE);
TaskInstance toleranceTask2 = taskInstanceMapper.queryById(5039);
TaskInstance toleranceTask2 = taskInstanceMapper.selectById(5039);
toleranceTask2.setState(ExecutionStatus.FAILURE);
List<TaskInstance> toleranceTaskList = new ArrayList<>(2);

Loading…
Cancel
Save