From d2a9e05a664a9bf12a29ae1873183b0173c0bf49 Mon Sep 17 00:00:00 2001 From: wen-hemin <39549317+wen-hemin@users.noreply.github.com> Date: Mon, 12 Jul 2021 10:21:17 +0800 Subject: [PATCH] =?UTF-8?q?[Fix-5778]:=20The=20scheduler=20list=E3=80=81pr?= =?UTF-8?q?eview=E3=80=81delete=20interface,=20projectName=20->=20projectC?= =?UTF-8?q?ode=20(#5779)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: createSchedule interface, process definition id -> process definition code * fix: add junit * fix junit * fix: projectName -> projectCode * fix UT * Optimize variable type * fix: the updateSchedule interface, projectName -> projectCode * fix comment * fix: The scheduler online/offline interface, projectName -> projectCode * fix UT * fix: the scheduler list-page interface, projectName -> projectCode, processDefinitionId -> processDefinitionCode * add UT * fix: The scheduler list、preview、delete interface, projectName -> projectCode Co-authored-by: wen-hemin --- .../api/controller/SchedulerController.java | 16 +++++++--------- .../api/service/SchedulerService.java | 11 +++++------ .../service/impl/SchedulerServiceImpl.java | 19 +++++++++---------- .../controller/SchedulerControllerTest.java | 16 +++++++++++----- .../src/js/conf/home/store/dag/actions.js | 4 ++-- 5 files changed, 34 insertions(+), 32 deletions(-) diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/SchedulerController.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/SchedulerController.java index ce5b776634..abd142ee98 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/SchedulerController.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/SchedulerController.java @@ -249,7 +249,7 @@ public class SchedulerController extends BaseController { * delete schedule by id * * @param loginUser login user - * @param projectName project name + * @param projectCode project code * @param scheduleId scheule id * @return delete result code */ @@ -262,10 +262,10 @@ public class SchedulerController extends BaseController { @ApiException(DELETE_SCHEDULE_CRON_BY_ID_ERROR) @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result deleteScheduleById(@RequestAttribute(value = SESSION_USER) User loginUser, - @PathVariable String projectName, + @ApiParam(name = "projectCode", value = "PROJECT_CODE", required = true) @PathVariable long projectCode, @RequestParam("scheduleId") Integer scheduleId ) { - Map result = schedulerService.deleteScheduleById(loginUser, projectName, scheduleId); + Map result = schedulerService.deleteScheduleById(loginUser, projectCode, scheduleId); return returnDataList(result); } @@ -273,7 +273,7 @@ public class SchedulerController extends BaseController { * query schedule list * * @param loginUser login user - * @param projectName project name + * @param projectCode project code * @return schedule list */ @ApiOperation(value = "queryScheduleList", notes = "QUERY_SCHEDULE_LIST_NOTES") @@ -281,8 +281,8 @@ public class SchedulerController extends BaseController { @ApiException(QUERY_SCHEDULE_LIST_ERROR) @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result queryScheduleList(@ApiIgnore @RequestAttribute(value = SESSION_USER) User loginUser, - @ApiParam(name = "projectName", value = "PROJECT_NAME", required = true) @PathVariable String projectName) { - Map result = schedulerService.queryScheduleList(loginUser, projectName); + @ApiParam(name = "projectCode", value = "PROJECT_CODE", required = true) @PathVariable long projectCode) { + Map result = schedulerService.queryScheduleList(loginUser, projectCode); return returnDataList(result); } @@ -290,7 +290,6 @@ public class SchedulerController extends BaseController { * preview schedule * * @param loginUser login user - * @param projectName project name * @param schedule schedule expression * @return the next five fire time */ @@ -303,10 +302,9 @@ public class SchedulerController extends BaseController { @ApiException(PREVIEW_SCHEDULE_ERROR) @AccessLogAnnotation(ignoreRequestArgs = "loginUser") public Result previewSchedule(@ApiIgnore @RequestAttribute(value = SESSION_USER) User loginUser, - @ApiParam(name = "projectName", value = "PROJECT_NAME", required = true) @PathVariable String projectName, @RequestParam(value = "schedule") String schedule ) { - Map result = schedulerService.previewSchedule(loginUser, projectName, schedule); + Map result = schedulerService.previewSchedule(loginUser, schedule); return returnDataList(result); } } diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/SchedulerService.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/SchedulerService.java index 908f8eeb64..5df3a1614e 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/SchedulerService.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/SchedulerService.java @@ -111,10 +111,10 @@ public interface SchedulerService { * query schedule list * * @param loginUser login user - * @param projectName project name + * @param projectCode project code * @return schedule list */ - Map queryScheduleList(User loginUser, String projectName); + Map queryScheduleList(User loginUser, long projectCode); /** * delete schedule @@ -129,19 +129,18 @@ public interface SchedulerService { * delete schedule by id * * @param loginUser login user - * @param projectName project name + * @param projectCode project code * @param scheduleId scheule id * @return delete result code */ - Map deleteScheduleById(User loginUser, String projectName, Integer scheduleId); + Map deleteScheduleById(User loginUser, long projectCode, Integer scheduleId); /** * preview schedule * * @param loginUser login user - * @param projectName project name * @param schedule schedule expression * @return the next five fire time */ - Map previewSchedule(User loginUser, String projectName, String schedule); + Map previewSchedule(User loginUser, String schedule); } diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/SchedulerServiceImpl.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/SchedulerServiceImpl.java index d966413130..350ab9a513 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/SchedulerServiceImpl.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/SchedulerServiceImpl.java @@ -446,13 +446,13 @@ public class SchedulerServiceImpl extends BaseServiceImpl implements SchedulerSe * query schedule list * * @param loginUser login user - * @param projectName project name + * @param projectCode project code * @return schedule list */ @Override - public Map queryScheduleList(User loginUser, String projectName) { + public Map queryScheduleList(User loginUser, long projectCode) { Map result = new HashMap<>(); - Project project = projectMapper.queryByName(projectName); + Project project = projectMapper.queryByCode(projectCode); // check project auth boolean hasProjectAndPerm = projectService.hasProjectAndPerm(loginUser, project, result); @@ -460,7 +460,7 @@ public class SchedulerServiceImpl extends BaseServiceImpl implements SchedulerSe return result; } - List schedules = scheduleMapper.querySchedulerListByProjectName(projectName); + List schedules = scheduleMapper.querySchedulerListByProjectName(project.getName()); result.put(Constants.DATA_LIST, schedules); putMsg(result, Status.SUCCESS); @@ -516,17 +516,17 @@ public class SchedulerServiceImpl extends BaseServiceImpl implements SchedulerSe * delete schedule by id * * @param loginUser login user - * @param projectName project name + * @param projectCode project code * @param scheduleId scheule id * @return delete result code */ @Override - public Map deleteScheduleById(User loginUser, String projectName, Integer scheduleId) { + public Map deleteScheduleById(User loginUser, long projectCode, Integer scheduleId) { Map result = new HashMap<>(); - Project project = projectMapper.queryByName(projectName); + Project project = projectMapper.queryByCode(projectCode); - Map checkResult = projectService.checkProjectAndAuth(loginUser, project, projectName); + Map checkResult = projectService.checkProjectAndAuth(loginUser, project, project.getName()); Status resultEnum = (Status) checkResult.get(Constants.STATUS); if (resultEnum != Status.SUCCESS) { return checkResult; @@ -566,12 +566,11 @@ public class SchedulerServiceImpl extends BaseServiceImpl implements SchedulerSe * preview schedule * * @param loginUser login user - * @param projectName project name * @param schedule schedule expression * @return the next five fire time */ @Override - public Map previewSchedule(User loginUser, String projectName, String schedule) { + public Map previewSchedule(User loginUser, String schedule) { Map result = new HashMap<>(); CronExpression cronExpression; ScheduleParam scheduleParam = JSONUtils.parseObject(schedule, ScheduleParam.class); diff --git a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/SchedulerControllerTest.java b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/SchedulerControllerTest.java index 1a88d63f36..5e62489948 100644 --- a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/SchedulerControllerTest.java +++ b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/SchedulerControllerTest.java @@ -183,10 +183,11 @@ public class SchedulerControllerTest extends AbstractControllerTest { logger.info(mvcResult.getResponse().getContentAsString()); } - @Test public void testQueryScheduleList() throws Exception { - MvcResult mvcResult = mockMvc.perform(post("/projects/{projectName}/schedule/list","cxc_1113") + Mockito.when(schedulerService.queryScheduleList(isA(User.class), isA(Long.class))).thenReturn(success()); + + MvcResult mvcResult = mockMvc.perform(post("/projects/{projectCode}/schedule/list",123) .header(SESSION_ID, sessionId)) .andExpect(status().isOk()) .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)) @@ -197,10 +198,12 @@ public class SchedulerControllerTest extends AbstractControllerTest { logger.info(mvcResult.getResponse().getContentAsString()); } - @Test public void testPreviewSchedule() throws Exception { - MvcResult mvcResult = mockMvc.perform(post("/projects/{projectName}/schedule/preview","cxc_1113") + Mockito.when(schedulerService.previewSchedule(isA(User.class), isA(String.class))) + .thenReturn(success()); + + MvcResult mvcResult = mockMvc.perform(post("/projects/{projectCode}/schedule/preview",123) .header(SESSION_ID, sessionId) .param("schedule","{'startTime':'2019-06-10 00:00:00','endTime':'2019-06-13 00:00:00','crontab':'0 0 3/6 * * ? *'}")) .andExpect(status().isCreated()) @@ -217,7 +220,10 @@ public class SchedulerControllerTest extends AbstractControllerTest { MultiValueMap paramsMap = new LinkedMultiValueMap<>(); paramsMap.add("scheduleId","37"); - MvcResult mvcResult = mockMvc.perform(get("/projects/{projectName}/schedule/delete","cxc_1113") + Mockito.when(schedulerService.deleteScheduleById(isA(User.class), isA(Long.class), isA(Integer.class))) + .thenReturn(success()); + + MvcResult mvcResult = mockMvc.perform(get("/projects/{projectCode}/schedule/delete",123) .header(SESSION_ID, sessionId) .params(paramsMap)) .andExpect(status().isOk()) diff --git a/dolphinscheduler-ui/src/js/conf/home/store/dag/actions.js b/dolphinscheduler-ui/src/js/conf/home/store/dag/actions.js index ec78b4862b..f7b8c0e73a 100644 --- a/dolphinscheduler-ui/src/js/conf/home/store/dag/actions.js +++ b/dolphinscheduler-ui/src/js/conf/home/store/dag/actions.js @@ -567,7 +567,7 @@ export default { */ previewSchedule ({ state }, payload) { return new Promise((resolve, reject) => { - io.post(`projects/${state.projectName}/schedule/preview`, payload, res => { + io.post(`projects/${state.projectCode}/schedule/preview`, payload, res => { resolve(res.data) // alert(res.data) }).catch(e => { @@ -827,7 +827,7 @@ export default { */ deleteTiming ({ state }, payload) { return new Promise((resolve, reject) => { - io.get(`projects/${state.projectName}/schedule/delete`, payload, res => { + io.get(`projects/${state.projectCode}/schedule/delete`, payload, res => { resolve(res) }).catch(e => { reject(e)