mirror of
https://gitee.com/dolphinscheduler/DolphinScheduler.git
synced 2024-12-12 12:25:16 +08:00
[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 <wenhemin@apache.com>
This commit is contained in:
parent
f1a9c4958d
commit
8f0c400ee0
@ -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<String, Object> result = dataAnalysisService.countCommandState(loginUser, projectCode, startDate, endDate);
|
||||
Map<String, Object> 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<String, Object> result = dataAnalysisService.countQueueState(loginUser, projectId);
|
||||
Map<String, Object> result = dataAnalysisService.countQueueState(loginUser);
|
||||
return returnDataList(result);
|
||||
}
|
||||
|
||||
|
@ -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<String, Object> countCommandState(User loginUser, long projectCode, String startDate, String endDate);
|
||||
Map<String, Object> countCommandState(User loginUser);
|
||||
|
||||
/**
|
||||
* count queue state
|
||||
*
|
||||
* @param loginUser login user
|
||||
* @param projectId project id
|
||||
* @return queue state count data
|
||||
*/
|
||||
Map<String, Object> countQueueState(User loginUser, int projectId);
|
||||
Map<String, Object> countQueueState(User loginUser);
|
||||
|
||||
}
|
||||
|
@ -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<String, Object> countCommandState(User loginUser, long projectCode, String startDate, String endDate) {
|
||||
public Map<String, Object> countCommandState(User loginUser) {
|
||||
Map<String, Object> 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<CommandType, Integer> 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<String, Object> countQueueState(User loginUser, int projectId) {
|
||||
public Map<String, Object> countQueueState(User loginUser) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
|
||||
boolean checkProject = checkProject(loginUser, projectId, result);
|
||||
if (!checkProject) {
|
||||
return result;
|
||||
}
|
||||
|
||||
//TODO need to add detail data info
|
||||
Map<String, Integer> 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<String, Object> result) {
|
||||
if (projectId != 0) {
|
||||
Project project = projectMapper.selectById(projectId);
|
||||
return projectService.hasProjectAndPerm(loginUser, project, result);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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<String, String> 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<String, String> 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();
|
||||
|
@ -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<String, Object> 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<CommandCount> 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(commandMapper.countCommandState(0, null, null, new Long[]{1L})).thenReturn(commandCounts);
|
||||
Mockito.when(errorCommandMapper.countCommandState(null, null, 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);
|
||||
|
||||
result = dataAnalysisServiceImpl.countCommandState(user, 1, startDate, endDate);
|
||||
Map<String, Object> 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<String, Object> 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<String, Object> 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<String, Object> 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<String, Object> result5 = dataAnalysisServiceImpl.countCommandState(user, 0, startDate, null);
|
||||
Map<String, Object> 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<String, Object> result6 = dataAnalysisServiceImpl.countCommandState(user, 0, null, null);
|
||||
Map<String, Object> 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<String, Object> result1 = dataAnalysisServiceImpl.countQueueState(user, 2);
|
||||
Assert.assertTrue(result1.isEmpty());
|
||||
|
||||
// when project check success when return all count are 0
|
||||
Map<String, Object> result2 = dataAnalysisServiceImpl.countQueueState(user, 1);
|
||||
Map<String, Object> 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<ExecuteStatusCount> getTaskInstanceStateCounts() {
|
||||
|
||||
List<ExecuteStatusCount> taskInstanceStateCounts = new ArrayList<>(1);
|
||||
ExecuteStatusCount executeStatusCount = new ExecuteStatusCount();
|
||||
executeStatusCount.setExecutionStatus(ExecutionStatus.RUNNING_EXECUTION);
|
||||
|
@ -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.
|
||||
*/
|
||||
<template>
|
||||
<div class="queue-count-model">
|
||||
<div v-show="!msg">
|
||||
<div class="data-area" v-spin="isSpin" style="height: 430px;">
|
||||
<div class="col-md-7">
|
||||
<div id="queue-pie" style="height:260px;margin-top: 100px;"></div>
|
||||
</div>
|
||||
<div class="col-md-5">
|
||||
<div class="table-small-model">
|
||||
<table>
|
||||
<tr>
|
||||
<th width="40">{{$t('#')}}</th>
|
||||
<th>{{$t('Number')}}</th>
|
||||
<th>{{$t('State')}}</th>
|
||||
</tr>
|
||||
<tr :key="$index" v-for="(item,$index) in queueList">
|
||||
<td><span>{{$index+1}}</span></td>
|
||||
<td><span><a href="javascript:" >{{item.value}}</a></span></td>
|
||||
<td><span class="ellipsis" style="width: 98%;" :title="item.key">{{item.key}}</span></td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div v-show="msg">
|
||||
<m-no-data :msg="msg" v-if="msg" :height="430"></m-no-data>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
<script>
|
||||
import _ from 'lodash'
|
||||
import { mapActions } from 'vuex'
|
||||
import { pie } from './chartConfig'
|
||||
import Chart from '@/module/ana-charts'
|
||||
import mNoData from '@/module/components/noData/noData'
|
||||
export default {
|
||||
name: 'queue-count',
|
||||
data () {
|
||||
return {
|
||||
isSpin: true,
|
||||
msg: '',
|
||||
queueList: []
|
||||
}
|
||||
},
|
||||
props: {
|
||||
searchParams: Object
|
||||
},
|
||||
methods: {
|
||||
...mapActions('projects', ['getQueueCount']),
|
||||
_handleQueue (res) {
|
||||
_.forEach(res.data, (v, k) => this.queueList.push({
|
||||
key: k === 'taskQueue' ? `${this.$t('Task queue')}` : `${this.$t('Task kill')}`,
|
||||
value: v
|
||||
}))
|
||||
const myChart = Chart.pie('#queue-pie', this.queueList, { title: '' })
|
||||
myChart.echart.setOption(_.assign(_.cloneDeep(pie), {
|
||||
color: ['#D5050B', '#0398E1']
|
||||
}))
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
searchParams: {
|
||||
deep: true,
|
||||
immediate: true,
|
||||
handler (o) {
|
||||
this.isSpin = true
|
||||
this.getQueueCount(o).then(res => {
|
||||
this.queueList = []
|
||||
this._handleQueue(res)
|
||||
this.isSpin = false
|
||||
}).catch(e => {
|
||||
this.msg = e.msg || 'error'
|
||||
this.isSpin = false
|
||||
})
|
||||
}
|
||||
}
|
||||
},
|
||||
created () {
|
||||
},
|
||||
mounted () {
|
||||
},
|
||||
components: { mNoData }
|
||||
}
|
||||
</script>
|
Loading…
Reference in New Issue
Block a user