Commit 1cb7eeb1 by huangfusuper

test环境修改 调度代码打磨

parent a16f9910
......@@ -13,6 +13,6 @@ public class TestServiceImpl {
public DispatchResponseDto test(){
return scriptExecutorService.runPythonScript(null);
return scriptExecutorService.runScript(null);
}
}
spring:
datasource:
driver-class-name: com.mysql.jdbc.Driver
url: jdbc:mysql://${CM_IP}/myth-job?Unicode=true&characterEncoding=UTF-8&useSSL=true
username: ${CM_USER}
password: ${CM_PWD}
url: jdbc:mysql://10.0.120.30:3307/myth-job?Unicode=true&characterEncoding=UTF-8&useSSL=true
username: root
password: root
redis:
database: 0
host: ${Redis_IP}
port: ${Redis_port}
host: 10.0.120.208
port: 6379
password:
timeout: 3000
pool:
......@@ -31,7 +31,7 @@ mybatis:
myth-rpc:
registry:
address: http://${Eureka_IP}/myth-register
address: http://10.0.120.208:8080/myth-register
env: pro
biz: byit-myth-job
logging:
......
spring:
datasource:
driver-class-name: com.mysql.jdbc.Driver
url: jdbc:mysql://${CM_IP}/myth-job?Unicode=true&characterEncoding=UTF-8&useSSL=true
username: ${CM_USER}
password: ${CM_PWD}
url: jdbc:mysql://10.0.120.30:3307/myth-job?Unicode=true&characterEncoding=UTF-8&useSSL=true
username: root
password: root
redis:
database: 0
host: ${Redis_IP}
port: ${Redis_port}
host: 10.0.120.208
port: 6379
password:
timeout: 3000
pool:
......@@ -32,7 +32,7 @@ mybatis:
myth-rpc:
registry:
address: http://${Eureka_IP}/myth-register
address: http://10.0.120.208:8080/myth-register
env: test
biz: byit-myth-job
logging:
......@@ -62,4 +62,10 @@ fdfs:
tracker-list:
- 10.0.120.216:22122
- 10.0.120.217:22122
- 10.0.120.218:22122
\ No newline at end of file
- 10.0.120.218:22122
myth:
plugin:
env: ${myth-rpc.registry.env}
biz: ${myth-rpc.registry.biz}
register:
url: ${myth-rpc.registry.address}
\ No newline at end of file
......@@ -5,8 +5,8 @@ package com.byit.enums;
*/
public enum EmailEnum {
IS_ALARM_YES("0","已经告警"),
IS_ALARM_NO("1","没有告警")
IS_ALARM_YES("1","已经告警"),
IS_ALARM_NO("0","没有告警")
;
private String code;
private String msg;
......
......@@ -16,6 +16,6 @@ public class RunScriptServiceImpl implements RunScriptService {
private ScriptExecutorService scriptExecutorService;
@Override
public DispatchResponseDto runScript(ScriptDto scriptDto) {
return scriptExecutorService.runPythonScript(scriptDto);
return scriptExecutorService.runScript(scriptDto);
}
}
......@@ -4,6 +4,7 @@ import com.byit.conf.MythJobAutoConfigure;
import com.byit.dto.plugin.JavaTask;
import com.byit.enums.NodeRunStatusPropertyEnum;
import com.byit.enums.ScheduleTypeEnum;
import com.byit.enums.task.RunResultEnum;
import com.byit.model.JobTaskRunLogWithBLOBs;
import com.byit.packet.request.PluginRpcRequestPacket;
import com.byit.packet.response.PluginRpcResponsePacket;
......@@ -22,6 +23,7 @@ import java.util.Date;
* @author huangfu
*/
public class JavaTaskJobTask implements TimerTask {
public static final String JAVA_SYNC = "JAVA_SYNC";
private final JavaTask javaTask;
public JavaTaskJobTask(JavaTask javaTask) {
......@@ -29,7 +31,7 @@ public class JavaTaskJobTask implements TimerTask {
}
@Override
public void run(Timeout timeout) throws Exception {
public void run(Timeout timeout) {
MythJobAutoConfigure.LOW_LEVEL_JOB_THREAD_POOL.execute(this::runJob);
}
......@@ -55,14 +57,13 @@ public class JavaTaskJobTask implements TimerTask {
try {
PluginRpcResponsePacket pluginRpcResponsePacket = service.runJava(request);
if(pluginRpcResponsePacket.isStatus()){
log.setTriggerCode(NodeRunStatusPropertyEnum.RUN_SUCCESS.getCode());
log.setTriggerCode(RunResultEnum.TRIGGER_SUCCESS.getCode());
}else{
log.setTriggerCode(NodeRunStatusPropertyEnum.RUN_FAILURE.getCode());
log.setTriggerCode(RunResultEnum.TRIGGER_ERROR.getCode());
}
log.setTriggerMsg(pluginRpcResponsePacket.getMsg());
}catch (Exception e){
log.setTriggerCode("2");
log.setTriggerCode(RunResultEnum.TRIGGER_ERROR.getCode());
log.setRunCode(NodeRunStatusPropertyEnum.RUN_FAILURE.getCode());
log.setRunMsg(javaTask.getTaskName()+":"+e.getMessage());
log.setTriggerMsg(javaTask.getTaskName()+":"+e.getMessage());
......@@ -81,14 +82,9 @@ public class JavaTaskJobTask implements TimerTask {
log.setHandlerName(javaTask.getTaskName());
log.setRunParams(javaTask.getParam());
log.setTriggerTime(new Date());
log.setJobType("JAVA_SYNC");
log.setJobType(JAVA_SYNC);
JobTaskRunLogServiceImpl jobTaskRunLogService = SpringUtil.getBean(JobTaskRunLogServiceImpl.class);
int i = jobTaskRunLogService.saveJobTaskRunLog(log);
return log.getLogId();
}
public JavaTask getJavaTask() {
return javaTask;
}
}
package com.byit.thread;
import com.byit.dto.executor.JobRunResultDto;
import com.byit.dto.web.ReturnResult;
import com.byit.enums.RunRecordingEnum;
import com.byit.model.JobTaskRunLogWithBLOBs;
import com.byit.packet.response.PluginRpcResponsePacket;
import com.byit.service.impl.JobTaskRunLogServiceImpl;
......
package com.byit.thread;
import com.byit.dto.executor.JobRunResultDto;
import com.byit.enums.EmailEnum;
import com.byit.model.JobTaskRunLogWithBLOBs;
import com.byit.service.impl.JobTaskRunLogServiceImpl;
import com.byit.util.SpringUtil;
......@@ -32,9 +33,6 @@ public class LogCallbackThread implements Runnable {
if (jobTaskRunLogById.getRunCount()>1) {
String runMsg = jobTaskRunLogById.getRunMsg()+"|"+jobRunResultDto.getReturnResult().getMsg();
//这里需要追加文件 TODO
//这里需要追加文件 TODO
jobTaskRunLog.setRunMsg(runMsg);
}else{
jobTaskRunLog.setRunMsg(jobRunResultDto.getReturnResult().getMsg());
......@@ -45,7 +43,7 @@ public class LogCallbackThread implements Runnable {
jobTaskRunLog.setEndTime(jobRunResultDto.getEndTime());
jobTaskRunLog.setRunCode(jobRunResultDto.getReturnResult().getCode());
jobTaskRunLog.setAlertEnd("0");
jobTaskRunLog.setAlertEnd(EmailEnum.IS_ALARM_NO.getCode());
mythJobTaskRunLogService.updateJobTaskRunLogWithBLOBs(jobTaskRunLog);
}
......
......@@ -18,17 +18,16 @@ import java.io.Serializable;
@NoArgsConstructor
public class ReturnResult<T> implements Serializable {
public static final long serialVersionUID = 1573630876693L;
public static final ReturnResult<String> SUCCESS = new ReturnResult<String>(null);
public static final ReturnResult FAIL = new ReturnResult(JobResultEnum.FAIL.getRes(), JobResultEnum.FAIL.getMsg());
public static final ReturnResult FAIL_TIMEOUT = new ReturnResult(JobResultEnum.FAIL_TIMEOUT.getRes(),JobResultEnum.FAIL_TIMEOUT.getMsg());
public static final ReturnResult<String> SUCCESS = new ReturnResult<>(null);
public static final ReturnResult<String> FAIL = new ReturnResult<>(JobResultEnum.FAIL.getCode(), JobResultEnum.FAIL.getMsg());
private String code;
private String msg;
private T content;
/**
* 默认就是错误
* @param code
* @param msg
* @param code 错误码
* @param msg 执行信息
*/
public ReturnResult(String code, String msg) {
this.code = code;
......@@ -37,10 +36,10 @@ public class ReturnResult<T> implements Serializable {
/**
* 默认就是成功
* @param content
* @param content 结果集
*/
private ReturnResult(T content) {
this.code = JobResultEnum.SUCCESS.getRes();
this.code = JobResultEnum.SUCCESS.getCode();
this.msg = JobResultEnum.SUCCESS.getMsg();
this.content = content;
}
......
......@@ -5,24 +5,23 @@ package com.byit.enums;
* @author huangfu
*/
public enum JobResultEnum implements IEnum {
SUCCESS("100200","任务执行成功","1"),
FAIL("100500","任务执行失败","2"),
FAIL_TIMEOUT("100502","超时错误","2"),
DISPATCH_SUCCESS("200200","调度成功","1"),
DISPATCH_FAIL("200500","调度失败","2"),
SUCCESS("100200","任务执行成功"),
FAIL("100500","任务执行失败"),
FAIL_TIMEOUT("100502","超时错误"),
DISPATCH_SUCCESS("200200","调度成功"),
DISPATCH_FAIL("200500","调度失败"),
KILL_SUCCESS("400000","执行数据被kill"),
RUN_MSG_FAIL("300000","执行结果异常","2");
RUN_MSG_FAIL("300000","执行结果异常");
private String code;
private String msg;
private String res;
JobResultEnum() {
}
JobResultEnum(String code, String msg,String res) {
JobResultEnum(String code, String msg) {
this.code = code;
this.msg = msg;
this.res = res;
}
......@@ -35,7 +34,4 @@ public enum JobResultEnum implements IEnum {
public String getMsg() {
return this.msg;
}
public String getRes() {
return this.res;
}
}
\ No newline at end of file
package com.byit.enums.task;
/**
* @author huangfu
*/
public enum RunResultEnum {
TRIGGER_SUCCESS("1","调度成功"),
TRIGGER_ERROR("2","调度失败"),
RUN_SUCCESS("1","执行成功"),
RUN_ERROR("2","执行失败"),
KILL_SUCCESS("5","节点被kill")
;
private String code;
private String msg;
RunResultEnum(String code, String msg) {
this.code = code;
this.msg = msg;
}
public String getCode() {
return code;
}
public String getMsg() {
return msg;
}
}
package com.byit.enums.task;
/**
* 运行类型枚举
* @author huangfu
*/
public enum RunTypeEnum {
PLUGIN_RUN("2","插件执行!"),
EXECUTIVE_MACHINE_RUN("1","执行机执行!")
;
private String code;
private String msg;
RunTypeEnum(String code, String msg) {
this.code = code;
this.msg = msg;
}
public String getCode() {
return code;
}
public String getMsg() {
return msg;
}
}
......@@ -14,5 +14,5 @@ public interface ScriptExecutorService {
* @param scriptDto 参数
* @return 调用结果
*/
DispatchResponseDto runPythonScript(ScriptDto scriptDto);
DispatchResponseDto runScript(ScriptDto scriptDto);
}
......@@ -33,7 +33,7 @@ public class RunJobServerHandler extends SimpleChannelInboundHandler<FullHttpReq
200,
60L,
TimeUnit.SECONDS,
new LinkedBlockingQueue<Runnable>(1000),
new LinkedBlockingQueue<>(1000),
r ->new Thread(r, "Netty RunJobServerHandler serverThread-" + r.hashCode()));
private static final String PENG = "PENG";
......@@ -42,23 +42,23 @@ public class RunJobServerHandler extends SimpleChannelInboundHandler<FullHttpReq
protected void channelRead0(ChannelHandlerContext ctx, FullHttpRequest req) throws Exception {
log.debug("----------------------有请求过来了------------------------");
DispatchResponseDto dispatchResponseDto = new DispatchResponseDto();
dispatchResponseDto.setCode(JobResultEnum.DISPATCH_FAIL.getRes());
dispatchResponseDto.setCode(JobResultEnum.DISPATCH_FAIL.getCode());
dispatchResponseDto.setMsg(JobResultEnum.DISPATCH_FAIL.getMsg());
if(req != null){
//解析 调度中心 的数据对象
AdminSenPluginDto adminSenPluginDto = analysisParam(req.content( ));
if(null == adminSenPluginDto){
throw new Exception("核心参数 为 null");
throw new Exception("核心参数为空!");
}
//检测是否有心跳参数,有心跳参数则为测试参数,且为PENG的话,服务端回复 PONG
String heartbeat = adminSenPluginDto.getHeartbeat();
if(null == heartbeat){
JOB_TRIGGER_POOL.execute(new RunJobThread(adminSenPluginDto));
dispatchResponseDto.setCode(JobResultEnum.DISPATCH_SUCCESS.getRes());
dispatchResponseDto.setCode(JobResultEnum.DISPATCH_SUCCESS.getCode());
dispatchResponseDto.setMsg(JobResultEnum.DISPATCH_SUCCESS.getMsg());
}else if(PENG.equals(heartbeat)){
log.debug("----------调度平台心跳检测-------------");
dispatchResponseDto.setCode(JobResultEnum.DISPATCH_SUCCESS.getRes());
dispatchResponseDto.setCode(JobResultEnum.DISPATCH_SUCCESS.getCode());
dispatchResponseDto.setMsg(JobResultEnum.DISPATCH_SUCCESS.getMsg());
dispatchResponseDto.setContent(PONG);
}
......@@ -78,8 +78,8 @@ public class RunJobServerHandler extends SimpleChannelInboundHandler<FullHttpReq
/**
* 格式化参数
* @param byteBuf
* @return
* @param byteBuf 将缓冲流更改为字符串
* @return 调用的必要信息承载类
*/
private AdminSenPluginDto analysisParam(ByteBuf byteBuf){
return JSON.parseObject(byteBuf.toString(CharsetUtil.UTF_8),AdminSenPluginDto.class);
......@@ -87,12 +87,11 @@ public class RunJobServerHandler extends SimpleChannelInboundHandler<FullHttpReq
/**
* 异常捕获
* @param ctx
* @param cause
* @throws Exception
* @param ctx 上线文对象
* @param cause 异常信息
*/
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
cause.printStackTrace();
ctx.close();
}
......
......@@ -45,16 +45,16 @@ public class RunJobThread implements Runnable {
log.info("---------服务器端:{},花费时间:{}-------------", jobRunResultDto,jobRunResultDto.getStartTime().getTime()-jobRunResultDto.getEndTime().getTime());
}
private ReturnResult runJob(String jobHandlerName, String param){
private ReturnResult<String> runJob(String jobHandlerName, String param){
Class<? extends IJobHandler> jobClass = JobUtils.jobCache.get(jobHandlerName);
try {
IJobHandler iJobHandler = jobClass.newInstance();
return iJobHandler.execute(param);
} catch (Exception e) {
e.printStackTrace( );
ReturnResult returnResult = new ReturnResult();
ReturnResult<String> returnResult = new ReturnResult<>();
returnResult.setMsg(e.getMessage());
returnResult.setCode(JobResultEnum.FAIL.getRes());
returnResult.setCode(JobResultEnum.FAIL.getCode());
return returnResult;
}
......
......@@ -21,8 +21,8 @@ myth-job:
spring:
redis:
database: 0
host: ${Redis_IP}
port: ${Redis_port}
host: 10.0.120.208
port: 6379
password:
timeout: 3000
pool:
......
# myth-rpc
myth-rpc:
registry:
address: http://${Eureka_IP}/myth-register
address: http://10.0.120.208:8080/myth-register
biz: byit-myth-job
env: test
remoting:
port: ${Remote_PORT}
port: 7776
logging:
config: classpath:logback.xml
......@@ -21,8 +21,8 @@ myth-job:
spring:
redis:
database: 0
host: ${Redis_IP}
port: ${Redis_port}
host: 10.0.120.208
port: 6379
password:
timeout: 3000
pool:
......
#路由规则参考byit-myth-rpc中的LoadBalance枚举类中的类型 默认是轮
�ɹ���ο�byit-myth-rpc�е�LoadBalanceö�����е����� Ĭ������ѯ
gateway:
load:
balance: ROUND
......@@ -12,11 +12,11 @@ logging:
springframework: INFO
myth-rpc:
registry:
address: http://${Eureka_IP}/myth-register
address: http://10.0.120.208:8080/myth-register
biz: byit-myth-job
env: test
remoting:
port: ${Remote_PORT}
port: 7776
spring:
datasource:
......@@ -25,9 +25,9 @@ spring:
idle-timeout: 60000
maximum-pool-size: 5
minimum-idle: 1
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
username: ${CM_USER}
password: root
url: jdbc:mysql://10.0.120.30:3307/myth-registry?useUnicode=true&useSSL=true&characterEncoding=utf-8&mysqlEncoding=utf8&zeroDateTimeBehavior=convertToNull&allowMultiQueries=false&autoReconnect=true&failOverReadOnly=false
username: root
zuul:
route:
refreshCron: 0/10 * * * * ?
......
......@@ -15,9 +15,9 @@ spring:
datasource:
driver-class-name: com.mysql.jdbc.Driver
type: org.apache.tomcat.jdbc.pool.DataSource
url: jdbc:mysql://${CM_IP}/myth-registry?Unicode=true&characterEncoding=UTF-8&autoReconnect=true&useSSL=false
username: ${CM_USER}
password: ${CM_PWD}
url: jdbc:mysql://10.0.120.30:3307/myth-registry?Unicode=true&characterEncoding=UTF-8&autoReconnect=true&useSSL=false
username: root
password: root
tomcat:
max-active: 30
max-wait: 10000
......
......@@ -23,6 +23,9 @@ import java.util.concurrent.ThreadPoolExecutor;
*/
public class NettyPluginServerHandler extends SimpleChannelInboundHandler<PluginRpcRequestPacket> {
public static final String TOKEN_NAME = "token";
public static final String HEADER_TOKEN_NAME = TOKEN_NAME;
public static final String HEADER_CONTENT_TYPE = "contentType";
private PluginServerFactory pluginServerFactory;
private ThreadPoolExecutor threadPoolExecutor;
......@@ -32,13 +35,12 @@ public class NettyPluginServerHandler extends SimpleChannelInboundHandler<Plugin
}
/**
* //TODO 这一块有问题 不能返回两次结果 考虑能否加一个结果回调,回调的方式由自己实现
* @param ctx
* @param msg
* @throws Exception
* 接收到消费方的请求 开始处理消费方的请求
* @param ctx 上下文对象
* @param msg 消息对象
*/
@Override
protected void channelRead0(ChannelHandlerContext ctx, PluginRpcRequestPacket msg) throws Exception {
protected void channelRead0(ChannelHandlerContext ctx, PluginRpcRequestPacket msg) {
if(PluginBeat.BEAT_ID.equals(msg.getRequestId())){
System.out.println("------接收到客户端的心跳连接-------"+ctx.channel().id().asShortText());
return;
......@@ -55,20 +57,20 @@ public class NettyPluginServerHandler extends SimpleChannelInboundHandler<Plugin
ReturnResult<String> execute = iJobHandler.execute(msg.getParam());
long endTime = System.currentTimeMillis();
rpcResponsePacket.setResult(execute);
rpcResponsePacket.setCode("000000");
rpcResponsePacket.setMsg("SUCCESS");
rpcResponsePacket.setCode(JobResultEnum.SUCCESS.getCode());
rpcResponsePacket.setMsg(JobResultEnum.SUCCESS.getMsg());
rpcResponsePacket.setStatus(true);
rpcResponsePacket.setRunTime(endTime-startTime);
rpcResponsePacket.setExtension(msg.getExtension());
sendMsg(rpcResponsePacket,msg);
}catch (Throwable e){
rpcResponsePacket.setCode("500000");
rpcResponsePacket.setCode(JobResultEnum.FAIL.getCode());
rpcResponsePacket.setMsg(e.getMessage());
rpcResponsePacket.setStatus(false);
rpcResponsePacket.setExtension(msg.getExtension());
ReturnResult<String> execute = new ReturnResult<>();
execute.setMsg(e.getMessage());
execute.setCode(JobResultEnum.FAIL.getRes());
execute.setCode(JobResultEnum.FAIL.getCode());
rpcResponsePacket.setResult(execute);
sendMsg(rpcResponsePacket,msg);
throw new RuntimeException(e);
......@@ -91,8 +93,8 @@ public class NettyPluginServerHandler extends SimpleChannelInboundHandler<Plugin
String responseStr = JSON.toJSONString(rpcResponsePacket);
HttpRequest post = HttpRequest.post(msg.getCallbackUrl());
post.header("token", "Token");
post.header("contentType","application/json");
post.header(HEADER_TOKEN_NAME, "Token");
post.header(HEADER_CONTENT_TYPE,"application/json");
post.body(responseStr).execute();
System.out.println("-------消息回复成功-----------");
}
......@@ -101,10 +103,9 @@ public class NettyPluginServerHandler extends SimpleChannelInboundHandler<Plugin
* 异常处理
* @param ctx 上下文对象
* @param cause 异常对象
* @throws Exception 异常信息
*/
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
cause.printStackTrace();
ctx.close();
}
......
......@@ -34,7 +34,7 @@ public class IndexController {
@ResponseBody
public DispatchResponseDto say1(String name){
DispatchResponseDto dispatchResponseDto = scriptExecutorService.runPythonScript(null);
DispatchResponseDto dispatchResponseDto = scriptExecutorService.runScript(null);
return dispatchResponseDto;
}
}
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