Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
提交反馈
为 GitLab 提交贡献
登录
切换导航
I
ibiz-boot-starters
项目
项目
详情
动态
版本
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
ibiz4jteam
ibiz-boot-starters
提交
741ace20
提交
741ace20
编写于
9月 16, 2022
作者:
sq3536
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
enableApi逻辑,datasource配置逻辑升级
上级
645b656c
变更
2
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
83 行增加
和
17 行删除
+83
-17
pom.xml
ibiz-boot-starter-parent/pom.xml
+1
-1
BootServiceHubSetting.java
...ntral/plugin/boot/core/runtime/BootServiceHubSetting.java
+82
-16
未找到文件。
ibiz-boot-starter-parent/pom.xml
浏览文件 @
741ace20
...
...
@@ -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>
...
...
ibiz-boot-starter/src/main/java/net/ibizsys/central/plugin/boot/core/runtime/BootServiceHubSetting.java
浏览文件 @
741ace20
...
...
@@ -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
人
到此讨论。请谨慎行事。
先完成此消息的编辑!
取消
想要评论请
注册
或
登录