下载采集器配置文件

segment2.0
linrf 2 years ago
parent 6f889cc009
commit 7d6bbc82a4

@ -3,7 +3,7 @@ api.base-package=com.docus.server
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://db.docus.cn:3306/docus-collector-scheduling?autoReconnect=true&allowMultiQueries=true&useSSL=false&useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai spring.datasource.url=jdbc:mysql://db.docus.cn:3306/docus-collector-scheduling?autoReconnect=true&allowMultiQueries=true&useSSL=false&useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai
spring.datasource.username=root spring.datasource.username=docus
spring.datasource.password=root spring.datasource.password=docus702
mybatis-plus.type-enums-package=com.docus.server.enums mybatis-plus.type-enums-package=com.docus.server.enums

@ -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.SchCollectorApi;
import com.docus.server.api.scheduling.management.SchCollectorConfigApi; import com.docus.server.api.scheduling.management.SchCollectorConfigApi;
import com.docus.server.common.download.downLoader.HttpDownloader; 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.schcollector.LoadSchCollectorVO;
import com.docus.server.vo.scheduling.management.schcollectorconfig.SchCollectorConfigVO;
import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.core.type.TypeReference;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
@ -19,10 +21,14 @@ import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.io.File;
import java.io.FileWriter;
import java.io.PrintWriter;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock; import java.util.concurrent.locks.ReentrantLock;
import java.util.stream.Collectors;
/** /**
* load collector package and config * load collector package and config
@ -37,6 +43,7 @@ public class LoadPackageCommandLineRunner implements CommandLineRunner {
@Value("${docus.collector-package-download-savePath:H://packages/}") @Value("${docus.collector-package-download-savePath:H://packages/}")
private String saveCollectorPackagePath; private String saveCollectorPackagePath;
@Value("${docus.collector-package-download-url}") @Value("${docus.collector-package-download-url}")
private String collectorPackageDownloadUrl; private String collectorPackageDownloadUrl;
@ -50,14 +57,69 @@ public class LoadPackageCommandLineRunner implements CommandLineRunner {
@Override @Override
public void run(String... args) throws Exception { public void run(String... args) throws Exception {
loadPackages(); // loadPackages();
loadConfig(); loadConfig();
} }
private void 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 { private void loadPackages() throws Exception {

@ -46,6 +46,8 @@ public interface SchCollectorConfigApi {
* *
* @return SchCollectorConfigVO * @return SchCollectorConfigVO
*/ */
@ApiOperation("查询所有")
@GetMapping("/findAll")
List<SchCollectorConfigVO> findAll(); List<SchCollectorConfigVO> findAll();
/** /**

Loading…
Cancel
Save