fix:主备切换测试
This commit is contained in:
@@ -1,76 +0,0 @@
|
||||
package com.Sample;
|
||||
|
||||
import cn.hutool.core.date.StopWatch;
|
||||
import com.google.gson.Gson;
|
||||
import racal.sunyard.main.SydApi4j;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
|
||||
public class TestCert {
|
||||
public static void main(String[] args) throws Exception {
|
||||
StopWatch stopWatch = new StopWatch();
|
||||
stopWatch.start();
|
||||
System.out.println("-----------start---------------");
|
||||
SydApi4j sydApi4j = new SydApi4j();
|
||||
String ipInfo = "/app/test/ipInfo.txt";
|
||||
String snmpInfo = "/app/test/snmp.txt";
|
||||
String certInfo = "/app/test/cert.txt";
|
||||
Map<String, String> map = readFileToMap(ipInfo);
|
||||
String ipInfos = map.getOrDefault("ipList", null);
|
||||
List<String> ipList = new ArrayList<>();
|
||||
if (ipInfos != null) {
|
||||
ipList = Arrays.asList(ipInfos.split(","));
|
||||
}
|
||||
int timeout = Integer.parseInt(map.get("timout"));
|
||||
String cert = readFileAsString(certInfo);
|
||||
String bkCode = map.get("bkcode");
|
||||
Map<String, String> snmpMap = readFileToMap(snmpInfo);
|
||||
Gson gson = new Gson();
|
||||
sydApi4j.importCertToServers(ipList, timeout, cert, bkCode, gson.toJson(snmpMap));
|
||||
System.out.println("------------end-----------------------");
|
||||
stopWatch.stop();
|
||||
System.out.println("耗时:" + stopWatch.getTotalTimeMillis() + "ms");
|
||||
|
||||
}
|
||||
public static Map<String, String> readFileToMap(String filePath) {
|
||||
Map<String, String> map = new HashMap<>();
|
||||
|
||||
try (BufferedReader br = new BufferedReader(new FileReader(filePath))) {
|
||||
String line;
|
||||
while ((line = br.readLine()) != null) {
|
||||
// 跳过空行和注释行(假设以#开头的为注释)
|
||||
if (line.trim().isEmpty() || line.startsWith("#")) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// 按分隔符分割键值(例如"="或":")
|
||||
String[] parts = line.split("=", 2); // 使用第二个参数限制分割次数
|
||||
if (parts.length == 2) {
|
||||
String key = parts[0].trim();
|
||||
String value = parts[1].trim();
|
||||
map.put(key, value);
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
public static String readFileAsString(String filePath) {
|
||||
StringBuilder content = new StringBuilder();
|
||||
try (BufferedReader br = new BufferedReader(new FileReader(filePath))) {
|
||||
String line;
|
||||
while ((line = br.readLine()) != null) {
|
||||
content.append(line).append("\n");
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return content.toString();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user