Commit ad58eced by huangfusuper

Merge remote-tracking branch 'origin/developer' into developer

parents 0634a7a8 2797f75f
...@@ -161,9 +161,28 @@ public class ApiFlowController { ...@@ -161,9 +161,28 @@ public class ApiFlowController {
return ResponseResult.ok("SUCCESS"); return ResponseResult.ok("SUCCESS");
} }
/**
* 获取整体运行的统计数据
* @param param
* @return
*/
@PostMapping("/loadStatisticData")
@ApiOperation("获取运行的统计数据")
public ResponseResult loadStatisticData(String param){ public ResponseResult loadStatisticData(String param){
CollectData collectData = apiFlowService.loadStatisticData(param); CollectData collectData = apiFlowService.loadStatisticData(param);
return ResponseResult.ok(collectData); return ResponseResult.ok(collectData);
} }
/**
* 获取节点运行的统计数据
* @param param
* @return
*/
@PostMapping("/loadNodeStatisticData")
@ApiOperation("获取运行的统计数据")
public ResponseResult loadNodeStatisticData(String param){
CollectData collectData = apiFlowService.loadNodeStatisticData(param);
return ResponseResult.ok(collectData);
}
} }
...@@ -88,4 +88,11 @@ public interface ApiFlowService { ...@@ -88,4 +88,11 @@ public interface ApiFlowService {
* @return * @return
*/ */
CollectData loadStatisticData(String param); CollectData loadStatisticData(String param);
/**
* 获取节点的汇总数据
* @param param
* @return
*/
CollectData loadNodeStatisticData(String param);
} }
package com.byit.mapper; package com.byit.mapper;
import com.byit.model.FlowStatusSnapshoot; import com.byit.model.FlowStatusSnapshoot;
import org.apache.ibatis.annotations.Param;
import java.util.List; import java.util.List;
...@@ -23,14 +24,14 @@ public interface FlowStatusSnapshootMapper { ...@@ -23,14 +24,14 @@ public interface FlowStatusSnapshootMapper {
* @param hour * @param hour
* @return * @return
*/ */
Integer exist(String date, String hour); Integer exist(@Param("date")String date, @Param("hour")String hour);
/** /**
* 批量保存 * 批量保存
* @param flowStatusSnapshootList * @param flowStatusSnapshootList
* @return * @return
*/ */
int saveList(List<FlowStatusSnapshoot> flowStatusSnapshootList); int saveList(@Param("flowStatusSnapshootList")List<FlowStatusSnapshoot> flowStatusSnapshootList);
/** /**
* 删除太长时间的快照 * 删除太长时间的快照
...@@ -45,5 +46,5 @@ public interface FlowStatusSnapshootMapper { ...@@ -45,5 +46,5 @@ public interface FlowStatusSnapshootMapper {
* @param endTime * @param endTime
* @return * @return
*/ */
List<FlowStatusSnapshoot> findByTime(Long startTime, Long endTime); List<FlowStatusSnapshoot> findByTime(@Param("startTime")Long startTime, @Param("endTime")Long endTime);
} }
\ No newline at end of file
...@@ -5,6 +5,7 @@ import com.byit.model.RunRecording; ...@@ -5,6 +5,7 @@ import com.byit.model.RunRecording;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
import java.util.Date;
import java.util.List; import java.util.List;
/** /**
...@@ -138,8 +139,8 @@ public interface RunRecordingMapper { ...@@ -138,8 +139,8 @@ public interface RunRecordingMapper {
*/ */
List<RunRecording> findUnFinishByRunId(String runId); List<RunRecording> findUnFinishByRunId(String runId);
List<RunRecording> findByStartAndEndTime(@Param("startDate")long startDate, List<RunRecording> findByStartAndEndTime(@Param("startDate")String startDate,
@Param("endDate")long endDate, @Param("endDate")String endDate,
@Param("flowIds")List<Integer> flowIds, @Param("flowIds")List<Integer> flowIds,
@Param("scheduleStatusList")List<String> scheduleStatusList, @Param("scheduleStatusList")List<String> scheduleStatusList,
@Param("executeStatusList")List<String> executeStatusList); @Param("executeStatusList")List<String> executeStatusList);
......
package com.byit.mapper; package com.byit.mapper;
import com.byit.dto.plugin.StatisticData;
import com.byit.model.WaitingRecord; import com.byit.model.WaitingRecord;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
import java.util.List; import java.util.List;
...@@ -31,4 +33,17 @@ public interface WaitingRecordMapper { ...@@ -31,4 +33,17 @@ public interface WaitingRecordMapper {
* @return * @return
*/ */
Integer findOrderByFlowId(Integer flowId); Integer findOrderByFlowId(Integer flowId);
/**
* 根据工作流id获取运行实例
* @param flowId
* @return
*/
List<WaitingRecord> findByFlowId(Integer flowId);
/**
* 查询运行汇总
* @param flowIdList
* @return
*/
StatisticData findStatusByStartAndEndTime(@Param("flowIdList")List<Integer> flowIdList);
} }
\ No newline at end of file
package com.byit.mapper; package com.byit.mapper;
import com.byit.dto.plugin.StatisticData;
import com.byit.model.WaitingTask; import com.byit.model.WaitingTask;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
import java.util.List; import java.util.List;
...@@ -22,4 +24,10 @@ public interface WaitingTaskMapper { ...@@ -22,4 +24,10 @@ public interface WaitingTaskMapper {
int updateByIdSelective(WaitingTask record); int updateByIdSelective(WaitingTask record);
/**
* 查询运行汇总
* @param flowIdList
* @return
*/
StatisticData findStatusByStartAndEndTime(@Param("flowIdList")List<Integer> flowIdList);
} }
\ No newline at end of file
package com.byit.thread.helper; package com.byit.thread.helper;
import com.byit.dto.plugin.StatisticData; import com.byit.dto.plugin.StatisticData;
import com.byit.mapper.FlowMapper; import com.byit.mapper.*;
import com.byit.mapper.FlowStatusSnapshootMapper; import com.byit.model.*;
import com.byit.mapper.JobTaskRunLogMapper;
import com.byit.mapper.RunRecordingMapper;
import com.byit.model.Flow;
import com.byit.model.FlowStatusSnapshoot;
import com.byit.model.RunRecording;
import com.byit.thread.BaseThreadRunHelper; import com.byit.thread.BaseThreadRunHelper;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
...@@ -39,6 +34,10 @@ public class StatusSnapshootThreadRunHelper extends BaseThreadRunHelper { ...@@ -39,6 +34,10 @@ public class StatusSnapshootThreadRunHelper extends BaseThreadRunHelper {
@Resource @Resource
private JobTaskRunLogMapper jobTaskRunLogMapper; private JobTaskRunLogMapper jobTaskRunLogMapper;
@Resource @Resource
private WaitingRecordMapper waitingRecordMapper;
@Resource
private WaitingTaskMapper waitingTaskMapper;
@Resource
private DataSource dataSource; private DataSource dataSource;
@Value("${myth-job.snapshoot-date}") @Value("${myth-job.snapshoot-date}")
private Integer snapshootDate; private Integer snapshootDate;
...@@ -66,9 +65,6 @@ public class StatusSnapshootThreadRunHelper extends BaseThreadRunHelper { ...@@ -66,9 +65,6 @@ public class StatusSnapshootThreadRunHelper extends BaseThreadRunHelper {
List<FlowStatusSnapshoot> flowStatusSnapshootList = new ArrayList<>(); List<FlowStatusSnapshoot> flowStatusSnapshootList = new ArrayList<>();
flowList.forEach(flow -> { flowList.forEach(flow -> {
RunRecording runRecording = runRecordingMapper.findMaxByFlowId(flow.getFlowId()); RunRecording runRecording = runRecordingMapper.findMaxByFlowId(flow.getFlowId());
if (runRecording != null){
//获取凌晨的时间戳
Long time = LocalDate.now().atStartOfDay(ZoneOffset.ofHours(8)).toInstant().toEpochMilli();
FlowStatusSnapshoot flowStatusSnapshoot = new FlowStatusSnapshoot(); FlowStatusSnapshoot flowStatusSnapshoot = new FlowStatusSnapshoot();
flowStatusSnapshoot.setDay(date); flowStatusSnapshoot.setDay(date);
flowStatusSnapshoot.setFlowId(flow.getFlowId()); flowStatusSnapshoot.setFlowId(flow.getFlowId());
...@@ -76,10 +72,18 @@ public class StatusSnapshootThreadRunHelper extends BaseThreadRunHelper { ...@@ -76,10 +72,18 @@ public class StatusSnapshootThreadRunHelper extends BaseThreadRunHelper {
flowStatusSnapshoot.setFlowName(flow.getFlowName()); flowStatusSnapshoot.setFlowName(flow.getFlowName());
flowStatusSnapshoot.setWorkspaceId(flow.getWorkspaceId()); flowStatusSnapshoot.setWorkspaceId(flow.getWorkspaceId());
flowStatusSnapshoot.setSnapshootTime(hourTime); flowStatusSnapshoot.setSnapshootTime(hourTime);
if (time.longValue() > runRecording.getTriggerTime().longValue()){
//统计运行实例的数据
//如果存在实例
if (runRecording != null){
//获取凌晨的时间戳
Long time = LocalDate.now().atStartOfDay(ZoneOffset.ofHours(8)).toInstant().toEpochMilli();
//从凌晨到现在是否有运行实例
if (time.longValue() > runRecording.getTriggerTime().longValue()){//今天不存在工作流的运行实例
flowStatusSnapshoot.setFlowStatus(1); flowStatusSnapshoot.setFlowStatus(1);
flowStatusSnapshoot.setUnstartNode(flow.getFlowNodeCount()); flowStatusSnapshoot.setUnstartNode(flow.getFlowNodeCount());
}else { }else { //存在工作流的运行实例
//判断运行状态
if (runRecording.getFlowStatus().equals("1") || runRecording.getFlowStatus().equals("2") || runRecording.getFlowStatus().equals("3")){ if (runRecording.getFlowStatus().equals("1") || runRecording.getFlowStatus().equals("2") || runRecording.getFlowStatus().equals("3")){
flowStatusSnapshoot.setFlowStatus(Integer.valueOf(runRecording.getFlowStatus())); flowStatusSnapshoot.setFlowStatus(Integer.valueOf(runRecording.getFlowStatus()));
}else { }else {
...@@ -94,6 +98,8 @@ public class StatusSnapshootThreadRunHelper extends BaseThreadRunHelper { ...@@ -94,6 +98,8 @@ public class StatusSnapshootThreadRunHelper extends BaseThreadRunHelper {
} }
//获取运行实例下各类状态的节点数目 //获取运行实例下各类状态的节点数目
StatisticData nodeStatistic = jobTaskRunLogMapper.findStatisticDataByRunIdAndFlowId(runRecording.getRunId(), flow.getFlowId()); StatisticData nodeStatistic = jobTaskRunLogMapper.findStatisticDataByRunIdAndFlowId(runRecording.getRunId(), flow.getFlowId());
//判断是否存在节点的运行日志
//存在节点运行日志
if (nodeStatistic != null){ if (nodeStatistic != null){
int sum = nodeStatistic.getFail() + nodeStatistic.getSuccess() + nodeStatistic.getRunIng() + nodeStatistic.getKill(); int sum = nodeStatistic.getFail() + nodeStatistic.getSuccess() + nodeStatistic.getRunIng() + nodeStatistic.getKill();
flowStatusSnapshoot.setUnstartNode(flow.getFlowNodeCount() - sum); flowStatusSnapshoot.setUnstartNode(flow.getFlowNodeCount() - sum);
...@@ -102,12 +108,38 @@ public class StatusSnapshootThreadRunHelper extends BaseThreadRunHelper { ...@@ -102,12 +108,38 @@ public class StatusSnapshootThreadRunHelper extends BaseThreadRunHelper {
flowStatusSnapshoot.setFailNode(nodeStatistic.getFail()); flowStatusSnapshoot.setFailNode(nodeStatistic.getFail());
flowStatusSnapshoot.setKillNode(nodeStatistic.getKill()); flowStatusSnapshoot.setKillNode(nodeStatistic.getKill());
}else { }else {
//不存在节点的运行日志
nodeStatistic.setUnstart(flow.getFlowNodeCount()); nodeStatistic.setUnstart(flow.getFlowNodeCount());
} }
}
}else {
//如果不存在运行实例
flowStatusSnapshoot.setUnstartNode(flow.getFlowNodeCount());
} }
flowStatusSnapshootList.add(flowStatusSnapshoot); flowStatusSnapshootList.add(flowStatusSnapshoot);
//获取排队的运行实例
List<WaitingRecord> waitingRecordList = waitingRecordMapper.findByFlowId(flow.getFlowId());
if (waitingRecordList != null && waitingRecordList.size() > 0){
//如果存在正在排队的实例
waitingRecordList.forEach(waitingRecord -> {
//创建工作流快照
FlowStatusSnapshoot waitingStatusSnapshoot = new FlowStatusSnapshoot();
waitingStatusSnapshoot.setDay(date);
waitingStatusSnapshoot.setFlowId(flow.getFlowId());
waitingStatusSnapshoot.setHour(hour);
waitingStatusSnapshoot.setFlowName(flow.getFlowName());
waitingStatusSnapshoot.setWorkspaceId(flow.getWorkspaceId());
waitingStatusSnapshoot.setSnapshootTime(hourTime);
waitingStatusSnapshoot.setFlowStatus(1);
//获取排队的节点数目
List<WaitingTask> waitingTaskList = waitingTaskMapper.findAllByWaitId(waitingRecord.getWaitId());
if (waitingTaskList != null && waitingTaskList.size() > 0){
waitingStatusSnapshoot.setUnstartNode(waitingTaskList.size());
}
flowStatusSnapshootList.add(waitingStatusSnapshoot);
});
} }
}); });
if (flowList != null && flowList.size() > 0){ if (flowList != null && flowList.size() > 0){
flowStatusSnapshootMapper.saveList(flowStatusSnapshootList); flowStatusSnapshootMapper.saveList(flowStatusSnapshootList);
......
...@@ -198,7 +198,7 @@ ...@@ -198,7 +198,7 @@
from flow_status_snapshoot from flow_status_snapshoot
where 'day' = #{date} and `hour` = #{hour} where 'day' = #{date} and `hour` = #{hour}
</select> </select>
<select id="findByTime" resultType="com.byit.model.FlowStatusSnapshoot"> <select id="findByTime" resultMap="BaseResultMap">
select select
<include refid="Base_Column_List" /> <include refid="Base_Column_List" />
from flow_status_snapshoot from flow_status_snapshoot
...@@ -233,7 +233,7 @@ ...@@ -233,7 +233,7 @@
#{flowStatusSnapshoot.runingNode,jdbcType=INTEGER}, #{flowStatusSnapshoot.runingNode,jdbcType=INTEGER},
#{flowStatusSnapshoot.successNode,jdbcType=INTEGER}, #{flowStatusSnapshoot.successNode,jdbcType=INTEGER},
#{flowStatusSnapshoot.failNode,jdbcType=INTEGER}, #{flowStatusSnapshoot.failNode,jdbcType=INTEGER},
#{flowStatusSnapshoot.killNode,jdbcType=INTEGER}, #{flowStatusSnapshoot.killNode,jdbcType=INTEGER}
) )
</foreach> </foreach>
</insert> </insert>
......
...@@ -129,9 +129,9 @@ ...@@ -129,9 +129,9 @@
from job_task_run_log from job_task_run_log
where start_time &gt;= ${startDate} where start_time &gt;= ${startDate}
and end_time &lt;= ${endDate} and end_time &lt;= ${endDate}
<if test="flowIds != null"> <if test="flowIdList != null">
and flow_id in ( and flow_id in (
<foreach collection="flowIds" item="flowId" separator=","> <foreach collection="flowIdList" item="flowId" separator=",">
#{flowId} #{flowId}
</foreach> </foreach>
) )
......
...@@ -158,15 +158,15 @@ ...@@ -158,15 +158,15 @@
from run_recording from run_recording
where start_time &gt;= ${startDate} where start_time &gt;= ${startDate}
and end_time &lt;= ${endDate} and end_time &lt;= ${endDate}
<if test="flowIds != null"> <if test="flowIdList != null">
and flow_id in ( and flow_id in (
<foreach collection="flowIds" item="flowId" separator=","> <foreach collection="flowIdList" item="flowId" separator=",">
#{flowId} #{flowId}
</foreach> </foreach>
) )
</if> </if>
</select> </select>
<select id="findMaxByFlowId" resultType="com.byit.model.RunRecording"> <select id="findMaxByFlowId" resultMap="BaseResultMap">
select <include refid="Base_Column_List" /> select <include refid="Base_Column_List" />
from run_recording from run_recording
where flow_id = #{flowId} where flow_id = #{flowId}
......
...@@ -48,6 +48,24 @@ ...@@ -48,6 +48,24 @@
from waiting_record from waiting_record
where flow_id = #{flowId} where flow_id = #{flowId}
</select> </select>
<select id="findByFlowId" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from waiting_record
where flow_id = #{flowId}
</select>
<select id="findStatusByStartAndEndTime" resultType="com.byit.dto.plugin.StatisticData">
select count(1) unstart
from waiting_record
where 1 = 1
<if test="flowIdList != null">
and flow_id in (
<foreach collection="flowIdList" item="flowId" separator=",">
#{flowId}
</foreach>
)
</if>
</select>
<delete id="deleteById" parameterType="java.lang.Integer"> <delete id="deleteById" parameterType="java.lang.Integer">
<!-- generated @mbg.generated date: 2020-03-12 --> <!-- generated @mbg.generated date: 2020-03-12 -->
......
...@@ -70,6 +70,18 @@ ...@@ -70,6 +70,18 @@
from waiting_task from waiting_task
where wait_id=#{waitId,jdbcType=INTEGER} where wait_id=#{waitId,jdbcType=INTEGER}
</select> </select>
<select id="findStatusByStartAndEndTime" resultType="com.byit.dto.plugin.StatisticData">
select count(1) unstart
from waiting_task
where 1 = 1
<if test="flowIdList != null">
and flow_id in (
<foreach collection="flowIdList" item="flowId" separator=",">
#{flowId}
</foreach>
)
</if>
</select>
<delete id="deleteById" parameterType="java.lang.Integer"> <delete id="deleteById" parameterType="java.lang.Integer">
<!-- generated @mbg.generated date: 2020-03-12 --> <!-- generated @mbg.generated date: 2020-03-12 -->
......
...@@ -22,8 +22,13 @@ public class CollectData { ...@@ -22,8 +22,13 @@ public class CollectData {
private StatisticData nodeData; private StatisticData nodeData;
/** /**
* 按时间段的汇总 * 节点按时间段的汇总
*/ */
private Map<String, StatisticData> collectMap; private Map<String, StatisticData> nodeCollectMap;
/**
* 工作流按时间段的汇总
*/
private Map<String, StatisticData> flowCollectMap;
} }
...@@ -91,7 +91,14 @@ public class JobUtils { ...@@ -91,7 +91,14 @@ public class JobUtils {
* 获取运行实例日志 * 获取运行实例日志
*/ */
public static final String REQUEST_LOADSCHEDULELOG = "/api/flow/loadScheduleLog"; public static final String REQUEST_LOADSCHEDULELOG = "/api/flow/loadScheduleLog";
/**
* 获取运行的统计数据
*/
public static final String REQUEST_LOADSTATISTICDATA = "/api/flow/loadStatisticData";
/**
* 获取节点运行的统计数据
*/
public static final String REQUEST_LOADNODESTATISTICDATA = "/api/flow/loadNodeStatisticData";
/** /**
* 补批工作流 * 补批工作流
*/ */
...@@ -344,6 +351,42 @@ public class JobUtils { ...@@ -344,6 +351,42 @@ public class JobUtils {
} }
/** /**
* 获取运行的统计数据接口
* @param startTime 开始时间 毫秒级别时间
* @param endTime 开始时间 毫秒级别时间
* @param workspaceName 工作空间名称
* @return
*/
public static ResponseResult loadStatisticData(Long startTime, Long endTime, String workspaceName){
Map<String, Object> param = new HashMap<>();
param.put("startTime", startTime);
param.put("endTime", endTime);
param.put("workspaceName", workspaceName);
String response = createHttpRequest(REQUEST_LOADSTATISTICDATA, "param=" + JSON.toJSONString(param));
log.info("--------------------获取运行的统计数据接口调用成功,结果为:{}------------------------",response);
return JSON.parseObject(response, ResponseResult.class);
}
/**
* 获取节点运行的统计数据
* @param startTime 开始时间 毫秒级别时间
* @param endTime 结束时间 毫秒级别时间
* @param workspaceName 工作空间名称
* @param flowName 工作流名称
* @return
*/
public static ResponseResult loadNodeStatisticData(Long startTime, Long endTime, String workspaceName, String flowName){
Map<String, Object> param = new HashMap<>();
param.put("startTime", startTime);
param.put("endTime", endTime);
param.put("workspaceName", workspaceName);
param.put("flowName", flowName);
String response = createHttpRequest(REQUEST_LOADNODESTATISTICDATA, "param=" + JSON.toJSONString(param));
log.info("--------------------获取节点运行的统计数据接口调用成功,结果为:{}------------------------",response);
return JSON.parseObject(response, ResponseResult.class);
}
/**
* 补批工作流 * 补批工作流
* @param workspaceName 工作空间名称 * @param workspaceName 工作空间名称
* @param flowName 工作流名称 * @param flowName 工作流名称
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment