[Feature][workflow list edit] add task list page api (#7743)

* fix 7597

* fix copy bug

* add task list page api

* fix total

* fix total
This commit is contained in:
JinYong Li 2021-12-31 13:39:20 +08:00 committed by GitHub
parent 1f97a62411
commit d7d13f7f51
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 267 additions and 61 deletions

View File

@ -34,6 +34,7 @@ import org.apache.dolphinscheduler.api.service.TaskDefinitionService;
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.TaskType;
import org.apache.dolphinscheduler.common.utils.ParameterUtils;
import org.apache.dolphinscheduler.dao.entity.User;
@ -257,18 +258,19 @@ public class TaskDefinitionController extends BaseController {
*
* @param loginUser login user
* @param projectCode project code
* @param searchWorkflowName searchWorkflowName
* @param searchTaskName searchTaskName
* @param taskType taskType
* @param searchVal search value
* @param userId user id
* @param pageNo page number
* @param pageSize page size
* @return task definition page
*/
@ApiOperation(value = "queryTaskDefinitionListPaging", notes = "QUERY_TASK_DEFINITION_LIST_PAGING_NOTES")
@ApiImplicitParams({
@ApiImplicitParam(name = "taskType", value = "TASK_TYPE", required = false, type = "String"),
@ApiImplicitParam(name = "searchVal", value = "SEARCH_VAL", required = false, type = "String"),
@ApiImplicitParam(name = "userId", value = "USER_ID", required = false, dataType = "Int", example = "100"),
@ApiImplicitParam(name = "projectCode", value = "PROJECT_CODE", required = false, type = "Long"),
@ApiImplicitParam(name = "searchWorkflowName", value = "SEARCH_WORKFLOW_NAME", required = false, type = "String"),
@ApiImplicitParam(name = "searchTaskName", value = "SEARCH_TASK_NAME", required = false, type = "String"),
@ApiImplicitParam(name = "taskType", value = "TASK_TYPE", required = true, dataType = "TaskType", example = "SHELL"),
@ApiImplicitParam(name = "pageNo", value = "PAGE_NO", required = true, dataType = "Int", example = "1"),
@ApiImplicitParam(name = "pageSize", value = "PAGE_SIZE", required = true, dataType = "Int", example = "10")
})
@ -278,18 +280,18 @@ public class TaskDefinitionController extends BaseController {
@AccessLogAnnotation(ignoreRequestArgs = "loginUser")
public Result queryTaskDefinitionListPaging(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
@ApiParam(name = "projectCode", value = "PROJECT_CODE", required = true) @PathVariable long projectCode,
@RequestParam(value = "taskType", required = false) String taskType,
@RequestParam(value = "searchVal", required = false) String searchVal,
@RequestParam(value = "userId", required = false, defaultValue = "0") Integer userId,
@RequestParam(value = "searchWorkflowName", required = false) String searchWorkflowName,
@RequestParam(value = "searchTaskName", required = false) String searchTaskName,
@RequestParam(value = "taskType", required = true) TaskType taskType,
@RequestParam("pageNo") Integer pageNo,
@RequestParam("pageSize") Integer pageSize) {
Result result = checkPageParams(pageNo, pageSize);
if (!result.checkResult()) {
return result;
}
taskType = ParameterUtils.handleEscapes(taskType);
searchVal = ParameterUtils.handleEscapes(searchVal);
return taskDefinitionService.queryTaskDefinitionListPaging(loginUser, projectCode, taskType, searchVal, userId, pageNo, pageSize);
searchWorkflowName = ParameterUtils.handleEscapes(searchWorkflowName);
searchTaskName = ParameterUtils.handleEscapes(searchTaskName);
return taskDefinitionService.queryTaskDefinitionListPaging(loginUser, projectCode, searchWorkflowName, searchTaskName, taskType, pageNo, pageSize);
}
/**

View File

@ -19,6 +19,7 @@ package org.apache.dolphinscheduler.api.service;
import org.apache.dolphinscheduler.api.utils.Result;
import org.apache.dolphinscheduler.common.enums.ReleaseState;
import org.apache.dolphinscheduler.common.enums.TaskType;
import org.apache.dolphinscheduler.dao.entity.User;
import java.util.Map;
@ -134,18 +135,18 @@ public interface TaskDefinitionService {
*
* @param loginUser login user
* @param projectCode project code
* @param searchWorkflowName searchWorkflowName
* @param searchTaskName searchTaskName
* @param taskType taskType
* @param searchVal search value
* @param userId user id
* @param pageNo page number
* @param pageSize page size
* @return task definition page
*/
Result queryTaskDefinitionListPaging(User loginUser,
long projectCode,
String taskType,
String searchVal,
Integer userId,
String searchWorkflowName,
String searchTaskName,
TaskType taskType,
Integer pageNo,
Integer pageSize);

View File

@ -77,8 +77,6 @@ import org.apache.dolphinscheduler.service.process.ProcessService;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.hadoop.mapred.TaskLog.LogName;
import org.apache.yetus.audience.InterfaceAudience.Public;
import java.io.BufferedOutputStream;
import java.io.IOException;
@ -1398,6 +1396,7 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
putMsg(result, Status.NOT_SUPPORT_COPY_TASK_TYPE, taskDefinitionLog.getTaskType());
throw new ServiceException(Status.NOT_SUPPORT_COPY_TASK_TYPE);
}
taskDefinitionLog.setProjectCode(targetProjectCode);
taskDefinitionLog.setCode(0L);
taskDefinitionLog.setVersion(0);
taskDefinitionLog.setName(taskDefinitionLog.getName() + "_copy_" + DateUtils.getCurrentTimeStamp());

View File

@ -28,6 +28,7 @@ import org.apache.dolphinscheduler.common.Constants;
import org.apache.dolphinscheduler.common.enums.AuthorizationType;
import org.apache.dolphinscheduler.common.enums.Flag;
import org.apache.dolphinscheduler.common.enums.ReleaseState;
import org.apache.dolphinscheduler.common.enums.TaskType;
import org.apache.dolphinscheduler.common.utils.CodeGenerateUtils;
import org.apache.dolphinscheduler.common.utils.CodeGenerateUtils.CodeGenerateException;
import org.apache.dolphinscheduler.common.utils.JSONUtils;
@ -36,6 +37,7 @@ import org.apache.dolphinscheduler.dao.entity.ProcessTaskRelationLog;
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.ProcessTaskRelationLogMapper;
import org.apache.dolphinscheduler.dao.mapper.ProcessTaskRelationMapper;
@ -65,6 +67,7 @@ import org.springframework.transaction.annotation.Transactional;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.google.common.collect.Lists;
/**
* task definition service impl
@ -440,9 +443,9 @@ public class TaskDefinitionServiceImpl extends BaseServiceImpl implements TaskDe
@Override
public Result queryTaskDefinitionListPaging(User loginUser,
long projectCode,
String taskType,
String searchVal,
Integer userId,
String searchWorkflowName,
String searchTaskName,
TaskType taskType,
Integer pageNo,
Integer pageSize) {
Result result = new Result();
@ -454,24 +457,36 @@ public class TaskDefinitionServiceImpl extends BaseServiceImpl implements TaskDe
putMsg(result, resultStatus);
return result;
}
if (StringUtils.isNotBlank(taskType)) {
taskType = taskType.toUpperCase();
}
Page<TaskDefinition> page = new Page<>(pageNo, pageSize);
IPage<TaskDefinition> taskDefinitionIPage = taskDefinitionMapper.queryDefineListPaging(
page, projectCode, taskType, searchVal, userId, isAdmin(loginUser));
if (StringUtils.isNotBlank(taskType)) {
List<TaskDefinition> records = taskDefinitionIPage.getRecords();
for (TaskDefinition pd : records) {
TaskDefinitionLog taskDefinitionLog = taskDefinitionLogMapper.queryByDefinitionCodeAndVersion(pd.getCode(), pd.getVersion());
User user = userMapper.selectById(taskDefinitionLog.getOperator());
pd.setModifyBy(user.getUserName());
Page<TaskMainInfo> page = new Page<>(pageNo, pageSize);
IPage<TaskMainInfo> taskMainInfoIPage = taskDefinitionMapper.queryDefineListPaging(page, projectCode, searchWorkflowName,
searchTaskName, taskType == null ? StringUtils.EMPTY : taskType.getDesc());
List<TaskMainInfo> records = taskMainInfoIPage.getRecords();
if (!records.isEmpty()) {
Map<Long, TaskMainInfo> taskMainInfoMap = new HashMap<>();
for (TaskMainInfo info : records) {
taskMainInfoMap.compute(info.getTaskCode(), (k, v) -> {
if (v == null) {
Map<Long, String> upstreamTaskMap = new HashMap<>();
if (info.getUpstreamTaskCode() != 0) {
upstreamTaskMap.put(info.getUpstreamTaskCode(), info.getUpstreamTaskName());
info.setUpstreamTaskCode(0L);
info.setUpstreamTaskName(StringUtils.EMPTY);
}
info.setUpstreamTaskMap(upstreamTaskMap);
v = info;
}
if (info.getUpstreamTaskCode() != 0) {
v.getUpstreamTaskMap().put(info.getUpstreamTaskCode(), info.getUpstreamTaskName());
}
return v;
});
}
taskDefinitionIPage.setRecords(records);
taskMainInfoIPage.setRecords(Lists.newArrayList(taskMainInfoMap.values()));
taskMainInfoIPage.setTotal(taskMainInfoMap.values().size());
}
PageInfo<TaskDefinition> pageInfo = new PageInfo<>(pageNo, pageSize);
pageInfo.setTotal((int) taskDefinitionIPage.getTotal());
pageInfo.setTotalList(taskDefinitionIPage.getRecords());
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;

View File

@ -0,0 +1,189 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.dolphinscheduler.dao.entity;
import org.apache.dolphinscheduler.common.enums.ReleaseState;
import java.util.Date;
import java.util.Map;
import com.fasterxml.jackson.annotation.JsonFormat;
/**
* task main info
*/
public class TaskMainInfo {
/**
* task name
*/
private String taskName;
/**
* task code
*/
private long taskCode;
/**
* task version
*/
private int taskVersion;
/**
* create time
*/
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date taskCreateTime;
/**
* update time
*/
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date taskUpdateTime;
/**
* processDefinitionCode
*/
private long processDefinitionCode;
/**
* processDefinitionVersion
*/
private int processDefinitionVersion;
/**
* processDefinitionName
*/
private String processDefinitionName;
/**
* processReleaseState
*/
private ReleaseState processReleaseState;
/**
* upstreamTaskMap(k:code,v:name)
*/
private Map<Long, String> upstreamTaskMap;
/**
* upstreamTaskCode
*/
private long upstreamTaskCode;
/**
* upstreamTaskName
*/
private String upstreamTaskName;
public String getTaskName() {
return taskName;
}
public void setTaskName(String taskName) {
this.taskName = taskName;
}
public long getTaskCode() {
return taskCode;
}
public void setTaskCode(long taskCode) {
this.taskCode = taskCode;
}
public int getTaskVersion() {
return taskVersion;
}
public void setTaskVersion(int taskVersion) {
this.taskVersion = taskVersion;
}
public Date getTaskCreateTime() {
return taskCreateTime;
}
public void setTaskCreateTime(Date taskCreateTime) {
this.taskCreateTime = taskCreateTime;
}
public Date getTaskUpdateTime() {
return taskUpdateTime;
}
public void setTaskUpdateTime(Date taskUpdateTime) {
this.taskUpdateTime = taskUpdateTime;
}
public long getProcessDefinitionCode() {
return processDefinitionCode;
}
public void setProcessDefinitionCode(long processDefinitionCode) {
this.processDefinitionCode = processDefinitionCode;
}
public int getProcessDefinitionVersion() {
return processDefinitionVersion;
}
public void setProcessDefinitionVersion(int processDefinitionVersion) {
this.processDefinitionVersion = processDefinitionVersion;
}
public String getProcessDefinitionName() {
return processDefinitionName;
}
public void setProcessDefinitionName(String processDefinitionName) {
this.processDefinitionName = processDefinitionName;
}
public ReleaseState getProcessReleaseState() {
return processReleaseState;
}
public void setProcessReleaseState(ReleaseState processReleaseState) {
this.processReleaseState = processReleaseState;
}
public Map<Long, String> getUpstreamTaskMap() {
return upstreamTaskMap;
}
public void setUpstreamTaskMap(Map<Long, String> upstreamTaskMap) {
this.upstreamTaskMap = upstreamTaskMap;
}
public long getUpstreamTaskCode() {
return upstreamTaskCode;
}
public void setUpstreamTaskCode(long upstreamTaskCode) {
this.upstreamTaskCode = upstreamTaskCode;
}
public String getUpstreamTaskName() {
return upstreamTaskName;
}
public void setUpstreamTaskName(String upstreamTaskName) {
this.upstreamTaskName = upstreamTaskName;
}
}

View File

@ -20,6 +20,7 @@ package org.apache.dolphinscheduler.dao.mapper;
import org.apache.dolphinscheduler.dao.entity.DefinitionGroupByUser;
import org.apache.dolphinscheduler.dao.entity.TaskDefinition;
import org.apache.dolphinscheduler.dao.entity.TaskDefinitionLog;
import org.apache.dolphinscheduler.dao.entity.TaskMainInfo;
import org.apache.ibatis.annotations.MapKey;
import org.apache.ibatis.annotations.Param;
@ -102,20 +103,18 @@ public interface TaskDefinitionMapper extends BaseMapper<TaskDefinition> {
int batchInsert(@Param("taskDefinitions") List<TaskDefinitionLog> taskDefinitions);
/**
* task definition page
* task main info page
*
* @param page page
* @param taskType taskType
* @param searchVal searchVal
* @param userId userId
* @param projectCode projectCode
* @param isAdmin isAdmin
* @return task definition IPage
* @param searchWorkflowName searchWorkflowName
* @param searchTaskName searchTaskName
* @param taskType taskType
* @return task main info IPage
*/
IPage<TaskDefinition> queryDefineListPaging(IPage<TaskDefinition> page,
@Param("projectCode") long projectCode,
@Param("taskType") String taskType,
@Param("searchVal") String searchVal,
@Param("userId") int userId,
@Param("isAdmin") boolean isAdmin);
IPage<TaskMainInfo> queryDefineListPaging(IPage<TaskMainInfo> page,
@Param("projectCode") long projectCode,
@Param("searchWorkflowName") String searchWorkflowName,
@Param("searchTaskName") String searchTaskName,
@Param("taskType") String taskType);
}

View File

@ -86,22 +86,23 @@
#{taskDefinition.delayTime},#{taskDefinition.resourceIds},#{taskDefinition.createTime},#{taskDefinition.updateTime}, #{taskDefinition.taskGroupId})
</foreach>
</insert>
<select id="queryDefineListPaging" resultType="org.apache.dolphinscheduler.dao.entity.TaskDefinition">
select td.id, td.code, td.name, td.version, td.description, td.project_code, td.user_id, td.task_type, td.task_params, td.flag,
td.task_priority, td.worker_group, td.environment_code, td.fail_retry_times, td.fail_retry_interval, td.timeout_flag, td.timeout_notify_strategy,
td.timeout, td.delay_time, td.resource_ids, td.create_time, td.update_time, u.user_name,p.name as project_name
<select id="queryDefineListPaging" resultType="org.apache.dolphinscheduler.dao.entity.TaskMainInfo">
select td.name task_name,td.code task_code,td.version task_version,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
JOIN t_ds_user u ON td.user_id = u.id
JOIN t_ds_project p ON td.project_code = p.code
where td.project_code = #{projectCode}
<if test=" taskType != null and taskType != ''">
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}
</if>
<if test=" searchVal != null and searchVal != ''">
and td.name like concat('%', #{searchVal}, '%')
<if test="searchWorkflowName != null and searchWorkflowName != ''">
and pd.name like concat('%', #{searchWorkflowName}, '%')
</if>
<if test=" userId != 0">
and td.user_id = #{userId}
<if test="searchTaskName != null and searchTaskName != ''">
and td.name like concat('%', #{searchTaskName}, '%')
</if>
order by td.update_time desc
</select>