增加服务端向客户端下发-文件下载
增加服务端向客户端下发-执行命令
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package com.tongran.agenttcp.server.enpoint;
|
||||
|
||||
import com.alibaba.fastjson2.JSONException;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.tongran.agenttcp.rocketmq.AgentProducer;
|
||||
import com.tongran.agenttcp.rocketmq.config.AgentMqConfig;
|
||||
@@ -29,9 +30,7 @@ public class AgentEndpoint {
|
||||
jsonObject.put("dataType",MsgEnum.登录认证.getValue());
|
||||
MqMsg mqMsg = MqMsg.builder().topic(agentMqConfig.getAgentTopic()).content(jsonObject.toString()).build();
|
||||
agentProducer.asyncSend(mqMsg);
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("resCode",1);
|
||||
return UpMsgResponse.builder().clientId(clientId).content(json.toString()).build();
|
||||
return UpMsgResponse.builder().clientId(clientId).build();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -64,24 +63,7 @@ public class AgentEndpoint {
|
||||
jsonObject.put("dataType",MsgEnum.心跳包.getValue());
|
||||
MqMsg mqMsg = MqMsg.builder().topic(agentMqConfig.getAgentTopic()).content(jsonObject.toString()).build();
|
||||
agentProducer.asyncSend(mqMsg);
|
||||
|
||||
// T0x04 obj = new T0x04();
|
||||
// StringBuilder res = new StringBuilder();
|
||||
// StringBuilder signData = new StringBuilder();
|
||||
// res.append("68");// 起始字符
|
||||
// res.append(obj.getLen());
|
||||
// signData.append(data.getSerialNumber());
|
||||
// signData.append("00");
|
||||
// signData.append(YkcUtil.coveringStr(Integer.toHexString(CmdEnum.心跳包应答.getValue())));
|
||||
// signData.append(data.getPileNumber());
|
||||
// signData.append(YkcUtil.coveringStr(Integer.toHexString(data.getGunNo())));
|
||||
// signData.append(YkcUtil.coveringStr(Integer.toHexString(0)));
|
||||
// res.append(signData);
|
||||
// String crc = EscapeUtil.fill(Integer.toHexString(CrcUtil.calcCrc16(signData.toString())), 4);
|
||||
// res.append(crc);
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("resCode",1);
|
||||
return UpMsgResponse.builder().clientId(clientId).content(json.toString()).build();
|
||||
return UpMsgResponse.builder().clientId(clientId).build();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -116,9 +98,7 @@ public class AgentEndpoint {
|
||||
jsonObject.put("dataType",MsgEnum.CPU包.getValue());
|
||||
MqMsg mqMsg = MqMsg.builder().topic(agentMqConfig.getAgentTopic()).content(jsonObject.toString()).build();
|
||||
agentProducer.asyncSend(mqMsg);
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("resCode",1);
|
||||
return UpMsgResponse.builder().clientId(clientId).content(json.toString()).build();
|
||||
return UpMsgResponse.builder().clientId(clientId).build();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -140,9 +120,7 @@ public class AgentEndpoint {
|
||||
jsonObject.put("dataType",MsgEnum.磁盘包.getValue());
|
||||
MqMsg mqMsg = MqMsg.builder().topic(agentMqConfig.getAgentTopic()).content(jsonObject.toString()).build();
|
||||
agentProducer.asyncSend(mqMsg);
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("resCode",1);
|
||||
return UpMsgResponse.builder().clientId(clientId).content(json.toString()).build();
|
||||
return UpMsgResponse.builder().clientId(clientId).build();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -164,9 +142,7 @@ public class AgentEndpoint {
|
||||
jsonObject.put("dataType",MsgEnum.内存包.getValue());
|
||||
MqMsg mqMsg = MqMsg.builder().topic(agentMqConfig.getAgentTopic()).content(jsonObject.toString()).build();
|
||||
agentProducer.asyncSend(mqMsg);
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("resCode",1);
|
||||
return UpMsgResponse.builder().clientId(clientId).content(json.toString()).build();
|
||||
return UpMsgResponse.builder().clientId(clientId).build();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -188,9 +164,7 @@ public class AgentEndpoint {
|
||||
jsonObject.put("dataType",MsgEnum.网卡包.getValue());
|
||||
MqMsg mqMsg = MqMsg.builder().topic(agentMqConfig.getAgentTopic()).content(jsonObject.toString()).build();
|
||||
agentProducer.asyncSend(mqMsg);
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("resCode",1);
|
||||
return UpMsgResponse.builder().clientId(clientId).content(json.toString()).build();
|
||||
return UpMsgResponse.builder().clientId(clientId).build();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -212,9 +186,7 @@ public class AgentEndpoint {
|
||||
jsonObject.put("dataType",MsgEnum.挂载点包.getValue());
|
||||
MqMsg mqMsg = MqMsg.builder().topic(agentMqConfig.getAgentTopic()).content(jsonObject.toString()).build();
|
||||
agentProducer.asyncSend(mqMsg);
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("resCode",1);
|
||||
return UpMsgResponse.builder().clientId(clientId).content(json.toString()).build();
|
||||
return UpMsgResponse.builder().clientId(clientId).build();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -236,9 +208,7 @@ public class AgentEndpoint {
|
||||
jsonObject.put("dataType",MsgEnum.系统包.getValue());
|
||||
MqMsg mqMsg = MqMsg.builder().topic(agentMqConfig.getAgentTopic()).content(jsonObject.toString()).build();
|
||||
agentProducer.asyncSend(mqMsg);
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("resCode",1);
|
||||
return UpMsgResponse.builder().clientId(clientId).content(json.toString()).build();
|
||||
return UpMsgResponse.builder().clientId(clientId).build();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -260,9 +230,7 @@ public class AgentEndpoint {
|
||||
jsonObject.put("dataType",MsgEnum.容器包.getValue());
|
||||
MqMsg mqMsg = MqMsg.builder().topic(agentMqConfig.getAgentTopic()).content(jsonObject.toString()).build();
|
||||
agentProducer.asyncSend(mqMsg);
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("resCode",1);
|
||||
return UpMsgResponse.builder().clientId(clientId).content(json.toString()).build();
|
||||
return UpMsgResponse.builder().clientId(clientId).build();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -284,9 +252,7 @@ public class AgentEndpoint {
|
||||
jsonObject.put("dataType",MsgEnum.交换机包.getValue());
|
||||
MqMsg mqMsg = MqMsg.builder().topic(agentMqConfig.getAgentTopic()).content(jsonObject.toString()).build();
|
||||
agentProducer.asyncSend(mqMsg);
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("resCode",1);
|
||||
return UpMsgResponse.builder().clientId(clientId).content(json.toString()).build();
|
||||
return UpMsgResponse.builder().clientId(clientId).build();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -320,7 +286,7 @@ public class AgentEndpoint {
|
||||
jsonObject.put("dataType",MsgEnum.更新CPU采集间隔应答.getValue());
|
||||
MqMsg mqMsg = MqMsg.builder().topic(agentMqConfig.getAgentTopic()).content(jsonObject.toString()).build();
|
||||
agentProducer.asyncSend(mqMsg);
|
||||
return null;
|
||||
return UpMsgResponse.builder().clientId(clientId).build();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -344,7 +310,7 @@ public class AgentEndpoint {
|
||||
jsonObject.put("dataType",MsgEnum.更新容器采集间隔应答.getValue());
|
||||
MqMsg mqMsg = MqMsg.builder().topic(agentMqConfig.getAgentTopic()).content(jsonObject.toString()).build();
|
||||
agentProducer.asyncSend(mqMsg);
|
||||
return null;
|
||||
return UpMsgResponse.builder().clientId(clientId).build();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -368,7 +334,7 @@ public class AgentEndpoint {
|
||||
jsonObject.put("dataType",MsgEnum.更新网卡采集间隔应答.getValue());
|
||||
MqMsg mqMsg = MqMsg.builder().topic(agentMqConfig.getAgentTopic()).content(jsonObject.toString()).build();
|
||||
agentProducer.asyncSend(mqMsg);
|
||||
return null;
|
||||
return UpMsgResponse.builder().clientId(clientId).build();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -392,7 +358,7 @@ public class AgentEndpoint {
|
||||
jsonObject.put("dataType",MsgEnum.更新交换机采集间隔应答.getValue());
|
||||
MqMsg mqMsg = MqMsg.builder().topic(agentMqConfig.getAgentTopic()).content(jsonObject.toString()).build();
|
||||
agentProducer.asyncSend(mqMsg);
|
||||
return null;
|
||||
return UpMsgResponse.builder().clientId(clientId).build();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -416,7 +382,7 @@ public class AgentEndpoint {
|
||||
jsonObject.put("dataType",MsgEnum.更新磁盘采集间隔应答.getValue());
|
||||
MqMsg mqMsg = MqMsg.builder().topic(agentMqConfig.getAgentTopic()).content(jsonObject.toString()).build();
|
||||
agentProducer.asyncSend(mqMsg);
|
||||
return null;
|
||||
return UpMsgResponse.builder().clientId(clientId).build();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -440,7 +406,7 @@ public class AgentEndpoint {
|
||||
jsonObject.put("dataType",MsgEnum.更新挂载采集间隔应答.getValue());
|
||||
MqMsg mqMsg = MqMsg.builder().topic(agentMqConfig.getAgentTopic()).content(jsonObject.toString()).build();
|
||||
agentProducer.asyncSend(mqMsg);
|
||||
return null;
|
||||
return UpMsgResponse.builder().clientId(clientId).build();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -464,7 +430,7 @@ public class AgentEndpoint {
|
||||
jsonObject.put("dataType",MsgEnum.更新内存采集间隔应答.getValue());
|
||||
MqMsg mqMsg = MqMsg.builder().topic(agentMqConfig.getAgentTopic()).content(jsonObject.toString()).build();
|
||||
agentProducer.asyncSend(mqMsg);
|
||||
return null;
|
||||
return UpMsgResponse.builder().clientId(clientId).build();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -488,7 +454,68 @@ public class AgentEndpoint {
|
||||
jsonObject.put("dataType",MsgEnum.更新系统采集间隔应答.getValue());
|
||||
MqMsg mqMsg = MqMsg.builder().topic(agentMqConfig.getAgentTopic()).content(jsonObject.toString()).build();
|
||||
agentProducer.asyncSend(mqMsg);
|
||||
return null;
|
||||
return UpMsgResponse.builder().clientId(clientId).build();
|
||||
}
|
||||
}
|
||||
|
||||
@AgentDispatcher(msgId = MsgEnum.文件下载)
|
||||
public class DownFileHandler implements AgentMsgHandler {
|
||||
@Override
|
||||
public String downHandle(String data) {
|
||||
JSONObject jsonObject = JSONObject.parseObject(data);
|
||||
String fileUrl = jsonObject.getString("fileUrl");
|
||||
String saveDir = "";
|
||||
try {
|
||||
saveDir = jsonObject.getString("saveDir");
|
||||
} catch (JSONException e) {
|
||||
saveDir = "";
|
||||
}
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("fileUrl",fileUrl);
|
||||
json.put("saveDir",saveDir);
|
||||
return json.toString();
|
||||
}
|
||||
}
|
||||
|
||||
@AgentDispatcher(msgId = MsgEnum.文件下载应答)
|
||||
public class DownFileRspHandler implements AgentMsgHandler {
|
||||
@Override
|
||||
public UpMsgResponse upHandle(String data, String clientId) {
|
||||
JSONObject jsonObject = JSONObject.parseObject(data);
|
||||
jsonObject.put("dataType",MsgEnum.文件下载应答.getValue());
|
||||
MqMsg mqMsg = MqMsg.builder().topic(agentMqConfig.getAgentTopic()).content(jsonObject.toString()).build();
|
||||
agentProducer.asyncSend(mqMsg);
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("resCode",1);
|
||||
return UpMsgResponse.builder().clientId(clientId).content(json.toString()).build();
|
||||
}
|
||||
}
|
||||
|
||||
@AgentDispatcher(msgId = MsgEnum.执行命令)
|
||||
public class ExecuteCommandHandler implements AgentMsgHandler {
|
||||
@Override
|
||||
public String downHandle(String data) {
|
||||
JSONObject jsonObject = JSONObject.parseObject(data);
|
||||
String scriptPath = jsonObject.getString("scriptPath");
|
||||
String command = jsonObject.getString("command");
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("scriptPath",scriptPath);
|
||||
json.put("command",command);
|
||||
return json.toString();
|
||||
}
|
||||
}
|
||||
|
||||
@AgentDispatcher(msgId = MsgEnum.执行命令应答)
|
||||
public class ExecuteCommandRspHandler implements AgentMsgHandler {
|
||||
@Override
|
||||
public UpMsgResponse upHandle(String data, String clientId) {
|
||||
JSONObject jsonObject = JSONObject.parseObject(data);
|
||||
jsonObject.put("dataType",MsgEnum.执行命令应答.getValue());
|
||||
MqMsg mqMsg = MqMsg.builder().topic(agentMqConfig.getAgentTopic()).content(jsonObject.toString()).build();
|
||||
agentProducer.asyncSend(mqMsg);
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("resCode",1);
|
||||
return UpMsgResponse.builder().clientId(clientId).content(json.toString()).build();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -37,7 +37,8 @@ public class AgentEncoderHandler extends ChannelOutboundHandlerAdapter {
|
||||
return;
|
||||
}
|
||||
AssertLog.info(">>[down]:IP:{},[content]==>{}", sessionManager.client(ctx), entity.getData());
|
||||
String json = JSON.toJSONString(entity);
|
||||
// String json = JSON.toJSONString(entity);
|
||||
String json = "agent-server:"+JSON.toJSONString(entity)+"@tong-ran";
|
||||
byte[] bytes = json.getBytes(StandardCharsets.UTF_8); // 显式指定 UTF-8
|
||||
// byte[] bytes = EscapeUtil.hexStringToByteArray(entity.getContent());
|
||||
ByteBuf buf = Unpooled.wrappedBuffer(bytes);
|
||||
|
||||
@@ -82,7 +82,15 @@ public enum MsgEnum {
|
||||
|
||||
更新系统采集间隔("TIME_SYSTEM"),
|
||||
|
||||
更新系统采集间隔应答("TIME_SYSTEM_RSP");
|
||||
更新系统采集间隔应答("TIME_SYSTEM_RSP"),
|
||||
|
||||
文件下载("DOWN_FILE"),
|
||||
|
||||
文件下载应答("DOWN_FILE_RSP"),
|
||||
|
||||
执行命令("EXECUTE_COMMAND"),
|
||||
|
||||
执行命令应答("EXECUTE_COMMAND_RSP");
|
||||
|
||||
private String value;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user