|
|
|
@ -9,7 +9,9 @@ import com.docus.core.util.json.JSON;
|
|
|
|
|
import com.docus.server.api.scheduling.management.SchCollectorApi;
|
|
|
|
|
import com.docus.server.api.scheduling.management.SchCollectorConfigApi;
|
|
|
|
|
import com.docus.server.common.download.downLoader.HttpDownloader;
|
|
|
|
|
import com.docus.server.enums.ConfigTypeEnum;
|
|
|
|
|
import com.docus.server.vo.scheduling.management.schcollector.LoadSchCollectorVO;
|
|
|
|
|
import com.docus.server.vo.scheduling.management.schcollectorconfig.SchCollectorConfigVO;
|
|
|
|
|
import com.fasterxml.jackson.core.type.TypeReference;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
|
@ -19,10 +21,14 @@ import org.springframework.data.redis.core.StringRedisTemplate;
|
|
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
import java.io.File;
|
|
|
|
|
import java.io.FileWriter;
|
|
|
|
|
import java.io.PrintWriter;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
import java.util.concurrent.locks.Lock;
|
|
|
|
|
import java.util.concurrent.locks.ReentrantLock;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* load collector package and config
|
|
|
|
@ -37,6 +43,7 @@ public class LoadPackageCommandLineRunner implements CommandLineRunner {
|
|
|
|
|
|
|
|
|
|
@Value("${docus.collector-package-download-savePath:H://packages/}")
|
|
|
|
|
private String saveCollectorPackagePath;
|
|
|
|
|
|
|
|
|
|
@Value("${docus.collector-package-download-url}")
|
|
|
|
|
private String collectorPackageDownloadUrl;
|
|
|
|
|
|
|
|
|
@ -50,14 +57,69 @@ public class LoadPackageCommandLineRunner implements CommandLineRunner {
|
|
|
|
|
@Override
|
|
|
|
|
public void run(String... args) throws Exception {
|
|
|
|
|
|
|
|
|
|
loadPackages();
|
|
|
|
|
// loadPackages();
|
|
|
|
|
|
|
|
|
|
loadConfig();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void loadConfig() {
|
|
|
|
|
schCollectorConfigApi.findAll();
|
|
|
|
|
List<SchCollectorConfigVO> schCollectorConfigVOList = schCollectorConfigApi.findAll();
|
|
|
|
|
|
|
|
|
|
List<SchCollectorConfigVO> publicConfig = schCollectorConfigVOList
|
|
|
|
|
.stream()
|
|
|
|
|
.filter(p -> ConfigTypeEnum.PUBLIC_CONFIG.equals(p.getConfigType()))
|
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
|
|
|
|
|
List<SchCollectorConfigVO> privateConfig = schCollectorConfigVOList
|
|
|
|
|
.stream()
|
|
|
|
|
.filter(p -> ConfigTypeEnum.PRIVATE_CONFIG.equals(p.getConfigType()))
|
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
|
|
|
|
|
Map<Long, List<SchCollectorConfigVO>> privateConfigMap = ListUtils.groupBy(privateConfig, SchCollectorConfigVO::getCollectorId);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Map<String, String> publicConfigMap = JSON.fromJSONWithGeneric(publicConfig.get(0).getConfigJson(), new TypeReference<Map<String, String>>() {
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
privateConfigMap.forEach((key, value) -> {
|
|
|
|
|
try {
|
|
|
|
|
if (Func.isNotEmpty(value)) {
|
|
|
|
|
|
|
|
|
|
SchCollectorConfigVO schCollectorConfigVO = value.get(0);
|
|
|
|
|
|
|
|
|
|
String privateConfigJson = schCollectorConfigVO.getConfigJson();
|
|
|
|
|
|
|
|
|
|
Map<String, String> privateConfigJsonMap = JSON.fromJSONWithGeneric(privateConfigJson, new TypeReference<Map<String, String>>() {
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
privateConfigJsonMap.putAll(publicConfigMap);
|
|
|
|
|
|
|
|
|
|
File file = new File(saveCollectorPackagePath + schCollectorConfigVO.getCollectorId() + "\\collector.json");
|
|
|
|
|
if (file.exists()) {
|
|
|
|
|
|
|
|
|
|
FileWriter fileWriter = new FileWriter(file);
|
|
|
|
|
fileWriter.write("");
|
|
|
|
|
fileWriter.flush();
|
|
|
|
|
fileWriter.close();
|
|
|
|
|
|
|
|
|
|
log.info("文件已经存在");
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
|
|
boolean result = file.createNewFile();
|
|
|
|
|
log.info("创建新文件是否成功:" + result + ",文件路径为:" + file.getPath());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PrintWriter writer = new PrintWriter(file, "UTF-8");
|
|
|
|
|
writer.println(JSON.toJSON(privateConfigJsonMap));
|
|
|
|
|
writer.flush();
|
|
|
|
|
writer.close();
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception ex) {
|
|
|
|
|
log.error(ex.getMessage(), ex);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void loadPackages() throws Exception {
|
|
|
|
|