diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/audit/operator/impl/WorkflowInstanceAuditOperatorImpl.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/audit/operator/impl/WorkflowInstanceAuditOperatorImpl.java index fec46ac1499d..1270e42e08c0 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/audit/operator/impl/WorkflowInstanceAuditOperatorImpl.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/audit/operator/impl/WorkflowInstanceAuditOperatorImpl.java @@ -24,7 +24,7 @@ import org.apache.dolphinscheduler.common.enums.AuditOperationType; import org.apache.dolphinscheduler.dao.entity.AuditLog; import org.apache.dolphinscheduler.dao.entity.WorkflowInstance; -import org.apache.dolphinscheduler.dao.mapper.WorkflowInstanceMapper; +import org.apache.dolphinscheduler.dao.repository.WorkflowInstanceDao; import org.apache.commons.lang3.math.NumberUtils; @@ -38,7 +38,7 @@ public class WorkflowInstanceAuditOperatorImpl extends BaseAuditOperator { @Autowired - private WorkflowInstanceMapper workflowInstanceMapper; + private WorkflowInstanceDao workflowInstanceDao; @Override public void modifyAuditOperationType(AuditType auditType, Map paramsMap, @@ -64,7 +64,7 @@ protected String getObjectNameFromIdentity(Object identity) { return ""; } - WorkflowInstance obj = workflowInstanceMapper.queryDetailById(objId); + WorkflowInstance obj = workflowInstanceDao.queryDetailById(objId); return obj == null ? "" : obj.getName(); } } diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/DataAnalysisServiceImpl.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/DataAnalysisServiceImpl.java index 66c6ba7752d1..bb832170b7c2 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/DataAnalysisServiceImpl.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/DataAnalysisServiceImpl.java @@ -36,13 +36,13 @@ import org.apache.dolphinscheduler.dao.entity.User; import org.apache.dolphinscheduler.dao.mapper.CommandMapper; import org.apache.dolphinscheduler.dao.mapper.ErrorCommandMapper; -import org.apache.dolphinscheduler.dao.mapper.WorkflowInstanceMapper; import org.apache.dolphinscheduler.dao.model.TaskInstanceStatusCountDto; import org.apache.dolphinscheduler.dao.model.WorkflowDefinitionCountDto; import org.apache.dolphinscheduler.dao.model.WorkflowInstanceStatusCountDto; import org.apache.dolphinscheduler.dao.repository.ProjectDao; import org.apache.dolphinscheduler.dao.repository.TaskInstanceDao; import org.apache.dolphinscheduler.dao.repository.WorkflowDefinitionDao; +import org.apache.dolphinscheduler.dao.repository.WorkflowInstanceDao; import org.apache.commons.collections4.CollectionUtils; @@ -76,7 +76,7 @@ public class DataAnalysisServiceImpl extends BaseServiceImpl implements DataAnal private ProjectService projectService; @Autowired - private WorkflowInstanceMapper workflowInstanceMapper; + private WorkflowInstanceDao workflowInstanceDao; @Autowired private WorkflowDefinitionDao workflowDefinitionDao; @@ -126,7 +126,7 @@ public WorkflowInstanceCountVO getWorkflowInstanceStateCountByProject(User login projectService.checkProjectAndAuthThrowException(loginUser, projectCode, PROJECT_OVERVIEW); Date start = startDate == null ? null : transformDate(startDate); Date end = endDate == null ? null : transformDate(endDate); - List workflowInstanceStatusCountDtos = workflowInstanceMapper + List workflowInstanceStatusCountDtos = workflowInstanceDao .countWorkflowInstanceStateByProjectCodes(start, end, Lists.newArrayList(projectCode)); return WorkflowInstanceCountVO.of(workflowInstanceStatusCountDtos); } @@ -143,7 +143,7 @@ public WorkflowInstanceCountVO getAllWorkflowInstanceStateCount(User loginUser, Date end = endDate == null ? null : transformDate(endDate); List workflowInstanceStatusCountDtos = - workflowInstanceMapper.countWorkflowInstanceStateByProjectCodes(start, end, projectCodes); + workflowInstanceDao.countWorkflowInstanceStateByProjectCodes(start, end, projectCodes); return WorkflowInstanceCountVO.of(workflowInstanceStatusCountDtos); } diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/TenantServiceImpl.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/TenantServiceImpl.java index 747ecf319685..bcdbc5a90c19 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/TenantServiceImpl.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/TenantServiceImpl.java @@ -36,10 +36,10 @@ import org.apache.dolphinscheduler.dao.entity.Tenant; import org.apache.dolphinscheduler.dao.entity.User; import org.apache.dolphinscheduler.dao.entity.WorkflowInstance; -import org.apache.dolphinscheduler.dao.mapper.WorkflowInstanceMapper; import org.apache.dolphinscheduler.dao.repository.ScheduleDao; import org.apache.dolphinscheduler.dao.repository.TenantDao; import org.apache.dolphinscheduler.dao.repository.UserDao; +import org.apache.dolphinscheduler.dao.repository.WorkflowInstanceDao; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.StringUtils; @@ -67,7 +67,7 @@ public class TenantServiceImpl extends BaseServiceImpl implements TenantService private TenantDao tenantDao; @Autowired - private WorkflowInstanceMapper workflowInstanceMapper; + private WorkflowInstanceDao workflowInstanceDao; @Autowired private ScheduleDao scheduleDao; @@ -244,11 +244,11 @@ public void deleteTenantById(User loginUser, int id) throws Exception { throw new ServiceException(Status.DELETE_TENANT_BY_ID_ERROR); } - workflowInstanceMapper.updateWorkflowInstanceByTenantCode(tenant.getTenantCode(), Constants.DEFAULT); + workflowInstanceDao.updateWorkflowInstanceByTenantCode(tenant.getTenantCode(), Constants.DEFAULT); } private List getWorkflowInstancesByTenant(Tenant tenant) { - return workflowInstanceMapper.queryByTenantCodeAndStatus( + return workflowInstanceDao.queryByTenantCodeAndStatus( tenant.getTenantCode(), WorkflowExecutionStatus.NOT_TERMINAL_STATES); } diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/WorkerGroupServiceImpl.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/WorkerGroupServiceImpl.java index ad10d9a1eace..ff0325d84b26 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/WorkerGroupServiceImpl.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/WorkerGroupServiceImpl.java @@ -43,10 +43,10 @@ import org.apache.dolphinscheduler.dao.entity.WorkflowInstance; import org.apache.dolphinscheduler.dao.mapper.EnvironmentWorkerGroupRelationMapper; import org.apache.dolphinscheduler.dao.mapper.TaskDefinitionMapper; -import org.apache.dolphinscheduler.dao.mapper.WorkflowInstanceMapper; import org.apache.dolphinscheduler.dao.repository.ScheduleDao; import org.apache.dolphinscheduler.dao.repository.WorkerGroupDao; import org.apache.dolphinscheduler.dao.repository.WorkflowDefinitionDao; +import org.apache.dolphinscheduler.dao.repository.WorkflowInstanceDao; import org.apache.dolphinscheduler.extract.base.client.Clients; import org.apache.dolphinscheduler.extract.master.IMasterContainerService; import org.apache.dolphinscheduler.registry.api.RegistryClient; @@ -81,7 +81,7 @@ public class WorkerGroupServiceImpl extends BaseServiceImpl implements WorkerGro private WorkerGroupDao workerGroupDao; @Autowired - private WorkflowInstanceMapper workflowInstanceMapper; + private WorkflowInstanceDao workflowInstanceDao; @Autowired private RegistryClient registryClient; @@ -322,7 +322,7 @@ public void deleteWorkerGroupById(User loginUser, Integer id) { log.error("Worker group does not exist, workerGroupId:{}.", id); throw new ServiceException(Status.DELETE_WORKER_GROUP_NOT_EXIST); } - List workflowInstances = workflowInstanceMapper.queryByWorkerGroupNameAndStatus( + List workflowInstances = workflowInstanceDao.queryByWorkerGroupNameAndStatus( workerGroup.getName(), WorkflowExecutionStatus.NOT_TERMINAL_STATES); if (CollectionUtils.isNotEmpty(workflowInstances)) { diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/WorkflowInstanceServiceImpl.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/WorkflowInstanceServiceImpl.java index 4cf2c553b9e3..7dccef947a37 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/WorkflowInstanceServiceImpl.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/WorkflowInstanceServiceImpl.java @@ -68,7 +68,6 @@ import org.apache.dolphinscheduler.dao.mapper.TaskDefinitionLogMapper; import org.apache.dolphinscheduler.dao.mapper.TaskDefinitionMapper; import org.apache.dolphinscheduler.dao.mapper.WorkflowDefinitionLogMapper; -import org.apache.dolphinscheduler.dao.mapper.WorkflowInstanceMapper; import org.apache.dolphinscheduler.dao.repository.ProjectDao; import org.apache.dolphinscheduler.dao.repository.TaskInstanceContextDao; import org.apache.dolphinscheduler.dao.repository.TaskInstanceDao; @@ -134,9 +133,6 @@ public class WorkflowInstanceServiceImpl extends BaseServiceImpl implements Work @Autowired private TaskInstanceService taskInstanceService; - @Autowired - WorkflowInstanceMapper workflowInstanceMapper; - @Autowired WorkflowInstanceDao workflowInstanceDao; @@ -198,7 +194,7 @@ public List queryTopNLongestRunningWorkflowInstance(User login throw new ServiceException(Status.START_TIME_BIGGER_THAN_END_TIME_ERROR, startTime, endTime); } - return workflowInstanceMapper.queryTopNWorkflowInstance(size, start, end, WorkflowExecutionStatus.SUCCESS, + return workflowInstanceDao.queryTopNWorkflowInstance(size, start, end, WorkflowExecutionStatus.SUCCESS, projectCode); } @@ -254,7 +250,7 @@ public Result> queryWorkflowInstanceList(User loginUs Page page = new Page<>(pageNo, pageSize); PageInfo pageInfo = new PageInfo<>(pageNo, pageSize); - IPage workflowInstanceList = workflowInstanceMapper.queryWorkflowInstanceListPaging( + IPage workflowInstanceList = workflowInstanceDao.queryWorkflowInstanceListPaging( page, projectCode, workflowDefinitionCode, @@ -600,7 +596,7 @@ public WorkflowInstanceVariablesDTO viewVariables(User loginUser, long projectCo // check user access for project projectService.checkProjectAndAuthThrowException(loginUser, projectCode, WORKFLOW_INSTANCE); - WorkflowInstance workflowInstance = workflowInstanceMapper.queryDetailById(workflowInstanceId); + WorkflowInstance workflowInstance = workflowInstanceDao.queryDetailById(workflowInstanceId); if (workflowInstance == null) { log.error("workflow instance does not exist, projectCode:{}, workflowInstanceId:{}.", projectCode, @@ -705,7 +701,7 @@ private Map> processLocalParams(WorkflowInstance wor public GanttDto viewGantt(User loginUser, long projectCode, Integer workflowInstanceId) throws Exception { // check user access for project projectService.checkProjectAndAuthThrowException(loginUser, projectCode, WORKFLOW_INSTANCE); - WorkflowInstance workflowInstance = workflowInstanceMapper.queryDetailById(workflowInstanceId); + WorkflowInstance workflowInstance = workflowInstanceDao.queryDetailById(workflowInstanceId); if (workflowInstance == null) { log.error("workflow instance does not exist, projectCode:{}, workflowInstanceId:{}.", projectCode, @@ -763,7 +759,7 @@ public GanttDto viewGantt(User loginUser, long projectCode, Integer workflowInst @Override public List queryByWorkflowDefinitionCodeAndStatus(Long workflowDefinitionCode, int[] states) { - return workflowInstanceMapper.queryByWorkflowDefinitionCodeAndStatus(workflowDefinitionCode, states); + return workflowInstanceDao.queryByWorkflowDefinitionCodeAndStatus(workflowDefinitionCode, states); } @Override @@ -775,7 +771,7 @@ public List queryByWorkflowCodeVersionStatus(Long workflowDefi @Override public List queryByWorkflowDefinitionCode(Long workflowDefinitionCode, int size) { - return workflowInstanceMapper.queryByWorkflowDefinitionCode(workflowDefinitionCode, size); + return workflowInstanceDao.queryByWorkflowDefinitionCode(workflowDefinitionCode, size); } @Override @@ -788,14 +784,14 @@ public List queryByTriggerCode(User loginUser, long projectCod if (triggerCode == null) { return Collections.emptyList(); } - return workflowInstanceMapper.queryByTriggerCode(triggerCode); + return workflowInstanceDao.queryByTriggerCode(triggerCode); } @Override public void deleteWorkflowInstanceByWorkflowDefinitionCode(long workflowDefinitionCode) { while (true) { List workflowInstances = - workflowInstanceMapper.queryByWorkflowDefinitionCode(workflowDefinitionCode, 100); + workflowInstanceDao.queryByWorkflowDefinitionCode(workflowDefinitionCode, 100); if (CollectionUtils.isEmpty(workflowInstances)) { break; } diff --git a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/WorkerGroupControllerTest.java b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/WorkerGroupControllerTest.java index b330d6215fbf..2be216fbddeb 100644 --- a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/WorkerGroupControllerTest.java +++ b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/WorkerGroupControllerTest.java @@ -27,8 +27,8 @@ import org.apache.dolphinscheduler.common.enums.WorkflowExecutionStatus; import org.apache.dolphinscheduler.common.utils.JSONUtils; import org.apache.dolphinscheduler.dao.entity.WorkerGroup; -import org.apache.dolphinscheduler.dao.mapper.WorkflowInstanceMapper; import org.apache.dolphinscheduler.dao.repository.WorkerGroupDao; +import org.apache.dolphinscheduler.dao.repository.WorkflowInstanceDao; import org.apache.dolphinscheduler.registry.api.RegistryClient; import org.apache.dolphinscheduler.registry.api.enums.RegistryNodeType; @@ -53,8 +53,8 @@ public class WorkerGroupControllerTest extends AbstractControllerTest { @MockBean(name = "workerGroupDao") private WorkerGroupDao workerGroupDao; - @MockBean(name = "processInstanceMapper") - private WorkflowInstanceMapper workflowInstanceMapper; + @MockBean + private WorkflowInstanceDao workflowInstanceDao; @MockBean(name = "registryClient") private RegistryClient registryClient; @@ -131,11 +131,11 @@ public void testDeleteById() throws Exception { workerGroup.setId(12); workerGroup.setName("测试"); Mockito.when(workerGroupDao.queryById(12)).thenReturn(workerGroup); - Mockito.when(workflowInstanceMapper.queryByWorkerGroupNameAndStatus("测试", + Mockito.when(workflowInstanceDao.queryByWorkerGroupNameAndStatus("测试", WorkflowExecutionStatus.NOT_TERMINAL_STATES)) .thenReturn(null); Mockito.when(workerGroupDao.deleteById(12)).thenReturn(true); - Mockito.when(workflowInstanceMapper.updateWorkflowInstanceByWorkerGroupName("测试", "")).thenReturn(1); + Mockito.when(workflowInstanceDao.updateWorkflowInstanceByWorkerGroupName("测试", "")).thenReturn(1); MvcResult mvcResult = mockMvc.perform(delete("/worker-groups/{id}", "12") .header("sessionId", sessionId)) diff --git a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/DataAnalysisServiceTest.java b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/DataAnalysisServiceTest.java index 84e2e56895c2..25bd8a1055cb 100644 --- a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/DataAnalysisServiceTest.java +++ b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/DataAnalysisServiceTest.java @@ -46,10 +46,10 @@ import org.apache.dolphinscheduler.dao.entity.User; import org.apache.dolphinscheduler.dao.mapper.CommandMapper; import org.apache.dolphinscheduler.dao.mapper.ErrorCommandMapper; -import org.apache.dolphinscheduler.dao.mapper.WorkflowInstanceMapper; import org.apache.dolphinscheduler.dao.repository.ProjectDao; import org.apache.dolphinscheduler.dao.repository.TaskInstanceDao; import org.apache.dolphinscheduler.dao.repository.WorkflowDefinitionDao; +import org.apache.dolphinscheduler.dao.repository.WorkflowInstanceDao; import org.apache.dolphinscheduler.plugin.task.api.enums.TaskExecutionStatus; import java.text.MessageFormat; @@ -92,7 +92,7 @@ public class DataAnalysisServiceTest { ProjectService projectService; @Mock - WorkflowInstanceMapper workflowInstanceMapper; + WorkflowInstanceDao workflowInstanceDao; @Mock WorkflowDefinitionDao workflowDefinitionDao; diff --git a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/TenantServiceTest.java b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/TenantServiceTest.java index 3fa5f7f082f2..96baa93fb697 100644 --- a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/TenantServiceTest.java +++ b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/TenantServiceTest.java @@ -38,10 +38,10 @@ import org.apache.dolphinscheduler.dao.entity.Tenant; import org.apache.dolphinscheduler.dao.entity.User; import org.apache.dolphinscheduler.dao.entity.WorkflowInstance; -import org.apache.dolphinscheduler.dao.mapper.WorkflowInstanceMapper; import org.apache.dolphinscheduler.dao.repository.ScheduleDao; import org.apache.dolphinscheduler.dao.repository.TenantDao; import org.apache.dolphinscheduler.dao.repository.UserDao; +import org.apache.dolphinscheduler.dao.repository.WorkflowInstanceDao; import org.apache.commons.collections4.CollectionUtils; @@ -87,7 +87,7 @@ public class TenantServiceTest { private ScheduleDao scheduleDao; @Mock - private WorkflowInstanceMapper workflowInstanceMapper; + private WorkflowInstanceDao workflowInstanceDao; @Mock private UserDao userDao; @@ -188,7 +188,7 @@ public void testDeleteTenantById() { when(resourcePermissionCheckService.resourcePermissionCheck(AuthorizationType.TENANT, null, 0, baseServiceLogger)).thenReturn(true); when(tenantDao.queryDetailById(1)).thenReturn(getTenant()); - when(workflowInstanceMapper.queryByTenantCodeAndStatus(tenantCode, + when(workflowInstanceDao.queryByTenantCodeAndStatus(tenantCode, WorkflowExecutionStatus.NOT_TERMINAL_STATES)) .thenReturn(getInstanceList()); when(scheduleDao.queryScheduleListByTenant(tenantCode)).thenReturn(getScheduleList()); @@ -202,7 +202,7 @@ public void testDeleteTenantById() { () -> tenantService.deleteTenantById(getLoginUser(), 1)); // DELETE_TENANT_BY_ID_FAIL_DEFINES - when(workflowInstanceMapper.queryByTenantCodeAndStatus(any(), any())).thenReturn(Collections.emptyList()); + when(workflowInstanceDao.queryByTenantCodeAndStatus(any(), any())).thenReturn(Collections.emptyList()); when(tenantDao.queryDetailById(2)).thenReturn(getTenant(2)); assertThrowsServiceException(Status.DELETE_TENANT_BY_ID_FAIL_DEFINES, () -> tenantService.deleteTenantById(getLoginUser(), 2)); diff --git a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/WorkerGroupServiceTest.java b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/WorkerGroupServiceTest.java index dddc793c0863..e0bc7f22f0db 100644 --- a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/WorkerGroupServiceTest.java +++ b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/WorkerGroupServiceTest.java @@ -37,9 +37,9 @@ import org.apache.dolphinscheduler.dao.entity.WorkflowInstance; import org.apache.dolphinscheduler.dao.mapper.EnvironmentWorkerGroupRelationMapper; import org.apache.dolphinscheduler.dao.mapper.TaskDefinitionMapper; -import org.apache.dolphinscheduler.dao.mapper.WorkflowInstanceMapper; import org.apache.dolphinscheduler.dao.repository.ScheduleDao; import org.apache.dolphinscheduler.dao.repository.WorkerGroupDao; +import org.apache.dolphinscheduler.dao.repository.WorkflowInstanceDao; import org.apache.dolphinscheduler.registry.api.RegistryClient; import org.apache.dolphinscheduler.registry.api.enums.RegistryNodeType; @@ -78,7 +78,7 @@ public class WorkerGroupServiceTest { private WorkerGroupDao workerGroupDao; @Mock - private WorkflowInstanceMapper workflowInstanceMapper; + private WorkflowInstanceDao workflowInstanceDao; @Mock private RegistryClient registryClient; @@ -233,7 +233,7 @@ public void giveRunningProcess_whenDeleteWorkerGroupById_expectFailed() { workflowInstance.setId(1); List workflowInstances = new ArrayList(); workflowInstances.add(workflowInstance); - when(workflowInstanceMapper.queryByWorkerGroupNameAndStatus(workerGroup.getName(), + when(workflowInstanceDao.queryByWorkerGroupNameAndStatus(workerGroup.getName(), WorkflowExecutionStatus.NOT_TERMINAL_STATES)) .thenReturn(workflowInstances); @@ -250,7 +250,7 @@ public void giveValidParams_whenDeleteWorkerGroupById_expectSuccess() { baseServiceLogger)).thenReturn(true); WorkerGroup workerGroup = getWorkerGroup(1); when(workerGroupDao.queryById(1)).thenReturn(workerGroup); - when(workflowInstanceMapper.queryByWorkerGroupNameAndStatus(workerGroup.getName(), + when(workflowInstanceDao.queryByWorkerGroupNameAndStatus(workerGroup.getName(), WorkflowExecutionStatus.NOT_TERMINAL_STATES)).thenReturn(null); when(taskDefinitionMapper.selectList(Mockito.any())).thenReturn(null); diff --git a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/WorkflowInstanceServiceTest.java b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/WorkflowInstanceServiceTest.java index f616eab48a18..b0f6edf51178 100644 --- a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/WorkflowInstanceServiceTest.java +++ b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/WorkflowInstanceServiceTest.java @@ -59,7 +59,6 @@ import org.apache.dolphinscheduler.dao.entity.WorkflowInstance; import org.apache.dolphinscheduler.dao.mapper.TaskDefinitionMapper; import org.apache.dolphinscheduler.dao.mapper.WorkflowDefinitionLogMapper; -import org.apache.dolphinscheduler.dao.mapper.WorkflowInstanceMapper; import org.apache.dolphinscheduler.dao.repository.ProjectDao; import org.apache.dolphinscheduler.dao.repository.TaskInstanceContextDao; import org.apache.dolphinscheduler.dao.repository.TaskInstanceDao; @@ -121,9 +120,6 @@ public class WorkflowInstanceServiceTest { @Mock WorkflowInstanceDao workflowInstanceDao; - @Mock - WorkflowInstanceMapper workflowInstanceMapper; - @Mock WorkflowDefinitionLogMapper workflowDefinitionLogMapper; @@ -226,7 +222,7 @@ public void testQueryWorkflowInstanceList() { Mockito.any(Project.class), Mockito.any()); when(workflowDefinitionDao.queryById(Mockito.any())).thenReturn(getProcessDefinition()); - when(workflowInstanceMapper.queryWorkflowInstanceListPaging(Mockito.any(Page.class), Mockito.any(), + when(workflowInstanceDao.queryWorkflowInstanceListPaging(Mockito.any(Page.class), Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any(), eq("192.168.xx.xx"), Mockito.any(), Mockito.any())).thenReturn(pageReturn); @@ -248,7 +244,7 @@ public void testQueryWorkflowInstanceList() { doNothing().when(projectService).checkProjectAndAuthThrowException(loginUser, projectCode, WORKFLOW_INSTANCE); when(usersService.queryUser(loginUser.getId())).thenReturn(loginUser); when(usersService.getUserIdByName(loginUser.getUserName())).thenReturn(loginUser.getId()); - when(workflowInstanceMapper.queryWorkflowInstanceListPaging( + when(workflowInstanceDao.queryWorkflowInstanceListPaging( Mockito.any(Page.class), eq(project.getCode()), eq(1L), @@ -268,7 +264,7 @@ public void testQueryWorkflowInstanceList() { Assertions.assertEquals(Status.SUCCESS.getCode(), (int) successRes.getCode()); // data parameter empty - when(workflowInstanceMapper.queryWorkflowInstanceListPaging(Mockito.any(Page.class), eq(project.getCode()), + when(workflowInstanceDao.queryWorkflowInstanceListPaging(Mockito.any(Page.class), eq(project.getCode()), eq(1L), eq(""), eq(""), Mockito.any(), eq("192.168.xx.xx"), eq(null), eq(null))).thenReturn(pageReturn); successRes = workflowInstanceService.queryWorkflowInstanceList(loginUser, projectCode, 1, "", @@ -287,7 +283,7 @@ public void testQueryWorkflowInstanceList() { Assertions.assertEquals(Status.SUCCESS.getCode(), (int) executorExistRes.getCode()); // executor name empty - when(workflowInstanceMapper.queryWorkflowInstanceListPaging(Mockito.any(Page.class), eq(project.getCode()), + when(workflowInstanceDao.queryWorkflowInstanceListPaging(Mockito.any(Page.class), eq(project.getCode()), eq(1L), eq(""), eq("admin"), Mockito.any(), eq("192.168.xx.xx"), eq(start), eq(end))).thenReturn(pageReturn); Result executorEmptyRes = @@ -318,7 +314,7 @@ public void queryByTriggerCode() { workflowInstanceService.queryByTriggerCode(loginUser, projectCode, null); Assertions.assertTrue(nullTriggerRes.isEmpty()); - when(workflowInstanceMapper.queryByTriggerCode(999L)).thenReturn(new ArrayList<>()); + when(workflowInstanceDao.queryByTriggerCode(999L)).thenReturn(new ArrayList<>()); List emptyRes = workflowInstanceService.queryByTriggerCode(loginUser, projectCode, 999L); Assertions.assertTrue(emptyRes.isEmpty()); } @@ -345,7 +341,7 @@ public void testQueryTopNLongestRunningWorkflowInstance() { assertThrowsServiceException(Status.NEGTIVE_SIZE_NUMBER_ERROR, () -> workflowInstanceService .queryTopNLongestRunningWorkflowInstance(loginUser, projectCode, -1, startTime, endTime)); - when(workflowInstanceMapper.queryTopNWorkflowInstance(Mockito.eq(size), Mockito.any(), Mockito.any(), + when(workflowInstanceDao.queryTopNWorkflowInstance(Mockito.eq(size), Mockito.any(), Mockito.any(), Mockito.eq(WorkflowExecutionStatus.SUCCESS), Mockito.eq(projectCode))) .thenReturn(new ArrayList<>()); List successRes = workflowInstanceService.queryTopNLongestRunningWorkflowInstance(loginUser, @@ -717,11 +713,11 @@ public void testViewVariables() { workflowInstance.setCommandType(CommandType.SCHEDULER); workflowInstance.setScheduleTime(new Date()); workflowInstance.setGlobalParams(""); - when(workflowInstanceMapper.queryDetailById(1)).thenReturn(workflowInstance); + when(workflowInstanceDao.queryDetailById(1)).thenReturn(workflowInstance); WorkflowInstanceVariablesDTO successRes = workflowInstanceService.viewVariables(loginUser, projectCode, 1); Assertions.assertNotNull(successRes); - when(workflowInstanceMapper.queryDetailById(1)).thenReturn(null); + when(workflowInstanceDao.queryDetailById(1)).thenReturn(null); assertThrowsServiceException(Status.WORKFLOW_INSTANCE_NOT_EXIST, () -> workflowInstanceService.viewVariables(loginUser, projectCode, 1)); @@ -754,7 +750,7 @@ public void testViewVariables_WithTimePlaceholders() { workflowInstance.setGlobalParams(globalParamsJson); workflowInstance.setWorkflowDefinitionCode(100L); - when(workflowInstanceMapper.queryDetailById(1)).thenReturn(workflowInstance); + when(workflowInstanceDao.queryDetailById(1)).thenReturn(workflowInstance); WorkflowDefinition workflowDefinition = new WorkflowDefinition(); workflowDefinition.setCode(100L); @@ -789,7 +785,7 @@ public void testViewVariables_InstanceNotFound() { doNothing().when(projectService) .checkProjectAndAuthThrowException(loginUser, projectCode, WORKFLOW_INSTANCE); - when(workflowInstanceMapper.queryDetailById(999)).thenReturn(null); + when(workflowInstanceDao.queryDetailById(999)).thenReturn(null); assertThrowsServiceException(Status.WORKFLOW_INSTANCE_NOT_EXIST, () -> workflowInstanceService.viewVariables(loginUser, projectCode, 999)); @@ -809,7 +805,7 @@ public void testViewVariables_EmptyGlobalParams() { workflowInstance.setGlobalParams(""); workflowInstance.setWorkflowDefinitionCode(101L); - when(workflowInstanceMapper.queryDetailById(2)).thenReturn(workflowInstance); + when(workflowInstanceDao.queryDetailById(2)).thenReturn(workflowInstance); WorkflowDefinition workflowDefinition = new WorkflowDefinition(); workflowDefinition.setCode(101L); @@ -833,11 +829,11 @@ public void testViewGantt() throws Exception { TaskInstance taskInstance = getTaskInstance(); taskInstance.setState(TaskExecutionStatus.RUNNING_EXECUTION); taskInstance.setStartTime(new Date()); - when(workflowInstanceMapper.queryDetailById(1)).thenReturn(workflowInstance); + when(workflowInstanceDao.queryDetailById(1)).thenReturn(workflowInstance); when(workflowDefinitionLogMapper.queryByDefinitionCodeAndVersion( workflowInstance.getWorkflowDefinitionCode(), workflowInstance.getWorkflowDefinitionVersion())).thenReturn(new WorkflowDefinitionLog()); - when(workflowInstanceMapper.queryDetailById(1)).thenReturn(workflowInstance); + when(workflowInstanceDao.queryDetailById(1)).thenReturn(workflowInstance); DAG graph = new DAG<>(); for (long i = 1; i <= 7; ++i) { graph.addNode(i, new TaskNode()); @@ -848,7 +844,7 @@ public void testViewGantt() throws Exception { Assertions.assertNotNull(workflowInstanceService.viewGantt(loginUser, projectCode, 1)); - when(workflowInstanceMapper.queryDetailById(1)).thenReturn(null); + when(workflowInstanceDao.queryDetailById(1)).thenReturn(null); assertThrowsServiceException(Status.WORKFLOW_INSTANCE_NOT_EXIST, () -> workflowInstanceService.viewGantt(loginUser, projectCode, 1)); @@ -882,7 +878,7 @@ public void testViewVariablesWithStartingParam() { workflowInstance.setScheduleTime(new Date()); workflowInstance.setCommandParam(JSONUtils.toJsonString(runWorkflowCommandParam)); - when(workflowInstanceMapper.queryDetailById(1)).thenReturn(workflowInstance); + when(workflowInstanceDao.queryDetailById(1)).thenReturn(workflowInstance); Assertions.assertNotNull(workflowInstanceService.viewVariables(loginUser, projectCode, 1)); final RunWorkflowCommandParam commandParamWithEmptyTimeZone = RunWorkflowCommandParam.builder() diff --git a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/repository/WorkflowInstanceDao.java b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/repository/WorkflowInstanceDao.java index 52b0770109fe..248391aa45fe 100644 --- a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/repository/WorkflowInstanceDao.java +++ b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/repository/WorkflowInstanceDao.java @@ -19,10 +19,16 @@ import org.apache.dolphinscheduler.common.enums.WorkflowExecutionStatus; import org.apache.dolphinscheduler.dao.entity.WorkflowInstance; +import org.apache.dolphinscheduler.dao.model.WorkflowInstanceStatusCountDto; import org.apache.dolphinscheduler.plugin.task.api.model.DateInterval; +import java.util.Collection; +import java.util.Date; import java.util.List; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; + public interface WorkflowInstanceDao extends IDao { /** @@ -92,4 +98,40 @@ List queryByWorkflowCodeVersionStatus(Long workflowDefinitionC * Query the workflow instances under the master that need to be failover. */ List queryNeedFailoverWorkflowInstances(String masterAddress); + + WorkflowInstance queryDetailById(int id); + + List countWorkflowInstanceStateByProjectCodes(Date startTime, + Date endTime, + Collection projectCodes); + + int updateWorkflowInstanceByTenantCode(String originTenantCode, String destTenantCode); + + int updateWorkflowInstanceByWorkerGroupName(String originWorkerGroupName, String destWorkerGroupName); + + List queryByTenantCodeAndStatus(String tenantCode, int[] states); + + List queryByWorkerGroupNameAndStatus(String workerGroupName, int[] states); + + List queryTopNWorkflowInstance(int size, + Date startTime, + Date endTime, + WorkflowExecutionStatus status, + long projectCode); + + IPage queryWorkflowInstanceListPaging(Page page, + Long projectCode, + Long workflowDefinitionCode, + String searchVal, + String executorName, + int[] statusArray, + String host, + Date startTime, + Date endTime); + + List queryByWorkflowDefinitionCodeAndStatus(Long workflowDefinitionCode, int[] states); + + List queryByWorkflowDefinitionCode(Long workflowDefinitionCode, int size); + + List queryByTriggerCode(Long triggerCode); } diff --git a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/repository/impl/WorkflowInstanceDaoImpl.java b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/repository/impl/WorkflowInstanceDaoImpl.java index 6f35057d4432..9d8772d6c77c 100644 --- a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/repository/impl/WorkflowInstanceDaoImpl.java +++ b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/repository/impl/WorkflowInstanceDaoImpl.java @@ -22,10 +22,13 @@ import org.apache.dolphinscheduler.dao.entity.WorkflowInstanceRelation; import org.apache.dolphinscheduler.dao.mapper.WorkflowInstanceMapper; import org.apache.dolphinscheduler.dao.mapper.WorkflowInstanceRelationMapper; +import org.apache.dolphinscheduler.dao.model.WorkflowInstanceStatusCountDto; import org.apache.dolphinscheduler.dao.repository.BaseDao; import org.apache.dolphinscheduler.dao.repository.WorkflowInstanceDao; import org.apache.dolphinscheduler.plugin.task.api.model.DateInterval; +import java.util.Collection; +import java.util.Date; import java.util.List; import lombok.NonNull; @@ -34,6 +37,9 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Repository; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; + @Slf4j @Repository public class WorkflowInstanceDaoImpl extends BaseDao @@ -175,4 +181,74 @@ public List queryNeedFailoverWorkflowInstances(String masterAd return mybatisMapper.queryByHostAndStatus(masterAddress, WorkflowExecutionStatus.NEED_FAILOVER_STATES); } + + @Override + public WorkflowInstance queryDetailById(int id) { + return mybatisMapper.queryDetailById(id); + } + + @Override + public List countWorkflowInstanceStateByProjectCodes(Date startTime, + Date endTime, + Collection projectCodes) { + return mybatisMapper.countWorkflowInstanceStateByProjectCodes(startTime, endTime, projectCodes); + } + + @Override + public int updateWorkflowInstanceByTenantCode(String originTenantCode, String destTenantCode) { + return mybatisMapper.updateWorkflowInstanceByTenantCode(originTenantCode, destTenantCode); + } + + @Override + public int updateWorkflowInstanceByWorkerGroupName(String originWorkerGroupName, String destWorkerGroupName) { + return mybatisMapper.updateWorkflowInstanceByWorkerGroupName(originWorkerGroupName, destWorkerGroupName); + } + + @Override + public List queryByTenantCodeAndStatus(String tenantCode, int[] states) { + return mybatisMapper.queryByTenantCodeAndStatus(tenantCode, states); + } + + @Override + public List queryByWorkerGroupNameAndStatus(String workerGroupName, int[] states) { + return mybatisMapper.queryByWorkerGroupNameAndStatus(workerGroupName, states); + } + + @Override + public List queryTopNWorkflowInstance(int size, + Date startTime, + Date endTime, + WorkflowExecutionStatus status, + long projectCode) { + return mybatisMapper.queryTopNWorkflowInstance(size, startTime, endTime, status, projectCode); + } + + @Override + public IPage queryWorkflowInstanceListPaging(Page page, + Long projectCode, + Long workflowDefinitionCode, + String searchVal, + String executorName, + int[] statusArray, + String host, + Date startTime, + Date endTime) { + return mybatisMapper.queryWorkflowInstanceListPaging(page, projectCode, workflowDefinitionCode, searchVal, + executorName, statusArray, host, startTime, endTime); + } + + @Override + public List queryByWorkflowDefinitionCodeAndStatus(Long workflowDefinitionCode, int[] states) { + return mybatisMapper.queryByWorkflowDefinitionCodeAndStatus(workflowDefinitionCode, states); + } + + @Override + public List queryByWorkflowDefinitionCode(Long workflowDefinitionCode, int size) { + return mybatisMapper.queryByWorkflowDefinitionCode(workflowDefinitionCode, size); + } + + @Override + public List queryByTriggerCode(Long triggerCode) { + return mybatisMapper.queryByTriggerCode(triggerCode); + } }