未验证 提交 4ddfb855 编写于 作者: J JinyLeeChina 提交者: GitHub

[Fix-6156] [API] refactor workflow lineage api (#6157)

* fix mysql create sentence bug

* fix mysql create sentence bug

* fix genTaskCodeList return same code and save proces error

* refactor workflow lineage api
Co-authored-by: NJinyLeeChina <297062848@qq.com>
上级 a632be73
...@@ -27,10 +27,8 @@ import org.apache.dolphinscheduler.common.utils.ParameterUtils; ...@@ -27,10 +27,8 @@ import org.apache.dolphinscheduler.common.utils.ParameterUtils;
import org.apache.dolphinscheduler.dao.entity.User; import org.apache.dolphinscheduler.dao.entity.User;
import org.apache.dolphinscheduler.dao.entity.WorkFlowLineage; import org.apache.dolphinscheduler.dao.entity.WorkFlowLineage;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
...@@ -54,23 +52,23 @@ import springfox.documentation.annotations.ApiIgnore; ...@@ -54,23 +52,23 @@ import springfox.documentation.annotations.ApiIgnore;
*/ */
@Api(tags = "WORK_FLOW_LINEAGE_TAG") @Api(tags = "WORK_FLOW_LINEAGE_TAG")
@RestController @RestController
@RequestMapping("lineages/{projectCode}") @RequestMapping("projects/{projectCode}/lineages")
public class WorkFlowLineageController extends BaseController { public class WorkFlowLineageController extends BaseController {
private static final Logger logger = LoggerFactory.getLogger(WorkFlowLineageController.class); private static final Logger logger = LoggerFactory.getLogger(WorkFlowLineageController.class);
@Autowired @Autowired
private WorkFlowLineageService workFlowLineageService; private WorkFlowLineageService workFlowLineageService;
@ApiOperation(value = "queryWorkFlowLineageByName", notes = "QUERY_WORKFLOW_LINEAGE_BY_NAME_NOTES") @ApiOperation(value = "queryLineageByWorkFlowName", notes = "QUERY_WORKFLOW_LINEAGE_BY_NAME_NOTES")
@GetMapping(value = "/list-name") @GetMapping(value = "/query-by-name")
@ResponseStatus(HttpStatus.OK) @ResponseStatus(HttpStatus.OK)
@AccessLogAnnotation(ignoreRequestArgs = "loginUser") @AccessLogAnnotation(ignoreRequestArgs = "loginUser")
public Result<List<WorkFlowLineage>> queryWorkFlowLineageByName(@ApiIgnore @RequestAttribute(value = SESSION_USER) User loginUser, public Result<List<WorkFlowLineage>> queryWorkFlowLineageByName(@ApiIgnore @RequestAttribute(value = SESSION_USER) User loginUser,
@ApiParam(name = "projectCode", value = "PROJECT_CODE", required = true, example = "1") @PathVariable long projectCode, @ApiParam(name = "projectCode", value = "PROJECT_CODE", required = true) @PathVariable long projectCode,
@ApiIgnore @RequestParam(value = "searchVal", required = false) String searchVal) { @RequestParam(value = "workFlowName", required = false) String workFlowName) {
try { try {
searchVal = ParameterUtils.handleEscapes(searchVal); workFlowName = ParameterUtils.handleEscapes(workFlowName);
Map<String, Object> result = workFlowLineageService.queryWorkFlowLineageByName(searchVal, projectCode); Map<String, Object> result = workFlowLineageService.queryWorkFlowLineageByName(projectCode, workFlowName);
return returnDataList(result); return returnDataList(result);
} catch (Exception e) { } catch (Exception e) {
logger.error(QUERY_WORKFLOW_LINEAGE_ERROR.getMsg(), e); logger.error(QUERY_WORKFLOW_LINEAGE_ERROR.getMsg(), e);
...@@ -78,24 +76,30 @@ public class WorkFlowLineageController extends BaseController { ...@@ -78,24 +76,30 @@ public class WorkFlowLineageController extends BaseController {
} }
} }
@ApiOperation(value = "queryWorkFlowLineageByIds", notes = "QUERY_WORKFLOW_LINEAGE_BY_IDS_NOTES") @ApiOperation(value = "queryLineageByWorkFlowCode", notes = "QUERY_WORKFLOW_LINEAGE_BY_CODES_NOTES")
@GetMapping(value = "/list-ids") @GetMapping(value = "/{workFlowCode}")
@ResponseStatus(HttpStatus.OK) @ResponseStatus(HttpStatus.OK)
@AccessLogAnnotation(ignoreRequestArgs = "loginUser") @AccessLogAnnotation(ignoreRequestArgs = "loginUser")
public Result<Map<String, Object>> queryWorkFlowLineageByIds(@ApiIgnore @RequestAttribute(value = SESSION_USER) User loginUser, public Result<Map<String, Object>> queryWorkFlowLineageByCode(@ApiIgnore @RequestAttribute(value = SESSION_USER) User loginUser,
@ApiParam(name = "projectCode", value = "PROJECT_CODE", required = true, example = "1") @PathVariable long projectCode, @ApiParam(name = "projectCode", value = "PROJECT_CODE", required = true) @PathVariable long projectCode,
@ApiIgnore @RequestParam(value = "ids", required = false) String ids) { @PathVariable(value = "workFlowCode", required = true) long workFlowCode) {
try { try {
ids = ParameterUtils.handleEscapes(ids); Map<String, Object> result = workFlowLineageService.queryWorkFlowLineageByCode(projectCode, workFlowCode);
Set<Integer> idsSet = new HashSet<>(); return returnDataList(result);
if (ids != null) { } catch (Exception e) {
String[] idsStr = ids.split(","); logger.error(QUERY_WORKFLOW_LINEAGE_ERROR.getMsg(), e);
for (String id : idsStr) { return error(QUERY_WORKFLOW_LINEAGE_ERROR.getCode(), QUERY_WORKFLOW_LINEAGE_ERROR.getMsg());
idsSet.add(Integer.parseInt(id)); }
} }
}
Map<String, Object> result = workFlowLineageService.queryWorkFlowLineageByIds(idsSet, projectCode); @ApiOperation(value = "queryWorkFlowList", notes = "QUERY_WORKFLOW_LINEAGE_NOTES")
@GetMapping(value = "/list")
@ResponseStatus(HttpStatus.OK)
@AccessLogAnnotation(ignoreRequestArgs = "loginUser")
public Result<Map<String, Object>> queryWorkFlowLineageByIds(@ApiIgnore @RequestAttribute(value = SESSION_USER) User loginUser,
@ApiParam(name = "projectCode", value = "PROJECT_CODE", required = true) @PathVariable long projectCode) {
try {
Map<String, Object> result = workFlowLineageService.queryWorkFlowLineage(projectCode);
return returnDataList(result); return returnDataList(result);
} catch (Exception e) { } catch (Exception e) {
logger.error(QUERY_WORKFLOW_LINEAGE_ERROR.getMsg(), e); logger.error(QUERY_WORKFLOW_LINEAGE_ERROR.getMsg(), e);
......
...@@ -25,8 +25,9 @@ import java.util.Set; ...@@ -25,8 +25,9 @@ import java.util.Set;
*/ */
public interface WorkFlowLineageService { public interface WorkFlowLineageService {
Map<String, Object> queryWorkFlowLineageByName(String workFlowName, long projectCode); Map<String, Object> queryWorkFlowLineageByName(long projectCode, String workFlowName);
Map<String, Object> queryWorkFlowLineageByIds(Set<Integer> ids, long projectCode); Map<String, Object> queryWorkFlowLineageByCode(long projectCode, long workFlowCode);
Map<String, Object> queryWorkFlowLineage(long projectCode);
} }
...@@ -50,65 +50,44 @@ public class WorkFlowLineageServiceImpl extends BaseServiceImpl implements WorkF ...@@ -50,65 +50,44 @@ public class WorkFlowLineageServiceImpl extends BaseServiceImpl implements WorkF
private ProjectMapper projectMapper; private ProjectMapper projectMapper;
@Override @Override
public Map<String, Object> queryWorkFlowLineageByName(String workFlowName, long projectCode) { public Map<String, Object> queryWorkFlowLineageByName(long projectCode, String workFlowName) {
Project project = projectMapper.queryByCode(projectCode);
Map<String, Object> result = new HashMap<>(); Map<String, Object> result = new HashMap<>();
List<WorkFlowLineage> workFlowLineageList = workFlowLineageMapper.queryByName(workFlowName, project.getCode()); Project project = projectMapper.queryByCode(projectCode);
if (project == null) {
putMsg(result, Status.PROJECT_NOT_FOUNT, projectCode);
return result;
}
List<WorkFlowLineage> workFlowLineageList = workFlowLineageMapper.queryWorkFlowLineageByName(projectCode, workFlowName);
result.put(Constants.DATA_LIST, workFlowLineageList); result.put(Constants.DATA_LIST, workFlowLineageList);
putMsg(result, Status.SUCCESS); putMsg(result, Status.SUCCESS);
return result; return result;
} }
private void getRelation(Map<Integer, WorkFlowLineage> workFlowLineageMap, @Override
Set<WorkFlowRelation> workFlowRelations, public Map<String, Object> queryWorkFlowLineageByCode(long projectCode, long workFlowCode) {
ProcessLineage processLineage) { Map<String, Object> result = new HashMap<>();
List<ProcessLineage> relations = workFlowLineageMapper.queryCodeRelation( Project project = projectMapper.queryByCode(projectCode);
processLineage.getPostTaskCode(), processLineage.getPostTaskVersion(), if (project == null) {
processLineage.getProcessDefinitionCode(), processLineage.getProjectCode()); putMsg(result, Status.PROJECT_NOT_FOUNT, projectCode);
if (!relations.isEmpty()) { return result;
Set<Integer> preWorkFlowIds = new HashSet<>();
List<ProcessLineage> preRelations = workFlowLineageMapper.queryCodeRelation(
processLineage.getPreTaskCode(), processLineage.getPreTaskVersion(),
processLineage.getProcessDefinitionCode(), processLineage.getProjectCode());
for (ProcessLineage preRelation : preRelations) {
WorkFlowLineage pre = workFlowLineageMapper.queryWorkFlowLineageByCode(
preRelation.getProcessDefinitionCode(), preRelation.getProjectCode());
preWorkFlowIds.add(pre.getWorkFlowId());
}
ProcessLineage postRelation = relations.get(0);
WorkFlowLineage post = workFlowLineageMapper.queryWorkFlowLineageByCode(
postRelation.getProcessDefinitionCode(), postRelation.getProjectCode());
if (!workFlowLineageMap.containsKey(post.getWorkFlowId())) {
post.setSourceWorkFlowId(StringUtils.join(preWorkFlowIds, ","));
workFlowLineageMap.put(post.getWorkFlowId(), post);
} else {
WorkFlowLineage workFlowLineage = workFlowLineageMap.get(post.getWorkFlowId());
String sourceWorkFlowId = workFlowLineage.getSourceWorkFlowId();
if (sourceWorkFlowId.equals("")) {
workFlowLineage.setSourceWorkFlowId(StringUtils.join(preWorkFlowIds, ","));
} else {
if (!preWorkFlowIds.isEmpty()) {
workFlowLineage.setSourceWorkFlowId(sourceWorkFlowId + "," + StringUtils.join(preWorkFlowIds, ","));
}
}
}
if (preWorkFlowIds.isEmpty()) {
workFlowRelations.add(new WorkFlowRelation(0, post.getWorkFlowId()));
} else {
for (Integer workFlowId : preWorkFlowIds) {
workFlowRelations.add(new WorkFlowRelation(workFlowId, post.getWorkFlowId()));
}
}
} }
WorkFlowLineage workFlowLineage = workFlowLineageMapper.queryWorkFlowLineageByCode(projectCode, workFlowCode);
result.put(Constants.DATA_LIST, workFlowLineage);
putMsg(result, Status.SUCCESS);
return result;
} }
@Override @Override
public Map<String, Object> queryWorkFlowLineageByIds(Set<Integer> ids, long projectCode) { public Map<String, Object> queryWorkFlowLineage(long projectCode) {
Map<String, Object> result = new HashMap<>(); Map<String, Object> result = new HashMap<>();
Project project = projectMapper.queryByCode(projectCode); Project project = projectMapper.queryByCode(projectCode);
List<ProcessLineage> processLineages = workFlowLineageMapper.queryRelationByIds(ids, project.getCode()); if (project == null) {
putMsg(result, Status.PROJECT_NOT_FOUNT, projectCode);
return result;
}
List<ProcessLineage> processLineages = workFlowLineageMapper.queryProcessLineage(projectCode);
Map<Integer, WorkFlowLineage> workFlowLineages = new HashMap<>(); Map<Long, WorkFlowLineage> workFlowLineages = new HashMap<>();
Set<WorkFlowRelation> workFlowRelations = new HashSet<>(); Set<WorkFlowRelation> workFlowRelations = new HashSet<>();
for (ProcessLineage processLineage : processLineages) { for (ProcessLineage processLineage : processLineages) {
...@@ -123,4 +102,42 @@ public class WorkFlowLineageServiceImpl extends BaseServiceImpl implements WorkF ...@@ -123,4 +102,42 @@ public class WorkFlowLineageServiceImpl extends BaseServiceImpl implements WorkF
return result; return result;
} }
private void getRelation(Map<Long, WorkFlowLineage> workFlowLineageMap,
Set<WorkFlowRelation> workFlowRelations,
ProcessLineage processLineage) {
List<ProcessLineage> relations = workFlowLineageMapper.queryCodeRelation(processLineage.getProjectCode(),
processLineage.getProcessDefinitionCode(), processLineage.getPostTaskCode(), processLineage.getPostTaskVersion());
if (!relations.isEmpty()) {
Set<Long> preWorkFlowCodes = new HashSet<>();
List<ProcessLineage> preRelations = workFlowLineageMapper.queryCodeRelation(processLineage.getProjectCode(),
processLineage.getProcessDefinitionCode(), processLineage.getPreTaskCode(), processLineage.getPreTaskVersion());
for (ProcessLineage preRelation : preRelations) {
preWorkFlowCodes.add(preRelation.getProcessDefinitionCode());
}
ProcessLineage postRelation = relations.get(0);
WorkFlowLineage post = workFlowLineageMapper.queryWorkFlowLineageByCode(postRelation.getProjectCode(), postRelation.getProcessDefinitionCode());
preWorkFlowCodes.remove(post.getWorkFlowCode());
if (!workFlowLineageMap.containsKey(post.getWorkFlowCode())) {
post.setSourceWorkFlowCode(StringUtils.join(preWorkFlowCodes, ","));
workFlowLineageMap.put(post.getWorkFlowCode(), post);
} else {
WorkFlowLineage workFlowLineage = workFlowLineageMap.get(post.getWorkFlowCode());
String sourceWorkFlowCode = workFlowLineage.getSourceWorkFlowCode();
if (StringUtils.isBlank(sourceWorkFlowCode)) {
post.setSourceWorkFlowCode(StringUtils.join(preWorkFlowCodes, ","));
} else {
if (!preWorkFlowCodes.isEmpty()) {
workFlowLineage.setSourceWorkFlowCode(sourceWorkFlowCode + "," + StringUtils.join(preWorkFlowCodes, ","));
}
}
}
if (preWorkFlowCodes.isEmpty()) {
workFlowRelations.add(new WorkFlowRelation(0L, post.getWorkFlowCode()));
} else {
for (long workFlowCode : preWorkFlowCodes) {
workFlowRelations.add(new WorkFlowRelation(workFlowCode, post.getWorkFlowCode()));
}
}
}
}
} }
...@@ -21,22 +21,27 @@ import org.apache.dolphinscheduler.api.enums.Status; ...@@ -21,22 +21,27 @@ import org.apache.dolphinscheduler.api.enums.Status;
import org.apache.dolphinscheduler.api.service.impl.WorkFlowLineageServiceImpl; import org.apache.dolphinscheduler.api.service.impl.WorkFlowLineageServiceImpl;
import org.apache.dolphinscheduler.api.utils.Result; import org.apache.dolphinscheduler.api.utils.Result;
import org.apache.dolphinscheduler.common.Constants; import org.apache.dolphinscheduler.common.Constants;
import org.apache.dolphinscheduler.common.enums.UserType;
import org.apache.dolphinscheduler.dao.entity.User;
import java.text.MessageFormat;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet;
import java.util.Map; import java.util.Map;
import java.util.Set;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks; import org.mockito.InjectMocks;
import org.mockito.Mock; import org.mockito.Mock;
import org.mockito.Mockito; import org.mockito.Mockito;
import org.mockito.junit.MockitoJUnitRunner;
/** /**
* work flow lineage controller test * work flow lineage controller test
*/ */
public class WorkFlowLineageControllerTest extends AbstractControllerTest { @RunWith(MockitoJUnitRunner.class)
public class WorkFlowLineageControllerTest {
@InjectMocks @InjectMocks
private WorkFlowLineageController workFlowLineageController; private WorkFlowLineageController workFlowLineageController;
...@@ -44,6 +49,26 @@ public class WorkFlowLineageControllerTest extends AbstractControllerTest { ...@@ -44,6 +49,26 @@ public class WorkFlowLineageControllerTest extends AbstractControllerTest {
@Mock @Mock
private WorkFlowLineageServiceImpl workFlowLineageService; private WorkFlowLineageServiceImpl workFlowLineageService;
protected User user;
@Before
public void before() {
User loginUser = new User();
loginUser.setId(1);
loginUser.setUserType(UserType.GENERAL_USER);
loginUser.setUserName("admin");
user = loginUser;
}
private void putMsg(Map<String, Object> result, Status status, Object... statusParams) {
result.put(Constants.STATUS, status);
if (statusParams != null && statusParams.length > 0) {
result.put(Constants.MSG, MessageFormat.format(status.getMsg(), statusParams));
} else {
result.put(Constants.MSG, status.getMsg());
}
}
@Test @Test
public void testQueryWorkFlowLineageByName() { public void testQueryWorkFlowLineageByName() {
long projectCode = 1L; long projectCode = 1L;
...@@ -51,23 +76,20 @@ public class WorkFlowLineageControllerTest extends AbstractControllerTest { ...@@ -51,23 +76,20 @@ public class WorkFlowLineageControllerTest extends AbstractControllerTest {
Map<String, Object> result = new HashMap<>(); Map<String, Object> result = new HashMap<>();
putMsg(result, Status.SUCCESS); putMsg(result, Status.SUCCESS);
result.put(Constants.DATA_LIST, 1); result.put(Constants.DATA_LIST, 1);
Mockito.when(workFlowLineageService.queryWorkFlowLineageByName(searchVal, projectCode)).thenReturn(result); Mockito.when(workFlowLineageService.queryWorkFlowLineageByName(projectCode, searchVal)).thenReturn(result);
Result response = workFlowLineageController.queryWorkFlowLineageByName(user, projectCode, searchVal); Result response = workFlowLineageController.queryWorkFlowLineageByName(user, projectCode, searchVal);
Assert.assertEquals(Status.SUCCESS.getCode(), response.getCode().intValue()); Assert.assertEquals(Status.SUCCESS.getCode(), response.getCode().intValue());
} }
@Test @Test
public void testQueryWorkFlowLineageByIds() { public void testQueryWorkFlowLineageByCode() {
long projectCode = 1L; long projectCode = 1L;
String ids = "1"; long code = 1L;
Map<String, Object> result = new HashMap<>(); Map<String, Object> result = new HashMap<>();
putMsg(result, Status.SUCCESS); putMsg(result, Status.SUCCESS);
result.put(Constants.DATA_LIST, 1); result.put(Constants.DATA_LIST, 1);
Set<Integer> idSet = new HashSet<>(); Mockito.when(workFlowLineageService.queryWorkFlowLineageByCode(projectCode, code)).thenReturn(result);
idSet.add(1); Result response = workFlowLineageController.queryWorkFlowLineageByCode(user, projectCode, code);
Mockito.when(workFlowLineageService.queryWorkFlowLineageByIds(idSet, projectCode)).thenReturn(result);
Result response = workFlowLineageController.queryWorkFlowLineageByIds(user, projectCode, ids);
Assert.assertEquals(Status.SUCCESS.getCode(), response.getCode().intValue()); Assert.assertEquals(Status.SUCCESS.getCode(), response.getCode().intValue());
} }
} }
...@@ -30,7 +30,6 @@ import org.apache.dolphinscheduler.dao.mapper.WorkFlowLineageMapper; ...@@ -30,7 +30,6 @@ import org.apache.dolphinscheduler.dao.mapper.WorkFlowLineageMapper;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
...@@ -76,20 +75,16 @@ public class WorkFlowLineageServiceTest { ...@@ -76,20 +75,16 @@ public class WorkFlowLineageServiceTest {
@Test @Test
public void testQueryWorkFlowLineageByName() { public void testQueryWorkFlowLineageByName() {
Project project = getProject("test"); Project project = getProject("test");
String searchVal = "test"; String name = "test";
when(projectMapper.queryByCode(1L)).thenReturn(project); when(projectMapper.queryByCode(1L)).thenReturn(project);
when(workFlowLineageMapper.queryByName(Mockito.any(), Mockito.any())).thenReturn(getWorkFlowLineages()); when(workFlowLineageMapper.queryWorkFlowLineageByName(Mockito.anyLong(), Mockito.any())).thenReturn(getWorkFlowLineages());
Map<String, Object> result = workFlowLineageService.queryWorkFlowLineageByName(searchVal, 1L); Map<String, Object> result = workFlowLineageService.queryWorkFlowLineageByName(1L, name);
List<WorkFlowLineage> workFlowLineageList = (List<WorkFlowLineage>) result.get(Constants.DATA_LIST); List<WorkFlowLineage> workFlowLineageList = (List<WorkFlowLineage>) result.get(Constants.DATA_LIST);
Assert.assertTrue(workFlowLineageList.size() > 0); Assert.assertTrue(workFlowLineageList.size() > 0);
} }
@Test @Test
public void testQueryWorkFlowLineageByIds() { public void testQueryWorkFlowLineage() {
Set<Integer> ids = new HashSet<>();
ids.add(1);
ids.add(2);
Project project = getProject("test"); Project project = getProject("test");
List<ProcessLineage> processLineages = new ArrayList<>(); List<ProcessLineage> processLineages = new ArrayList<>();
...@@ -104,20 +99,16 @@ public class WorkFlowLineageServiceTest { ...@@ -104,20 +99,16 @@ public class WorkFlowLineageServiceTest {
processLineages.add(processLineage); processLineages.add(processLineage);
WorkFlowLineage workFlowLineage = new WorkFlowLineage(); WorkFlowLineage workFlowLineage = new WorkFlowLineage();
workFlowLineage.setSourceWorkFlowId(""); workFlowLineage.setSourceWorkFlowCode("");
when(projectMapper.queryByCode(1L)).thenReturn(project); when(projectMapper.queryByCode(1L)).thenReturn(project);
when(workFlowLineageMapper.queryRelationByIds(ids, project.getCode())).thenReturn(processLineages); when(workFlowLineageMapper.queryProcessLineage(project.getCode())).thenReturn(processLineages);
when(workFlowLineageMapper.queryCodeRelation(processLineage.getPostTaskCode() when(workFlowLineageMapper.queryCodeRelation(processLineage.getProjectCode(), processLineage.getProcessDefinitionCode(),
, processLineage.getPreTaskVersion() processLineage.getPostTaskCode(), processLineage.getPreTaskVersion())).thenReturn(processLineages);
, processLineage.getProcessDefinitionCode() when(workFlowLineageMapper.queryWorkFlowLineageByCode(processLineage.getProjectCode(), processLineage.getProcessDefinitionCode()))
, processLineage.getProjectCode())) .thenReturn(workFlowLineage);
.thenReturn(processLineages);
when(workFlowLineageMapper Map<String, Object> result = workFlowLineageService.queryWorkFlowLineage(1L);
.queryWorkFlowLineageByCode(processLineage.getProcessDefinitionCode(), processLineage.getProjectCode()))
.thenReturn(workFlowLineage);
Map<String, Object> result = workFlowLineageService.queryWorkFlowLineageByIds(ids, 1L);
Map<String, Object> workFlowLists = (Map<String, Object>) result.get(Constants.DATA_LIST); Map<String, Object> workFlowLists = (Map<String, Object>) result.get(Constants.DATA_LIST);
Collection<WorkFlowLineage> workFlowLineages = (Collection<WorkFlowLineage>) workFlowLists.get(Constants.WORKFLOW_LIST); Collection<WorkFlowLineage> workFlowLineages = (Collection<WorkFlowLineage>) workFlowLists.get(Constants.WORKFLOW_LIST);
...@@ -129,7 +120,7 @@ public class WorkFlowLineageServiceTest { ...@@ -129,7 +120,7 @@ public class WorkFlowLineageServiceTest {
private List<WorkFlowLineage> getWorkFlowLineages() { private List<WorkFlowLineage> getWorkFlowLineages() {
List<WorkFlowLineage> workFlowLineages = new ArrayList<>(); List<WorkFlowLineage> workFlowLineages = new ArrayList<>();
WorkFlowLineage workFlowLineage = new WorkFlowLineage(); WorkFlowLineage workFlowLineage = new WorkFlowLineage();
workFlowLineage.setWorkFlowId(1); workFlowLineage.setWorkFlowCode(1);
workFlowLineage.setWorkFlowName("testdag"); workFlowLineage.setWorkFlowName("testdag");
workFlowLineages.add(workFlowLineage); workFlowLineages.add(workFlowLineage);
return workFlowLineages; return workFlowLineages;
......
...@@ -25,12 +25,12 @@ public class ProcessLineage { ...@@ -25,12 +25,12 @@ public class ProcessLineage {
/** /**
* project code * project code
*/ */
private Long projectCode; private long projectCode;
/** /**
* post task code * post task code
*/ */
private Long postTaskCode; private long postTaskCode;
/** /**
* post task version * post task version
...@@ -40,7 +40,7 @@ public class ProcessLineage { ...@@ -40,7 +40,7 @@ public class ProcessLineage {
/** /**
* pre task code * pre task code
*/ */
private Long preTaskCode; private long preTaskCode;
/** /**
* pre task version * pre task version
...@@ -50,46 +50,42 @@ public class ProcessLineage { ...@@ -50,46 +50,42 @@ public class ProcessLineage {
/** /**
* process definition code * process definition code
*/ */
private Long processDefinitionCode; private long processDefinitionCode;
/** /**
* process definition version * process definition version
*/ */
private int processDefinitionVersion; private int processDefinitionVersion;
public Long getProjectCode() { public long getProjectCode() {
return projectCode; return projectCode;
} }
public void setProjectCode(Long projectCode) { public void setProjectCode(long projectCode) {
this.projectCode = projectCode; this.projectCode = projectCode;
} }
public Long getProcessDefinitionCode() { public long getPostTaskCode() {
return processDefinitionCode; return postTaskCode;
}
public void setProcessDefinitionCode(Long processDefinitionCode) {
this.processDefinitionCode = processDefinitionCode;
} }
public int getProcessDefinitionVersion() { public void setPostTaskCode(long postTaskCode) {
return processDefinitionVersion; this.postTaskCode = postTaskCode;
} }
public void setProcessDefinitionVersion(int processDefinitionVersion) { public int getPostTaskVersion() {
this.processDefinitionVersion = processDefinitionVersion; return postTaskVersion;
} }
public void setPostTaskCode(Long postTaskCode) { public void setPostTaskVersion(int postTaskVersion) {
this.postTaskCode = postTaskCode; this.postTaskVersion = postTaskVersion;
} }
public Long getPreTaskCode() { public long getPreTaskCode() {
return preTaskCode; return preTaskCode;
} }
public void setPreTaskCode(Long preTaskCode) { public void setPreTaskCode(long preTaskCode) {
this.preTaskCode = preTaskCode; this.preTaskCode = preTaskCode;
} }
...@@ -101,20 +97,19 @@ public class ProcessLineage { ...@@ -101,20 +97,19 @@ public class ProcessLineage {
this.preTaskVersion = preTaskVersion; this.preTaskVersion = preTaskVersion;
} }
public int getPostTaskVersion() { public long getProcessDefinitionCode() {
return postTaskVersion; return processDefinitionCode;
} }
public void setPostTaskVersion(int postTaskVersion) { public void setProcessDefinitionCode(long processDefinitionCode) {
this.postTaskVersion = postTaskVersion; this.processDefinitionCode = processDefinitionCode;
} }
public long getPostTaskCode() { public int getProcessDefinitionVersion() {
return postTaskCode; return processDefinitionVersion;
} }
public void setPostTaskCode(long postTaskCode) { public void setProcessDefinitionVersion(int processDefinitionVersion) {
this.postTaskCode = postTaskCode; this.processDefinitionVersion = processDefinitionVersion;
} }
} }
...@@ -19,29 +19,21 @@ package org.apache.dolphinscheduler.dao.entity; ...@@ -19,29 +19,21 @@ package org.apache.dolphinscheduler.dao.entity;
import java.util.Date; import java.util.Date;
public class WorkFlowLineage { public class WorkFlowLineage {
private int workFlowId; private long workFlowCode;
private String workFlowName; private String workFlowName;
private String workFlowPublishStatus; private String workFlowPublishStatus;
private Date scheduleStartTime; private Date scheduleStartTime;
private Date scheduleEndTime; private Date scheduleEndTime;
private String crontab; private String crontab;
private int schedulePublishStatus; private int schedulePublishStatus;
private String sourceWorkFlowId; private String sourceWorkFlowCode;
public String getSourceWorkFlowId() { public long getWorkFlowCode() {
return sourceWorkFlowId; return workFlowCode;
} }
public void setSourceWorkFlowId(String sourceWorkFlowId) { public void setWorkFlowCode(long workFlowCode) {
this.sourceWorkFlowId = sourceWorkFlowId; this.workFlowCode = workFlowCode;
}
public int getWorkFlowId() {
return workFlowId;
}
public void setWorkFlowId(int workFlowId) {
this.workFlowId = workFlowId;
} }
public String getWorkFlowName() { public String getWorkFlowName() {
...@@ -91,4 +83,12 @@ public class WorkFlowLineage { ...@@ -91,4 +83,12 @@ public class WorkFlowLineage {
public void setSchedulePublishStatus(int schedulePublishStatus) { public void setSchedulePublishStatus(int schedulePublishStatus) {
this.schedulePublishStatus = schedulePublishStatus; this.schedulePublishStatus = schedulePublishStatus;
} }
public String getSourceWorkFlowCode() {
return sourceWorkFlowCode;
}
public void setSourceWorkFlowCode(String sourceWorkFlowCode) {
this.sourceWorkFlowCode = sourceWorkFlowCode;
}
} }
...@@ -19,42 +19,30 @@ package org.apache.dolphinscheduler.dao.entity; ...@@ -19,42 +19,30 @@ package org.apache.dolphinscheduler.dao.entity;
import java.util.Objects; import java.util.Objects;
public class WorkFlowRelation { public class WorkFlowRelation {
private int sourceWorkFlowId; private long sourceWorkFlowCode;
private int targetWorkFlowId; private long targetWorkFlowCode;
public int getSourceWorkFlowId() { public long getSourceWorkFlowCode() {
return sourceWorkFlowId; return sourceWorkFlowCode;
} }
public void setSourceWorkFlowId(int sourceWorkFlowId) { public void setSourceWorkFlowCode(long sourceWorkFlowCode) {
this.sourceWorkFlowId = sourceWorkFlowId; this.sourceWorkFlowCode = sourceWorkFlowCode;
} }
public int getTargetWorkFlowId() { public long getTargetWorkFlowCode() {
return targetWorkFlowId; return targetWorkFlowCode;
} }
public void setTargetWorkFlowId(int targetWorkFlowId) { public void setTargetWorkFlowCode(long targetWorkFlowCode) {
this.targetWorkFlowId = targetWorkFlowId; this.targetWorkFlowCode = targetWorkFlowCode;
} }
public WorkFlowRelation() { public WorkFlowRelation() {
} }
public WorkFlowRelation(int sourceWorkFlowId, int targetWorkFlowId) { public WorkFlowRelation(long sourceWorkFlowCode, long targetWorkFlowCode) {
this.sourceWorkFlowId = sourceWorkFlowId; this.sourceWorkFlowCode = sourceWorkFlowCode;
this.targetWorkFlowId = targetWorkFlowId; this.targetWorkFlowCode = targetWorkFlowCode;
}
@Override
public boolean equals(Object obj) {
return obj instanceof WorkFlowRelation
&& this.sourceWorkFlowId == ((WorkFlowRelation) obj).getSourceWorkFlowId()
&& this.targetWorkFlowId == ((WorkFlowRelation) obj).getTargetWorkFlowId();
}
@Override
public int hashCode() {
return Objects.hash(sourceWorkFlowId, targetWorkFlowId);
} }
} }
...@@ -22,47 +22,45 @@ import org.apache.dolphinscheduler.dao.entity.WorkFlowLineage; ...@@ -22,47 +22,45 @@ import org.apache.dolphinscheduler.dao.entity.WorkFlowLineage;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
import java.util.List; import java.util.List;
import java.util.Set;
public interface WorkFlowLineageMapper { public interface WorkFlowLineageMapper {
/** /**
* queryByName * queryByName
* *
* @param searchVal searchVal
* @param projectCode projectCode * @param projectCode projectCode
* @param workFlowName workFlowName
* @return WorkFlowLineage list * @return WorkFlowLineage list
*/ */
List<WorkFlowLineage> queryByName(@Param("searchVal") String searchVal, @Param("projectCode") Long projectCode); List<WorkFlowLineage> queryWorkFlowLineageByName(@Param("projectCode") long projectCode, @Param("workFlowName") String workFlowName);
/** /**
* queryCodeRelation * queryWorkFlowLineageByCode
* *
* @param taskCode taskCode * @param projectCode projectCode
* @param taskVersion taskVersion * @param workFlowCode workFlowCode
* @param processDefinitionCode processDefinitionCode * @return WorkFlowLineage
* @return ProcessLineage
*/ */
List<ProcessLineage> queryCodeRelation( WorkFlowLineage queryWorkFlowLineageByCode(@Param("projectCode") long projectCode, @Param("workFlowCode") long workFlowCode);
@Param("taskCode") Long taskCode, @Param("taskVersion") int taskVersion,
@Param("processDefinitionCode") Long processDefinitionCode, @Param("projectCode") Long projectCode);
/** /**
* queryRelationByIds * queryProcessLineage
* *
* @param ids ids
* @param projectCode projectCode * @param projectCode projectCode
* @return ProcessLineage * @return ProcessLineage list
*/ */
List<ProcessLineage> queryRelationByIds(@Param("ids") Set<Integer> ids, @Param("projectCode") Long projectCode); List<ProcessLineage> queryProcessLineage(@Param("projectCode") long projectCode);
/** /**
* queryWorkFlowLineageByCode * queryCodeRelation
* *
* @param taskCode taskCode
* @param taskVersion taskVersion
* @param processDefinitionCode processDefinitionCode * @param processDefinitionCode processDefinitionCode
* @param projectCode projectCode * @return ProcessLineage list
* @return WorkFlowLineage
*/ */
WorkFlowLineage queryWorkFlowLineageByCode(@Param("processDefinitionCode") Long processDefinitionCode, @Param("projectCode") Long projectCode); List<ProcessLineage> queryCodeRelation(@Param("projectCode") long projectCode,
@Param("processDefinitionCode") long processDefinitionCode,
@Param("taskCode") long taskCode,
@Param("taskVersion") int taskVersion);
} }
...@@ -19,34 +19,41 @@ ...@@ -19,34 +19,41 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" > <!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.WorkFlowLineageMapper"> <mapper namespace="org.apache.dolphinscheduler.dao.mapper.WorkFlowLineageMapper">
<select id="queryByName" resultType="org.apache.dolphinscheduler.dao.entity.WorkFlowLineage"> <select id="queryWorkFlowLineageByName" resultType="org.apache.dolphinscheduler.dao.entity.WorkFlowLineage">
select tepd.id as work_flow_id,tepd.name as work_flow_name select tepd.code as work_flow_code,tepd.name as work_flow_name
from t_ds_process_definition tepd from t_ds_process_definition tepd
left join t_ds_schedules tes on tepd.code = tes.process_definition_code left join t_ds_schedules tes on tepd.code = tes.process_definition_code
where tepd.project_code = #{projectCode} where tepd.project_code = #{projectCode}
<if test="searchVal != null and searchVal != ''"> <if test="workFlowName != null and workFlowName != ''">
and tepd.name like concat('%', #{searchVal}, '%') and tepd.name like concat('%', #{workFlowName}, '%')
</if> </if>
</select> </select>
<select id="queryRelationByIds" resultType="org.apache.dolphinscheduler.dao.entity.ProcessLineage"> <select id="queryWorkFlowLineageByCode" resultType="org.apache.dolphinscheduler.dao.entity.WorkFlowLineage">
select ptr.project_code, select tepd.code as work_flow_code,tepd.name as work_flow_name,
ptr.post_task_code, "" as source_work_flow_code,
ptr.post_task_version, tepd.release_state as work_flow_publish_status,
ptr.pre_task_code, tes.start_time as schedule_start_time,
ptr.pre_task_version, tes.end_time as schedule_end_time,
ptr.process_definition_code, tes.crontab as crontab,
ptr.process_definition_version tes.release_state as schedule_publish_status
from t_ds_process_definition pd from t_ds_process_definition tepd
join t_ds_process_task_relation ptr on pd.code = ptr.process_definition_code and pd.version = left join t_ds_schedules tes on tepd.code = tes.process_definition_code
where tepd.project_code = #{projectCode} and tepd.code = #{workFlowCode}
</select>
<select id="queryProcessLineage" resultType="org.apache.dolphinscheduler.dao.entity.ProcessLineage">
select ptr.project_code,
ptr.post_task_code,
ptr.post_task_version,
ptr.pre_task_code,
ptr.pre_task_version,
ptr.process_definition_code,
ptr.process_definition_version ptr.process_definition_version
from t_ds_process_definition pd
join t_ds_process_task_relation ptr on pd.code = ptr.process_definition_code
and pd.version = ptr.process_definition_version
where pd.project_code = #{projectCode} where pd.project_code = #{projectCode}
<if test="ids != null and ids.size()>0">
and pd.id in
<foreach collection="ids" index="index" item="i" open="(" separator="," close=")">
#{i}
</foreach>
</if>
</select> </select>
<select id="queryCodeRelation" resultType="org.apache.dolphinscheduler.dao.entity.ProcessLineage"> <select id="queryCodeRelation" resultType="org.apache.dolphinscheduler.dao.entity.ProcessLineage">
...@@ -58,23 +65,9 @@ ...@@ -58,23 +65,9 @@
process_definition_code, process_definition_code,
process_definition_version process_definition_version
from t_ds_process_task_relation from t_ds_process_task_relation
where post_task_code = #{taskCode} where project_code = #{projectCode}
and post_task_version = #{taskVersion}
and process_definition_code = #{processDefinitionCode} and process_definition_code = #{processDefinitionCode}
and project_code = #{projectCode} and post_task_code = #{taskCode}
</select> and post_task_version = #{taskVersion}
<select id="queryWorkFlowLineageByCode" resultType="org.apache.dolphinscheduler.dao.entity.WorkFlowLineage">
select tepd.id as work_flow_id,tepd.name as work_flow_name,
"" as source_work_flow_id,
tepd.release_state as work_flow_publish_status,
tes.start_time as schedule_start_time,
tes.end_time as schedule_end_time,
tes.crontab as crontab,
tes.release_state as schedule_publish_status
from t_ds_process_definition tepd
left join t_ds_schedules tes on tepd.code = tes.process_definition_code
where tepd.project_code = #{projectCode} and tepd.code = #{processDefinitionCode}
</select> </select>
</mapper> </mapper>
...@@ -26,7 +26,6 @@ import org.apache.dolphinscheduler.dao.entity.Schedule; ...@@ -26,7 +26,6 @@ import org.apache.dolphinscheduler.dao.entity.Schedule;
import org.apache.dolphinscheduler.dao.entity.WorkFlowLineage; import org.apache.dolphinscheduler.dao.entity.WorkFlowLineage;
import java.util.Date; import java.util.Date;
import java.util.HashSet;
import java.util.List; import java.util.List;
import org.junit.Assert; import org.junit.Assert;
...@@ -81,9 +80,8 @@ public class WorkFlowLineageMapperTest { ...@@ -81,9 +80,8 @@ public class WorkFlowLineageMapperTest {
/** /**
* insert * insert
* *
* @return ProcessDefinition
*/ */
private ProcessDefinition insertOneProcessDefinition() { private void insertOneProcessDefinition() {
//insertOne //insertOne
ProcessDefinition processDefinition = new ProcessDefinition(); ProcessDefinition processDefinition = new ProcessDefinition();
processDefinition.setCode(1L); processDefinition.setCode(1L);
...@@ -93,15 +91,13 @@ public class WorkFlowLineageMapperTest { ...@@ -93,15 +91,13 @@ public class WorkFlowLineageMapperTest {
processDefinition.setUpdateTime(new Date()); processDefinition.setUpdateTime(new Date());
processDefinition.setCreateTime(new Date()); processDefinition.setCreateTime(new Date());
processDefinitionMapper.insert(processDefinition); processDefinitionMapper.insert(processDefinition);
return processDefinition;
} }
/** /**
* insert * insert
* *
* @return Schedule
*/ */
private Schedule insertOneSchedule(int id) { private void insertOneSchedule(int id) {
//insertOne //insertOne
Schedule schedule = new Schedule(); Schedule schedule = new Schedule();
schedule.setStartTime(new Date()); schedule.setStartTime(new Date());
...@@ -114,38 +110,32 @@ public class WorkFlowLineageMapperTest { ...@@ -114,38 +110,32 @@ public class WorkFlowLineageMapperTest {
schedule.setUpdateTime(new Date()); schedule.setUpdateTime(new Date());
schedule.setProcessDefinitionCode(id); schedule.setProcessDefinitionCode(id);
scheduleMapper.insert(schedule); scheduleMapper.insert(schedule);
return schedule;
} }
@Test @Test
public void testQueryByName() { public void testQueryWorkFlowLineageByName() {
insertOneProcessDefinition(); insertOneProcessDefinition();
ProcessDefinition processDefinition = processDefinitionMapper.queryByCode(1L); ProcessDefinition processDefinition = processDefinitionMapper.queryByCode(1L);
insertOneSchedule(processDefinition.getId()); insertOneSchedule(processDefinition.getId());
List<WorkFlowLineage> workFlowLineages = workFlowLineageMapper.queryByName(processDefinition.getName(), processDefinition.getProjectCode()); List<WorkFlowLineage> workFlowLineages = workFlowLineageMapper.queryWorkFlowLineageByName(processDefinition.getProjectCode(), processDefinition.getName());
Assert.assertNotEquals(workFlowLineages.size(), 0); Assert.assertNotEquals(workFlowLineages.size(), 0);
} }
@Test @Test
public void testQueryCodeRelation() { public void testQueryCodeRelation() {
ProcessTaskRelation processTaskRelation = insertOneProcessTaskRelation(); ProcessTaskRelation processTaskRelation = insertOneProcessTaskRelation();
List<ProcessLineage> workFlowLineages = workFlowLineageMapper.queryCodeRelation(processTaskRelation.getProjectCode(),
List<ProcessLineage> workFlowLineages = workFlowLineageMapper.queryCodeRelation( processTaskRelation.getProcessDefinitionCode(), processTaskRelation.getPostTaskCode(), processTaskRelation.getPostTaskVersion());
processTaskRelation.getPostTaskCode(), processTaskRelation.getPostTaskVersion(),
processTaskRelation.getProcessDefinitionCode(), processTaskRelation.getProjectCode());
Assert.assertNotEquals(workFlowLineages.size(), 0); Assert.assertNotEquals(workFlowLineages.size(), 0);
} }
@Test @Test
public void testQueryRelationByIds() { public void testQueryWorkFlowLineage() {
insertOneProcessDefinition(); insertOneProcessDefinition();
ProcessDefinition processDefinition = processDefinitionMapper.queryByCode(1L); ProcessDefinition processDefinition = processDefinitionMapper.queryByCode(1L);
insertOneProcessTaskRelation(); insertOneProcessTaskRelation();
List<ProcessLineage> workFlowLineages = workFlowLineageMapper.queryProcessLineage(processDefinition.getProjectCode());
HashSet<Integer> set = new HashSet<>();
set.add(processDefinition.getId());
List<ProcessLineage> workFlowLineages = workFlowLineageMapper.queryRelationByIds(set, processDefinition.getProjectCode());
Assert.assertNotEquals(workFlowLineages.size(), 0); Assert.assertNotEquals(workFlowLineages.size(), 0);
} }
...@@ -154,8 +144,7 @@ public class WorkFlowLineageMapperTest { ...@@ -154,8 +144,7 @@ public class WorkFlowLineageMapperTest {
insertOneProcessDefinition(); insertOneProcessDefinition();
ProcessDefinition processDefinition = processDefinitionMapper.queryByCode(1L); ProcessDefinition processDefinition = processDefinitionMapper.queryByCode(1L);
insertOneSchedule(processDefinition.getId()); insertOneSchedule(processDefinition.getId());
WorkFlowLineage workFlowLineages = workFlowLineageMapper.queryWorkFlowLineageByCode(processDefinition.getProjectCode(), processDefinition.getCode());
WorkFlowLineage workFlowLineages = workFlowLineageMapper.queryWorkFlowLineageByCode(processDefinition.getCode(), processDefinition.getProjectCode());
Assert.assertNotNull(workFlowLineages); Assert.assertNotNull(workFlowLineages);
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册