Commit 9731d298 by huangfusuper

运行实例验证是否完成流程修改

parent 6d59c6e9
...@@ -18,6 +18,11 @@ public interface RunRecordingMapper { ...@@ -18,6 +18,11 @@ public interface RunRecordingMapper {
*/ */
List<RunRecording> findRunRecordingByEndAndNotIsAlarm(); List<RunRecording> findRunRecordingByEndAndNotIsAlarm();
/** /**
* 查询运行中的运行实例
* @return
*/
List<RunRecording> findRunningRunRecording();
/**
* 这个方法是会根据任务流的id和运行标识找到唯一对应的一个任务流,这个任务流就是一个虚拟节点 * 这个方法是会根据任务流的id和运行标识找到唯一对应的一个任务流,这个任务流就是一个虚拟节点
* @param flowId * @param flowId
* @param runId * @param runId
......
...@@ -132,6 +132,11 @@ public class RunRecording implements Serializable { ...@@ -132,6 +132,11 @@ public class RunRecording implements Serializable {
*/ */
@ApiModelProperty("快速失败标识 0 不快速失败 1 快速失败") @ApiModelProperty("快速失败标识 0 不快速失败 1 快速失败")
private String failFast; private String failFast;
/**
* 工作流节点数量
*/
@ApiModelProperty("工作流节点数量")
private Integer flowNodeCount;
/** /**
......
...@@ -14,6 +14,13 @@ public interface RunRecordingService { ...@@ -14,6 +14,13 @@ public interface RunRecordingService {
* @return * @return
*/ */
List<RunRecording> findRunRecordingByEndAndNotIsAlarm(); List<RunRecording> findRunRecordingByEndAndNotIsAlarm();
/**
* 查询运行中的运行实例
* @return
*/
List<RunRecording> findRunningRunRecording();
/** /**
* 这个方法是会根据任务流的id和运行标识找到唯一对应的一个任务流,这个任务流就是一个虚拟节点 * 这个方法是会根据任务流的id和运行标识找到唯一对应的一个任务流,这个任务流就是一个虚拟节点
* @param flowId * @param flowId
...@@ -54,4 +61,6 @@ public interface RunRecordingService { ...@@ -54,4 +61,6 @@ public interface RunRecordingService {
* @return * @return
*/ */
int deleteById(Integer recordingId); int deleteById(Integer recordingId);
} }
\ No newline at end of file
...@@ -29,6 +29,11 @@ public class RunRecordingServiceImpl implements RunRecordingService { ...@@ -29,6 +29,11 @@ public class RunRecordingServiceImpl implements RunRecordingService {
} }
@Override @Override
public List<RunRecording> findRunningRunRecording() {
return null;
}
@Override
public RunRecording findRunRecordingByFlowIdAndRunId(Integer flowId, String runId) { public RunRecording findRunRecordingByFlowIdAndRunId(Integer flowId, String runId) {
return runRecordingMapper.findRunRecordingByFlowIdAndRunId(flowId,runId); return runRecordingMapper.findRunRecordingByFlowIdAndRunId(flowId,runId);
} }
......
...@@ -73,6 +73,7 @@ public class LogScanHelper { ...@@ -73,6 +73,7 @@ public class LogScanHelper {
public void start(){ public void start(){
virtualNodeScanMethod(); virtualNodeScanMethod();
//TODO 不推荐使用,详情见方法介绍
notAlarmedNodeScanMethod(); notAlarmedNodeScanMethod();
errorNodeScan(); errorNodeScan();
} }
...@@ -173,6 +174,9 @@ public class LogScanHelper { ...@@ -173,6 +174,9 @@ public class LogScanHelper {
} }
/** /**
* @deprecated 废除原因:不需要这条线程去扫描结束节点,只需要扫描对应工作流的节点数目是否全部匹配即可
* 这一操作需要放置到扫描运行实例的线程里面
* @deprecatedDate 2020年3月6日10:36:19
* 未告警的节点扫描 * 未告警的节点扫描
*/ */
private void notAlarmedNodeScanMethod(){ private void notAlarmedNodeScanMethod(){
......
...@@ -69,9 +69,22 @@ public class RunRecordingScanHelper { ...@@ -69,9 +69,22 @@ public class RunRecordingScanHelper {
private final JobTaskRunLogService jobTaskRunLogService; private final JobTaskRunLogService jobTaskRunLogService;
private final RunRecordingService runRecordingService; private final RunRecordingService runRecordingService;
private final FileSystem fileSystem; private final FileSystem fileSystem;
/**
* 查询完结且没有告警的节点线程是否停止
*/
private volatile boolean runRecordingThreadStop = false; private volatile boolean runRecordingThreadStop = false;
/**
* 查询完结且没有告警的节点线程
*/
private Thread runRecordingThread; private Thread runRecordingThread;
/**
* 判断工作流是否完结是否停止
*/
private volatile boolean judgeFlowIsEndStop = false;
/**
* 判断工作流是否完结的线程
*/
private Thread judgeFlowIsEndThread;
@Autowired @Autowired
public RunRecordingScanHelper(EmailAlarmService emailAlarmService, JobTaskRunLogService jobTaskRunLogService, RunRecordingService runRecordingService, FileSystem fileSystem) { public RunRecordingScanHelper(EmailAlarmService emailAlarmService, JobTaskRunLogService jobTaskRunLogService, RunRecordingService runRecordingService, FileSystem fileSystem) {
...@@ -82,9 +95,99 @@ public class RunRecordingScanHelper { ...@@ -82,9 +95,99 @@ public class RunRecordingScanHelper {
} }
public void start() { public void start() {
scanRunRecThread();
judgeFlowIsEndThread();
}
/**
* 判断工作流是否完结
*/
public void judgeFlowIsEndThread(){
judgeFlowIsEndThread = new Thread(() ->{
dateAligned(5000);
log.info("----------------------【com.byit.thread.RunRecordingScanThread#judgeFlowIsEnd】-------------------");
while (judgeFlowIsEndStop){
boolean isSleep = false;
Connection conn = null;
Boolean connAutoCommit = null;
PreparedStatement preparedStatement = null;
try {
conn = dataSource.getConnection();
connAutoCommit = conn.getAutoCommit();
conn.setAutoCommit(false);
preparedStatement = conn.prepareStatement("SELECT * FROM JOB_LOCK WHERE LOCK_NAME = 'judge_flow_end_lock' FOR UPDATE ");
preparedStatement.execute();
//进行操作
}catch (Exception e){
if (!judgeFlowIsEndStop) {
e.printStackTrace();
}
}finally {
if (conn != null) {
try {
conn.commit();
} catch (SQLException e) {
if (!judgeFlowIsEndStop) {
log.error("--------------------【提交行锁出错】---------------------");
}
}
}
try {
if (conn != null) {
conn.setAutoCommit(connAutoCommit);
}
} catch (SQLException e) {
if (!judgeFlowIsEndStop) {
log.error("--------------------【恢复自动提交出错】---------------------");
}
}
if (preparedStatement != null) {
try {
preparedStatement.close();
} catch (SQLException e) {
if (!judgeFlowIsEndStop) {
log.error("--------------------【关闭执行器出错】---------------------");
}
}
}
try {
if(conn!=null){
conn.close();
}
} catch (SQLException e) {
if (!judgeFlowIsEndStop) {
log.error("--------------------【关闭链接出错】---------------------");
}
}
}
if(isSleep){
dateAligned(10000);
}
}
});
}
/**
* 扫描未完成的工作流
*/
private void judgeFlowIsEnd(){
//查询未完结的工作流实例
}
/**
* 查询完结且没有告警的节点线程构建
*/
private void scanRunRecThread(){
runRecordingThread = new Thread(() -> { runRecordingThread = new Thread(() -> {
dateAligned(5000); dateAligned(5000);
log.info("--------------------【com.byit.thread.RunRecordingScanThread#start】init success----------------------"); log.info("--------------------【com.byit.thread.RunRecordingScanThread#scanRunRecThread】init success----------------------");
while (!runRecordingThreadStop) { while (!runRecordingThreadStop) {
boolean isSleep = false; boolean isSleep = false;
Connection conn = null; Connection conn = null;
...@@ -135,7 +238,9 @@ public class RunRecordingScanHelper { ...@@ -135,7 +238,9 @@ public class RunRecordingScanHelper {
} }
try { try {
if(conn!=null){
conn.close(); conn.close();
}
} catch (SQLException e) { } catch (SQLException e) {
if (!runRecordingThreadStop) { if (!runRecordingThreadStop) {
log.error("--------------------【关闭链接出错】---------------------"); log.error("--------------------【关闭链接出错】---------------------");
...@@ -153,6 +258,9 @@ public class RunRecordingScanHelper { ...@@ -153,6 +258,9 @@ public class RunRecordingScanHelper {
runRecordingThread.start(); runRecordingThread.start();
} }
/**
* 查询完结 但是没有告警的节点
*/
private void scanRunRec() { private void scanRunRec() {
//查询完结且未告警的工作流信息 //查询完结且未告警的工作流信息
List<RunRecording> runRecordingByEndAndNotIsAlarm = runRecordingService.findRunRecordingByEndAndNotIsAlarm(); List<RunRecording> runRecordingByEndAndNotIsAlarm = runRecordingService.findRunRecordingByEndAndNotIsAlarm();
......
...@@ -27,7 +27,6 @@ ...@@ -27,7 +27,6 @@
<result column="is_update" jdbcType="CHAR" property="isUpdate" /> <result column="is_update" jdbcType="CHAR" property="isUpdate" />
</resultMap> </resultMap>
<sql id="Base_Column_List"> <sql id="Base_Column_List">
<!-- generated @mbg.generated date: 2019-12-31 -->
flow_id, alarm_email, exec_type, flow_cron, flow_desc, flow_name, flow_node_count, flow_id, alarm_email, exec_type, flow_cron, flow_desc, flow_name, flow_node_count,
flow_timeout, is_inner, alarml_action, priority, trigger_next_time, workspace_id, flow_timeout, is_inner, alarml_action, priority, trigger_next_time, workspace_id,
author, add_time, start_up, principal, version_name, repeat_count, remaining_count, author, add_time, start_up, principal, version_name, repeat_count, remaining_count,
...@@ -150,6 +149,7 @@ ...@@ -150,6 +149,7 @@
<if test="isUpdate != null"> <if test="isUpdate != null">
is_update, is_update,
</if> </if>
</trim> </trim>
<trim prefix="values (" suffix=")" suffixOverrides=","> <trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="flowId != null"> <if test="flowId != null">
...@@ -218,6 +218,7 @@ ...@@ -218,6 +218,7 @@
<if test="isUpdate != null"> <if test="isUpdate != null">
#{isUpdate,jdbcType=CHAR}, #{isUpdate,jdbcType=CHAR},
</if> </if>
</trim> </trim>
</insert> </insert>
<update id="updateByIdSelective" parameterType="com.byit.model.Flow"> <update id="updateByIdSelective" parameterType="com.byit.model.Flow">
......
...@@ -21,11 +21,12 @@ ...@@ -21,11 +21,12 @@
<result column="is_alarm" jdbcType="CHAR" property="isAlarm" /> <result column="is_alarm" jdbcType="CHAR" property="isAlarm" />
<result column="is_inner" jdbcType="CHAR" property="isInner" /> <result column="is_inner" jdbcType="CHAR" property="isInner" />
<result column="fail_fast" jdbcType="CHAR" property="failFast" /> <result column="fail_fast" jdbcType="CHAR" property="failFast" />
<result column="flow_node_count" jdbcType="VARCHAR" property="flowNodeCount" />
</resultMap> </resultMap>
<sql id="Base_Column_List"> <sql id="Base_Column_List">
recording_id, run_id, alarm_email, dispatch_ip, flow_name, flow_run_result, flow_status, recording_id, run_id, alarm_email, dispatch_ip, flow_name, flow_run_result, flow_status,
flow_timeout, flow_version_name, alarml_action, priority, trigger_time, principal, flow_timeout, flow_version_name, alarml_action, priority, trigger_time, principal,
flow_id, start_time, end_time, is_alarm,is_inner,fail_fast flow_id, start_time, end_time, is_alarm,is_inner,fail_fast, flow_node_count
</sql> </sql>
<!--查询已完结 没有告警的--> <!--查询已完结 没有告警的-->
...@@ -36,6 +37,13 @@ ...@@ -36,6 +37,13 @@
where flow_status ='4' and is_alarm = '1' where flow_status ='4' and is_alarm = '1'
</select> </select>
<select id="findRunningRunRecording" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from run_recording
where flow_status = '2'
</select>
<select id="findRunRecordingByFlowIdAndRunId" resultMap="BaseResultMap" > <select id="findRunRecordingByFlowIdAndRunId" resultMap="BaseResultMap" >
select select
<include refid="Base_Column_List" /> <include refid="Base_Column_List" />
...@@ -169,6 +177,9 @@ ...@@ -169,6 +177,9 @@
<if test="failFast != null"> <if test="failFast != null">
fail_fast, fail_fast,
</if> </if>
<if test="flowNodeCount != null">
flow_node_count,
</if>
</trim> </trim>
<trim prefix="values (" suffix=")" suffixOverrides=","> <trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="recordingId != null"> <if test="recordingId != null">
...@@ -228,6 +239,9 @@ ...@@ -228,6 +239,9 @@
<if test="failFast != null"> <if test="failFast != null">
#{failFast,jdbcType=CHAR}, #{failFast,jdbcType=CHAR},
</if> </if>
<if test="flowNodeCount != null">
#{flowNodeCount,jdbcType=INTEGER},
</if>
</trim> </trim>
</insert> </insert>
<update id="updateRunRecordingById" parameterType="com.byit.model.RunRecording"> <update id="updateRunRecordingById" parameterType="com.byit.model.RunRecording">
...@@ -287,6 +301,9 @@ ...@@ -287,6 +301,9 @@
<if test="failFast != null"> <if test="failFast != null">
fail_fast = #{failFast,jdbcType=CHAR}, fail_fast = #{failFast,jdbcType=CHAR},
</if> </if>
<if test="flowNodeCount != null">
flow_node_count = #{flowNodeCount,jdbcType=INTEGER},
</if>
</set> </set>
where recording_id = #{recordingId,jdbcType=INTEGER} where recording_id = #{recordingId,jdbcType=INTEGER}
</update> </update>
...@@ -348,6 +365,9 @@ ...@@ -348,6 +365,9 @@
<if test="failFast != null"> <if test="failFast != null">
fail_fast = #{failFast,jdbcType=CHAR}, fail_fast = #{failFast,jdbcType=CHAR},
</if> </if>
<if test="flowNodeCount != null">
flow_node_count = #{flowNodeCount,jdbcType=INTEGER},
</if>
</set> </set>
where flow_id = #{flowId,jdbcType=INTEGER} and run_id = #{runId,jdbcType=VARCHAR} where flow_id = #{flowId,jdbcType=INTEGER} and run_id = #{runId,jdbcType=VARCHAR}
</update> </update>
......
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