From 8f0c400ee094e9f93fd74e9d09f6258903f56d91 Mon Sep 17 00:00:00 2001 From: wen-hemin <39549317+wen-hemin@users.noreply.github.com> Date: Tue, 20 Jul 2021 11:01:50 +0800 Subject: [PATCH] [Fix-5518]: the command state count interface and queue state count interface, remove unused paramaters (#5853) * fix: the data analysis state count interface, projectId change to projectCode * fix: the data analysis state count interface, projectId change to projectCode * fix checkstyle * fix checkstyle * fix: the process state count page use "projectCode" * fix: English comments * fix: the user definition count interface, projectId change to projectCode * fix comment * fix: the command state count interface, projectId change to projectCode * fix: the command state count interface and queue state count interface, remove unused paramaters * fix comments Co-authored-by: wen-hemin --- .../controller/DataAnalysisController.java | 26 +---- .../api/service/DataAnalysisService.java | 8 +- .../service/impl/DataAnalysisServiceImpl.java | 47 +------- .../DataAnalysisControllerTest.java | 17 +-- .../api/service/DataAnalysisServiceTest.java | 51 ++------- .../pages/index/_source/queueCount.vue | 101 ------------------ 6 files changed, 18 insertions(+), 232 deletions(-) delete mode 100644 dolphinscheduler-ui/src/js/conf/home/pages/projects/pages/index/_source/queueCount.vue diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/DataAnalysisController.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/DataAnalysisController.java index 0f707a697b..a99ceb4d8a 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/DataAnalysisController.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/DataAnalysisController.java @@ -140,27 +140,16 @@ public class DataAnalysisController extends BaseController { * statistical command status data * * @param loginUser login user - * @param startDate start date - * @param endDate end date - * @param projectCode project code - * @return command state in project code + * @return command state of user projects */ @ApiOperation(value = "countCommandState", notes = "COUNT_COMMAND_STATE_NOTES") - @ApiImplicitParams({ - @ApiImplicitParam(name = "startDate", value = "START_DATE", dataType = "String"), - @ApiImplicitParam(name = "endDate", value = "END_DATE", dataType = "String"), - @ApiImplicitParam(name = "projectCode", value = "PROJECT_CODE", dataType = "Long", example = "100") - }) @GetMapping(value = "/command-state-count") @ResponseStatus(HttpStatus.OK) @ApiException(COMMAND_STATE_COUNT_ERROR) @AccessLogAnnotation(ignoreRequestArgs = "loginUser") - public Result countCommandState(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, - @RequestParam(value = "startDate", required = false) String startDate, - @RequestParam(value = "endDate", required = false) String endDate, - @RequestParam(value = "projectCode", required = false, defaultValue = "0") long projectCode) { + public Result countCommandState(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser) { - Map result = dataAnalysisService.countCommandState(loginUser, projectCode, startDate, endDate); + Map result = dataAnalysisService.countCommandState(loginUser); return returnDataList(result); } @@ -168,21 +157,16 @@ public class DataAnalysisController extends BaseController { * queue count * * @param loginUser login user - * @param projectId project id * @return queue state count */ @ApiOperation(value = "countQueueState", notes = "COUNT_QUEUE_STATE_NOTES") - @ApiImplicitParams({ - @ApiImplicitParam(name = "projectId", value = "PROJECT_ID", dataType = "Int", example = "100") - }) @GetMapping(value = "/queue-count") @ResponseStatus(HttpStatus.OK) @ApiException(QUEUE_COUNT_ERROR) @AccessLogAnnotation(ignoreRequestArgs = "loginUser") - public Result countQueueState(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser, - @RequestParam(value = "projectId", required = false, defaultValue = "0") int projectId) { + public Result countQueueState(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser) { - Map result = dataAnalysisService.countQueueState(loginUser, projectId); + Map result = dataAnalysisService.countQueueState(loginUser); return returnDataList(result); } diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/DataAnalysisService.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/DataAnalysisService.java index 1a68514fb5..9a5dbe50ca 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/DataAnalysisService.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/DataAnalysisService.java @@ -61,20 +61,16 @@ public interface DataAnalysisService { * statistical command status data * * @param loginUser login user - * @param projectCode project code - * @param startDate start date - * @param endDate end date * @return command state count data */ - Map countCommandState(User loginUser, long projectCode, String startDate, String endDate); + Map countCommandState(User loginUser); /** * count queue state * * @param loginUser login user - * @param projectId project id * @return queue state count data */ - Map countQueueState(User loginUser, int projectId); + Map countQueueState(User loginUser); } 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 fcc69c71ef..2377439ba8 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 @@ -202,46 +202,20 @@ public class DataAnalysisServiceImpl extends BaseServiceImpl implements DataAnal * statistical command status data * * @param loginUser login user - * @param projectCode project code - * @param startDate start date - * @param endDate end date * @return command state count data */ @Override - public Map countCommandState(User loginUser, long projectCode, String startDate, String endDate) { + public Map countCommandState(User loginUser) { Map result = new HashMap<>(); - if (projectCode != 0) { - Project project = projectMapper.queryByCode(projectCode); - result = projectService.checkProjectAndAuth(loginUser, project, project.getName()); - if (result.get(Constants.STATUS) != Status.SUCCESS) { - return result; - } - } - /** * find all the task lists in the project under the user * statistics based on task status execution, failure, completion, wait, total */ Date start = null; - if (StringUtils.isNotEmpty(startDate)) { - start = DateUtils.getScheduleDate(startDate); - if (Objects.isNull(start)) { - putMsg(result, Status.REQUEST_PARAMS_NOT_VALID_ERROR, Constants.START_END_DATE); - return result; - } - } Date end = null; - if (StringUtils.isNotEmpty(endDate)) { - end = DateUtils.getScheduleDate(endDate); - if (Objects.isNull(end)) { - putMsg(result, Status.REQUEST_PARAMS_NOT_VALID_ERROR, Constants.START_END_DATE); - return result; - } - } + Long[] projectCodeArray = getProjectCodesArrays(loginUser); - Long[] projectCodeArray = projectCode == 0 ? getProjectCodesArrays(loginUser) - : new Long[] { projectCode }; // count normal command state Map normalCountCommandCounts = commandMapper.countCommandState(loginUser.getId(), start, end, projectCodeArray) .stream() @@ -279,19 +253,12 @@ public class DataAnalysisServiceImpl extends BaseServiceImpl implements DataAnal /** * count queue state * - * @param loginUser login user - * @param projectId project id * @return queue state count data */ @Override - public Map countQueueState(User loginUser, int projectId) { + public Map countQueueState(User loginUser) { Map result = new HashMap<>(); - boolean checkProject = checkProject(loginUser, projectId, result); - if (!checkProject) { - return result; - } - //TODO need to add detail data info Map dataMap = new HashMap<>(); dataMap.put("taskQueue", 0); @@ -301,12 +268,4 @@ public class DataAnalysisServiceImpl extends BaseServiceImpl implements DataAnal return result; } - private boolean checkProject(User loginUser, int projectId, Map result) { - if (projectId != 0) { - Project project = projectMapper.selectById(projectId); - return projectService.hasProjectAndPerm(loginUser, project, result); - } - return true; - } - } diff --git a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/DataAnalysisControllerTest.java b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/DataAnalysisControllerTest.java index 382a795ab5..d63ffff30e 100644 --- a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/DataAnalysisControllerTest.java +++ b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/controller/DataAnalysisControllerTest.java @@ -110,15 +110,8 @@ public class DataAnalysisControllerTest extends AbstractControllerTest { @Test public void testCountCommandState() throws Exception { - PowerMockito.when(projectMapper.queryByCode(Mockito.any())).thenReturn(getProject("test")); - - MultiValueMap paramsMap = new LinkedMultiValueMap<>(); - paramsMap.add("startDate","2019-12-01 00:00:00"); - paramsMap.add("endDate","2019-12-15 23:59:59"); - paramsMap.add("projectId","16"); MvcResult mvcResult = mockMvc.perform(get("/projects/analysis/command-state-count") - .header("sessionId", sessionId) - .params(paramsMap)) + .header("sessionId", sessionId)) .andExpect(status().isOk()) .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)) .andReturn(); @@ -127,16 +120,10 @@ public class DataAnalysisControllerTest extends AbstractControllerTest { logger.info(mvcResult.getResponse().getContentAsString()); } - @Test public void testCountQueueState() throws Exception { - PowerMockito.when(projectMapper.selectById(Mockito.any())).thenReturn(getProject("test")); - - MultiValueMap paramsMap = new LinkedMultiValueMap<>(); - paramsMap.add("projectId","16"); MvcResult mvcResult = mockMvc.perform(get("/projects/analysis/queue-count") - .header("sessionId", sessionId) - .params(paramsMap)) + .header("sessionId", sessionId)) .andExpect(status().isOk()) .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)) .andReturn(); 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 eb942333ee..deb8cf0124 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 @@ -251,54 +251,20 @@ public class DataAnalysisServiceTest { @Test public void testCountCommandState() { - String startDate = "2020-02-11 16:02:18"; - String endDate = "2020-02-11 16:03:18"; - - Mockito.when(projectMapper.queryByCode(Mockito.any())).thenReturn(getProject("test")); - - //checkProject false - Map result = dataAnalysisServiceImpl.countCommandState(user, 2, startDate, endDate); - Assert.assertTrue(result.isEmpty()); - - putMsg(result, Status.SUCCESS, null); - Mockito.when(projectService.checkProjectAndAuth(any(), any(), any())).thenReturn(result); - List commandCounts = new ArrayList<>(1); CommandCount commandCount = new CommandCount(); commandCount.setCommandType(CommandType.START_PROCESS); commandCounts.add(commandCount); - Mockito.when(commandMapper.countCommandState(0, DateUtils.getScheduleDate(startDate), - DateUtils.getScheduleDate(endDate), new Long[]{1L})).thenReturn(commandCounts); - - Mockito.when(errorCommandMapper.countCommandState(DateUtils.getScheduleDate(startDate), - DateUtils.getScheduleDate(endDate), new Long[]{1L})).thenReturn(commandCounts); - Mockito.when(projectService.hasProjectAndPerm(Mockito.any(), Mockito.any(), Mockito.any())).thenReturn(true); + Mockito.when(commandMapper.countCommandState(0, null, null, new Long[]{1L})).thenReturn(commandCounts); + Mockito.when(errorCommandMapper.countCommandState(null, null, new Long[]{1L})).thenReturn(commandCounts); - result = dataAnalysisServiceImpl.countCommandState(user, 1, startDate, endDate); + Map result = dataAnalysisServiceImpl.countCommandState(user); Assert.assertEquals(Status.SUCCESS, result.get(Constants.STATUS)); - // when all date in illegal format then return error message - String startDate2 = "illegalDateString"; - String endDate2 = "illegalDateString"; - Map result2 = dataAnalysisServiceImpl.countCommandState(user, 0, startDate2, endDate2); - Assert.assertEquals(Status.REQUEST_PARAMS_NOT_VALID_ERROR, result2.get(Constants.STATUS)); - - // when one of date in illegal format then return error message - String startDate3 = "2020-08-22 09:23:10"; - String endDate3 = "illegalDateString"; - Map result3 = dataAnalysisServiceImpl.countCommandState(user, 0, startDate3, endDate3); - Assert.assertEquals(Status.REQUEST_PARAMS_NOT_VALID_ERROR, result3.get(Constants.STATUS)); - - // when one of date in illegal format then return error message - String startDate4 = "illegalDateString"; - String endDate4 = "2020-08-22 09:23:10"; - Map result4 = dataAnalysisServiceImpl.countCommandState(user, 0, startDate4, endDate4); - Assert.assertEquals(Status.REQUEST_PARAMS_NOT_VALID_ERROR, result4.get(Constants.STATUS)); - // when no command found then return all count are 0 Mockito.when(commandMapper.countCommandState(anyInt(), any(), any(), any())).thenReturn(Collections.emptyList()); Mockito.when(errorCommandMapper.countCommandState(any(), any(), any())).thenReturn(Collections.emptyList()); - Map result5 = dataAnalysisServiceImpl.countCommandState(user, 0, startDate, null); + Map result5 = dataAnalysisServiceImpl.countCommandState(user); assertThat(result5).containsEntry(Constants.STATUS, Status.SUCCESS); assertThat(result5.get(Constants.DATA_LIST)).asList().extracting("errorCount").allMatch(count -> count.equals(0)); assertThat(result5.get(Constants.DATA_LIST)).asList().extracting("normalCount").allMatch(count -> count.equals(0)); @@ -313,7 +279,7 @@ public class DataAnalysisServiceTest { Mockito.when(commandMapper.countCommandState(anyInt(), any(), any(), any())).thenReturn(Collections.singletonList(normalCommandCount)); Mockito.when(errorCommandMapper.countCommandState(any(), any(), any())).thenReturn(Collections.singletonList(errorCommandCount)); - Map result6 = dataAnalysisServiceImpl.countCommandState(user, 0, null, null); + Map result6 = dataAnalysisServiceImpl.countCommandState(user); assertThat(result6).containsEntry(Constants.STATUS, Status.SUCCESS); CommandStateCount commandStateCount = new CommandStateCount(); @@ -325,12 +291,8 @@ public class DataAnalysisServiceTest { @Test public void testCountQueueState() { - // when project check fail then return nothing - Map result1 = dataAnalysisServiceImpl.countQueueState(user, 2); - Assert.assertTrue(result1.isEmpty()); - // when project check success when return all count are 0 - Map result2 = dataAnalysisServiceImpl.countQueueState(user, 1); + Map result2 = dataAnalysisServiceImpl.countQueueState(user); assertThat(result2.get(Constants.DATA_LIST)).extracting("taskQueue", "taskKill") .isNotEmpty() .allMatch(count -> count.equals(0)); @@ -340,7 +302,6 @@ public class DataAnalysisServiceTest { * get list */ private List getTaskInstanceStateCounts() { - List taskInstanceStateCounts = new ArrayList<>(1); ExecuteStatusCount executeStatusCount = new ExecuteStatusCount(); executeStatusCount.setExecutionStatus(ExecutionStatus.RUNNING_EXECUTION); diff --git a/dolphinscheduler-ui/src/js/conf/home/pages/projects/pages/index/_source/queueCount.vue b/dolphinscheduler-ui/src/js/conf/home/pages/projects/pages/index/_source/queueCount.vue deleted file mode 100644 index 5f2dae37ea..0000000000 --- a/dolphinscheduler-ui/src/js/conf/home/pages/projects/pages/index/_source/queueCount.vue +++ /dev/null @@ -1,101 +0,0 @@ -/* - * 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. - */ - -