|
|
|
@ -21,15 +21,17 @@ import cn.escheduler.api.dto.DefineUserDto;
|
|
|
|
|
import cn.escheduler.api.dto.TaskCountDto; |
|
|
|
|
import cn.escheduler.api.enums.Status; |
|
|
|
|
import cn.escheduler.api.utils.Constants; |
|
|
|
|
import cn.escheduler.common.enums.ExecutionStatus; |
|
|
|
|
import cn.escheduler.common.enums.UserType; |
|
|
|
|
import cn.escheduler.common.queue.ITaskQueue; |
|
|
|
|
import cn.escheduler.common.queue.TaskQueueFactory; |
|
|
|
|
import cn.escheduler.common.utils.DateUtils; |
|
|
|
|
import cn.escheduler.dao.mapper.ProcessDefinitionMapper; |
|
|
|
|
import cn.escheduler.dao.mapper.ProcessInstanceMapper; |
|
|
|
|
import cn.escheduler.dao.mapper.ProjectMapper; |
|
|
|
|
import cn.escheduler.dao.mapper.TaskInstanceMapper; |
|
|
|
|
import cn.escheduler.dao.mapper.*; |
|
|
|
|
import cn.escheduler.dao.model.DefinitionGroupByUser; |
|
|
|
|
import cn.escheduler.dao.model.ExecuteStatusCount; |
|
|
|
|
import cn.escheduler.dao.model.Project; |
|
|
|
|
import cn.escheduler.dao.model.User; |
|
|
|
|
import org.apache.commons.lang.StringUtils; |
|
|
|
|
import org.slf4j.Logger; |
|
|
|
|
import org.slf4j.LoggerFactory; |
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
@ -55,15 +57,21 @@ public class DataAnalysisService {
|
|
|
|
|
@Autowired |
|
|
|
|
ProjectService projectService; |
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
TaskInstanceMapper taskInstanceMapper; |
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
ProcessInstanceMapper processInstanceMapper; |
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
ProcessDefinitionMapper processDefinitionMapper; |
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
CommandMapper commandMapper; |
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
ErrorCommandMapper errorCommandMapper; |
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
TaskInstanceMapper taskInstanceMapper; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* statistical task instance status data |
|
|
|
|
* |
|
|
|
@ -206,4 +214,157 @@ public class DataAnalysisService {
|
|
|
|
|
} |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* statistical command status data |
|
|
|
|
* |
|
|
|
|
* @param loginUser |
|
|
|
|
* @param projectId |
|
|
|
|
* @param startDate |
|
|
|
|
* @param endDate |
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
|
public Map<String, Object> countCommandState(User loginUser, int projectId, String startDate, String endDate) { |
|
|
|
|
|
|
|
|
|
Map<String, Object> result = new HashMap<>(5); |
|
|
|
|
if(projectId != 0){ |
|
|
|
|
Project project = projectMapper.queryById(projectId); |
|
|
|
|
result = projectService.checkProjectAndAuth(loginUser, project, String.valueOf(projectId)); |
|
|
|
|
|
|
|
|
|
if (getResultStatus(result)){ |
|
|
|
|
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; |
|
|
|
|
Date end = null; |
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
start = DateUtils.getScheduleDate(startDate); |
|
|
|
|
end = DateUtils.getScheduleDate(endDate); |
|
|
|
|
} catch (Exception e) { |
|
|
|
|
logger.error(e.getMessage(),e); |
|
|
|
|
putErrorRequestParamsMsg(result); |
|
|
|
|
return result; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// count command state
|
|
|
|
|
List<ExecuteStatusCount> commandStateCounts = |
|
|
|
|
commandMapper.countCommandState(loginUser.getId(), |
|
|
|
|
loginUser.getUserType(), start, end, projectId); |
|
|
|
|
|
|
|
|
|
// count error command state
|
|
|
|
|
List<ExecuteStatusCount> errorCommandStateCounts = |
|
|
|
|
errorCommandMapper.countCommandState(loginUser.getId(), |
|
|
|
|
loginUser.getUserType(), start, end, projectId); |
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
Map<ExecutionStatus,Map<String,Integer>> dataMap = new HashMap<>(); |
|
|
|
|
|
|
|
|
|
Map<String,Integer> commonCommand = new HashMap<>(); |
|
|
|
|
commonCommand.put("commandState",0); |
|
|
|
|
commonCommand.put("errorCommandState",0); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// init data map
|
|
|
|
|
dataMap.put(ExecutionStatus.SUBMITTED_SUCCESS,commonCommand); |
|
|
|
|
dataMap.put(ExecutionStatus.RUNNING_EXEUTION,commonCommand); |
|
|
|
|
dataMap.put(ExecutionStatus.READY_PAUSE,commonCommand); |
|
|
|
|
dataMap.put(ExecutionStatus.PAUSE,commonCommand); |
|
|
|
|
dataMap.put(ExecutionStatus.READY_STOP,commonCommand); |
|
|
|
|
dataMap.put(ExecutionStatus.STOP,commonCommand); |
|
|
|
|
dataMap.put(ExecutionStatus.FAILURE,commonCommand); |
|
|
|
|
dataMap.put(ExecutionStatus.SUCCESS,commonCommand); |
|
|
|
|
dataMap.put(ExecutionStatus.NEED_FAULT_TOLERANCE,commonCommand); |
|
|
|
|
dataMap.put(ExecutionStatus.KILL,commonCommand); |
|
|
|
|
dataMap.put(ExecutionStatus.WAITTING_THREAD,commonCommand); |
|
|
|
|
dataMap.put(ExecutionStatus.WAITTING_DEPEND,commonCommand); |
|
|
|
|
|
|
|
|
|
// put command state
|
|
|
|
|
for (ExecuteStatusCount executeStatusCount : commandStateCounts){ |
|
|
|
|
Map<String,Integer> commandStateCountsMap = new HashMap<>(dataMap.get(executeStatusCount.getExecutionStatus())); |
|
|
|
|
commandStateCountsMap.put("commandState", executeStatusCount.getCount()); |
|
|
|
|
dataMap.put(executeStatusCount.getExecutionStatus(),commandStateCountsMap); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// put error command state
|
|
|
|
|
for (ExecuteStatusCount errorExecutionStatus : errorCommandStateCounts){ |
|
|
|
|
Map<String,Integer> errorCommandStateCountsMap = new HashMap<>(dataMap.get(errorExecutionStatus.getExecutionStatus())); |
|
|
|
|
errorCommandStateCountsMap.put("errorCommandState",errorExecutionStatus.getCount()); |
|
|
|
|
dataMap.put(errorExecutionStatus.getExecutionStatus(),errorCommandStateCountsMap); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
result.put(Constants.DATA_LIST, dataMap); |
|
|
|
|
putMsg(result, Status.SUCCESS); |
|
|
|
|
return result; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* count queue state |
|
|
|
|
* @param loginUser |
|
|
|
|
* @param projectId |
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
|
public Map<String, Object> countQueueState(User loginUser, int projectId) { |
|
|
|
|
Map<String, Object> result = new HashMap<>(5); |
|
|
|
|
if(projectId != 0){ |
|
|
|
|
Project project = projectMapper.queryById(projectId); |
|
|
|
|
result = projectService.checkProjectAndAuth(loginUser, project, String.valueOf(projectId)); |
|
|
|
|
|
|
|
|
|
if (getResultStatus(result)){ |
|
|
|
|
return result; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
ITaskQueue tasksQueue = TaskQueueFactory.getTaskQueueInstance(); |
|
|
|
|
List<String> tasksQueueList = tasksQueue.getAllTasks(cn.escheduler.common.Constants.SCHEDULER_TASKS_QUEUE); |
|
|
|
|
List<String> tasksKillList = tasksQueue.getAllTasks(cn.escheduler.common.Constants.SCHEDULER_TASKS_KILL); |
|
|
|
|
|
|
|
|
|
Map<String,Integer> dataMap = new HashMap<>(); |
|
|
|
|
if (loginUser.getUserType() == UserType.ADMIN_USER){ |
|
|
|
|
dataMap.put("taskQueue",tasksQueueList.size()); |
|
|
|
|
dataMap.put("taskKill",tasksKillList.size()); |
|
|
|
|
|
|
|
|
|
result.put(Constants.DATA_LIST, dataMap); |
|
|
|
|
putMsg(result, Status.SUCCESS); |
|
|
|
|
return result; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
int[] tasksQueueIds = new int[tasksQueueList.size()]; |
|
|
|
|
int[] tasksKillIds = new int[tasksKillList.size()]; |
|
|
|
|
|
|
|
|
|
int i =0; |
|
|
|
|
for (String taskQueueStr : tasksQueueList){ |
|
|
|
|
if (StringUtils.isNotEmpty(taskQueueStr)){ |
|
|
|
|
String[] splits = taskQueueStr.split("_"); |
|
|
|
|
if (splits.length == 4){ |
|
|
|
|
tasksQueueIds[i++]=Integer.parseInt(splits[3]); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
i = 0; |
|
|
|
|
for (String taskKillStr : tasksKillList){ |
|
|
|
|
if (StringUtils.isNotEmpty(taskKillStr)){ |
|
|
|
|
String[] splits = taskKillStr.split("_"); |
|
|
|
|
if (splits.length == 2){ |
|
|
|
|
tasksKillIds[i++]=Integer.parseInt(splits[1]); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Integer taskQueueCount = taskInstanceMapper.countTask(loginUser.getId(),loginUser.getUserType(),projectId, tasksQueueIds); |
|
|
|
|
Integer taskKillCount = taskInstanceMapper.countTask(loginUser.getId(),loginUser.getUserType(),projectId, tasksQueueIds); |
|
|
|
|
|
|
|
|
|
dataMap.put("taskQueue",taskQueueCount); |
|
|
|
|
dataMap.put("taskKill",taskKillCount); |
|
|
|
|
|
|
|
|
|
result.put(Constants.DATA_LIST, dataMap); |
|
|
|
|
putMsg(result, Status.SUCCESS); |
|
|
|
|
return result; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|