|
|
|
@ -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; |
|
|
|
@ -148,6 +149,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,6 +174,13 @@ public class ErrorInfoUploader {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
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<>(); |
|
|
|
@ -174,7 +191,7 @@ public class ErrorInfoUploader {
|
|
|
|
|
String suffix = filePath.substring(filePath.lastIndexOf(".")); |
|
|
|
|
|
|
|
|
|
if (suffix.endsWith(SUFFIX)) { |
|
|
|
|
String content = IOUtils.inputStream2String(new FileInputStream(file)); |
|
|
|
|
String content = IOUtils.inputStream2String(Files.newInputStream(file.toPath())); |
|
|
|
|
if (content.length() > MAX_ERROR_SIZE) { |
|
|
|
|
CommonIOUtils.deleteFile(file); |
|
|
|
|
continue; |
|
|
|
@ -182,6 +199,15 @@ public class ErrorInfoUploader {
|
|
|
|
|
jsonArray.put(new JSONObject(content)); |
|
|
|
|
tempFiles.add(file); |
|
|
|
|
if (jsonArray.length() == MAX_ITEMS || count == files.length) { |
|
|
|
|
processInfos(jsonArray, needSend2Cloud, tempFiles); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void processInfos(JSONArray jsonArray, boolean needSend2Cloud, List<File> tempFiles) { |
|
|
|
|
if (needSend2Cloud) { |
|
|
|
|
String url = CloudCenter.getInstance().acquireUrlByKind("design.error"); |
|
|
|
|
if (StringUtils.isBlank(url)) { |
|
|
|
|
return; |
|
|
|
@ -190,14 +216,22 @@ public class ErrorInfoUploader {
|
|
|
|
|
deleteFiles(tempFiles); |
|
|
|
|
} |
|
|
|
|
jsonArray = new JSONArray(); |
|
|
|
|
} else { |
|
|
|
|
sendInfos4AnalysisAndClearFiles(jsonArray, tempFiles); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} catch (Exception ignore) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 提供给云端运维监听的方法(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) { |
|
|
|
|