1、mtr探测设备增加并发限制。
2、开发防火墙策略区分ipv4和ipv6。 3、脚本执行策略下发时间优化。
This commit is contained in:
+2
-1
@@ -76,7 +76,8 @@ public class RmMtrPolicyConfigController extends BaseController
|
|||||||
@PostMapping
|
@PostMapping
|
||||||
public AjaxResult add(@RequestBody RmMtrPolicyConfig rmMtrPolicyConfig)
|
public AjaxResult add(@RequestBody RmMtrPolicyConfig rmMtrPolicyConfig)
|
||||||
{
|
{
|
||||||
return toAjax(rmMtrPolicyConfigService.insertRmMtrPolicyConfig(rmMtrPolicyConfig));
|
int rows = rmMtrPolicyConfigService.insertRmMtrPolicyConfig(rmMtrPolicyConfig);
|
||||||
|
return toAjax(rows);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
+2
@@ -33,5 +33,7 @@ public class InitialHeartbeatListen extends BaseEntity
|
|||||||
private String version;
|
private String version;
|
||||||
/** 服务启动时间 */
|
/** 服务启动时间 */
|
||||||
private Long startupTime;
|
private Long startupTime;
|
||||||
|
/** cpu核数 */
|
||||||
|
private Integer cpucores;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+2
@@ -91,4 +91,6 @@ public class RmMtrClientRegistration extends BaseEntity
|
|||||||
private String mtrClientIds;
|
private String mtrClientIds;
|
||||||
/** 多条件 */
|
/** 多条件 */
|
||||||
private String queryName;
|
private String queryName;
|
||||||
|
/** cpu核数 */
|
||||||
|
private Integer cpucores;
|
||||||
}
|
}
|
||||||
|
|||||||
+5
@@ -371,6 +371,11 @@ public class MessageHandler {
|
|||||||
}
|
}
|
||||||
needUpdate = true;
|
needUpdate = true;
|
||||||
}
|
}
|
||||||
|
if(rmMtrClientRegistration.getCpucores() == null ||
|
||||||
|
rmMtrClientRegistration.getCpucores() != heartbeat.getCpucores()){
|
||||||
|
updateData.setCpucores(heartbeat.getCpucores());
|
||||||
|
needUpdate = true;
|
||||||
|
}
|
||||||
if(needUpdate){
|
if(needUpdate){
|
||||||
rmMtrClientRegistrationService.updateRmMtrClientRegistration(updateData);
|
rmMtrClientRegistrationService.updateRmMtrClientRegistration(updateData);
|
||||||
}
|
}
|
||||||
|
|||||||
+2
@@ -65,6 +65,8 @@ public class RmMtrClientRegistrationServiceImpl implements IRmMtrClientRegistrat
|
|||||||
@Override
|
@Override
|
||||||
public List<RmMtrClientRegistration> selectRmMtrClientRegistrationList(RmMtrClientRegistration rmMtrClientRegistration)
|
public List<RmMtrClientRegistration> selectRmMtrClientRegistrationList(RmMtrClientRegistration rmMtrClientRegistration)
|
||||||
{
|
{
|
||||||
|
rmMtrClientRegistration.setOnlineStatus("1");
|
||||||
|
rmMtrClientRegistration.setRegisterStatus("1");
|
||||||
List<RmMtrClientRegistration> list = rmMtrClientRegistrationMapper.selectRmMtrClientRegistrationList(rmMtrClientRegistration);
|
List<RmMtrClientRegistration> list = rmMtrClientRegistrationMapper.selectRmMtrClientRegistrationList(rmMtrClientRegistration);
|
||||||
for (RmMtrClientRegistration mtrClientRegistration : list) {
|
for (RmMtrClientRegistration mtrClientRegistration : list) {
|
||||||
// 处理网卡信息
|
// 处理网卡信息
|
||||||
|
|||||||
+76
@@ -5,7 +5,9 @@ import com.tongran.common.core.domain.R;
|
|||||||
import com.tongran.common.core.utils.DateUtils;
|
import com.tongran.common.core.utils.DateUtils;
|
||||||
import com.tongran.common.core.utils.StringUtils;
|
import com.tongran.common.core.utils.StringUtils;
|
||||||
import com.tongran.common.security.utils.SecurityUtils;
|
import com.tongran.common.security.utils.SecurityUtils;
|
||||||
|
import com.tongran.mtragent.domain.RmMtrClientRegistration;
|
||||||
import com.tongran.mtragent.domain.RmMtrPolicyConfig;
|
import com.tongran.mtragent.domain.RmMtrPolicyConfig;
|
||||||
|
import com.tongran.mtragent.mapper.RmMtrClientRegistrationMapper;
|
||||||
import com.tongran.mtragent.mapper.RmMtrPolicyConfigMapper;
|
import com.tongran.mtragent.mapper.RmMtrPolicyConfigMapper;
|
||||||
import com.tongran.mtragent.service.IRmMtrPolicyConfigService;
|
import com.tongran.mtragent.service.IRmMtrPolicyConfigService;
|
||||||
import com.tongran.system.api.RemoteRocketMqService;
|
import com.tongran.system.api.RemoteRocketMqService;
|
||||||
@@ -28,6 +30,8 @@ public class RmMtrPolicyConfigServiceImpl implements IRmMtrPolicyConfigService
|
|||||||
@Autowired
|
@Autowired
|
||||||
private RmMtrPolicyConfigMapper rmMtrPolicyConfigMapper;
|
private RmMtrPolicyConfigMapper rmMtrPolicyConfigMapper;
|
||||||
@Autowired
|
@Autowired
|
||||||
|
private RmMtrClientRegistrationMapper rmMtrClientRegistrationMapper;
|
||||||
|
@Autowired
|
||||||
private RemoteRocketMqService remoteRocketMqService;
|
private RemoteRocketMqService remoteRocketMqService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -129,6 +133,8 @@ public class RmMtrPolicyConfigServiceImpl implements IRmMtrPolicyConfigService
|
|||||||
@Override
|
@Override
|
||||||
public int insertRmMtrPolicyConfig(RmMtrPolicyConfig rmMtrPolicyConfig)
|
public int insertRmMtrPolicyConfig(RmMtrPolicyConfig rmMtrPolicyConfig)
|
||||||
{
|
{
|
||||||
|
// 检查是否超出限制
|
||||||
|
checkServerNum(rmMtrPolicyConfig);
|
||||||
rmMtrPolicyConfig.setCreateTime(DateUtils.getNowDate());
|
rmMtrPolicyConfig.setCreateTime(DateUtils.getNowDate());
|
||||||
rmMtrPolicyConfig.setUpdateTime(DateUtils.getNowDate());
|
rmMtrPolicyConfig.setUpdateTime(DateUtils.getNowDate());
|
||||||
rmMtrPolicyConfig.setCreateBy(SecurityUtils.getUsername());
|
rmMtrPolicyConfig.setCreateBy(SecurityUtils.getUsername());
|
||||||
@@ -149,12 +155,82 @@ public class RmMtrPolicyConfigServiceImpl implements IRmMtrPolicyConfigService
|
|||||||
@Override
|
@Override
|
||||||
public int updateRmMtrPolicyConfig(RmMtrPolicyConfig rmMtrPolicyConfig)
|
public int updateRmMtrPolicyConfig(RmMtrPolicyConfig rmMtrPolicyConfig)
|
||||||
{
|
{
|
||||||
|
// 检查是否超出限制
|
||||||
|
checkServerNum(rmMtrPolicyConfig);
|
||||||
rmMtrPolicyConfig.setUpdateTime(DateUtils.getNowDate());
|
rmMtrPolicyConfig.setUpdateTime(DateUtils.getNowDate());
|
||||||
// 给ip赋值
|
// 给ip赋值
|
||||||
setServerip(rmMtrPolicyConfig);
|
setServerip(rmMtrPolicyConfig);
|
||||||
return rmMtrPolicyConfigMapper.updateRmMtrPolicyConfig(rmMtrPolicyConfig);
|
return rmMtrPolicyConfigMapper.updateRmMtrPolicyConfig(rmMtrPolicyConfig);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void checkServerNum(RmMtrPolicyConfig rmMtrPolicyConfig){
|
||||||
|
if (rmMtrPolicyConfig.getMtrClientId() == null) {
|
||||||
|
throw new RuntimeException("MTR客户端ID不能为空");
|
||||||
|
}
|
||||||
|
// 获取CPU核心数
|
||||||
|
int cpuCores = getCpuCores(rmMtrPolicyConfig.getMtrClientId());
|
||||||
|
if(cpuCores == 0){
|
||||||
|
// cpu核数未采集
|
||||||
|
throw new RuntimeException("该MTRAgent的cpu核数未上报,请检查详情,待cpu核数上报后重试");
|
||||||
|
}
|
||||||
|
Set<String> serverSet = isPolicyCountExceeded(rmMtrPolicyConfig);
|
||||||
|
if(serverSet == null) {
|
||||||
|
return; // 没有服务器或客户端ID为空,直接返回
|
||||||
|
}
|
||||||
|
if(serverSet.size() > cpuCores){
|
||||||
|
// 设置错误信息,包含已下发的服务器列表
|
||||||
|
String errorMessage = String.format("探测服务器数量超过节点并发数量限制(%d),已开启探测的服务器clientId为: %s",
|
||||||
|
cpuCores, String.join(", ", serverSet));
|
||||||
|
throw new RuntimeException(errorMessage);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 检查策略数量是否超过CPU核心数限制
|
||||||
|
*
|
||||||
|
* @param newPolicy 新增或修改的策略
|
||||||
|
* @return true-超过限制,false-未超过限制
|
||||||
|
*/
|
||||||
|
private Set<String> isPolicyCountExceeded(RmMtrPolicyConfig newPolicy) {
|
||||||
|
|
||||||
|
// 获取当前客户端应该执行的策略列表
|
||||||
|
List<RmMtrPolicyConfig> currentPolicies = getPoliciesForMtrClient(newPolicy.getMtrClientId());
|
||||||
|
|
||||||
|
// 获取新策略中的服务器ID列表(去重)
|
||||||
|
List<String> newServerIds = getServerIdsFromPolicy(newPolicy);
|
||||||
|
if (newServerIds.isEmpty()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取当前已分配的服务器ID列表(去重)
|
||||||
|
Set<String> currentServerIds = new HashSet<>();
|
||||||
|
for (RmMtrPolicyConfig policy : currentPolicies) {
|
||||||
|
// 如果是修改操作,需要排除当前策略本身
|
||||||
|
if (newPolicy.getId() != null &&
|
||||||
|
newPolicy.getId().equals(policy.getId())) {
|
||||||
|
continue; // 跳过当前正在修改的策略
|
||||||
|
}
|
||||||
|
List<String> serverIds = getServerIdsFromPolicy(policy);
|
||||||
|
currentServerIds.addAll(serverIds);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 计算新增的不重复服务器数量
|
||||||
|
Set<String> allServerIds = new HashSet<>(currentServerIds);
|
||||||
|
allServerIds.addAll(newServerIds);
|
||||||
|
return allServerIds;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 获取CPU核心数
|
||||||
|
*/
|
||||||
|
private int getCpuCores(String mtrClientId) {
|
||||||
|
RmMtrClientRegistration query = new RmMtrClientRegistration();
|
||||||
|
query.setMtrClientId(mtrClientId);
|
||||||
|
RmMtrClientRegistration rmMtrRegistMsg = rmMtrClientRegistrationMapper.getMsgByMtrClientId(query);
|
||||||
|
if(rmMtrRegistMsg != null && rmMtrRegistMsg.getCpucores() != null){
|
||||||
|
return rmMtrRegistMsg.getCpucores() * 2;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 批量删除mtr探测策略配置
|
* 批量删除mtr探测策略配置
|
||||||
*
|
*
|
||||||
|
|||||||
+7
-3
@@ -13,6 +13,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||||||
<result property="registerTime" column="register_time" />
|
<result property="registerTime" column="register_time" />
|
||||||
<result property="registerStatus" column="register_status" />
|
<result property="registerStatus" column="register_status" />
|
||||||
<result property="onlineStatus" column="online_status" />
|
<result property="onlineStatus" column="online_status" />
|
||||||
|
<result property="cpucores" column="cpucores" />
|
||||||
<result property="heartbeatInterval" column="heartbeat_interval" />
|
<result property="heartbeatInterval" column="heartbeat_interval" />
|
||||||
<result property="heartbeatCount" column="heartbeat_count" />
|
<result property="heartbeatCount" column="heartbeat_count" />
|
||||||
<result property="method" column="method" />
|
<result property="method" column="method" />
|
||||||
@@ -29,7 +30,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||||||
</resultMap>
|
</resultMap>
|
||||||
|
|
||||||
<sql id="selectRmMtrClientRegistrationVo">
|
<sql id="selectRmMtrClientRegistrationVo">
|
||||||
select id, mtr_client_id, description, version, logical_node, register_time, register_status, online_status, heartbeat_interval, heartbeat_count, method, scheduled_update_time, file_path, file_md5, last_update_result, last_update_time, network_info, create_time, update_time, create_by, update_by from rm_mtr_client_registration
|
select id, mtr_client_id, description, version, logical_node, register_time, register_status, online_status, cpucores, heartbeat_interval, heartbeat_count, method, scheduled_update_time, file_path, file_md5, last_update_result, last_update_time, network_info, create_time, update_time, create_by, update_by from rm_mtr_client_registration
|
||||||
</sql>
|
</sql>
|
||||||
|
|
||||||
<select id="selectRmMtrClientRegistrationList" parameterType="RmMtrClientRegistration" resultMap="RmMtrClientRegistrationResult">
|
<select id="selectRmMtrClientRegistrationList" parameterType="RmMtrClientRegistration" resultMap="RmMtrClientRegistrationResult">
|
||||||
@@ -80,6 +81,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||||||
<if test="registerTime != null">register_time,</if>
|
<if test="registerTime != null">register_time,</if>
|
||||||
<if test="registerStatus != null and registerStatus != ''">register_status,</if>
|
<if test="registerStatus != null and registerStatus != ''">register_status,</if>
|
||||||
<if test="onlineStatus != null and onlineStatus != ''">online_status,</if>
|
<if test="onlineStatus != null and onlineStatus != ''">online_status,</if>
|
||||||
|
<if test="cpucores != null">cpucores,</if>
|
||||||
<if test="heartbeatInterval != null">heartbeat_interval,</if>
|
<if test="heartbeatInterval != null">heartbeat_interval,</if>
|
||||||
<if test="heartbeatCount != null">heartbeat_count,</if>
|
<if test="heartbeatCount != null">heartbeat_count,</if>
|
||||||
<if test="method != null">method,</if>
|
<if test="method != null">method,</if>
|
||||||
@@ -93,7 +95,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||||||
<if test="updateTime != null">update_time,</if>
|
<if test="updateTime != null">update_time,</if>
|
||||||
<if test="createBy != null">create_by,</if>
|
<if test="createBy != null">create_by,</if>
|
||||||
<if test="updateBy != null">update_by,</if>
|
<if test="updateBy != null">update_by,</if>
|
||||||
</trim>
|
</trim>
|
||||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||||
<if test="mtrClientId != null and mtrClientId != ''">#{mtrClientId},</if>
|
<if test="mtrClientId != null and mtrClientId != ''">#{mtrClientId},</if>
|
||||||
<if test="description != null">#{description},</if>
|
<if test="description != null">#{description},</if>
|
||||||
@@ -102,6 +104,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||||||
<if test="registerTime != null">#{registerTime},</if>
|
<if test="registerTime != null">#{registerTime},</if>
|
||||||
<if test="registerStatus != null and registerStatus != ''">#{registerStatus},</if>
|
<if test="registerStatus != null and registerStatus != ''">#{registerStatus},</if>
|
||||||
<if test="onlineStatus != null and onlineStatus != ''">#{onlineStatus},</if>
|
<if test="onlineStatus != null and onlineStatus != ''">#{onlineStatus},</if>
|
||||||
|
<if test="cpucores != null">#{cpucores},</if>
|
||||||
<if test="heartbeatInterval != null">#{heartbeatInterval},</if>
|
<if test="heartbeatInterval != null">#{heartbeatInterval},</if>
|
||||||
<if test="heartbeatCount != null">#{heartbeatCount},</if>
|
<if test="heartbeatCount != null">#{heartbeatCount},</if>
|
||||||
<if test="method != null">#{method},</if>
|
<if test="method != null">#{method},</if>
|
||||||
@@ -115,7 +118,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||||||
<if test="updateTime != null">#{updateTime},</if>
|
<if test="updateTime != null">#{updateTime},</if>
|
||||||
<if test="createBy != null">#{createBy},</if>
|
<if test="createBy != null">#{createBy},</if>
|
||||||
<if test="updateBy != null">#{updateBy},</if>
|
<if test="updateBy != null">#{updateBy},</if>
|
||||||
</trim>
|
</trim>
|
||||||
</insert>
|
</insert>
|
||||||
|
|
||||||
<update id="updateRmMtrClientRegistration" parameterType="RmMtrClientRegistration">
|
<update id="updateRmMtrClientRegistration" parameterType="RmMtrClientRegistration">
|
||||||
@@ -128,6 +131,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||||||
<if test="registerTime != null">register_time = #{registerTime},</if>
|
<if test="registerTime != null">register_time = #{registerTime},</if>
|
||||||
<if test="registerStatus != null and registerStatus != ''">register_status = #{registerStatus},</if>
|
<if test="registerStatus != null and registerStatus != ''">register_status = #{registerStatus},</if>
|
||||||
<if test="onlineStatus != null and onlineStatus != ''">online_status = #{onlineStatus},</if>
|
<if test="onlineStatus != null and onlineStatus != ''">online_status = #{onlineStatus},</if>
|
||||||
|
<if test="cpucores != null">cpucores = #{cpucores},</if>
|
||||||
<if test="heartbeatInterval != null">heartbeat_interval = #{heartbeatInterval},</if>
|
<if test="heartbeatInterval != null">heartbeat_interval = #{heartbeatInterval},</if>
|
||||||
<if test="heartbeatCount != null">heartbeat_count = #{heartbeatCount},</if>
|
<if test="heartbeatCount != null">heartbeat_count = #{heartbeatCount},</if>
|
||||||
<if test="method != null">method = #{method},</if>
|
<if test="method != null">method = #{method},</if>
|
||||||
|
|||||||
@@ -12,6 +12,8 @@ public class RspVo {
|
|||||||
private String resMag;
|
private String resMag;
|
||||||
/** 路由 */
|
/** 路由 */
|
||||||
private String addRoute;
|
private String addRoute;
|
||||||
|
/** 业务网卡名称 */
|
||||||
|
private String netName;
|
||||||
/** 时间戳 */
|
/** 时间戳 */
|
||||||
private long timestamp = Instant.now().getEpochSecond();
|
private long timestamp = Instant.now().getEpochSecond();
|
||||||
}
|
}
|
||||||
|
|||||||
+42
-23
@@ -628,6 +628,7 @@ public class RmResourceRegistrationServiceImpl implements IRmResourceRegistratio
|
|||||||
rspVo.setResCode(1);
|
rspVo.setResCode(1);
|
||||||
rspVo.setResMag("注册成功");
|
rspVo.setResMag("注册成功");
|
||||||
rspVo.setAddRoute(JSONObject.toJSONString(routeMsg));
|
rspVo.setAddRoute(JSONObject.toJSONString(routeMsg));
|
||||||
|
rspVo.setNetName(networkInfo.getName());
|
||||||
messageVo.setData(JSONObject.toJSONString(rspVo));
|
messageVo.setData(JSONObject.toJSONString(rspVo));
|
||||||
remoteRocketMqService.sendAsyncProducerMessage(
|
remoteRocketMqService.sendAsyncProducerMessage(
|
||||||
"tr_agent_down", "", "regist_rsp", JSONObject.toJSONString(messageVo), SecurityConstants.INNER
|
"tr_agent_down", "", "regist_rsp", JSONObject.toJSONString(messageVo), SecurityConstants.INNER
|
||||||
@@ -745,36 +746,54 @@ public class RmResourceRegistrationServiceImpl implements IRmResourceRegistratio
|
|||||||
RmNetworkInterfaceRemote queryParam = new RmNetworkInterfaceRemote();
|
RmNetworkInterfaceRemote queryParam = new RmNetworkInterfaceRemote();
|
||||||
queryParam.setClientId(clientId);
|
queryParam.setClientId(clientId);
|
||||||
|
|
||||||
Optional.ofNullable(remoteRocketMqService.getNetworkInterfaceList(queryParam, SecurityConstants.INNER))
|
R<List<RmNetworkInterfaceRemote>> netList = remoteRocketMqService.getNetworkInterfaceList(queryParam, SecurityConstants.INNER);
|
||||||
|
|
||||||
|
// 获取所有bindIp为1或3的网络接口
|
||||||
|
List<RmNetworkInterfaceRemote> filteredNetworks = Optional.ofNullable(netList)
|
||||||
.map(R::getData)
|
.map(R::getData)
|
||||||
.flatMap(list -> list.stream()
|
.map(list -> list.stream()
|
||||||
.filter(ni -> "1".equals(ni.getBindIp()) || "3".equals(ni.getBindIp()))
|
.filter(ni -> "1".equals(ni.getBindIp()) || "3".equals(ni.getBindIp()))
|
||||||
.findFirst())
|
.collect(Collectors.toList()))
|
||||||
.ifPresent(network -> {
|
.orElse(Collections.emptyList());
|
||||||
updateData.setRegistrationStatus("1");
|
|
||||||
|
|
||||||
// 发送注册响应
|
// 如果有符合条件的网络接口
|
||||||
RouteMsg routeMsg = new RouteMsg();
|
if (!filteredNetworks.isEmpty()) {
|
||||||
routeMsg.setName(network.getInterfaceName());
|
updateData.setRegistrationStatus("1");
|
||||||
routeMsg.setGateway(network.getGateway());
|
|
||||||
|
|
||||||
MessageVo messageVo = new MessageVo();
|
// 拼接所有符合条件的网络接口名称,用分号隔开
|
||||||
messageVo.setClientId(clientId);
|
StringBuilder netNameBuilder = new StringBuilder();
|
||||||
messageVo.setDataType(MsgEnum.注册应答.getValue());
|
for (int i = 0; i < filteredNetworks.size(); i++) {
|
||||||
|
if (i > 0) {
|
||||||
|
netNameBuilder.append(";");
|
||||||
|
}
|
||||||
|
netNameBuilder.append(filteredNetworks.get(i).getInterfaceName());
|
||||||
|
}
|
||||||
|
String netName = netNameBuilder.toString();
|
||||||
|
|
||||||
RspVo rspVo = new RspVo();
|
// 发送注册响应
|
||||||
rspVo.setResCode(1);
|
RouteMsg routeMsg = new RouteMsg();
|
||||||
rspVo.setResMag("注册成功");
|
routeMsg.setName(filteredNetworks.get(0).getInterfaceName()); // 使用拼接后的网络接口名称
|
||||||
rspVo.setAddRoute(JSONObject.toJSONString(routeMsg));
|
routeMsg.setGateway(filteredNetworks.get(0).getGateway()); // 使用第一个网络接口的网关,或者您可以根据需要调整
|
||||||
|
|
||||||
messageVo.setData(JSONObject.toJSONString(rspVo));
|
MessageVo messageVo = new MessageVo();
|
||||||
|
messageVo.setClientId(clientId);
|
||||||
|
messageVo.setDataType(MsgEnum.注册应答.getValue());
|
||||||
|
|
||||||
remoteRocketMqService.sendAsyncProducerMessage(
|
RspVo rspVo = new RspVo();
|
||||||
"tr_agent_down", "", "regist_rsp", JSONObject.toJSONString(messageVo), SecurityConstants.INNER
|
rspVo.setResCode(1);
|
||||||
);
|
rspVo.setResMag("注册成功");
|
||||||
// 注册成功,下发优先级为0的策略
|
rspVo.setAddRoute(JSONObject.toJSONString(routeMsg));
|
||||||
remoteRocketMqService.issueDefaultPolicyByClientId(clientId, SecurityConstants.INNER);
|
rspVo.setNetName(netName);
|
||||||
});
|
|
||||||
|
messageVo.setData(JSONObject.toJSONString(rspVo));
|
||||||
|
|
||||||
|
remoteRocketMqService.sendAsyncProducerMessage(
|
||||||
|
"tr_agent_down", "", "regist_rsp", JSONObject.toJSONString(messageVo), SecurityConstants.INNER
|
||||||
|
);
|
||||||
|
|
||||||
|
// 注册成功,下发优先级为0的策略
|
||||||
|
remoteRocketMqService.issueDefaultPolicyByClientId(clientId, SecurityConstants.INNER);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
rmResourceRegistrationMapper.updateRmResourceRegistration(updateData);
|
rmResourceRegistrationMapper.updateRmResourceRegistration(updateData);
|
||||||
|
|||||||
@@ -15,6 +15,8 @@ public class PolicyTypeVo {
|
|||||||
private String versions;
|
private String versions;
|
||||||
/** 路由信息 */
|
/** 路由信息 */
|
||||||
private String routes;
|
private String routes;
|
||||||
|
/** 业务网卡名称*/
|
||||||
|
private String netName;
|
||||||
/** 时间戳 */
|
/** 时间戳 */
|
||||||
private Long timestamp = Instant.now().getEpochSecond();
|
private Long timestamp = Instant.now().getEpochSecond();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -353,6 +353,8 @@ public class MessageHandler {
|
|||||||
rmDeploymentPolicyService.issueDeployPolicyMsgByClientId(clientId);
|
rmDeploymentPolicyService.issueDeployPolicyMsgByClientId(clientId);
|
||||||
// 如果路由有变化,更新路由信息
|
// 如果路由有变化,更新路由信息
|
||||||
rmNetworkInterfaceService.updateRouteMsg(clientId);
|
rmNetworkInterfaceService.updateRouteMsg(clientId);
|
||||||
|
// 如果业务网卡名称有变化,更新防火墙策略
|
||||||
|
rmNetworkInterfaceService.issueNetName(clientId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -926,6 +928,32 @@ public class MessageHandler {
|
|||||||
String collectValue = systemDataVo.getValue();
|
String collectValue = systemDataVo.getValue();
|
||||||
insertData.setCollectType(collectType);
|
insertData.setCollectType(collectType);
|
||||||
insertData.setCollectValue(collectValue);
|
insertData.setCollectValue(collectValue);
|
||||||
|
|
||||||
|
// 定义需要先删后插的collectType列表
|
||||||
|
List<String> specialCollectTypes = Arrays.asList(
|
||||||
|
"kernelMaxprocCollect",
|
||||||
|
"memorySizeTotalCollect",
|
||||||
|
"systemBoottimeCollect",
|
||||||
|
"systemCpuNum",
|
||||||
|
"systemDiskSizeTotalCollect",
|
||||||
|
"systemLocaltimeCollect",
|
||||||
|
"systemSwArchCollect",
|
||||||
|
"systemSwOsCollect",
|
||||||
|
"systemUnameCollect",
|
||||||
|
"systemUptimeCollect"
|
||||||
|
);
|
||||||
|
|
||||||
|
// 如果collectType在特殊列表中,先删除上个时间段的记录
|
||||||
|
if (specialCollectTypes.contains(collectType)) {
|
||||||
|
|
||||||
|
// 删除相同clientId、collectType和时间范围内的记录
|
||||||
|
InitialSystemOtherCollectData deleteData = new InitialSystemOtherCollectData();
|
||||||
|
deleteData.setClientId(message.getClientId());
|
||||||
|
deleteData.setCollectType(collectType);
|
||||||
|
deleteData.setCreateTime(createTime);
|
||||||
|
iInitialSystemOtherCollectDataService.deleteInitialSystemOtherCollectData(deleteData);
|
||||||
|
}
|
||||||
|
|
||||||
iInitialSystemOtherCollectDataService.insertInitialSystemOtherCollectData(insertData);
|
iInitialSystemOtherCollectDataService.insertInitialSystemOtherCollectData(insertData);
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@@ -1239,6 +1267,7 @@ public class MessageHandler {
|
|||||||
if (isSwitch) {
|
if (isSwitch) {
|
||||||
rmAlarmLog.setClientId(switchName);
|
rmAlarmLog.setClientId(switchName);
|
||||||
rmAlarmLog.setAlarmType("2");
|
rmAlarmLog.setAlarmType("2");
|
||||||
|
alarmContent = switchName + "下线";
|
||||||
} else {
|
} else {
|
||||||
// 查询管理网公网ip
|
// 查询管理网公网ip
|
||||||
RmNetworkInterface rmNetworkInterface = new RmNetworkInterface();
|
RmNetworkInterface rmNetworkInterface = new RmNetworkInterface();
|
||||||
|
|||||||
+7
@@ -67,4 +67,11 @@ public interface InitialSystemOtherCollectDataMapper
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
Map getMonitorMsg(InitialSystemOtherCollectData initialSystemOtherCollectData);
|
Map getMonitorMsg(InitialSystemOtherCollectData initialSystemOtherCollectData);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除上一次的详情
|
||||||
|
* @param deleteData
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
int deleteInitialSystemOtherCollectData(InitialSystemOtherCollectData deleteData);
|
||||||
}
|
}
|
||||||
|
|||||||
+7
@@ -116,4 +116,11 @@ public interface IInitialSystemOtherCollectDataService
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
Map<String, Object> procNumEcharts(InitialSystemOtherCollectData initialSystemOtherCollectData);
|
Map<String, Object> procNumEcharts(InitialSystemOtherCollectData initialSystemOtherCollectData);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除上一次的详情,除去图形
|
||||||
|
* @param deleteData
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
int deleteInitialSystemOtherCollectData(InitialSystemOtherCollectData deleteData);
|
||||||
}
|
}
|
||||||
|
|||||||
+6
@@ -79,4 +79,10 @@ public interface IRmNetworkInterfaceService
|
|||||||
* @param clientId
|
* @param clientId
|
||||||
*/
|
*/
|
||||||
void updateRouteMsg(String clientId);
|
void updateRouteMsg(String clientId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 下发业务网卡名称
|
||||||
|
* @param clientId
|
||||||
|
*/
|
||||||
|
void issueNetName(String clientId);
|
||||||
}
|
}
|
||||||
|
|||||||
+5
@@ -309,4 +309,9 @@ public class InitialSystemOtherCollectDataServiceImpl implements IInitialSystemO
|
|||||||
|
|
||||||
return resultMap;
|
return resultMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int deleteInitialSystemOtherCollectData(InitialSystemOtherCollectData deleteData) {
|
||||||
|
return initialSystemOtherCollectDataMapper.deleteInitialSystemOtherCollectData(deleteData);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-2
@@ -348,7 +348,7 @@ public class RmDeploymentPolicyServiceImpl implements IRmDeploymentPolicyService
|
|||||||
scriptPolicyVo.setPolicyTime(timestampInSecondes);
|
scriptPolicyVo.setPolicyTime(timestampInSecondes);
|
||||||
}
|
}
|
||||||
String[] clientIdArr = policy.getDeployDevice().split("\n");
|
String[] clientIdArr = policy.getDeployDevice().split("\n");
|
||||||
sendDeploymentPolicy(clientIdArr, scriptPolicyVo);
|
sendDeploymentPolicy(clientIdArr, scriptPolicyVo, policy.getCreateTime().getTime() /1000);
|
||||||
// 更新策略状态为已下发
|
// 更新策略状态为已下发
|
||||||
RmDeploymentPolicy deploymentPolicy = new RmDeploymentPolicy();
|
RmDeploymentPolicy deploymentPolicy = new RmDeploymentPolicy();
|
||||||
deploymentPolicy.setId(policy.getId());
|
deploymentPolicy.setId(policy.getId());
|
||||||
@@ -367,13 +367,14 @@ public class RmDeploymentPolicyServiceImpl implements IRmDeploymentPolicyService
|
|||||||
/**
|
/**
|
||||||
* 发送配置到设备
|
* 发送配置到设备
|
||||||
*/
|
*/
|
||||||
private void sendDeploymentPolicy(String[] clientIdArr, ServerScriptPolicyVo scriptPolicyVo) {
|
private void sendDeploymentPolicy(String[] clientIdArr, ServerScriptPolicyVo scriptPolicyVo, long createTime) {
|
||||||
MessageProducer messageProducer = new MessageProducer();
|
MessageProducer messageProducer = new MessageProducer();
|
||||||
|
|
||||||
PolicyVo<ServerScriptPolicyVo> policyVo = new PolicyVo();
|
PolicyVo<ServerScriptPolicyVo> policyVo = new PolicyVo();
|
||||||
List<ServerScriptPolicyVo> list = new ArrayList<>();
|
List<ServerScriptPolicyVo> list = new ArrayList<>();
|
||||||
list.add(scriptPolicyVo);
|
list.add(scriptPolicyVo);
|
||||||
policyVo.setContents(list);
|
policyVo.setContents(list);
|
||||||
|
policyVo.setUpTime(createTime);
|
||||||
String policyVoStr = JSONObject.toJSONString(policyVo);
|
String policyVoStr = JSONObject.toJSONString(policyVo);
|
||||||
PolicyTypeVo policyTypeVo = new PolicyTypeVo();
|
PolicyTypeVo policyTypeVo = new PolicyTypeVo();
|
||||||
policyTypeVo.setScripts(policyVoStr);
|
policyTypeVo.setScripts(policyVoStr);
|
||||||
|
|||||||
+31
@@ -179,4 +179,35 @@ public class RmNetworkInterfaceServiceImpl implements IRmNetworkInterfaceService
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void issueNetName(String clientId) {
|
||||||
|
RmNetworkInterface rmNetworkInterface = new RmNetworkInterface();
|
||||||
|
rmNetworkInterface.setClientIds(clientId);
|
||||||
|
List<RmNetworkInterface> networkInterfaces = rmNetworkInterfaceMapper.selectRmNetworkInterfaceList(rmNetworkInterface);
|
||||||
|
// 拼接所有符合条件的网络接口名称,用分号隔开
|
||||||
|
StringBuilder netNameBuilder = new StringBuilder();
|
||||||
|
for (int i = 0; i < networkInterfaces.size(); i++) {
|
||||||
|
if (i > 0) {
|
||||||
|
netNameBuilder.append(";");
|
||||||
|
}
|
||||||
|
netNameBuilder.append(networkInterfaces.get(i).getInterfaceName());
|
||||||
|
}
|
||||||
|
String netName = netNameBuilder.toString();
|
||||||
|
MessageProducer messageProducer = new MessageProducer();
|
||||||
|
PolicyTypeVo policyTypeVo = new PolicyTypeVo();
|
||||||
|
policyTypeVo.setNetName(netName);
|
||||||
|
String configJson = JSONObject.toJSONString(policyTypeVo);
|
||||||
|
DeviceMessage message = new DeviceMessage();
|
||||||
|
message.setClientId(clientId);
|
||||||
|
message.setData(configJson);
|
||||||
|
message.setDataType(MsgEnum.获取最新策略应答.getValue());
|
||||||
|
|
||||||
|
messageProducer.sendAsyncProducerMessage(
|
||||||
|
producerMode.getAgentTopic(),
|
||||||
|
"",
|
||||||
|
"",
|
||||||
|
JSONObject.toJSONString(message)
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+16
@@ -101,4 +101,20 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||||||
) latest ON t.collect_type = latest.collect_type AND t.create_time = latest.max_time
|
) latest ON t.collect_type = latest.collect_type AND t.create_time = latest.max_time
|
||||||
WHERE t.client_id = #{clientId}
|
WHERE t.client_id = #{clientId}
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
<delete id="deleteInitialSystemOtherCollectData" parameterType="InitialSystemOtherCollectData">
|
||||||
|
delete from initial_system_other_collect_data
|
||||||
|
<where>
|
||||||
|
<choose>
|
||||||
|
<when test="clientId != null and collectType != null and createTime != null">
|
||||||
|
AND client_id = #{clientId}
|
||||||
|
AND collect_type = #{collectType}
|
||||||
|
AND create_time < #{createTime}
|
||||||
|
</when>
|
||||||
|
<otherwise>
|
||||||
|
and 1=0
|
||||||
|
</otherwise>
|
||||||
|
</choose>
|
||||||
|
</where>
|
||||||
|
</delete>
|
||||||
</mapper>
|
</mapper>
|
||||||
Reference in New Issue
Block a user