Commit 7df52bfa by huangfusuper

【优化Netty服务】修改调度Netty服务器时的回复对象

parent 1dcf47e2
......@@ -3,6 +3,7 @@ package com.byit.task;
import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSON;
import com.byit.job.dto.AdminSenPluginDto;
import com.byit.job.dto.DispatchResponseDto;
import com.byit.job.exceptions.plugin.PluginException;
import com.byit.job.utils.IpUtil;
import com.byit.model.MythJobTaskRunLog;
......@@ -47,31 +48,34 @@ public class JavaBeanJobTask implements TimerTask {
adminSenPluginDto.setLogId(mythJobTaskSchedule.getLogId());
//这里获取的是调度结果
String result = HttpUtil.post(url, JSON.toJSONString(adminSenPluginDto),10*1000);
DispatchResponseDto dispatchResponseDto = JSON.parseObject(result, DispatchResponseDto.class);
//修改调度结果
saveLog(mythJobTaskSchedule, url, result);
log.debug("---------------{}------------",result);
}catch (PluginException ignored){
saveLog(mythJobTaskSchedule, "", ignored.getMessage());
log.error("-------------通讯异常:{},{}",ignored.getIEnum().getCode(),ignored.getIEnum().getMsg());
}catch (Exception e){
saveLog(mythJobTaskSchedule, "", "未知错误!!");
e.printStackTrace();
}
}
private Integer saveLog(MythJobTaskSchedule mythJobTaskSchedule,String url,String result){
MythJobTaskRunLog mythJobTaskRunLog = new MythJobTaskRunLog();
private void saveLog(MythJobTaskSchedule mythJobTaskSchedule, String url, String result){
DispatchResponseDto dispatchResponseDto = JSON.parseObject(result, DispatchResponseDto.class);
MythJobTaskRunLogServiceImpl mythJobTaskRunLogService = SpringUtil.getBean(MythJobTaskRunLogServiceImpl.class);
MythJobTaskRunLog mythJobTaskRunLog = mythJobTaskRunLogService.findMythJobTaskRunLogById(mythJobTaskSchedule.getLogId());
//版本id需要查验
//还需要携带版本的名字
mythJobTaskRunLog.setLogId(mythJobTaskSchedule.getLogId());
mythJobTaskRunLog.setRunType("2");
mythJobTaskRunLog.setLocalNodeHandlerName(mythJobTaskSchedule.getLocalNodeHandlerName());
mythJobTaskRunLog.setTriggerTime(new Date());
mythJobTaskRunLog.setTriggerCode(result);
mythJobTaskRunLog.setTriggerMsg("SUCCESS");
MythJobTaskRunLogServiceImpl mythJobTaskRunLogService = SpringUtil.getBean(MythJobTaskRunLogServiceImpl.class);
MythJobTaskRunLog mythJobTaskRunLogSave = mythJobTaskRunLogService.save(mythJobTaskRunLog);
return mythJobTaskRunLogSave.getLogId();
mythJobTaskRunLog.setTriggerCode(dispatchResponseDto.getCode());
mythJobTaskRunLog.setTriggerMsg(dispatchResponseDto.getMsg());
mythJobTaskRunLogService.save(mythJobTaskRunLog);
}
}
......@@ -25,8 +25,7 @@ public class LogCallbackThread implements Runnable {
public void run() {
log.debug("--------------------任务执行完成---------------------");
MythJobTaskRunLogServiceImpl mythJobTaskRunLogService = SpringUtil.getBean(MythJobTaskRunLogServiceImpl.class);
MythJobTaskRunLog mythJobTaskRunLog = new MythJobTaskRunLog( );
mythJobTaskRunLog.setLogId(jobRunResultDto.getLogId());
MythJobTaskRunLog mythJobTaskRunLog = mythJobTaskRunLogService.findMythJobTaskRunLogById(jobRunResultDto.getLogId( ));
mythJobTaskRunLog.setRunTime(jobRunResultDto.getEndTime());
mythJobTaskRunLog.setRunCode(jobRunResultDto.getReturnResult().getCode());
mythJobTaskRunLog.setRunMsg(jobRunResultDto.getReturnResult().getMsg());
......
package com.byit.job.dto;
import lombok.Data;
/**
* @program: byit-myth-job->DispatchResponseDto
* @description: TODO
* @author: huangfu
* @date: 2019/12/23 11:12
**/
@Data
public class DispatchResponseDto {
private String code;
private String msg;
private String content;
}
......@@ -5,6 +5,7 @@ import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.byit.job.dto.AdminSenPluginDto;
import com.byit.job.dto.DispatchResponseDto;
import com.byit.job.enums.plugin.PluginEnum;
import com.byit.job.exceptions.plugin.PluginException;
import com.byit.rpc.remoting.invoker.route.RpcLoadBalance;
......@@ -32,8 +33,9 @@ public class IpUtil {
AdminSenPluginDto adminSenPluginDto = new AdminSenPluginDto( );
adminSenPluginDto.setHeartbeat("PENG");
String heartbeatRes = HttpUtil.post(url, JSON.toJSONString(adminSenPluginDto), 2 * 1000);
DispatchResponseDto dispatchResponseDto = JSON.parseObject(heartbeatRes, DispatchResponseDto.class);
log.debug("------------------接收心跳包--------------------");
return "PONG".equals(heartbeatRes);
return "PONG".equals((dispatchResponseDto!=null?dispatchResponseDto.getContent():""));
}catch (Exception e){
log.error("--------------------{},服务不可用------------------",url);
return false;
......
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