优化pppoe数据处理。
This commit is contained in:
@@ -106,11 +106,6 @@ public class AppInitializer implements CommandLineRunner {
|
||||
dynamicTaskService.scheduleTask("upFrpcMsg", businessTasks::upFrpcMsgTask, 15000, 300000);
|
||||
AssertLog.info("检测PppoE配置");
|
||||
agentService.handleRebootRecovery();
|
||||
AssertLog.info("启动macvlan状态上报定时任务 - 延迟: {}ms, 间隔: {}ms", 15000, 120000);
|
||||
dynamicTaskService.scheduleTask("upMacvlanStatus", businessTasks::upMacvlanStatus, 15000, 120000);
|
||||
// 检测PppoE配置模式配置
|
||||
AssertLog.info("检测PppoE配置模式配置");
|
||||
agentService.checkPppoEMode();
|
||||
}else{
|
||||
//未注册,发送注册
|
||||
try {
|
||||
|
||||
@@ -865,11 +865,6 @@ public class BusinessTasks {
|
||||
dynamicTaskService.scheduleTask("upFrpcMsg", businessTasks::upFrpcMsgTask, 15000, 300000);
|
||||
AssertLog.info("检测PppoE配置");
|
||||
agentService.handleRebootRecovery();
|
||||
AssertLog.info("启动macvlan状态上报定时任务 - 延迟: {}ms, 间隔: {}ms", 15000, 120000);
|
||||
dynamicTaskService.scheduleTask("upMacvlanStatus", businessTasks::upMacvlanStatus, 15000, 120000);
|
||||
// 检测PppoE配置模式配置
|
||||
AssertLog.info("检测PppoE配置模式配置");
|
||||
agentService.checkPppoEMode();
|
||||
}else{
|
||||
//未注册,发送注册
|
||||
try {
|
||||
|
||||
@@ -37,7 +37,6 @@ public interface AgentService {
|
||||
void addFirewall(String netName);
|
||||
|
||||
void checkFirewall();
|
||||
void checkPppoEMode();
|
||||
|
||||
void checkAndAddFirewallPeriodically();
|
||||
|
||||
|
||||
@@ -323,11 +323,6 @@ public class AgentServiceImpl implements AgentService {
|
||||
dynamicTaskService.scheduleTask("upFrpcMsg", businessTasks::upFrpcMsgTask, 15000, 300000);
|
||||
AssertLog.info("检测PppoE配置");
|
||||
handleRebootRecovery();
|
||||
AssertLog.info("启动macvlan状态上报定时任务 - 延迟: {}ms, 间隔: {}ms", 15000, 120000);
|
||||
dynamicTaskService.scheduleTask("upMacvlanStatus", businessTasks::upMacvlanStatus, 15000, 120000);
|
||||
// 检测PppoE配置模式配置
|
||||
AssertLog.info("检测PppoE配置模式配置");
|
||||
checkPppoEMode();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -934,55 +929,29 @@ public class AgentServiceImpl implements AgentService {
|
||||
AssertLog.error("PPPoE配置方式为空");
|
||||
return;
|
||||
}
|
||||
if("2".equals(pppoeConfigMode)){
|
||||
// 保存配置方式到pppoemode.conf
|
||||
if (!pppoeConfigMode.equals(GlobalConfig.PPPOEMODE)) {
|
||||
if("1".equals(pppoeConfigMode)){
|
||||
|
||||
String csvFilePath = properties.getPoePath() + "/macvlan_vlan.csv";
|
||||
|
||||
if (enable == 1L) {
|
||||
// 启用PPPoE时生成CSV文件
|
||||
try {
|
||||
// 1. 将pppoe配置方式写入配置文件
|
||||
String[] lines = {
|
||||
"# pppoe配置方式配置文件",
|
||||
"# 生成时间: " + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()),
|
||||
"# pppoe配置方式(1静态ip配置,2非saas平台配置)",
|
||||
"pppoeConfigMode=" + pppoeConfigMode,
|
||||
"",
|
||||
"# 配置元信息",
|
||||
"lastUpdateTime=" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()),
|
||||
};
|
||||
|
||||
// 检查目录并写入配置文件
|
||||
if (AdvancedAsyncDownloader.createSingleDirectoryIfNotExists(properties.getConfPath())) {
|
||||
AgentUtil.bufferedWriter(properties.getConfPath() + "/pppoemode.conf", lines);
|
||||
}
|
||||
|
||||
// 更新全局变量
|
||||
GlobalConfig.PPPOEMODE = pppoeConfigMode;
|
||||
|
||||
generateCsvFile(pppoeEO, csvFilePath);
|
||||
updateAndExecuteScript(pppoeEO.getPppoeInterface(), csvFilePath);
|
||||
} catch (Exception e) {
|
||||
AssertLog.info("配置PPPOE配置方式时发生错误: {}", e.getMessage());
|
||||
AssertLog.info("生成CSV文件或执行脚本失败: {}", e.getMessage());
|
||||
}
|
||||
} else if (enable == 0L) {
|
||||
// 禁用PPPoE时删除CSV文件
|
||||
try {
|
||||
deleteCsvFile(csvFilePath);
|
||||
} catch (Exception e) {
|
||||
AssertLog.info("删除CSV文件失败: {}", e.getMessage());
|
||||
}
|
||||
} else {
|
||||
AssertLog.info("无效的PPPoE启用状态: {}", enable);
|
||||
}
|
||||
}
|
||||
|
||||
String csvFilePath = properties.getPoePath() + "/macvlan_vlan.csv";
|
||||
|
||||
if (enable == 1L) {
|
||||
// 启用PPPoE时生成CSV文件
|
||||
try {
|
||||
generateCsvFile(pppoeEO, csvFilePath);
|
||||
updateAndExecuteScript(pppoeEO.getPppoeInterface(), csvFilePath);
|
||||
} catch (Exception e) {
|
||||
AssertLog.info("生成CSV文件或执行脚本失败: {}", e.getMessage());
|
||||
}
|
||||
} else if (enable == 0L) {
|
||||
// 禁用PPPoE时删除CSV文件
|
||||
try {
|
||||
deleteCsvFile(csvFilePath);
|
||||
} catch (Exception e) {
|
||||
AssertLog.info("删除CSV文件失败: {}", e.getMessage());
|
||||
}
|
||||
} else {
|
||||
AssertLog.info("无效的PPPoE启用状态: {}", enable);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1136,10 +1105,10 @@ public class AgentServiceImpl implements AgentService {
|
||||
}
|
||||
|
||||
// 清理临时文件
|
||||
// File tempFile = new File(tempCsvPath);
|
||||
// if (tempFile.exists()) {
|
||||
// FileUtils.deleteQuietly(tempFile);
|
||||
// }
|
||||
File tempFile = new File(tempCsvPath);
|
||||
if (tempFile.exists()) {
|
||||
FileUtils.deleteQuietly(tempFile);
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
AssertLog.error("脚本执行失败: {}", e.getMessage());
|
||||
@@ -1339,9 +1308,6 @@ public class AgentServiceImpl implements AgentService {
|
||||
|
||||
return config;
|
||||
}
|
||||
/**
|
||||
* 检查frpc进程是否在运行
|
||||
*/
|
||||
/**
|
||||
* 检查frpc进程是否在运行
|
||||
*/
|
||||
@@ -2134,27 +2100,6 @@ public class AgentServiceImpl implements AgentService {
|
||||
AssertLog.debug("业务网卡配置文件不存在: {}", businessNetFile.getPath());
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void checkPppoEMode() {
|
||||
File pppoemode = new File(properties.getConfPath() + "/pppoemode.conf");
|
||||
if (pppoemode.exists()) {
|
||||
Properties props = new Properties();
|
||||
try (InputStream input = Files.newInputStream(pppoemode.toPath())) {
|
||||
props.load(input);
|
||||
|
||||
String pppoeConfigMode = props.getProperty("pppoeConfigMode");
|
||||
if (StringUtils.isNotBlank(pppoeConfigMode)) {
|
||||
GlobalConfig.PPPOEMODE = pppoeConfigMode;
|
||||
AssertLog.info("应用启动时加载pppoe配置模式配置成功");
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
AssertLog.error("应用启动时加载pppoe配置模式配置异常:{}", e.getMessage());
|
||||
}
|
||||
} else {
|
||||
AssertLog.debug("pppoe配置模式配置文件不存在: {}", pppoemode.getPath());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void caseTypeBySystem(String type, int interval, boolean collect){
|
||||
@@ -2436,25 +2381,84 @@ public class AgentServiceImpl implements AgentService {
|
||||
}
|
||||
|
||||
AssertLog.info("CSV文件存在: {}", csvFilePath);
|
||||
try {
|
||||
// 读取原始CSV中的所有网卡信息
|
||||
List<String> allInterfaceInfo = getMacvlanInfoFromCsv(csvFilePath);
|
||||
|
||||
// 从CSV读取macvlan网卡名称
|
||||
String macvlanInterface = getFirstMacvlanFromCsv(csvFilePath);
|
||||
if (macvlanInterface == null) {
|
||||
AssertLog.error("无法从CSV文件中解析出macvlan网卡名称");
|
||||
return;
|
||||
if (allInterfaceInfo.isEmpty()) {
|
||||
AssertLog.error("CSV文件中没有有效的网卡配置");
|
||||
return;
|
||||
}
|
||||
|
||||
// 检查每个网卡是否存在,收集不存在的网卡信息
|
||||
List<String> missingInterfaceInfo = new ArrayList<>();
|
||||
for (String interfaceInfo : allInterfaceInfo) {
|
||||
String macvlanName = extractMacvlanName(interfaceInfo);
|
||||
if (macvlanName != null) {
|
||||
if (!checkInterfaceExists(macvlanName, interfaceInfo)) {
|
||||
missingInterfaceInfo.add(interfaceInfo);
|
||||
AssertLog.info("网卡 {} 需要重新配置,将添加到处理列表", macvlanName);
|
||||
} else {
|
||||
AssertLog.info("网卡 {} 已存在且配置正确,跳过处理", macvlanName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 如果所有网卡都存在,不执行脚本
|
||||
if (missingInterfaceInfo.isEmpty()) {
|
||||
AssertLog.info("所有网卡已存在,跳过脚本执行");
|
||||
return;
|
||||
}
|
||||
|
||||
// 创建只包含不存在网卡的新CSV文件
|
||||
String tempCsvPath = createTempCsvForMissingInterfaces(missingInterfaceInfo);
|
||||
if (tempCsvPath == null) {
|
||||
AssertLog.error("创建临时CSV文件失败");
|
||||
return;
|
||||
}
|
||||
|
||||
String scriptPath = properties.getPoePath() + "/multi_wan_conntrack.sh";
|
||||
File scriptFile = new File(scriptPath);
|
||||
|
||||
if (!scriptFile.exists()) {
|
||||
AssertLog.error("脚本文件不存在: {}", scriptPath);
|
||||
return;
|
||||
}
|
||||
// 执行脚本
|
||||
ProcessBuilder pb = new ProcessBuilder("/bin/bash", scriptPath);
|
||||
pb.redirectErrorStream(true);
|
||||
pb.directory(new File(properties.getPoePath()));
|
||||
|
||||
Process process = pb.start();
|
||||
|
||||
// 读取脚本输出
|
||||
StringBuilder output = new StringBuilder();
|
||||
try (BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()))) {
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
output.append(line).append("\n");
|
||||
AssertLog.info("脚本输出: {}", line);
|
||||
}
|
||||
}
|
||||
|
||||
int exitCode = process.waitFor();
|
||||
|
||||
if (exitCode == 0) {
|
||||
AssertLog.info("脚本执行成功: {}", scriptPath);
|
||||
} else {
|
||||
AssertLog.error("脚本执行失败,退出码: {},输出: {}", exitCode, output.toString());
|
||||
}
|
||||
|
||||
// 清理临时文件
|
||||
File tempFile = new File(tempCsvPath);
|
||||
if (tempFile.exists()) {
|
||||
FileUtils.deleteQuietly(tempFile);
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
AssertLog.error("脚本执行失败: {}", e.getMessage());
|
||||
}
|
||||
|
||||
// 检查网卡是否存在
|
||||
boolean interfaceExists = checkInterfaceExists(macvlanInterface);
|
||||
|
||||
if (!interfaceExists) {
|
||||
// CSV存在 && 网卡不存在 → 执行脚本
|
||||
AssertLog.info("macvlan网卡不存在: {},执行脚本", macvlanInterface);
|
||||
updateAndExecuteScript("eth0", csvFilePath);
|
||||
} else {
|
||||
// 其他情况都不执行
|
||||
AssertLog.info("macvlan网卡已存在: {},不执行脚本", macvlanInterface);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public List<MacVlanVO> upMacvlanStatus() {
|
||||
|
||||
@@ -180,6 +180,9 @@ public class NetworkInterfaceUtil {
|
||||
if (parent.getSubInterfaces() == null) {
|
||||
parent.setSubInterfaces(new ArrayList<>());
|
||||
}
|
||||
if(info.getIpv4() != null){
|
||||
info.setStatus(getmacVlanStatus(info.getName())?"1":"0");
|
||||
}
|
||||
parent.getSubInterfaces().add(info);
|
||||
AssertLog.info(" 添加到父接口 {} 的子接口列表", parentName);
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user