|
|
|
@ -1,40 +1,50 @@
|
|
|
|
|
package com.docus.server.common.netty.client.handler;
|
|
|
|
|
|
|
|
|
|
import com.docus.core.util.StringUtils;
|
|
|
|
|
import com.docus.core.util.Func;
|
|
|
|
|
import com.docus.core.util.ListUtils;
|
|
|
|
|
import com.docus.core.util.json.JSON;
|
|
|
|
|
import com.docus.server.common.CommMsg;
|
|
|
|
|
import com.docus.server.common.MsgConstants;
|
|
|
|
|
import com.docus.server.common.netty.CommMsg;
|
|
|
|
|
import com.docus.server.common.netty.client.NettyClient;
|
|
|
|
|
import com.docus.server.common.netty.server.CollectorChannelCacheMap;
|
|
|
|
|
import com.docus.server.common.utils.StartUpExeUtils;
|
|
|
|
|
import com.docus.server.dto.scheduling.management.schcollector.task.SchCollectorTaskDTO;
|
|
|
|
|
import io.netty.buffer.ByteBuf;
|
|
|
|
|
import com.docus.server.vo.scheduling.management.schcollector.LoadSchCollectorVO;
|
|
|
|
|
import com.fasterxml.jackson.core.type.TypeReference;
|
|
|
|
|
import io.netty.channel.Channel;
|
|
|
|
|
import io.netty.channel.ChannelHandlerContext;
|
|
|
|
|
import io.netty.channel.SimpleChannelInboundHandler;
|
|
|
|
|
import lombok.AllArgsConstructor;
|
|
|
|
|
import lombok.NoArgsConstructor;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
import java.io.Serializable;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
|
|
@Slf4j
|
|
|
|
|
public class ClientHandler extends SimpleChannelInboundHandler<ByteBuf> {
|
|
|
|
|
@Resource
|
|
|
|
|
private CollectorChannelCacheMap collectorChannelCacheMap;
|
|
|
|
|
@AllArgsConstructor
|
|
|
|
|
@NoArgsConstructor
|
|
|
|
|
public class ClientHandler extends SimpleChannelInboundHandler<CommMsg<Serializable>> {
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
protected void channelRead0(ChannelHandlerContext context, ByteBuf msg) throws Exception {
|
|
|
|
|
ByteBuf buf = (ByteBuf) msg;
|
|
|
|
|
//创建目标大小的数组
|
|
|
|
|
byte[] barray = new byte[buf.readableBytes()];
|
|
|
|
|
//把数据从bytebuf转移到byte[]
|
|
|
|
|
buf.getBytes(0, barray);
|
|
|
|
|
//将byte[]转成字符串用于打印
|
|
|
|
|
String message = new String(barray);
|
|
|
|
|
|
|
|
|
|
//空消息不处理
|
|
|
|
|
if (!StringUtils.hasText(message)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
private NettyClient nettyClient;
|
|
|
|
|
|
|
|
|
|
CommMsg commMsg = JSON.fromJSON(message, CommMsg.class);
|
|
|
|
|
@Override
|
|
|
|
|
protected void channelRead0(ChannelHandlerContext context, CommMsg commMsg) throws Exception {
|
|
|
|
|
// ByteBuf buf = (ByteBuf) msg;
|
|
|
|
|
// //创建目标大小的数组
|
|
|
|
|
// byte[] barray = new byte[buf.readableBytes()];
|
|
|
|
|
// //把数据从bytebuf转移到byte[]
|
|
|
|
|
// buf.getBytes(0, barray);
|
|
|
|
|
// //将byte[]转成字符串用于打印
|
|
|
|
|
// String message = new String(barray);
|
|
|
|
|
//
|
|
|
|
|
// //空消息不处理
|
|
|
|
|
// if (!StringUtils.hasText(message)) {
|
|
|
|
|
// return;
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// CommMsg commMsg = JSON.fromJSON(message, CommMsg.class);
|
|
|
|
|
|
|
|
|
|
String messageType = commMsg.getMessageType();
|
|
|
|
|
String messageTime = commMsg.getMessageTime();
|
|
|
|
@ -43,33 +53,61 @@ public class ClientHandler extends SimpleChannelInboundHandler<ByteBuf> {
|
|
|
|
|
log.info("======== 【终端客户端-收到调度器消息】, 消息时间={}, 消息类型={}, 消息内容={}", messageTime, messageType, messageContent + " ======== ");
|
|
|
|
|
|
|
|
|
|
if (messageType.equals(MsgConstants.TERMINATOR_RESTART)) {
|
|
|
|
|
log.info("【终端客户端-收到调度器下发任务】接受到终端重启命令,内容={}", messageContent);
|
|
|
|
|
log.info("【终端客户端-收到调度器消息】接受到终端重启命令,内容={}", messageContent);
|
|
|
|
|
|
|
|
|
|
} else if (messageType.equals(MsgConstants.COLLECTOR_RESTART)) {
|
|
|
|
|
log.info("【终端客户端-收到调度器下发任务】收到采集器重启命令,内容={}", messageContent);
|
|
|
|
|
log.info("【终端客户端-收到调度器消息】收到采集器重启命令,内容={}", messageContent);
|
|
|
|
|
|
|
|
|
|
} else if (messageType.equals(MsgConstants.VIRTUAL_RESTART)) {
|
|
|
|
|
log.info("【终端客户端-收到调度器下发任务】收到虚拟机重启命令,内容={}", messageContent);
|
|
|
|
|
log.info("【终端客户端-收到调度器消息】收到虚拟机重启命令,内容={}", messageContent);
|
|
|
|
|
|
|
|
|
|
} else if (messageType.equals(MsgConstants.UPDATE_COLLECTOR_FILE)) {
|
|
|
|
|
log.info("【终端客户端-收到调度器下发任务】收到更新采集器文件命令,内容={}", messageContent);
|
|
|
|
|
log.info("【终端客户端-收到调度器消息】收到更新采集器文件命令,内容={}", messageContent);
|
|
|
|
|
|
|
|
|
|
} else if (messageType.equals(MsgConstants.UPDATE_COLLECTOR_CONFIG)) {
|
|
|
|
|
log.info("【终端客户端-收到调度器下发任务】收到更新采集器配置命令,内容={}", messageContent);
|
|
|
|
|
log.info("【终端客户端-收到调度器消息】收到更新采集器配置命令,内容={}", messageContent);
|
|
|
|
|
|
|
|
|
|
} else if (messageType.equals(MsgConstants.SCH_DISTRIBUTE_TASKS)) {
|
|
|
|
|
log.info("【终端客户端-收到调度器下发任务】收到采集调度器下发任务命令,内容={}", messageContent);
|
|
|
|
|
log.info("【终端客户端-收到调度器消息】收到采集调度器下发任务命令,内容={}", messageContent);
|
|
|
|
|
|
|
|
|
|
//下发任务: 判断这个任务采集器类型在指定目录是否存在、
|
|
|
|
|
//如果不存在:下拉该采集器类型最新的版本更新包到指定的部署路径,并且启动该exe采集器,将任务tcp给对应采集器
|
|
|
|
|
//如果存在:
|
|
|
|
|
|
|
|
|
|
SchCollectorTaskDTO schCollectorTaskDTO = JSON.fromJSON(JSON.toJSON(messageContent), SchCollectorTaskDTO.class);
|
|
|
|
|
SchCollectorTaskDTO schCollectorTaskDTO = JSON.fromJSON(messageContent, SchCollectorTaskDTO.class);
|
|
|
|
|
String collectorId = schCollectorTaskDTO.getTaskInfo().getTasks().get(0).getCollectorId();
|
|
|
|
|
collectorChannelCacheMap.writeAndFlush(collectorId, commMsg);
|
|
|
|
|
|
|
|
|
|
Long compareCollectorId = Long.valueOf(collectorId);
|
|
|
|
|
|
|
|
|
|
String packageValue = nettyClient.getRedisMsg();
|
|
|
|
|
CollectorChannelCacheMap collectorChannelCacheMap = nettyClient.getCollectorChannelCacheMap();
|
|
|
|
|
String saveCollectorPackagePath = nettyClient.getSaveCollectorPackagePath();
|
|
|
|
|
|
|
|
|
|
List<LoadSchCollectorVO> redisLoadSchCollectors = JSON.fromJSONWithGeneric(packageValue, new TypeReference<List<LoadSchCollectorVO>>() {
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
Map<Long, LoadSchCollectorVO> collectorVoMap = ListUtils.toMap(redisLoadSchCollectors, LoadSchCollectorVO::getCollectorId);
|
|
|
|
|
|
|
|
|
|
if (collectorVoMap.containsKey(compareCollectorId)) {
|
|
|
|
|
LoadSchCollectorVO loadSchCollectorVO = collectorVoMap.get(compareCollectorId);
|
|
|
|
|
String processName = loadSchCollectorVO.getProcessName();
|
|
|
|
|
|
|
|
|
|
if (Func.isNotBlank(processName)) {
|
|
|
|
|
boolean isExistProcess = StartUpExeUtils.checkProcessOnly(processName);
|
|
|
|
|
//存在指定采集器id进程
|
|
|
|
|
if (isExistProcess) {
|
|
|
|
|
collectorChannelCacheMap.writeAndFlush(collectorId, commMsg);
|
|
|
|
|
} else {
|
|
|
|
|
//不存在进程,则启动指定采集器进程
|
|
|
|
|
StartUpExeUtils.startUpExeOnly(saveCollectorPackagePath + collectorId + "\\collector\\" + processName);
|
|
|
|
|
collectorChannelCacheMap.writeAndFlush(collectorId, commMsg);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} else if (messageType.equals(MsgConstants.HAS_VALID_COLLECTOR)) {
|
|
|
|
|
log.info("【终端客户端-收到调度器下发任务】是否有可用类型的采集器命令,内容={}", messageContent);
|
|
|
|
|
log.info("【终端客户端-收到调度器消息】是否有可用类型的采集器命令,内容={}", messageContent);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//下发任务: 判断这个任务采集器类型在指定目录是否存在、
|
|
|
|
|