Commit e640ec86 by guominglei

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

parents edb3b0a1 e9acfd09
...@@ -36,7 +36,7 @@ public interface ApiFlowService { ...@@ -36,7 +36,7 @@ public interface ApiFlowService {
* @param flow * @param flow
* @return * @return
*/ */
void validateFlow(Integer workspaceId, PluginFlow flow); void validateFlow(Integer workspaceId, PluginFlow flow, boolean isInner);
/** /**
* 重跑任务 * 重跑任务
......
...@@ -158,10 +158,10 @@ public class ApiFlowServiceImpl implements ApiFlowService { ...@@ -158,10 +158,10 @@ public class ApiFlowServiceImpl implements ApiFlowService {
flow.setTriggerNextTime(StringUtils.isEmpty(pluginFlow.getConfig().getFlowCron()) ? null : new CronExpression(pluginFlow.getConfig().getFlowCron()).getNextValidTimeAfter(new Date()).getTime()); flow.setTriggerNextTime(StringUtils.isEmpty(pluginFlow.getConfig().getFlowCron()) ? null : new CronExpression(pluginFlow.getConfig().getFlowCron()).getNextValidTimeAfter(new Date()).getTime());
//设置超时时间,未设置默认30分钟 //设置超时时间,未设置默认30分钟
flow.setFlowTimeout(null == pluginFlow.getConfig().getFlowTimeout() ? 1000 * 60 * 120 : pluginFlow.getConfig().getFlowTimeout()); flow.setFlowTimeout(null == pluginFlow.getConfig().getFlowTimeout() ? 1000 * 60 * 120 : pluginFlow.getConfig().getFlowTimeout());
Flow oldFlow = flowMapper.getByWorkSpaceAndName(workspaceId, pluginFlow.getName());
//判断是否是重发 //判断是否是重发
if (pluginFlow.isRePublish()){ if ((pluginFlow.isRePublish() && !isInnner) || (isInnner && null != oldFlow)){
Flow oldFlow = flowMapper.getByWorkSpaceAndName(workspaceId, pluginFlow.getName());
String version = oldFlow.getVersionName(); String version = oldFlow.getVersionName();
Integer versionTag = Integer.valueOf(version.split("\\.")[1]); Integer versionTag = Integer.valueOf(version.split("\\.")[1]);
flow.setFlowId(oldFlow.getFlowId()); flow.setFlowId(oldFlow.getFlowId());
...@@ -261,8 +261,11 @@ public class ApiFlowServiceImpl implements ApiFlowService { ...@@ -261,8 +261,11 @@ public class ApiFlowServiceImpl implements ApiFlowService {
node.setNodeName(pluginNode.getName()); node.setNodeName(pluginNode.getName());
if (PluginNodeTypeEnum.FLOW.getCode().equals(pluginNode.getType())){ if (PluginNodeTypeEnum.FLOW.getCode().equals(pluginNode.getType())){
PluginFlow pluginFlow = (PluginFlow) pluginNode;
//TODO 这段逻辑我不确定需要和明雷对接
pluginFlow.getConfig().setFlowCron(flow.getFlowCron());
//如果是内嵌工作流先保存工作流信息 //如果是内嵌工作流先保存工作流信息
Flow innerFlow = saveFlow((PluginFlow) pluginNode, flow.getWorkspaceId(), true); Flow innerFlow = saveFlow(pluginFlow, flow.getWorkspaceId(), true);
node.setIsVirtual(NodePropertyEnum.IS_VIRTUAL.getCode()); node.setIsVirtual(NodePropertyEnum.IS_VIRTUAL.getCode());
node.setMapFlowId(innerFlow.getFlowId()); node.setMapFlowId(innerFlow.getFlowId());
}else { }else {
...@@ -339,7 +342,7 @@ public class ApiFlowServiceImpl implements ApiFlowService { ...@@ -339,7 +342,7 @@ public class ApiFlowServiceImpl implements ApiFlowService {
PluginFlow flow = pluginPackage.getFlow(); PluginFlow flow = pluginPackage.getFlow();
//校验工作流参数配置 //校验工作流参数配置
validateFlow(workspace.getWorkspaceId(), flow); validateFlow(workspace.getWorkspaceId(), flow, false);
//校验工作流名称是否重复 //校验工作流名称是否重复
HashSet<String> flowNameSet = new HashSet<>(); HashSet<String> flowNameSet = new HashSet<>();
//用来工作流的内嵌关系 //用来工作流的内嵌关系
...@@ -383,7 +386,7 @@ public class ApiFlowServiceImpl implements ApiFlowService { ...@@ -383,7 +386,7 @@ public class ApiFlowServiceImpl implements ApiFlowService {
ValidationUtil.isTrueValidation(!(node instanceof PluginFlow), "工作流的type设置错误,只有当节点为内嵌工作流是type才允许设置为flow"); ValidationUtil.isTrueValidation(!(node instanceof PluginFlow), "工作流的type设置错误,只有当节点为内嵌工作流是type才允许设置为flow");
//校验父工作流和内嵌工作流的执行类型是否一致 //校验父工作流和内嵌工作流的执行类型是否一致
ValidationUtil.isTrueValidation(!(flow.getConfig().getExecType().equals(((PluginFlow) node).getConfig().getExecType())), "内嵌工作流的调度配置必须和父工作流配置保持一致!"); ValidationUtil.isTrueValidation(!(flow.getConfig().getExecType().equals(((PluginFlow) node).getConfig().getExecType())), "内嵌工作流的调度配置必须和父工作流配置保持一致!");
validateFlow(workspace.getWorkspaceId(), (PluginFlow) node); validateFlow(workspace.getWorkspaceId(), (PluginFlow) node, true);
if(FlowPropertyEnum.NO_SCHEDULE.getCode().equals(flow.getConfig().getScheduleFollow())){ if(FlowPropertyEnum.NO_SCHEDULE.getCode().equals(flow.getConfig().getScheduleFollow())){
ValidationUtil.dataNotBank( ((PluginFlow) node).getConfig().getFlowCron(), "工作流设置为不跟随调度时节点必须设置调度时间!"); ValidationUtil.dataNotBank( ((PluginFlow) node).getConfig().getFlowCron(), "工作流设置为不跟随调度时节点必须设置调度时间!");
} }
...@@ -419,7 +422,7 @@ public class ApiFlowServiceImpl implements ApiFlowService { ...@@ -419,7 +422,7 @@ public class ApiFlowServiceImpl implements ApiFlowService {
} }
@Override @Override
public void validateFlow(Integer workspaceId, PluginFlow pluginFlow) { public void validateFlow(Integer workspaceId, PluginFlow pluginFlow, boolean isInner) {
ValidationUtil.dataNotBank(pluginFlow.getName(), "工作流名称不允许为空!"); ValidationUtil.dataNotBank(pluginFlow.getName(), "工作流名称不允许为空!");
ValidationUtil.dataNotNull(pluginFlow.getNodeList(), "工作流下属节点不允许为空!"); ValidationUtil.dataNotNull(pluginFlow.getNodeList(), "工作流下属节点不允许为空!");
ValidationUtil.dataNotNull(pluginFlow.getConfig(), "工作流配置不允许为空!"); ValidationUtil.dataNotNull(pluginFlow.getConfig(), "工作流配置不允许为空!");
...@@ -434,10 +437,12 @@ public class ApiFlowServiceImpl implements ApiFlowService { ...@@ -434,10 +437,12 @@ public class ApiFlowServiceImpl implements ApiFlowService {
Flow flow = flowMapper.getByWorkSpaceAndName(workspaceId, pluginFlow.getName()); Flow flow = flowMapper.getByWorkSpaceAndName(workspaceId, pluginFlow.getName());
//判断是否是重发 //判断是否是重发
//是重发 //是重发
if (pluginFlow.isRePublish()){ if (!isInner){
ValidationUtil.dataNotNull(flow, "工作流【"+ pluginFlow.getName() + "】不存在!"); if (pluginFlow.isRePublish()){
}else {//不是重发 ValidationUtil.dataNotNull(flow, "工作流【"+ pluginFlow.getName() + "】不存在!");
ValidationUtil.isTrueValidation(null != flow, "工作流【"+ pluginFlow.getName() + "】已存在!"); }else {//不是重发
ValidationUtil.isTrueValidation(null != flow, "工作流【"+ pluginFlow.getName() + "】已存在!");
}
} }
} }
......
...@@ -145,7 +145,7 @@ public class ApiNodeServiceImpl implements ApiNodeService { ...@@ -145,7 +145,7 @@ public class ApiNodeServiceImpl implements ApiNodeService {
String killResult = HttpUtil.post(killUrl, requestMap); String killResult = HttpUtil.post(killUrl, requestMap);
log.debug("请求结果{}", killResult); log.debug("请求结果{}", killResult);
ResponseResult responseResult = JSON.parseObject(killResult, ResponseResult.class); ResponseResult responseResult = JSON.parseObject(killResult, ResponseResult.class);
ValidationUtil.isTrueValidation(!"SUCCESS".equals(responseResult.getResult()), "杀死job失败,错误信息为:" + responseResult.getResult()); ValidationUtil.isTrueValidation(!"SUCCESS".equals(responseResult.getResult()), "杀死job失败,错误信息为:" + responseResult.getMsg());
return true; return true;
} }
......
spring: spring:
datasource: datasource:
driver-class-name: com.mysql.jdbc.Driver driver-class-name: com.mysql.jdbc.Driver
url: jdbc:mysql://${CM_IP}/myth-job?Unicode=true&characterEncoding=UTF-8&useSSL=true url: jdbc:mysql://${CM_IP}/${CM_DB}?Unicode=true&characterEncoding=UTF-8&useSSL=true
username: ${CM_USER} username: ${CM_USER}
password: ${CM_PWD} password: ${CM_PWD}
......
...@@ -58,7 +58,7 @@ ...@@ -58,7 +58,7 @@
</encoder> </encoder>
</appender> </appender>
<logger name="com.byit.thread.helper" level="info" additivity="false"> <logger name="com.byit.thread.helper" level="debug" additivity="false">
<appender-ref ref="console"/> <appender-ref ref="console"/>
</logger> </logger>
<!--<logger name="com.byit.factory.DaemonScanThreadRunHelperRedisLock" level="debug" additivity="false"> <!--<logger name="com.byit.factory.DaemonScanThreadRunHelperRedisLock" level="debug" additivity="false">
......
...@@ -47,16 +47,15 @@ public class DaemonScanThreadRunHelperRedisLock extends BaseDaemonScanThreadRunH ...@@ -47,16 +47,15 @@ public class DaemonScanThreadRunHelperRedisLock extends BaseDaemonScanThreadRunH
dateAligned(CYCLE_INTERVAL,threadName); dateAligned(CYCLE_INTERVAL,threadName);
//调用业务操作 //调用业务操作
sleepTime = examplesValue.start(); sleepTime = examplesValue.start();
RedissLockUtil.unlock(lockName);
} }
}catch (Exception e) { }catch (Exception e) {
RedissLockUtil.unlock(lockName);
if(!THREAD_GROUP_STOP){ if(!THREAD_GROUP_STOP){
log.error("---------{}---------",e.getMessage()); log.error("---------{}---------",e.getMessage());
} }
}finally {
RedissLockUtil.unlock(lockName);
log.debug("------------{},解锁成功,锁名称为{}----------",threadName,lockName);
} }
sleepTime = sleepTime==null?examplesValue.UNIVERSAL_WAIT_TIME:sleepTime; sleepTime = sleepTime==null || sleepTime<=0?examplesValue.UNIVERSAL_WAIT_TIME:sleepTime;
dateAligned(sleepTime,threadName); dateAligned(sleepTime,threadName);
} }
}); });
......
...@@ -55,8 +55,9 @@ public class NodeVerificationImpl implements NodeVerification { ...@@ -55,8 +55,9 @@ public class NodeVerificationImpl implements NodeVerification {
public boolean superiorNodeStatus(JobTask thisJobTask) { public boolean superiorNodeStatus(JobTask thisJobTask) {
//获取该节点的运行标识 //获取该节点的运行标识
String runId = thisJobTask.getRunId(); String runId = thisJobTask.getRunId();
String reRunId;
if(ScheduleTypeEnum.REPEAT.getCode().equals(thisJobTask.getScheduleType())) { if(ScheduleTypeEnum.REPEAT.getCode().equals(thisJobTask.getScheduleType())) {
runId = thisJobTask.getReRunId(); reRunId = thisJobTask.getReRunId();
} }
//查询该节点的依赖节点 //查询该节点的依赖节点
......
...@@ -29,6 +29,13 @@ public interface JobTaskMapper { ...@@ -29,6 +29,13 @@ public interface JobTaskMapper {
List<JobTask> findAllByRunId(@Param("runId")String runId,@Param("flowId")Integer flowId); List<JobTask> findAllByRunId(@Param("runId")String runId,@Param("flowId")Integer flowId);
/** /**
*
* @param runId
* @return
*/
List<JobTask> findByRunId(@Param("runId") String runId);
/**
* 根据id查询 * 根据id查询
* @param id * @param id
* @return * @return
......
...@@ -27,6 +27,8 @@ public interface JobTaskService { ...@@ -27,6 +27,8 @@ public interface JobTaskService {
*/ */
List<JobTask> findJobTaskByRunId(String runId,Integer flowId); List<JobTask> findJobTaskByRunId(String runId,Integer flowId);
List<JobTask> findByRunId(String runId);
/** /**
* 添加单个任务节点 * 添加单个任务节点
* @param jobTask * @param jobTask
......
...@@ -467,7 +467,7 @@ public class FlowServiceImpl implements FlowService { ...@@ -467,7 +467,7 @@ public class FlowServiceImpl implements FlowService {
String killResult = HttpUtil.post(killUrl, requestMap); String killResult = HttpUtil.post(killUrl, requestMap);
log.info("请求结果{}", killResult); log.info("请求结果{}", killResult);
ResponseResult responseResult = JSON.parseObject(killResult, ResponseResult.class); ResponseResult responseResult = JSON.parseObject(killResult, ResponseResult.class);
ValidationUtil.isTrueValidation(!"SUCCESS".equals(responseResult.getResult()), "杀死job失败,错误信息为:" + responseResult.getResult()); ValidationUtil.isTrueValidation(!"SUCCESS".equals(responseResult.getResult()), "杀死job失败,错误信息为:" + responseResult.getMsg());
return true; return true;
} }
......
...@@ -32,7 +32,7 @@ public class FlowStatusSnapshootServiceImpl implements FlowStatusSnapshootServic ...@@ -32,7 +32,7 @@ public class FlowStatusSnapshootServiceImpl implements FlowStatusSnapshootServic
public void removeAndSaveSnapshoot(List<FlowStatusSnapshoot> allFlow) { public void removeAndSaveSnapshoot(List<FlowStatusSnapshoot> allFlow) {
if(CollectionUtil.isEmpty(allFlow)) { if(CollectionUtil.isEmpty(allFlow)) {
log.info("-----------------无需快照插入-------------------"); log.debug("-----------------无需快照插入-------------------");
return; return;
} }
//获取当天的日期 //获取当天的日期
...@@ -40,6 +40,9 @@ public class FlowStatusSnapshootServiceImpl implements FlowStatusSnapshootServic ...@@ -40,6 +40,9 @@ public class FlowStatusSnapshootServiceImpl implements FlowStatusSnapshootServic
String thisHourStr = DateUtil.dateFormat(new Date(), "HH"); String thisHourStr = DateUtil.dateFormat(new Date(), "HH");
String hourBefStr = String.valueOf(Integer.parseInt(thisHourStr)+1); String hourBefStr = String.valueOf(Integer.parseInt(thisHourStr)+1);
if (hourBefStr.length() ==1 ) {
hourBefStr = "0"+hourBefStr;
}
//20201212 12:12:12 //20201212 12:12:12
Date date = DateUtil.strFormatDate(thisDateStr + " " + hourBefStr + ":00:00", "yyyy-MM-dd HH:mm:ss"); Date date = DateUtil.strFormatDate(thisDateStr + " " + hourBefStr + ":00:00", "yyyy-MM-dd HH:mm:ss");
long between = cn.hutool.core.date.DateUtil.between(new Date(), date, DateUnit.MINUTE); long between = cn.hutool.core.date.DateUtil.between(new Date(), date, DateUnit.MINUTE);
......
...@@ -43,6 +43,11 @@ public class JobTaskServiceImpl implements JobTaskService { ...@@ -43,6 +43,11 @@ public class JobTaskServiceImpl implements JobTaskService {
return jobTaskMapper.findAllByRunId(runId,flowId); return jobTaskMapper.findAllByRunId(runId,flowId);
} }
@Override
public List<JobTask> findByRunId(String runId) {
return jobTaskMapper.findByRunId(runId);
}
/** /**
* 添加一个任务 * 添加一个任务
* @param jobTask 任务实体 * @param jobTask 任务实体
......
...@@ -3,13 +3,16 @@ package com.byit.service.mapservice; ...@@ -3,13 +3,16 @@ package com.byit.service.mapservice;
import com.byit.model.JobTask; import com.byit.model.JobTask;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.net.UnknownHostException;
/** /**
* @author 任务表和日志表的映射业务类,保证是一个事务+原子性 * @author 任务表和日志表的映射业务类,保证是一个事务+原子性
*/ */
public interface TaskAndLogServer { public interface TaskAndLogServer {
/** /**
* 添加失败日志,删除任务表的任务 * 添加失败日志,删除任务表的任务
* @param jobTask * @param jobTask 任务节点
* @param isInner 虚节点
*/ */
void addRunLogAndRemoveTask(JobTask jobTask); void addRunLogAndRemoveTask(JobTask jobTask,boolean isInner) throws UnknownHostException;
} }
...@@ -71,34 +71,37 @@ public class RunRecordingAndEmailServiceImpl implements RunRecordingAndEmailServ ...@@ -71,34 +71,37 @@ public class RunRecordingAndEmailServiceImpl implements RunRecordingAndEmailServ
public void saveEmailAndRunRecording(RunRecording runRecording) { public void saveEmailAndRunRecording(RunRecording runRecording) {
//这一步是根据flowId和RunId查询对应的节点信息 //这一步是根据flowId和RunId查询对应的节点信息
List<JobTaskRunLogWithBLOBs> jobTaskRunLogByFlowIdAndRunId = jobTaskRunLogService.findJobTaskRunLogWithBLOBsByFlowIdAndRunId(runRecording.getFlowId(), runRecording.getRunId()); List<JobTaskRunLogWithBLOBs> jobTaskRunLogByFlowIdAndRunId = jobTaskRunLogService.findJobTaskRunLogWithBLOBsByFlowIdAndRunId(runRecording.getFlowId(), runRecording.getRunId());
String flowName = runRecording.getFlowName(); if (runRecording.getFlowNodeCount() == jobTaskRunLogByFlowIdAndRunId.size()) {
//String senContentHtml = runMsgHtml(jobTaskRunLogByFlowIdAndRunId, flowName) String flowName = runRecording.getFlowName();
Integer workspaceId = runRecording.getWorkspaceId(); //String senContentHtml = runMsgHtml(jobTaskRunLogByFlowIdAndRunId, flowName)
Workspace workspace = workspaceService.findOneById(workspaceId); Integer workspaceId = runRecording.getWorkspaceId();
String workspaceName = null; Workspace workspace = workspaceService.findOneById(workspaceId);
String workspaceName = null;
if(workspace != null){ if(workspace != null){
workspaceName = formatWorkspaceName(workspace.getWorkspaceName()); workspaceName = formatWorkspaceName(workspace.getWorkspaceName());
}
long flowEndTime = runRecording.getEndTime() == null? System.currentTimeMillis():runRecording.getEndTime().getTime();
long flowStartTime = runRecording.getStartTime() == null? System.currentTimeMillis():runRecording.getStartTime().getTime();
String senContentHtml = buildHtml(flowName,workspaceName,jobTaskRunLogByFlowIdAndRunId,flowEndTime-flowStartTime);
EmailAlarm emailAlarm = EmailAlarm.builder()
.flowId(runRecording.getFlowId())
.flowName(flowName)
.runId(runRecording.getRunId())
.versionName(runRecording.getFlowVersionName())
.alarmEmail(runRecording.getAlarmEmail())
.alarmContent(senContentHtml)
.alarmResult("0")
.flowRes(runRecording.getFlowRunResult())
.alarmTitle(flowName)
.build();
//保存邮箱
emailAlarmService.saveEmailAlarm(emailAlarm);
//修改为已告警
runRecording.setIsAlarm("0");
runRecordingService.updateRunRecordingById(runRecording);
} }
long flowEndTime = runRecording.getEndTime() == null? System.currentTimeMillis():runRecording.getEndTime().getTime();
long flowStartTime = runRecording.getStartTime() == null? System.currentTimeMillis():runRecording.getStartTime().getTime();
String senContentHtml = buildHtml(flowName,workspaceName,jobTaskRunLogByFlowIdAndRunId,flowEndTime-flowStartTime);
EmailAlarm emailAlarm = EmailAlarm.builder()
.flowId(runRecording.getFlowId())
.flowName(flowName)
.runId(runRecording.getRunId())
.versionName(runRecording.getFlowVersionName())
.alarmEmail(runRecording.getAlarmEmail())
.alarmContent(senContentHtml)
.alarmResult("0")
.flowRes(runRecording.getFlowRunResult())
.alarmTitle(flowName)
.build();
//保存邮箱
emailAlarmService.saveEmailAlarm(emailAlarm);
//修改为已告警
runRecording.setIsAlarm("0");
runRecordingService.updateRunRecordingById(runRecording);
} }
/** /**
......
...@@ -107,14 +107,14 @@ public class RunRecordingAndJobTaskServiceImpl implements RunRecordingAndJobTask ...@@ -107,14 +107,14 @@ public class RunRecordingAndJobTaskServiceImpl implements RunRecordingAndJobTask
.flowStatus("2") .flowStatus("2")
.flowTimeout(virFlow.getFlowTimeout()) .flowTimeout(virFlow.getFlowTimeout())
.dispatchIp(InetAddress.getLocalHost().getHostAddress()) .dispatchIp(InetAddress.getLocalHost().getHostAddress())
.alarmEmail(virFlow.getAlarmEmail()) .alarmEmail(mainRecording.getAlarmEmail())
.alarmlAction(virFlow.getAlarmlAction()) .alarmlAction(mainRecording.getAlarmlAction())
.priority(virFlow.getPriority()) .priority(virFlow.getPriority())
.triggerTime(equals?jobTask.getTriggerTime():virFlow.getTriggerNextTime()) .triggerTime(equals?jobTask.getTriggerTime():virFlow.getTriggerNextTime())
.principal(virFlow.getPrincipal()) .principal(virFlow.getPrincipal())
.startTime(new Date()) .startTime(new Date())
.flowNodeCount(virFlow.getFlowNodeCount()) .flowNodeCount(virFlow.getFlowNodeCount())
.isAlarm(EmailEnum.IS_ALARM_NO.getCode()) .isAlarm(mainRecording.getIsAlarm())
.isInner(FlowPropertyEnum.IS_INNER.getCode()) .isInner(FlowPropertyEnum.IS_INNER.getCode())
.failFast(RunRecordingEnum.FAIL_FAST_NO.getCode()) .failFast(RunRecordingEnum.FAIL_FAST_NO.getCode())
.workspaceId(virFlow.getWorkspaceId()) .workspaceId(virFlow.getWorkspaceId())
......
package com.byit.service.mapservice.impl; package com.byit.service.mapservice.impl;
import com.byit.enums.EmailEnum;
import com.byit.enums.FlowPropertyEnum;
import com.byit.enums.RunRecordingEnum; import com.byit.enums.RunRecordingEnum;
import com.byit.enums.task.RunResultEnum; import com.byit.enums.task.RunResultEnum;
import com.byit.model.JobTaskRunLog; import com.byit.model.*;
import com.byit.model.JobTaskRunLogWithBLOBs; import com.byit.service.*;
import com.byit.model.NodeVersion;
import com.byit.model.RunRecording;
import com.byit.service.JobTaskRunLogService;
import com.byit.service.JobTaskService;
import com.byit.service.NodeVersionService;
import com.byit.service.RunRecordingService;
import com.byit.service.mapservice.RunRecordingAndLogService; import com.byit.service.mapservice.RunRecordingAndLogService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
...@@ -23,36 +22,42 @@ import java.util.stream.Collectors; ...@@ -23,36 +22,42 @@ import java.util.stream.Collectors;
* @author huangfu * @author huangfu
*/ */
@Service @Service
@Slf4j
public class RunRecordingAndLogServiceImpl implements RunRecordingAndLogService { public class RunRecordingAndLogServiceImpl implements RunRecordingAndLogService {
public static final String TRIGGER_MSG = "任务执行超时,被强制执行快速失败!"; public static final String TRIGGER_MSG = "任务执行超时,被强制执行快速失败!";
private final JobTaskRunLogService jobTaskRunLogService; private final JobTaskRunLogService jobTaskRunLogService;
private final RunRecordingService runRecordingService; private final RunRecordingService runRecordingService;
private final NodeVersionService nodeVersionService; private final NodeVersionService nodeVersionService;
private final JobTaskService jobTaskService; private final JobTaskService jobTaskService;
private final FlowService flowService;
public RunRecordingAndLogServiceImpl(JobTaskRunLogService jobTaskRunLogService, RunRecordingService runRecordingService, public RunRecordingAndLogServiceImpl(JobTaskRunLogService jobTaskRunLogService, RunRecordingService runRecordingService,
NodeVersionService nodeVersionService, JobTaskService jobTaskService) { NodeVersionService nodeVersionService, JobTaskService jobTaskService, FlowService flowService) {
this.jobTaskRunLogService = jobTaskRunLogService; this.jobTaskRunLogService = jobTaskRunLogService;
this.runRecordingService = runRecordingService; this.runRecordingService = runRecordingService;
this.nodeVersionService = nodeVersionService; this.nodeVersionService = nodeVersionService;
this.jobTaskService = jobTaskService; this.jobTaskService = jobTaskService;
this.flowService = flowService;
} }
@Override @Override
public void logAndRunRecordingFailFast(RunRecording runRecording) { public void logAndRunRecordingFailFast(RunRecording runRecording) {
String runId = runRecording.getRunId(); String runId = runRecording.getRunId();
Integer flowId = runRecording.getFlowId(); //Integer flowId = runRecording.getFlowId();
//查询该实例对应的所由日志节点 //查询该实例对应的所由日志节点
List<JobTaskRunLogWithBLOBs> jobTaskRunLog = jobTaskRunLogService.findJobTaskRunLogWithBLOBsByFlowIdAndRunId(flowId, runId); //List<JobTaskRunLogWithBLOBs> jobTaskRunLog = jobTaskRunLogService.findJobTaskRunLogWithBLOBsByFlowIdAndRunId(flowId, runId);
List<Integer> logNodeId = jobTaskRunLog.stream().map(JobTaskRunLog::getNodeId).collect(Collectors.toList()); //List<Integer> logNodeId = jobTaskRunLog.stream().map(JobTaskRunLog::getNodeId).collect(Collectors.toList());
List<NodeVersion> allByFlowId = nodeVersionService.findAllByFlowId(flowId); //List<NodeVersion> allByFlowId = nodeVersionService.findAllByFlowId(flowId);
//筛选没在日志里面的节点 //筛选没在日志里面的节点
List<NodeVersion> notLogNode = allByFlowId.stream().filter(nodeVersion -> !(logNodeId.contains(nodeVersion.getNodeId()))).collect(Collectors.toList()); //List<NodeVersion> notLogNode = allByFlowId.stream().filter(nodeVersion -> !(logNodeId.contains(nodeVersion.getNodeId()))).collect(Collectors.toList());
//将这些节点置为失败并将实例也置为失败 //将这些节点置为失败并将实例也置为失败
//保存错误日志节点 //保存错误日志节点
notLogNode.forEach(node ->{
//查询task所有的对应节点
List<JobTask> byRunId = jobTaskService.findByRunId(runId);
byRunId.forEach(task ->{
JobTaskRunLogWithBLOBs log = new JobTaskRunLogWithBLOBs(); JobTaskRunLogWithBLOBs log = new JobTaskRunLogWithBLOBs();
BeanUtils.copyProperties(node,log); BeanUtils.copyProperties(task,log);
log.setTriggerCode(RunResultEnum.TRIGGER_ERROR.getCode()); log.setTriggerCode(RunResultEnum.TRIGGER_ERROR.getCode());
log.setTriggerMsg(TRIGGER_MSG); log.setTriggerMsg(TRIGGER_MSG);
log.setRunCode(RunResultEnum.RUN_ERROR.getCode()); log.setRunCode(RunResultEnum.RUN_ERROR.getCode());
...@@ -74,7 +79,67 @@ public class RunRecordingAndLogServiceImpl implements RunRecordingAndLogService ...@@ -74,7 +79,67 @@ public class RunRecordingAndLogServiceImpl implements RunRecordingAndLogService
runRecording.setFlowRunResult(RunRecordingEnum.RUN_FLOW_FAILURE.getCode()); runRecording.setFlowRunResult(RunRecordingEnum.RUN_FLOW_FAILURE.getCode());
runRecording.setFailFast(RunRecordingEnum.FAIL_FAST_YES.getCode()); runRecording.setFailFast(RunRecordingEnum.FAIL_FAST_YES.getCode());
runRecordingService.updateRunRecordingById(runRecording); runRecordingService.updateRunRecordingById(runRecording);
//筛选虚节点
List<JobTask> virtualTasks = byRunId.stream().filter(task -> "0".equals(task.getIsVirtual())).collect(Collectors.toList());
virtualTasks.forEach(virtualTask -> {
Integer mapFlowId = virtualTask.getMapFlowId();
List<NodeVersion> allByFlowId = nodeVersionService.findAllByFlowId(mapFlowId);
allByFlowId.forEach(node ->{
JobTaskRunLogWithBLOBs log = new JobTaskRunLogWithBLOBs();
BeanUtils.copyProperties(node,log);
log.setTriggerCode(RunResultEnum.TRIGGER_ERROR.getCode());
log.setTriggerMsg(TRIGGER_MSG);
log.setRunCode(RunResultEnum.RUN_ERROR.getCode());
log.setTriggerMsg(TRIGGER_MSG);
Date thisTime = new Date();
log.setStartTime(thisTime);
log.setEndTime(thisTime);
log.setRunId(runId);
log.setFlowName(runRecording.getFlowName());
log.setTriggerTime(thisTime);
jobTaskRunLogService.saveJobTaskRunLog(log);
});
//执行实例的快速失败
Flow virFlow = flowService.findFlowById(mapFlowId);
log.info("-----------【虚节点保存运行记录】--------------");
//保存进运行记录表
RunRecording virtualRunRecording = null;
try {
virtualRunRecording = RunRecording.builder()
.runId(virtualTask.getRunId())
.flowId(mapFlowId)
.flowName(virFlow.getFlowName())
.flowVersionName(virFlow.getVersionName())
.flowStatus("4")
.flowRunResult("2")
.flowTimeout(virFlow.getFlowTimeout())
.dispatchIp(InetAddress.getLocalHost().getHostAddress())
.alarmEmail(virFlow.getAlarmEmail())
.alarmlAction(virFlow.getAlarmlAction())
.priority(virFlow.getPriority())
.triggerTime(runRecording.getTriggerTime())
.principal(virFlow.getPrincipal())
.startTime(new Date())
.flowNodeCount(virFlow.getFlowNodeCount())
.isAlarm(EmailEnum.IS_ALARM_NO.getCode())
.isInner(FlowPropertyEnum.IS_INNER.getCode())
.failFast(RunRecordingEnum.FAIL_FAST_YES.getCode())
.workspaceId(virFlow.getWorkspaceId())
.repeatTime(runRecording.getRepeatTime())
.operator(virtualTask.getOperator())
.scheduleType(virtualTask.getScheduleType())
.build();
} catch (UnknownHostException e) {
e.printStackTrace();
}
runRecordingService.saveRunRecording(virtualRunRecording);
});
//删除task里面的数据 //删除task里面的数据
jobTaskService.removeByRunId(runId); jobTaskService.removeByRunId(runId);
} }
} }
package com.byit.service.mapservice.impl; package com.byit.service.mapservice.impl;
import cn.hutool.core.collection.CollectionUtil;
import com.byit.enums.EmailEnum;
import com.byit.enums.FlowPropertyEnum;
import com.byit.enums.RunRecordingEnum;
import com.byit.job.utils.CronExpression;
import com.byit.job.utils.PlaceholderUtils; import com.byit.job.utils.PlaceholderUtils;
import com.byit.model.JobTask; import com.byit.model.*;
import com.byit.model.JobTaskRunLogWithBLOBs; import com.byit.service.*;
import com.byit.service.JobTaskRunLogService;
import com.byit.service.JobTaskService;
import com.byit.service.mapservice.TaskAndLogServer; import com.byit.service.mapservice.TaskAndLogServer;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
...@@ -12,7 +15,12 @@ import org.springframework.beans.BeanUtils; ...@@ -12,7 +15,12 @@ import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.text.ParseException;
import java.util.Date; import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
/** /**
* @author huangfu * @author huangfu
...@@ -23,14 +31,25 @@ import java.util.Date; ...@@ -23,14 +31,25 @@ import java.util.Date;
public class TaskAndLogServerImpl implements TaskAndLogServer { public class TaskAndLogServerImpl implements TaskAndLogServer {
private final JobTaskService jobTaskService; private final JobTaskService jobTaskService;
private final JobTaskRunLogService jobTaskRunLogService; private final JobTaskRunLogService jobTaskRunLogService;
private final FlowService flowService;
private final RunRecordingService runRecordingService;
private final NodeService nodeService;
/**
* 节点依赖查询操作
*/
private final NodeDependencyService nodeDependencyService;
public TaskAndLogServerImpl(JobTaskService jobTaskService, JobTaskRunLogService jobTaskRunLogService) { public TaskAndLogServerImpl(JobTaskService jobTaskService, JobTaskRunLogService jobTaskRunLogService, FlowService flowService, RunRecordingService runRecordingService, NodeService nodeService, NodeDependencyService nodeDependencyService) {
this.jobTaskService = jobTaskService; this.jobTaskService = jobTaskService;
this.jobTaskRunLogService = jobTaskRunLogService; this.jobTaskRunLogService = jobTaskRunLogService;
this.flowService = flowService;
this.runRecordingService = runRecordingService;
this.nodeService = nodeService;
this.nodeDependencyService = nodeDependencyService;
} }
@Override @Override
public void addRunLogAndRemoveTask(JobTask jobTask) { public void addRunLogAndRemoveTask(JobTask jobTask, boolean isInner) throws UnknownHostException {
Date thisDate = new Date(); Date thisDate = new Date();
//删除任务节点 //删除任务节点
jobTaskService.removeMythJobTaskById(jobTask.getId()); jobTaskService.removeMythJobTaskById(jobTask.getId());
...@@ -75,5 +94,68 @@ public class TaskAndLogServerImpl implements TaskAndLogServer { ...@@ -75,5 +94,68 @@ public class TaskAndLogServerImpl implements TaskAndLogServer {
//添加日志节点 //添加日志节点
jobTaskRunLogService.saveJobTaskRunLog(jobTaskRunLog); jobTaskRunLogService.saveJobTaskRunLog(jobTaskRunLog);
if (isInner) {
RunRecording mainRecording = runRecordingService.findRunRecordingByFlowIdAndRunId(jobTask.getFlowId(), jobTask.getRunId());
log.error("------该节点是虚节点,先将该节点对应的实例保存--------");
//查询该节点对应的工作流
Integer mapFlowId = jobTask.getMapFlowId();
Flow virFlow = flowService.findFlowById(mapFlowId);
//保存进运行记录表 快速失败
RunRecording runRecording = RunRecording.builder()
.runId(jobTask.getRunId())
.flowId(jobTask.getMapFlowId())
.flowName(virFlow.getFlowName())
.flowVersionName(jobTask.getVersionName())
.flowStatus("4")
.flowRunResult("2")
.flowTimeout(virFlow.getFlowTimeout())
.dispatchIp(InetAddress.getLocalHost().getHostAddress())
.alarmEmail(mainRecording.getAlarmEmail())
.alarmlAction(mainRecording.getAlarmlAction())
.priority(virFlow.getPriority())
.triggerTime(jobTask.getTriggerTime())
.principal(virFlow.getPrincipal())
.startTime(new Date())
.flowNodeCount(virFlow.getFlowNodeCount())
.isAlarm(mainRecording.getIsAlarm())
.isInner(FlowPropertyEnum.IS_INNER.getCode())
.failFast(RunRecordingEnum.FAIL_FAST_YES.getCode())
.workspaceId(virFlow.getWorkspaceId())
.build();
runRecordingService.saveRunRecording(runRecording);
log.error("在将该虚节点对应的节点拉取过来");
//获取所有的节点,开始将所有节点保存到任务表
List<Node> nodeByFlowIdAndVersionName = nodeService.findNodeByFlowIdAndVersionName(mapFlowId);
List<JobTask> jobTasks = nodeByFlowIdAndVersionName.stream()
.map(node -> {
JobTask task = new JobTask();
List<Integer> dependIdByNodeId = nodeDependencyService.findDependIdByNodeId(jobTask.getNodeId());
if(CollectionUtil.isNotEmpty(dependIdByNodeId)){
String parentIds = StringUtils.join(dependIdByNodeId, ",");
task.setNodeDepend(parentIds);
}
BeanUtils.copyProperties(node, task);
task.setTriggerTime(jobTask.getTriggerTime());
task.setRunId(jobTask.getRunId());
task.setTriggerStatus("1");
task.setFlowName(runRecording.getFlowName());
task.setOperator(jobTask.getOperator());
task.setScheduleType(jobTask.getScheduleType());
return task;
}).collect(Collectors.toList());
jobTaskService.saveJobTasks(jobTasks);
log.info("-----------saveRunRecordingAndTask end【虚节点保存服务】--------------");
if(StringUtils.isNotBlank(virFlow.getFlowCron())){
try {
virFlow.setTriggerNextTime(new CronExpression(virFlow.getFlowCron()).getNextValidTimeAfter(new Date()).getTime());
} catch (ParseException e) {
e.printStackTrace();
}
flowService.updateByIdSelective(virFlow);
}
}
} }
} }
...@@ -32,7 +32,7 @@ public class JobSnapshotThreadRunHelper extends BaseThreadRunHelper { ...@@ -32,7 +32,7 @@ public class JobSnapshotThreadRunHelper extends BaseThreadRunHelper {
@Value("${myth-job.snapshoot-date}") @Value("${myth-job.snapshoot-date}")
private Long snapshootDate; private Long snapshootDate;
private final FlowStatusSnapshootMapper flowStatusSnapshootMapper; private final FlowStatusSnapshootMapper flowStatusSnapshootMapper;
private static final String LOCK_NAME = "JobSnapshotThreadRunHelper"; private static final String LOCK_NAME = "job_snapshot_thread_run_helper";
private static final Long SELLP_TIME = 300000L; private static final Long SELLP_TIME = 300000L;
private final DataSource dataSource; private final DataSource dataSource;
private final FlowService flowService; private final FlowService flowService;
......
...@@ -21,6 +21,7 @@ import org.springframework.beans.BeanUtils; ...@@ -21,6 +21,7 @@ import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import javax.sql.DataSource; import javax.sql.DataSource;
import java.net.UnknownHostException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
...@@ -105,7 +106,11 @@ public class JobTaskThreadRunHelper extends BaseThreadRunHelper { ...@@ -105,7 +106,11 @@ public class JobTaskThreadRunHelper extends BaseThreadRunHelper {
} }
}catch (SuperiorNodeRunException se) { }catch (SuperiorNodeRunException se) {
//删除这个数据 并且添加到日志 //删除这个数据 并且添加到日志
taskAndLogServer.addRunLogAndRemoveTask(jobTask); try {
taskAndLogServer.addRunLogAndRemoveTask(jobTask,true);
} catch (UnknownHostException e) {
e.printStackTrace();
}
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
...@@ -125,7 +130,11 @@ public class JobTaskThreadRunHelper extends BaseThreadRunHelper { ...@@ -125,7 +130,11 @@ public class JobTaskThreadRunHelper extends BaseThreadRunHelper {
} }
}catch (SuperiorNodeRunException se) { }catch (SuperiorNodeRunException se) {
//删除这个数据 并且添加到日志 //删除这个数据 并且添加到日志
taskAndLogServer.addRunLogAndRemoveTask(jobTask); try {
taskAndLogServer.addRunLogAndRemoveTask(jobTask,false);
} catch (UnknownHostException e) {
e.printStackTrace();
}
} }
} }
} }
......
...@@ -59,17 +59,17 @@ public class MakeUpFlowThreadRunHelper extends BaseThreadRunHelper { ...@@ -59,17 +59,17 @@ public class MakeUpFlowThreadRunHelper extends BaseThreadRunHelper {
Map<Integer, WaitingRecord> nextRunFlow = allByTriggerTime.stream() Map<Integer, WaitingRecord> nextRunFlow = allByTriggerTime.stream()
.collect(Collectors.toMap(WaitingRecord::getFlowId, Function.identity(), BinaryOperator.minBy(Comparator.comparingInt(WaitingRecord::getWaitOrder)))); .collect(Collectors.toMap(WaitingRecord::getFlowId, Function.identity(), BinaryOperator.minBy(Comparator.comparingInt(WaitingRecord::getWaitOrder))));
log.info("-------筛选后的数据为:{}----------", JSON.toJSONString(nextRunFlow)); log.debug("-------筛选后的数据为:{}----------", JSON.toJSONString(nextRunFlow));
for (WaitingRecord value : nextRunFlow.values()) { for (WaitingRecord value : nextRunFlow.values()) {
boolean runRecordingIsRunning = runRecordingService.findRunRecordingIsRunning(value.getFlowId()); boolean runRecordingIsRunning = runRecordingService.findRunRecordingIsRunning(value.getFlowId());
log.info("-------{}的运行状态为{}",value,runRecordingIsRunning); log.debug("-------{}的运行状态为{}",value,runRecordingIsRunning);
log.info("==================================================的运行状态为{}======================================" ,runRecordingIsRunning); log.debug("==================================================的运行状态为{}======================================" ,runRecordingIsRunning);
if(!runRecordingIsRunning){ if(!runRecordingIsRunning){
runRecordingAndJobTaskService.updateRunRecordingAndTask(value); runRecordingAndJobTaskService.updateRunRecordingAndTask(value);
} }
} }
log.info("============================com.byit.thread.helper.MakeUpFlowThreadRunHelper.start 执行完成====================================="); log.debug("============================com.byit.thread.helper.MakeUpFlowThreadRunHelper.start 执行完成=====================================");
return UNIVERSAL_WAIT_TIME; return UNIVERSAL_WAIT_TIME;
} }
......
...@@ -23,6 +23,7 @@ import org.springframework.beans.BeanUtils; ...@@ -23,6 +23,7 @@ import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import javax.sql.DataSource; import javax.sql.DataSource;
import java.net.UnknownHostException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
...@@ -166,7 +167,11 @@ public class TaskThreadRunHelper extends BaseThreadRunHelper { ...@@ -166,7 +167,11 @@ public class TaskThreadRunHelper extends BaseThreadRunHelper {
//如果有失败的节点 就把该节点置为失败 //如果有失败的节点 就把该节点置为失败
if(CollectionUtil.isNotEmpty(errorJobLog)){ if(CollectionUtil.isNotEmpty(errorJobLog)){
//删除这个数据 并且添加到日志 //删除这个数据 并且添加到日志
taskAndLogServer.addRunLogAndRemoveTask(thisJobTask); try {
taskAndLogServer.addRunLogAndRemoveTask(thisJobTask,false);
} catch (UnknownHostException e) {
e.printStackTrace();
}
}else{ }else{
//执行代码 //执行代码
runJobTask(thisJobTask,jobTaskSchedules); runJobTask(thisJobTask,jobTaskSchedules);
......
...@@ -10,6 +10,7 @@ import lombok.extern.slf4j.Slf4j; ...@@ -10,6 +10,7 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import javax.sql.DataSource; import javax.sql.DataSource;
import java.util.Date;
import java.util.List; import java.util.List;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors; import java.util.stream.Collectors;
...@@ -38,7 +39,7 @@ public class TimeoutExampleThreadRunHelper extends BaseThreadRunHelper { ...@@ -38,7 +39,7 @@ public class TimeoutExampleThreadRunHelper extends BaseThreadRunHelper {
List<RunRecording> allRunIng = runRecordingService.findAllRunIng(new FlowConditionDto()); List<RunRecording> allRunIng = runRecordingService.findAllRunIng(new FlowConditionDto());
List<RunRecording> timeoutRunRecordings = allRunIng.stream().filter(runRecording -> { List<RunRecording> timeoutRunRecordings = allRunIng.stream().filter(runRecording -> {
long startTime = runRecording.getStartTime().getTime(); long startTime = runRecording.getTriggerTime();
long thisTime = System.currentTimeMillis(); long thisTime = System.currentTimeMillis();
Long flowTimeout = runRecording.getFlowTimeout(); Long flowTimeout = runRecording.getFlowTimeout();
long time = thisTime - startTime; long time = thisTime - startTime;
......
...@@ -72,6 +72,15 @@ ...@@ -72,6 +72,15 @@
from job_task from job_task
where run_id=#{runId,jdbcType=VARCHAR} and flow_Id = #{flowId,jdbcType = INTEGER} where run_id=#{runId,jdbcType=VARCHAR} and flow_Id = #{flowId,jdbcType = INTEGER}
</select> </select>
<select id="findByRunId" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
,
<include refid="Blob_Column_List" />
from job_task
where run_id=#{runId,jdbcType=VARCHAR}
</select>
<!--根据id查询--> <!--根据id查询-->
<select id="findJobTaskById" parameterType="java.lang.Integer" resultMap="ResultMapWithBLOBs"> <select id="findJobTaskById" parameterType="java.lang.Integer" resultMap="ResultMapWithBLOBs">
select select
...@@ -467,7 +476,7 @@ ...@@ -467,7 +476,7 @@
</foreach> </foreach>
</delete> </delete>
<delete id="deleteByRunId" parameterType="java.lang.Integer"> <delete id="deleteByRunId">
delete from job_task delete from job_task
where run_id = #{runId,jdbcType=VARCHAR} where run_id = #{runId,jdbcType=VARCHAR}
</delete> </delete>
......
...@@ -126,14 +126,14 @@ ...@@ -126,14 +126,14 @@
where run_id = #{runId,jdbcType=VARCHAR} and flow_id = #{flowId,jdbcType=INTEGER} and schedule_type != 4 where run_id = #{runId,jdbcType=VARCHAR} and flow_id = #{flowId,jdbcType=INTEGER} and schedule_type != 4
</select> </select>
<select id="findRunRecordingById" parameterType="java.lang.Integer" resultMap="BaseResultMap"> <select id="findRunRecordingById" resultMap="BaseResultMap">
select select
<include refid="Base_Column_List" /> <include refid="Base_Column_List" />
from run_recording from run_recording
where recording_id = #{recordingId,jdbcType=INTEGER} and schedule_type != 4 where recording_id = #{recordingId,jdbcType=INTEGER} and schedule_type != 4
</select> </select>
<select id="findOnScheduleByFlowId" parameterType="java.lang.Integer" resultMap="BaseResultMap"> <select id="findOnScheduleByFlowId" resultMap="BaseResultMap">
select select
<include refid="Base_Column_List" /> <include refid="Base_Column_List" />
from run_recording from run_recording
...@@ -141,7 +141,7 @@ ...@@ -141,7 +141,7 @@
and flow_status not in ('1','4') and schedule_type != 4 and flow_status not in ('1','4') and schedule_type != 4
</select> </select>
<select id="findUnStartByFlowId" parameterType="java.lang.Integer" resultMap="BaseResultMap"> <select id="findUnStartByFlowId" resultMap="BaseResultMap">
select select
<include refid="Base_Column_List" /> <include refid="Base_Column_List" />
from run_recording from run_recording
...@@ -291,13 +291,13 @@ ...@@ -291,13 +291,13 @@
) flow ) flow
</select> </select>
<delete id="deleteById" parameterType="java.lang.Integer"> <delete id="deleteById">
<!-- generated @mbg.generated date: 2019-12-25 --> <!-- generated @mbg.generated date: 2019-12-25 -->
delete from run_recording delete from run_recording
where recording_id = #{recordingId,jdbcType=INTEGER} where recording_id = #{recordingId,jdbcType=INTEGER}
</delete> </delete>
<delete id="deleteByRunId" parameterType="java.lang.Integer"> <delete id="deleteByRunId">
delete from run_recording delete from run_recording
where run_id = #{runId,jdbcType=INTEGER} where run_id = #{runId,jdbcType=INTEGER}
</delete> </delete>
......
...@@ -62,7 +62,7 @@ public class CommandAndScriptProcessingMachine implements ProcessingMachine { ...@@ -62,7 +62,7 @@ public class CommandAndScriptProcessingMachine implements ProcessingMachine {
} }
if (paramAndPlaceholderDto != null) { if (paramAndPlaceholderDto != null) {
//执行命令参数的替换 //执行命令参数的替换
command = PlaceholderUtils.commandReplace(command,paramAndPlaceholderDto.getParam()); //command = PlaceholderUtils.commandReplace(command,paramAndPlaceholderDto.getParam());
log.debug("-----命令参数替换完成,命令为:[{}]------------",command); log.debug("-----命令参数替换完成,命令为:[{}]------------",command);
scriptDto.setCommand(command); scriptDto.setCommand(command);
} }
......
...@@ -6,9 +6,11 @@ import com.byit.node.ProcessingNodeChain; ...@@ -6,9 +6,11 @@ import com.byit.node.ProcessingNodeChain;
import com.byit.node.machine.ProcessingMachine; import com.byit.node.machine.ProcessingMachine;
import com.byit.process.MythJobProcess; import com.byit.process.MythJobProcess;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
...@@ -36,11 +38,17 @@ public class RunScriptProcessingMachine implements ProcessingMachine { ...@@ -36,11 +38,17 @@ public class RunScriptProcessingMachine implements ProcessingMachine {
try { try {
boolean isRunNode = scriptDto.getRunId().contains("REAL:EXEC:"); boolean isRunNode = scriptDto.getRunId().contains("REAL:EXEC:");
List<String> cmdList = Arrays.asList(scriptDto.getCommand().split(" ")); List<String> cmdList = Arrays.asList(scriptDto.getCommand().split(" "));
List<String> newCmdList = new ArrayList<>();
cmdList.forEach(cmd ->{
if (StringUtils.isNotBlank(cmd)) {
newCmdList.add(cmd);
}
});
MythJobProcess mythJobProcess; MythJobProcess mythJobProcess;
if(isRunNode) { if(isRunNode) {
mythJobProcess = new MythJobProcess(cmdList, null, null, scriptDto.getLogId(), stringRedisTemplate); mythJobProcess = new MythJobProcess(newCmdList, null, null, scriptDto.getLogId(), stringRedisTemplate);
}else { }else {
mythJobProcess = new MythJobProcess(cmdList, null, null, scriptDto.getLogId(), null); mythJobProcess = new MythJobProcess(newCmdList, null, null, scriptDto.getLogId(), null);
} }
//保存日志 //保存日志
......
...@@ -222,16 +222,16 @@ public class MythJobProcess implements Callable<String>{ ...@@ -222,16 +222,16 @@ public class MythJobProcess implements Callable<String>{
try { try {
if (this.isExecuteAsUser) { if (this.isExecuteAsUser) {
final String cmd = String.format("%s %s %s -9 %d", this.executeAsUserBinary, this.effectiveUser, KILL_COMMAND, this.processId); final String cmd = String.format("%s %s %s -9 %d", this.executeAsUserBinary, this.effectiveUser, KILL_COMMAND, this.processId);
System.out.println("执行命令" + cmd); log.debug("执行命令:{}", cmd);
Runtime.getRuntime().exec(cmd); Runtime.getRuntime().exec(cmd);
} else { } else {
final String cmd = String.format("%s -9 %d", KILL_COMMAND, this.processId); final String cmd = String.format("%s -9 %d", KILL_COMMAND, this.processId);
System.out.println("执行命令" + cmd); log.debug("执行命令:{}", cmd);
Runtime.getRuntime().exec(cmd); Runtime.getRuntime().exec(cmd);
} }
return this.completeLatch.await(time, unit); return this.completeLatch.await(time, unit);
} catch (final IOException e) { } catch (final IOException e) {
log.error("尝试杀死失败.", e); log.error("尝试杀死失败.{}", e.getMessage());
} }
} }
//如果是杀死将退出值改为-100 //如果是杀死将退出值改为-100
...@@ -246,7 +246,7 @@ public class MythJobProcess implements Callable<String>{ ...@@ -246,7 +246,7 @@ public class MythJobProcess implements Callable<String>{
* 强制杀死这个过程 * 强制杀死这个过程
*/ */
public void hardKill() { public void hardKill() {
log.info("强制杀死这个过程"); log.debug("强制杀死这个过程");
//判断是否已经开始运行 //判断是否已经开始运行
checkStarted(); checkStarted();
//判断是否正在执行 //判断是否正在执行
...@@ -255,15 +255,15 @@ public class MythJobProcess implements Callable<String>{ ...@@ -255,15 +255,15 @@ public class MythJobProcess implements Callable<String>{
try { try {
if (this.isExecuteAsUser) { if (this.isExecuteAsUser) {
final String cmd = String.format("%s %s %s -9 %d", this.executeAsUserBinary, this.effectiveUser, KILL_COMMAND, this.processId); final String cmd = String.format("%s %s %s -9 %d", this.executeAsUserBinary, this.effectiveUser, KILL_COMMAND, this.processId);
System.out.println("执行命令" + cmd); log.debug("执行命令:{}", cmd);
Runtime.getRuntime().exec(cmd); Runtime.getRuntime().exec(cmd);
} else { } else {
final String cmd = String.format("%s -9 %d", KILL_COMMAND, this.processId); final String cmd = String.format("%s -9 %d", KILL_COMMAND, this.processId);
System.out.println("执行命令" + cmd); log.debug("执行命令:{}" ,cmd);
Runtime.getRuntime().exec(cmd); Runtime.getRuntime().exec(cmd);
} }
} catch (final IOException e) { } catch (final IOException e) {
log.error("Kill attempt failed.", e); log.error("Kill attempt failed.:{}", e.getMessage());
} }
} }
this.process.destroy(); this.process.destroy();
......
...@@ -25,7 +25,7 @@ spring: ...@@ -25,7 +25,7 @@ spring:
maximum-pool-size: 5 maximum-pool-size: 5
minimum-idle: 1 minimum-idle: 1
password: ${CM_PWD} password: ${CM_PWD}
url: jdbc:mysql://${CM_IP}/myth-registry?useUnicode=true&useSSL=true&characterEncoding=utf-8&mysqlEncoding=utf8&zeroDateTimeBehavior=convertToNull&allowMultiQueries=false&autoReconnect=true&failOverReadOnly=false url: jdbc:mysql://${CM_IP}/${CM_DB}?useUnicode=true&useSSL=true&characterEncoding=utf-8&mysqlEncoding=utf8&zeroDateTimeBehavior=convertToNull&allowMultiQueries=false&autoReconnect=true&failOverReadOnly=false
username: ${CM_USER} username: ${CM_USER}
zuul: zuul:
route: route:
......
...@@ -65,7 +65,7 @@ public class ApiController { ...@@ -65,7 +65,7 @@ public class ApiController {
try { try {
registryParamVO = JacksonUtil.readValue(data, RegistryParamVO.class); registryParamVO = JacksonUtil.readValue(data, RegistryParamVO.class);
} catch (Exception e) { } catch (Exception e) {
System.out.print(e); System.err.println(e.getMessage());
} }
// parse param // parse param
...@@ -197,7 +197,7 @@ public class ApiController { ...@@ -197,7 +197,7 @@ public class ApiController {
//注册数据就是从这里加载的 //注册数据就是从这里加载的
registryParamVO = JacksonUtil.readValue(data, RegistryParamVO.class); registryParamVO = JacksonUtil.readValue(data, RegistryParamVO.class);
} catch (Exception e) { } catch (Exception e) {
System.out.println(e); System.err.println(e.getMessage());
} }
// parse param // parse param
......
...@@ -15,7 +15,7 @@ spring: ...@@ -15,7 +15,7 @@ spring:
datasource: datasource:
driver-class-name: com.mysql.jdbc.Driver driver-class-name: com.mysql.jdbc.Driver
type: org.apache.tomcat.jdbc.pool.DataSource type: org.apache.tomcat.jdbc.pool.DataSource
url: jdbc:mysql://${CM_IP}/myth-registry?Unicode=true&characterEncoding=UTF-8&autoReconnect=true&useSSL=false url: jdbc:mysql://${CM_IP}/${CM_DB}?Unicode=true&characterEncoding=UTF-8&autoReconnect=true&useSSL=false
username: ${CM_USER} username: ${CM_USER}
password: ${CM_PWD} password: ${CM_PWD}
tomcat: tomcat:
......
...@@ -40,12 +40,4 @@ public enum LoadBalance { ...@@ -40,12 +40,4 @@ public enum LoadBalance {
} }
return defaultRouter; return defaultRouter;
} }
}
class test{
public static void main(String[] args) {
for (LoadBalance value : LoadBalance.values( )) {
System.out.println(value );
}
}
} }
\ No newline at end of file
...@@ -27,10 +27,10 @@ public class NettyClientHandler extends SimpleChannelInboundHandler<RpcResponse> ...@@ -27,10 +27,10 @@ public class NettyClientHandler extends SimpleChannelInboundHandler<RpcResponse>
@Override @Override
protected void channelRead0(ChannelHandlerContext ctx, RpcResponse rpcResponse) throws Exception { protected void channelRead0(ChannelHandlerContext ctx, RpcResponse rpcResponse) throws Exception {
logger.info("------------------客户端接收到响应:{}--------------",rpcResponse); logger.debug("------------------客户端接收到响应:{}--------------",rpcResponse);
// notify response // notify response
rpcInvokerFactory.notifyInvokerFuture(rpcResponse.getRequestId(), rpcResponse); rpcInvokerFactory.notifyInvokerFuture(rpcResponse.getRequestId(), rpcResponse);
logger.info("------------------客户端解锁---------------"); logger.debug("------------------客户端解锁---------------");
} }
@Override @Override
......
package com.byit.param.defaultparam;
import com.alibaba.fastjson.JSON;
import com.byit.packet.response.PluginRpcResponsePacket;
import com.byit.param.ResultCallback;
import io.netty.channel.ChannelHandlerContext;
/**
* 默认的回调方式
* @author huangfu
*/
public class DefaultResultCallback implements ResultCallback {
@Override
public void resultCallback(ChannelHandlerContext ctx, PluginRpcResponsePacket pluginRpcResponsePacket) {
System.out.println(pluginRpcResponsePacket);
System.out.println(JSON.toJSONString(pluginRpcResponsePacket));
}
}
...@@ -32,7 +32,6 @@ public class NettyClientHandler extends SimpleChannelInboundHandler<PluginRpcRes ...@@ -32,7 +32,6 @@ public class NettyClientHandler extends SimpleChannelInboundHandler<PluginRpcRes
//判断事件是否是心跳事件 //判断事件是否是心跳事件
if( evt instanceof IdleStateEvent){ if( evt instanceof IdleStateEvent){
pluginConnectClient.send(PluginBeat.PLUGIN_RPC_REQUEST_PACKET); pluginConnectClient.send(PluginBeat.PLUGIN_RPC_REQUEST_PACKET);
System.out.println("------客户端发送心跳请求-----");
}else{ }else{
super.userEventTriggered(ctx, evt); super.userEventTriggered(ctx, evt);
} }
......
...@@ -6,7 +6,6 @@ import com.byit.handler.PacketEncodeHandler; ...@@ -6,7 +6,6 @@ import com.byit.handler.PacketEncodeHandler;
import com.byit.init.PluginClientInitialization; import com.byit.init.PluginClientInitialization;
import com.byit.packet.request.PluginRpcRequestPacket; import com.byit.packet.request.PluginRpcRequestPacket;
import com.byit.param.PluginBeat; import com.byit.param.PluginBeat;
import com.byit.rpc.remoting.net.params.Beat;
import com.byit.utils.IpUtil; import com.byit.utils.IpUtil;
import io.netty.bootstrap.Bootstrap; import io.netty.bootstrap.Bootstrap;
import io.netty.channel.*; import io.netty.channel.*;
...@@ -55,9 +54,8 @@ public class NettyPluginConnectionClient extends PluginConnectClient { ...@@ -55,9 +54,8 @@ public class NettyPluginConnectionClient extends PluginConnectClient {
this.channel = bootstrap.connect(ip, port).sync().channel(); this.channel = bootstrap.connect(ip, port).sync().channel();
// valid // valid
if (!isValidate()) { if (!isValidate()) {
System.out.println("------关闭链接"); System.err.println("------关闭链接--------");
close(); close();
return;
} }
} }
...@@ -65,7 +63,7 @@ public class NettyPluginConnectionClient extends PluginConnectClient { ...@@ -65,7 +63,7 @@ public class NettyPluginConnectionClient extends PluginConnectClient {
@Override @Override
public void close() { public void close() {
if(this.channel !=null && isValidate()){ if(this.channel !=null && isValidate()){
System.out.println("------关闭链接"+channel.id().asShortText()); System.err.println(String.format("------关闭链接%s------", channel.id().asShortText()));
this.channel.close(); this.channel.close();
} }
...@@ -83,7 +81,7 @@ public class NettyPluginConnectionClient extends PluginConnectClient { ...@@ -83,7 +81,7 @@ public class NettyPluginConnectionClient extends PluginConnectClient {
} }
@Override @Override
public void send(PluginRpcRequestPacket pluginRpcRequestPacket) throws Exception { public void send(PluginRpcRequestPacket pluginRpcRequestPacket) {
this.channel.writeAndFlush(pluginRpcRequestPacket); this.channel.writeAndFlush(pluginRpcRequestPacket);
} }
} }
package com.byit.factory; package com.byit.factory;
import com.byit.callback.RemainingOperationsCallBack;
import com.byit.registry.PluginServiceRegistry;
import com.byit.server.PluginServer;
import com.byit.task.annotations.TaskHandler; import com.byit.task.annotations.TaskHandler;
import com.byit.task.handler.interfaces.IJobHandler; import com.byit.task.handler.interfaces.IJobHandler;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
...@@ -12,7 +9,6 @@ import org.springframework.aop.support.AopUtils; ...@@ -12,7 +9,6 @@ import org.springframework.aop.support.AopUtils;
import org.springframework.beans.BeansException; import org.springframework.beans.BeansException;
import org.springframework.beans.factory.DisposableBean; import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean; import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware; import org.springframework.context.ApplicationContextAware;
...@@ -64,7 +60,6 @@ public class RpcSpringPluginServerFactory extends PluginServerFactory implements ...@@ -64,7 +60,6 @@ public class RpcSpringPluginServerFactory extends PluginServerFactory implements
} }
if(target != null){ if(target != null){
TaskHandler annotation = target.getClass().getAnnotation(TaskHandler.class); TaskHandler annotation = target.getClass().getAnnotation(TaskHandler.class);
System.out.println("注解:"+annotation);
String taskName = annotation.taskName(); String taskName = annotation.taskName();
super.addService(taskName,value); super.addService(taskName,value);
String expand = annotation.expand(); String expand = annotation.expand();
...@@ -73,7 +68,7 @@ public class RpcSpringPluginServerFactory extends PluginServerFactory implements ...@@ -73,7 +68,7 @@ public class RpcSpringPluginServerFactory extends PluginServerFactory implements
} }
} }
}else{ }else{
System.err.println("警告!bean"+key+"不是【com.byit.task.handler.interfaces.IJobHandler】类型!忽略该bean!"); System.out.println(String.format("警告!bean %s 不是【com.byit.task.handler.interfaces.IJobHandler】类型!忽略该bean!",key));
} }
}); });
} }
...@@ -93,7 +88,7 @@ public class RpcSpringPluginServerFactory extends PluginServerFactory implements ...@@ -93,7 +88,7 @@ public class RpcSpringPluginServerFactory extends PluginServerFactory implements
} }
private static Object getCglibProxyTargetObject(Object proxy) throws Exception { private static Object getCglibProxyTargetObject(Object proxy) throws Exception {
System.out.println(proxy+"-------该对象为cglib代理对象-------"); System.out.println(String.format("%s:-------该对象为cglib代理对象-------", proxy));
Field h = proxy.getClass().getDeclaredField("CGLIB$CALLBACK_0"); Field h = proxy.getClass().getDeclaredField("CGLIB$CALLBACK_0");
h.setAccessible(true); h.setAccessible(true);
Object dynamicAdvisedInterceptor = h.get(proxy); Object dynamicAdvisedInterceptor = h.get(proxy);
...@@ -108,7 +103,7 @@ public class RpcSpringPluginServerFactory extends PluginServerFactory implements ...@@ -108,7 +103,7 @@ public class RpcSpringPluginServerFactory extends PluginServerFactory implements
private static Object getJdkDynamicProxyTargetObject(Object proxy) throws Exception { private static Object getJdkDynamicProxyTargetObject(Object proxy) throws Exception {
System.out.println(proxy+"-------该对象为jdk代理对象-------"); System.out.println(String.format("-------%s,该对象为jdk代理对象-------", proxy));
Field h = proxy.getClass().getSuperclass().getDeclaredField("h"); Field h = proxy.getClass().getSuperclass().getDeclaredField("h");
h.setAccessible(true); h.setAccessible(true);
AopProxy aopProxy = (AopProxy) h.get(proxy); AopProxy aopProxy = (AopProxy) h.get(proxy);
......
...@@ -53,7 +53,7 @@ public class MainNettyPluginServer extends PluginServer { ...@@ -53,7 +53,7 @@ public class MainNettyPluginServer extends PluginServer {
ChannelFuture closeFuture = channelFuture.channel().closeFuture().sync(); ChannelFuture closeFuture = channelFuture.channel().closeFuture().sync();
closeFuture.addListener(future ->{ closeFuture.addListener(future ->{
if (future.isSuccess()) { if (future.isSuccess()) {
System.out.println("-----------------"); System.err.println("--------服务关闭---------");
} }
}); });
}catch (Exception e){ }catch (Exception e){
...@@ -78,7 +78,7 @@ public class MainNettyPluginServer extends PluginServer { ...@@ -78,7 +78,7 @@ public class MainNettyPluginServer extends PluginServer {
@Override @Override
public void stop() { public void stop() {
System.out.println("-------------"); System.err.println("--------服务关闭---------");
super.onStop(); super.onStop();
} }
} }
...@@ -42,7 +42,6 @@ public class NettyPluginServerHandler extends SimpleChannelInboundHandler<Plugin ...@@ -42,7 +42,6 @@ public class NettyPluginServerHandler extends SimpleChannelInboundHandler<Plugin
@Override @Override
protected void channelRead0(ChannelHandlerContext ctx, PluginRpcRequestPacket msg) { protected void channelRead0(ChannelHandlerContext ctx, PluginRpcRequestPacket msg) {
if(PluginBeat.BEAT_ID.equals(msg.getRequestId())){ if(PluginBeat.BEAT_ID.equals(msg.getRequestId())){
System.out.println("------接收到客户端的心跳连接-------");
return; return;
} }
PluginRpcResponsePacket transferPluginRpcResponse = new PluginRpcResponsePacket(); PluginRpcResponsePacket transferPluginRpcResponse = new PluginRpcResponsePacket();
...@@ -114,7 +113,7 @@ public class NettyPluginServerHandler extends SimpleChannelInboundHandler<Plugin ...@@ -114,7 +113,7 @@ public class NettyPluginServerHandler extends SimpleChannelInboundHandler<Plugin
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception { public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
if (evt instanceof IdleStateEvent){ if (evt instanceof IdleStateEvent){
ctx.channel().close(); ctx.channel().close();
System.out.println("-------心跳超时,关闭链接-------"); System.err.println("-------心跳超时,关闭链接-------");
} else { } else {
super.userEventTriggered(ctx, evt); super.userEventTriggered(ctx, evt);
} }
......
package com.byit.controller; package com.byit.controller;
import com.alibaba.fastjson.JSON;
import com.byit.packet.request.PluginRpcRequestPacket;
import com.byit.packet.response.PluginRpcResponsePacket;
import com.byit.param.defaultparam.DefaultResultCallback;
import com.byit.service.TestService; import com.byit.service.TestService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
@RestController @RestController
......
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