提交 741ace20 编写于 作者: sq3536's avatar sq3536

enableApi逻辑,datasource配置逻辑升级

上级 645b656c
......@@ -23,7 +23,7 @@
<revision>2.4.0-SNAPSHOT</revision>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<ibiz-boot-starter.version>2.4.0-SNAPSHOT</ibiz-boot-starter.version>
<ibiz.cloud.version>8.1.0.181</ibiz.cloud.version>
<ibiz.cloud.version>8.1.0.205</ibiz.cloud.version>
<spring-cloud.version>2020.0.1</spring-cloud.version>
<spring-cloud-starter-bootstrap.version>3.0.1</spring-cloud-starter-bootstrap.version>
<fastjson.version>1.2.83</fastjson.version>
......
......@@ -9,7 +9,10 @@ import com.baomidou.dynamic.datasource.spring.boot.autoconfigure.DynamicDataSour
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.extern.slf4j.Slf4j;
import net.ibizsys.central.ISystemRuntimeSetting;
import net.ibizsys.central.cloud.core.ServiceHubSettingBase;
import net.ibizsys.central.cloud.core.util.ConfigEntity;
import net.ibizsys.central.cloud.core.util.NacosConfigUtils;
import net.ibizsys.central.cloud.core.util.domain.DataSource;
import net.ibizsys.central.cloud.core.util.domain.DeploySystem;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -44,6 +47,11 @@ public class BootServiceHubSetting extends ServiceHubSettingBase {
*/
public final static String DATAID_DBINST_PREFIX = "dbinst-";
/**
* 参数:默认数据库实例标记
*/
public final static String PARAM_DEFAULTDBINSTTAG = "defaultdbinsttag";
@JsonIgnore
@JSONField(serialize = false)
@Autowired
......@@ -111,11 +119,11 @@ public class BootServiceHubSetting extends ServiceHubSettingBase {
Map<String, Object> commonSettings = null;
List<DataSource> dataSourceList = new ArrayList<DataSource>();
Map<String, DataSource> dataSourceMap = new HashMap<String, DataSource>();
Yaml yaml = new Yaml();
// 本方法启动的时候获取内容
String content = configService.getConfig(DATAID_SERVICEHUB_PREFIX + this.getId(), this.nacosConfigProperties.getGroup(), 5000);
if(StringUtils.hasLength(content)) {
Yaml yaml = new Yaml();
Map config = yaml.loadAs(content, Map.class);
Object value = config.get("enableappgateway");
......@@ -155,30 +163,61 @@ public class BootServiceHubSetting extends ServiceHubSettingBase {
Object objDataSources = config.get("datasources");
if (objDataSources instanceof Map) {
Map<String, Object> map = (Map<String, Object>) objDataSources;
for (Map.Entry<String, Object> entry : map.entrySet()) {
for (java.util.Map.Entry<String, Object> entry : map.entrySet()) {
DataSource dataSource = new DataSource();
Map<String, Object> source = (Map<String, Object>) entry.getValue();
dataSource.putAll(source);
//进一步处理属性,这些属性将完全复制之数据源配置
for (Map.Entry<String, Object> item : source.entrySet()) {
String strKey = item.getKey().replace("-", "");
if (strKey.equals(item.getKey())) {
continue;
Object objDataSource = entry.getValue();
if(objDataSource instanceof Map) {
Map<String, Object> source = (Map<String, Object>)objDataSource;
dataSource.putAll(source);
//进一步处理属性,这些属性将完全复制之数据源配置
for (java.util.Map.Entry<String, Object> item : source.entrySet()) {
String strKey = item.getKey().replace("-", "");
if(strKey.equals(item.getKey())) {
continue;
}
dataSource.set(strKey, item.getValue());
}
if (ObjectUtils.isEmpty(dataSource.getDriverClassName())) {
dataSource.setDriverClassName((String) dataSource.get("driver-class-name"));
}
dataSource.set(strKey, item.getValue());
}
else {
String strDBInstConfigKey = String.format("%1$s%2$s", DATAID_DBINST_PREFIX, objDataSource);
String strBackupConfigId = strDBInstConfigKey;
strDBInstConfigKey = NacosConfigUtils.getDataId(strBackupConfigId);
if(!strBackupConfigId.equals(strDBInstConfigKey)) {
log.warn(String.format("键名[%1$s]包含非法字符,转换至[%2$s],可能会出现键名冲突", strBackupConfigId, strDBInstConfigKey));
}
String strDBInstConfig = configService.getConfig(strDBInstConfigKey, this.nacosConfigProperties.getGroup(), 5000);
if(!StringUtils.hasLength(strDBInstConfig)) {
log.warn(String.format("未定义数据库实例[%1$s]配置,访问可能会出现问题", strDBInstConfigKey));
continue;
}
dataSource.setDataSourceId(entry.getKey());
if (ObjectUtils.isEmpty(dataSource.getDriverClassName())) {
dataSource.setDriverClassName((String) dataSource.get("driver-class-name"));
ConfigEntity configEntity = new ConfigEntity(strDBInstConfig);
String strDBInstConfigExKey = String.format("%1$s%2$s-ex", DATAID_DBINST_PREFIX, objDataSource);
strDBInstConfigExKey = NacosConfigUtils.getDataId(strDBInstConfigExKey);
String strDBInstConfigEx = configService.getConfig(strDBInstConfigExKey, this.nacosConfigProperties.getGroup(), 5000);
if(StringUtils.hasLength(strDBInstConfigExKey)) {
ConfigEntity configexEntity = new ConfigEntity(strDBInstConfigEx);
configexEntity.copyTo(configEntity);
}
configEntity.copyTo(dataSource);
}
if (ObjectUtils.isEmpty(dataSource.getJdbcUrl())) {
dataSource.setJdbcUrl((String) dataSource.get("url"));
}
dataSource.setDataSourceId(entry.getKey());
dataSourceList.add(dataSource);
dataSourceMap.put(dataSource.getDataSourceId(), dataSource);
}
this.setDataSources(dataSourceList);
}
......@@ -197,6 +236,7 @@ public class BootServiceHubSetting extends ServiceHubSettingBase {
dataSource.setUsername(entry.getValue().getUsername());
dataSource.setPassword(entry.getValue().getPassword());
dataSourceList.add(dataSource);
dataSourceMap.put(dataSource.getDataSourceId(), dataSource);
});
this.setDataSources(dataSourceList);
}
......@@ -208,10 +248,19 @@ public class BootServiceHubSetting extends ServiceHubSettingBase {
if (ObjectUtils.isEmpty(item)) {
continue;
}
//判断是否指定接口
String strEnableAPIs = "";
String strItem = item.toString();
int nPos = strItem.indexOf(":");
if(nPos != -1) {
item = strItem.substring(0, nPos);
strEnableAPIs = strItem.substring(nPos + 1);
}
DeploySystem deploySystem = new DeploySystem();
String deploySystemConfig = configService.getConfig(DATAID_DEPLOYSYSTEM_PREFIX + item.toString(), this.nacosConfigProperties.getGroup(), 5000);
if (StringUtils.hasLength(deploySystemConfig)) {
Yaml yaml = new Yaml();
Map map2 = yaml.loadAs(deploySystemConfig, Map.class);
deploySystem.putAll(map2);
deploySystem.setDeploySystemId(item.toString());
......@@ -230,6 +279,23 @@ public class BootServiceHubSetting extends ServiceHubSettingBase {
}
deploySystem.setSettings(settings);
}
//放入启动接口
if(StringUtils.hasLength(strEnableAPIs)) {
if(deploySystem.getSettings()==null) {
deploySystem.setSettings(new HashMap<String, Object>());
}
deploySystem.getSettings().put(ISystemRuntimeSetting.PARAM_ENABLEAPIS, strEnableAPIs);
//deploySystem.setAPIs(Arrays.asList(strInterfaces.split("[;]")));
}
//判断是否存在默认数据源
String strDefaultDBInstTag = String.format("%1$s__default", deploySystem.getDeploySystemId());
if(dataSourceMap.containsKey(strDefaultDBInstTag)) {
if(deploySystem.getSettings()==null) {
deploySystem.setSettings(new HashMap<String, Object>());
}
deploySystem.getSettings().put(PARAM_DEFAULTDBINSTTAG, strDefaultDBInstTag);
}
deploySystemList.add(deploySystem);
}
this.setDeploySystems(deploySystemList);
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册