Browse Source

[Improvement] optimization task definition & fix in the task definition list, if one task have more pre task, the task list can't show all task (#13106)

* fix in the task definition list, if one task have more pre task, the task list can't show all task

* modify code style

* in the task definition, delete search workflow name filter, and  fix in the task definition list, if one task have more pre task, the task list can't show all task

* modify code style

* modify code style

* delete useless select sql

* add annotation

Co-authored-by: fanwanlong <fanwanlong@kezaihui.com>
3.2.0-release
jackfanwan 2 years ago committed by GitHub
parent
commit
cb8d125e0f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/TaskDefinitionController.java
  2. 2
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/TaskDefinitionService.java
  3. 42
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/TaskDefinitionServiceImpl.java
  4. 33
      dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/TaskDefinitionServiceImplTest.java
  5. 11
      dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/TaskDefinitionMapper.java
  6. 25
      dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/TaskDefinitionMapper.xml
  7. 15
      dolphinscheduler-ui/src/views/projects/task/definition/batch-task.tsx

4
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/TaskDefinitionController.java

@ -349,7 +349,6 @@ public class TaskDefinitionController extends BaseController {
@AccessLogAnnotation(ignoreRequestArgs = "loginUser") @AccessLogAnnotation(ignoreRequestArgs = "loginUser")
public Result queryTaskDefinitionListPaging(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser, public Result queryTaskDefinitionListPaging(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@Parameter(name = "projectCode", description = "PROJECT_CODE", required = true) @PathVariable long projectCode, @Parameter(name = "projectCode", description = "PROJECT_CODE", required = true) @PathVariable long projectCode,
@RequestParam(value = "searchWorkflowName", required = false) String searchWorkflowName,
@RequestParam(value = "searchTaskName", required = false) String searchTaskName, @RequestParam(value = "searchTaskName", required = false) String searchTaskName,
@RequestParam(value = "taskType", required = false) String taskType, @RequestParam(value = "taskType", required = false) String taskType,
@RequestParam(value = "taskExecuteType", required = false, defaultValue = "BATCH") TaskExecuteType taskExecuteType, @RequestParam(value = "taskExecuteType", required = false, defaultValue = "BATCH") TaskExecuteType taskExecuteType,
@ -359,9 +358,8 @@ public class TaskDefinitionController extends BaseController {
if (!result.checkResult()) { if (!result.checkResult()) {
return result; return result;
} }
searchWorkflowName = ParameterUtils.handleEscapes(searchWorkflowName);
searchTaskName = ParameterUtils.handleEscapes(searchTaskName); searchTaskName = ParameterUtils.handleEscapes(searchTaskName);
return taskDefinitionService.queryTaskDefinitionListPaging(loginUser, projectCode, searchWorkflowName, return taskDefinitionService.queryTaskDefinitionListPaging(loginUser, projectCode,
searchTaskName, taskType, taskExecuteType, pageNo, pageSize); searchTaskName, taskType, taskExecuteType, pageNo, pageSize);
} }

2
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/TaskDefinitionService.java

@ -217,7 +217,6 @@ public interface TaskDefinitionService {
* *
* @param loginUser login user * @param loginUser login user
* @param projectCode project code * @param projectCode project code
* @param searchWorkflowName searchWorkflowName
* @param searchTaskName searchTaskName * @param searchTaskName searchTaskName
* @param taskType taskType * @param taskType taskType
* @param taskExecuteType taskExecuteType * @param taskExecuteType taskExecuteType
@ -227,7 +226,6 @@ public interface TaskDefinitionService {
*/ */
Result queryTaskDefinitionListPaging(User loginUser, Result queryTaskDefinitionListPaging(User loginUser,
long projectCode, long projectCode,
String searchWorkflowName,
String searchTaskName, String searchTaskName,
String taskType, String taskType,
TaskExecuteType taskExecuteType, TaskExecuteType taskExecuteType,

42
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/TaskDefinitionServiceImpl.java

@ -1045,7 +1045,6 @@ public class TaskDefinitionServiceImpl extends BaseServiceImpl implements TaskDe
@Override @Override
public Result queryTaskDefinitionListPaging(User loginUser, public Result queryTaskDefinitionListPaging(User loginUser,
long projectCode, long projectCode,
String searchWorkflowName,
String searchTaskName, String searchTaskName,
String taskType, String taskType,
TaskExecuteType taskExecuteType, TaskExecuteType taskExecuteType,
@ -1063,12 +1062,33 @@ public class TaskDefinitionServiceImpl extends BaseServiceImpl implements TaskDe
} }
taskType = taskType == null ? StringUtils.EMPTY : taskType; taskType = taskType == null ? StringUtils.EMPTY : taskType;
Page<TaskMainInfo> page = new Page<>(pageNo, pageSize); Page<TaskMainInfo> page = new Page<>(pageNo, pageSize);
IPage<TaskMainInfo> taskMainInfoIPage = // first, query task code by page size
taskDefinitionMapper.queryDefineListPaging(page, projectCode, searchWorkflowName, IPage<TaskMainInfo> taskMainInfoIPage = taskDefinitionMapper.queryDefineListPaging(page, projectCode,
searchTaskName, taskType, taskExecuteType); searchTaskName, taskType, taskExecuteType);
List<TaskMainInfo> records = taskMainInfoIPage.getRecords(); // then, query task relevant info by task code
fillRecords(projectCode, taskMainInfoIPage);
PageInfo<TaskMainInfo> pageInfo = new PageInfo<>(pageNo, pageSize);
pageInfo.setTotal((int) taskMainInfoIPage.getTotal());
pageInfo.setTotalList(taskMainInfoIPage.getRecords());
result.setData(pageInfo);
putMsg(result, Status.SUCCESS);
return result;
}
private void fillRecords(long projectCode, IPage<TaskMainInfo> taskMainInfoIPage) {
List<TaskMainInfo> records = Collections.emptyList();
if (CollectionUtils.isNotEmpty(taskMainInfoIPage.getRecords())) {
// query task relevant info by task code
records = taskDefinitionMapper.queryDefineListByCodeList(projectCode,
taskMainInfoIPage.getRecords().stream().map(TaskMainInfo::getTaskCode)
.collect(Collectors.toList()));
}
// because first step, so need init records
taskMainInfoIPage.setRecords(Collections.emptyList());
if (CollectionUtils.isNotEmpty(records)) { if (CollectionUtils.isNotEmpty(records)) {
// task code and task info map
Map<Long, TaskMainInfo> taskMainInfoMap = new HashMap<>(); Map<Long, TaskMainInfo> taskMainInfoMap = new HashMap<>();
// construct task code and relevant upstream task list map
for (TaskMainInfo info : records) { for (TaskMainInfo info : records) {
taskMainInfoMap.compute(info.getTaskCode(), (k, v) -> { taskMainInfoMap.compute(info.getTaskCode(), (k, v) -> {
if (v == null) { if (v == null) {
@ -1087,14 +1107,14 @@ public class TaskDefinitionServiceImpl extends BaseServiceImpl implements TaskDe
return v; return v;
}); });
} }
// because taskMainInfoMap's value is TaskMainInfo,
// TaskMainInfo have task code info, so only need gain taskMainInfoMap's values
taskMainInfoIPage.setRecords(Lists.newArrayList(taskMainInfoMap.values())); taskMainInfoIPage.setRecords(Lists.newArrayList(taskMainInfoMap.values()));
} }
PageInfo<TaskMainInfo> pageInfo = new PageInfo<>(pageNo, pageSize); }
pageInfo.setTotal((int) taskMainInfoIPage.getTotal());
pageInfo.setTotalList(taskMainInfoIPage.getRecords()); private void fillWorkflowInfo(long projectCode, IPage<TaskMainInfo> taskMainInfoIPage) {
result.setData(pageInfo);
putMsg(result, Status.SUCCESS);
return result;
} }
@Override @Override

33
dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/TaskDefinitionServiceImplTest.java

@ -32,6 +32,7 @@ import org.apache.dolphinscheduler.api.enums.Status;
import org.apache.dolphinscheduler.api.exceptions.ServiceException; import org.apache.dolphinscheduler.api.exceptions.ServiceException;
import org.apache.dolphinscheduler.api.service.impl.ProjectServiceImpl; import org.apache.dolphinscheduler.api.service.impl.ProjectServiceImpl;
import org.apache.dolphinscheduler.api.service.impl.TaskDefinitionServiceImpl; import org.apache.dolphinscheduler.api.service.impl.TaskDefinitionServiceImpl;
import org.apache.dolphinscheduler.api.utils.Result;
import org.apache.dolphinscheduler.common.constants.Constants; import org.apache.dolphinscheduler.common.constants.Constants;
import org.apache.dolphinscheduler.common.enums.Flag; import org.apache.dolphinscheduler.common.enums.Flag;
import org.apache.dolphinscheduler.common.enums.Priority; import org.apache.dolphinscheduler.common.enums.Priority;
@ -43,6 +44,7 @@ import org.apache.dolphinscheduler.dao.entity.ProcessTaskRelation;
import org.apache.dolphinscheduler.dao.entity.Project; import org.apache.dolphinscheduler.dao.entity.Project;
import org.apache.dolphinscheduler.dao.entity.TaskDefinition; import org.apache.dolphinscheduler.dao.entity.TaskDefinition;
import org.apache.dolphinscheduler.dao.entity.TaskDefinitionLog; import org.apache.dolphinscheduler.dao.entity.TaskDefinitionLog;
import org.apache.dolphinscheduler.dao.entity.TaskMainInfo;
import org.apache.dolphinscheduler.dao.entity.User; import org.apache.dolphinscheduler.dao.entity.User;
import org.apache.dolphinscheduler.dao.mapper.ProcessDefinitionMapper; import org.apache.dolphinscheduler.dao.mapper.ProcessDefinitionMapper;
import org.apache.dolphinscheduler.dao.mapper.ProcessTaskRelationMapper; import org.apache.dolphinscheduler.dao.mapper.ProcessTaskRelationMapper;
@ -54,6 +56,7 @@ import org.apache.dolphinscheduler.service.task.TaskPluginManager;
import java.text.MessageFormat; import java.text.MessageFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -67,6 +70,9 @@ import org.mockito.Mock;
import org.mockito.Mockito; import org.mockito.Mockito;
import org.mockito.junit.jupiter.MockitoExtension; import org.mockito.junit.jupiter.MockitoExtension;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@ExtendWith(MockitoExtension.class) @ExtendWith(MockitoExtension.class)
public class TaskDefinitionServiceImplTest { public class TaskDefinitionServiceImplTest {
@ -306,6 +312,33 @@ public class TaskDefinitionServiceImplTest {
Assertions.assertEquals(Status.SUCCESS, genTaskCodeList.get(Constants.STATUS)); Assertions.assertEquals(Status.SUCCESS, genTaskCodeList.get(Constants.STATUS));
} }
@Test
public void testQueryTaskDefinitionListPaging() {
Project project = getProject();
Map<String, Object> checkResult = new HashMap<>();
checkResult.put(Constants.STATUS, Status.SUCCESS);
Integer pageNo = 1;
Integer pageSize = 10;
IPage<TaskMainInfo> taskMainInfoIPage = new Page<>();
TaskMainInfo taskMainInfo = new TaskMainInfo();
taskMainInfo.setTaskCode(TASK_CODE);
taskMainInfo.setUpstreamTaskCode(4L);
taskMainInfo.setUpstreamTaskName("4");
taskMainInfoIPage.setRecords(Collections.singletonList(taskMainInfo));
taskMainInfoIPage.setTotal(10L);
Mockito.when(projectMapper.queryByCode(PROJECT_CODE)).thenReturn(project);
Mockito.when(projectService.checkProjectAndAuth(user, project, PROJECT_CODE, TASK_DEFINITION))
.thenReturn(checkResult);
Mockito.when(taskDefinitionMapper.queryDefineListPaging(Mockito.any(Page.class), Mockito.anyLong(),
Mockito.isNull(), Mockito.anyString(), Mockito.isNull()))
.thenReturn(taskMainInfoIPage);
Mockito.when(taskDefinitionMapper.queryDefineListByCodeList(PROJECT_CODE, Collections.singletonList(3L)))
.thenReturn(Collections.singletonList(taskMainInfo));
Result result = taskDefinitionService.queryTaskDefinitionListPaging(user, PROJECT_CODE,
null, null, null, pageNo, pageSize);
Assertions.assertEquals(Status.SUCCESS.getMsg(), result.getMsg());
}
@Test @Test
public void testReleaseTaskDefinition() { public void testReleaseTaskDefinition() {
Mockito.when(projectMapper.queryByCode(PROJECT_CODE)).thenReturn(getProject()); Mockito.when(projectMapper.queryByCode(PROJECT_CODE)).thenReturn(getProject());

11
dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/TaskDefinitionMapper.java

@ -111,7 +111,6 @@ public interface TaskDefinitionMapper extends BaseMapper<TaskDefinition> {
* *
* @param page page * @param page page
* @param projectCode projectCode * @param projectCode projectCode
* @param searchWorkflowName searchWorkflowName
* @param searchTaskName searchTaskName * @param searchTaskName searchTaskName
* @param taskType taskType * @param taskType taskType
* @param taskExecuteType taskExecuteType * @param taskExecuteType taskExecuteType
@ -119,11 +118,19 @@ public interface TaskDefinitionMapper extends BaseMapper<TaskDefinition> {
*/ */
IPage<TaskMainInfo> queryDefineListPaging(IPage<TaskMainInfo> page, IPage<TaskMainInfo> queryDefineListPaging(IPage<TaskMainInfo> page,
@Param("projectCode") long projectCode, @Param("projectCode") long projectCode,
@Param("searchWorkflowName") String searchWorkflowName,
@Param("searchTaskName") String searchTaskName, @Param("searchTaskName") String searchTaskName,
@Param("taskType") String taskType, @Param("taskType") String taskType,
@Param("taskExecuteType") TaskExecuteType taskExecuteType); @Param("taskExecuteType") TaskExecuteType taskExecuteType);
/**
* task main info
* @param projectCode project code
* @param codeList code list
* @return task main info
*/
List<TaskMainInfo> queryDefineListByCodeList(@Param("projectCode") long projectCode,
@Param("codeList") List<Long> codeList);
/** /**
* query task definition by code list * query task definition by code list
* *

25
dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/TaskDefinitionMapper.xml

@ -109,13 +109,8 @@
</foreach> </foreach>
</insert> </insert>
<select id="queryDefineListPaging" resultType="org.apache.dolphinscheduler.dao.entity.TaskMainInfo"> <select id="queryDefineListPaging" resultType="org.apache.dolphinscheduler.dao.entity.TaskMainInfo">
select td.name task_name,td.code task_code,td.version task_version,td.task_type,td.create_time task_create_time,td.update_time task_update_time, select td.code task_code
pd.code process_definition_code,pd.version process_definition_version,pd.name process_definition_name,pd.release_state process_release_state,
pt.pre_task_code upstream_task_code,up.name upstream_task_name
from t_ds_task_definition td from t_ds_task_definition td
LEFT JOIN t_ds_process_task_relation pt ON td.code = pt.post_task_code and td.version=pt.post_task_version
LEFT JOIN t_ds_process_definition pd ON pt.process_definition_code = pd.code and pt.process_definition_version=pd.version
LEFT JOIN t_ds_task_definition up on pt.pre_task_code=up.code and pt.pre_task_version=up.version
WHERE td.project_code = #{projectCode} WHERE td.project_code = #{projectCode}
<if test="taskType != ''"> <if test="taskType != ''">
and td.task_type = #{taskType} and td.task_type = #{taskType}
@ -123,14 +118,26 @@
<if test="taskExecuteType != null"> <if test="taskExecuteType != null">
and td.task_execute_type = #{taskExecuteType.code} and td.task_execute_type = #{taskExecuteType.code}
</if> </if>
<if test="searchWorkflowName != null and searchWorkflowName != ''">
and pd.name like concat('%', #{searchWorkflowName}, '%')
</if>
<if test="searchTaskName != null and searchTaskName != ''"> <if test="searchTaskName != null and searchTaskName != ''">
and td.name like concat('%', #{searchTaskName}, '%') and td.name like concat('%', #{searchTaskName}, '%')
</if> </if>
order by td.update_time desc order by td.update_time desc
</select> </select>
<select id="queryDefineListByCodeList" resultType="org.apache.dolphinscheduler.dao.entity.TaskMainInfo">
select td.name task_name,td.code task_code,td.version task_version,td.task_type,td.create_time task_create_time,td.update_time task_update_time,
pd.code process_definition_code,pd.version process_definition_version,pd.name process_definition_name,pd.release_state process_release_state,
pt.pre_task_code upstream_task_code,up.name upstream_task_name
from t_ds_task_definition td
LEFT JOIN t_ds_process_task_relation pt ON td.code = pt.post_task_code and td.version=pt.post_task_version
LEFT JOIN t_ds_process_definition pd ON pt.process_definition_code = pd.code and pt.process_definition_version=pd.version
LEFT JOIN t_ds_task_definition up on pt.pre_task_code=up.code and pt.pre_task_version=up.version
WHERE td.project_code = #{projectCode} and td.code in
<foreach collection="codeList" item="code" open="(" separator="," close=")">
#{code}
</foreach>
</select>
<select id="queryByCodeList" resultType="org.apache.dolphinscheduler.dao.entity.TaskDefinition"> <select id="queryByCodeList" resultType="org.apache.dolphinscheduler.dao.entity.TaskDefinition">
select select
<include refid="baseSql"/> <include refid="baseSql"/>

15
dolphinscheduler-ui/src/views/projects/task/definition/batch-task.tsx

@ -60,7 +60,6 @@ const BatchTaskDefinition = defineComponent({
pageSize: variables.pageSize, pageSize: variables.pageSize,
pageNo: variables.page, pageNo: variables.page,
searchTaskName: variables.searchTaskName, searchTaskName: variables.searchTaskName,
searchWorkflowName: variables.searchWorkflowName,
taskType: variables.taskType taskType: variables.taskType
}) })
} }
@ -80,11 +79,6 @@ const BatchTaskDefinition = defineComponent({
onSearch() onSearch()
} }
const onClearSearchWorkflowName = () => {
variables.searchWorkflowName = null
onSearch()
}
const onClearSearchTaskType = () => { const onClearSearchTaskType = () => {
variables.taskType = null variables.taskType = null
onSearch() onSearch()
@ -126,7 +120,6 @@ const BatchTaskDefinition = defineComponent({
...toRefs(task), ...toRefs(task),
onSearch, onSearch,
onClearSearchTaskName, onClearSearchTaskName,
onClearSearchWorkflowName,
onClearSearchTaskType, onClearSearchTaskType,
requestData, requestData,
onUpdatePageSize, onUpdatePageSize,
@ -165,14 +158,6 @@ const BatchTaskDefinition = defineComponent({
placeholder={t('project.task.task_name')} placeholder={t('project.task.task_name')}
onClear={this.onClearSearchTaskName} onClear={this.onClearSearchTaskName}
/> />
<NInput
allowInput={this.trim}
size='small'
clearable
v-model={[this.searchWorkflowName, 'value']}
placeholder={t('project.task.workflow_name')}
onClear={this.onClearSearchWorkflowName}
/>
<NSelect <NSelect
v-model={[this.taskType, 'value']} v-model={[this.taskType, 'value']}
size='small' size='small'

Loading…
Cancel
Save