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")
public Result queryTaskDefinitionListPaging(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@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 = "taskType", required = false) String taskType,
@RequestParam(value = "taskExecuteType", required = false, defaultValue = "BATCH") TaskExecuteType taskExecuteType,
@ -359,9 +358,8 @@ public class TaskDefinitionController extends BaseController {
if (!result.checkResult()) {
return result;
}
searchWorkflowName = ParameterUtils.handleEscapes(searchWorkflowName);
searchTaskName = ParameterUtils.handleEscapes(searchTaskName);
return taskDefinitionService.queryTaskDefinitionListPaging(loginUser, projectCode, searchWorkflowName,
return taskDefinitionService.queryTaskDefinitionListPaging(loginUser, projectCode,
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 projectCode project code
* @param searchWorkflowName searchWorkflowName
* @param searchTaskName searchTaskName
* @param taskType taskType
* @param taskExecuteType taskExecuteType
@ -227,7 +226,6 @@ public interface TaskDefinitionService {
*/
Result queryTaskDefinitionListPaging(User loginUser,
long projectCode,
String searchWorkflowName,
String searchTaskName,
String taskType,
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
public Result queryTaskDefinitionListPaging(User loginUser,
long projectCode,
String searchWorkflowName,
String searchTaskName,
String taskType,
TaskExecuteType taskExecuteType,
@ -1063,12 +1062,33 @@ public class TaskDefinitionServiceImpl extends BaseServiceImpl implements TaskDe
}
taskType = taskType == null ? StringUtils.EMPTY : taskType;
Page<TaskMainInfo> page = new Page<>(pageNo, pageSize);
IPage<TaskMainInfo> taskMainInfoIPage =
taskDefinitionMapper.queryDefineListPaging(page, projectCode, searchWorkflowName,
searchTaskName, taskType, taskExecuteType);
List<TaskMainInfo> records = taskMainInfoIPage.getRecords();
// first, query task code by page size
IPage<TaskMainInfo> taskMainInfoIPage = taskDefinitionMapper.queryDefineListPaging(page, projectCode,
searchTaskName, taskType, taskExecuteType);
// 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)) {
// task code and task info map
Map<Long, TaskMainInfo> taskMainInfoMap = new HashMap<>();
// construct task code and relevant upstream task list map
for (TaskMainInfo info : records) {
taskMainInfoMap.compute(info.getTaskCode(), (k, v) -> {
if (v == null) {
@ -1087,14 +1107,14 @@ public class TaskDefinitionServiceImpl extends BaseServiceImpl implements TaskDe
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()));
}
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 fillWorkflowInfo(long projectCode, IPage<TaskMainInfo> taskMainInfoIPage) {
}
@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.service.impl.ProjectServiceImpl;
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.enums.Flag;
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.TaskDefinition;
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.mapper.ProcessDefinitionMapper;
import org.apache.dolphinscheduler.dao.mapper.ProcessTaskRelationMapper;
@ -54,6 +56,7 @@ import org.apache.dolphinscheduler.service.task.TaskPluginManager;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@ -67,6 +70,9 @@ import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.junit.jupiter.MockitoExtension;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@ExtendWith(MockitoExtension.class)
public class TaskDefinitionServiceImplTest {
@ -306,6 +312,33 @@ public class TaskDefinitionServiceImplTest {
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
public void testReleaseTaskDefinition() {
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 projectCode projectCode
* @param searchWorkflowName searchWorkflowName
* @param searchTaskName searchTaskName
* @param taskType taskType
* @param taskExecuteType taskExecuteType
@ -119,11 +118,19 @@ public interface TaskDefinitionMapper extends BaseMapper<TaskDefinition> {
*/
IPage<TaskMainInfo> queryDefineListPaging(IPage<TaskMainInfo> page,
@Param("projectCode") long projectCode,
@Param("searchWorkflowName") String searchWorkflowName,
@Param("searchTaskName") String searchTaskName,
@Param("taskType") String taskType,
@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
*

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

@ -109,13 +109,8 @@
</foreach>
</insert>
<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,
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
select td.code task_code
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}
<if test="taskType != ''">
and td.task_type = #{taskType}
@ -123,14 +118,26 @@
<if test="taskExecuteType != null">
and td.task_execute_type = #{taskExecuteType.code}
</if>
<if test="searchWorkflowName != null and searchWorkflowName != ''">
and pd.name like concat('%', #{searchWorkflowName}, '%')
</if>
<if test="searchTaskName != null and searchTaskName != ''">
and td.name like concat('%', #{searchTaskName}, '%')
</if>
order by td.update_time desc
</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
<include refid="baseSql"/>

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

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

Loading…
Cancel
Save