|
|
|
@ -20,9 +20,10 @@ import com.fr.stable.StableUtils;
|
|
|
|
|
import com.fr.stable.StringUtils; |
|
|
|
|
|
|
|
|
|
import java.io.File; |
|
|
|
|
import java.io.FileInputStream; |
|
|
|
|
import java.io.FileOutputStream; |
|
|
|
|
import java.io.IOException; |
|
|
|
|
import java.io.InputStream; |
|
|
|
|
import java.nio.file.Files; |
|
|
|
|
import java.util.ArrayList; |
|
|
|
|
import java.util.HashMap; |
|
|
|
|
import java.util.List; |
|
|
|
@ -37,6 +38,8 @@ public class ErrorInfoUploader {
|
|
|
|
|
public static final String SUFFIX = ".json"; |
|
|
|
|
public static final String FOLDER_NAME = "errorInfo"; |
|
|
|
|
|
|
|
|
|
private static final String CLOUD_KEY = "design.error"; |
|
|
|
|
|
|
|
|
|
private static ErrorInfoUploader collector; |
|
|
|
|
// 在一台不能上网的电脑里发现了10w个errorinfo...
|
|
|
|
|
private static final int MAX_ERROR_SIZE = 2000; |
|
|
|
@ -148,6 +151,15 @@ public class ErrorInfoUploader {
|
|
|
|
|
// 判断更新解决方案缓存.
|
|
|
|
|
checkUpdateSolution(); |
|
|
|
|
|
|
|
|
|
dealErrorInfo(true); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 处理错误信息 |
|
|
|
|
* |
|
|
|
|
* @param needSend2Cloud 是否需要上传到云中心 |
|
|
|
|
*/ |
|
|
|
|
public void dealErrorInfo(boolean needSend2Cloud) { |
|
|
|
|
//读取文件夹里的json, 加入上传队列中.
|
|
|
|
|
File folder = new File(StableUtils.pathJoin(ProductConstants.getEnvHome(), FOLDER_NAME)); |
|
|
|
|
if (!folder.exists()) { |
|
|
|
@ -164,41 +176,65 @@ public class ErrorInfoUploader {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
if (ArrayUtils.isNotEmpty(files)) { |
|
|
|
|
JSONArray jsonArray = new JSONArray(); |
|
|
|
|
List<File> tempFiles = new ArrayList<>(); |
|
|
|
|
int count = 0; |
|
|
|
|
for (File file : files) { |
|
|
|
|
count++; |
|
|
|
|
String filePath = file.getPath(); |
|
|
|
|
String suffix = filePath.substring(filePath.lastIndexOf(".")); |
|
|
|
|
|
|
|
|
|
if (suffix.endsWith(SUFFIX)) { |
|
|
|
|
String content = IOUtils.inputStream2String(new FileInputStream(file)); |
|
|
|
|
if (content.length() > MAX_ERROR_SIZE) { |
|
|
|
|
CommonIOUtils.deleteFile(file); |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
jsonArray.put(new JSONObject(content)); |
|
|
|
|
tempFiles.add(file); |
|
|
|
|
if (jsonArray.length() == MAX_ITEMS || count == files.length) { |
|
|
|
|
String url = CloudCenter.getInstance().acquireUrlByKind("design.error"); |
|
|
|
|
if (StringUtils.isBlank(url)) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
if (sendErrorInfo(url, jsonArray)) { |
|
|
|
|
deleteFiles(tempFiles); |
|
|
|
|
} |
|
|
|
|
jsonArray = new JSONArray(); |
|
|
|
|
} |
|
|
|
|
dealFiles(files, needSend2Cloud); |
|
|
|
|
} catch (Exception ignore) { |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void dealFiles(File[] files, boolean needSend2Cloud) throws IOException { |
|
|
|
|
if (ArrayUtils.isNotEmpty(files)) { |
|
|
|
|
JSONArray jsonArray = new JSONArray(); |
|
|
|
|
List<File> tempFiles = new ArrayList<>(); |
|
|
|
|
int count = 0; |
|
|
|
|
for (File file : files) { |
|
|
|
|
count++; |
|
|
|
|
String filePath = file.getPath(); |
|
|
|
|
String suffix = filePath.substring(filePath.lastIndexOf(".")); |
|
|
|
|
|
|
|
|
|
if (suffix.endsWith(SUFFIX)) { |
|
|
|
|
String content = IOUtils.inputStream2String(Files.newInputStream(file.toPath())); |
|
|
|
|
if (content.length() > MAX_ERROR_SIZE) { |
|
|
|
|
CommonIOUtils.deleteFile(file); |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
jsonArray.put(new JSONObject(content)); |
|
|
|
|
tempFiles.add(file); |
|
|
|
|
if (jsonArray.length() == MAX_ITEMS || count == files.length) { |
|
|
|
|
processInfos(jsonArray, needSend2Cloud, tempFiles); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} catch (Exception ignore) { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void processInfos(JSONArray jsonArray, boolean needSend2Cloud, List<File> tempFiles) { |
|
|
|
|
if (needSend2Cloud) { |
|
|
|
|
String url = CloudCenter.getInstance().acquireUrlByKind(CLOUD_KEY); |
|
|
|
|
if (StringUtils.isBlank(url)) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
if (sendErrorInfo(url, jsonArray)) { |
|
|
|
|
deleteFiles(tempFiles); |
|
|
|
|
} |
|
|
|
|
jsonArray = new JSONArray(); |
|
|
|
|
} else { |
|
|
|
|
sendInfos4AnalysisAndClearFiles(jsonArray, tempFiles); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 提供给云端运维监听的方法(beforeExecute) |
|
|
|
|
* |
|
|
|
|
* @param jsonArray 要提交的信息 |
|
|
|
|
* @param tempFiles 要删除的文件 |
|
|
|
|
*/ |
|
|
|
|
private void sendInfos4AnalysisAndClearFiles(JSONArray jsonArray, List<File> tempFiles) { |
|
|
|
|
deleteFiles(tempFiles); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void deleteFiles(List<File> files) { |
|
|
|
|
for (File file : files) { |
|
|
|
|
CommonIOUtils.deleteFile(file); |
|
|
|
|