Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
H
haoban-manage3.0
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
haoban3.0
haoban-manage3.0
Commits
b2be902c
Commit
b2be902c
authored
Jun 02, 2024
by
王祖波
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
holo定时读配置初始化
parent
c58de993
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
43 additions
and
3 deletions
+43
-3
HoloDataSource.java
...anage/service/dao/mapper/content/holo/HoloDataSource.java
+43
-3
No files found.
haoban-manage3-service/src/main/java/com/gic/haoban/manage/service/dao/mapper/content/holo/HoloDataSource.java
View file @
b2be902c
package
com
.
gic
.
haoban
.
manage
.
service
.
dao
.
mapper
.
content
.
holo
;
package
com
.
gic
.
haoban
.
manage
.
service
.
dao
.
mapper
.
content
.
holo
;
import
cn.hutool.core.lang.Pair
;
import
cn.hutool.core.lang.TypeReference
;
import
cn.hutool.http.HttpUtil
;
import
cn.hutool.json.JSON
;
import
cn.hutool.json.JSONUtil
;
import
com.alibaba.hologres.client.HoloClient
;
import
com.alibaba.hologres.client.HoloClient
;
import
com.alibaba.hologres.client.HoloConfig
;
import
com.alibaba.hologres.client.HoloConfig
;
import
com.ctrip.framework.apollo.Config
;
import
com.ctrip.framework.apollo.Config
;
...
@@ -9,6 +14,11 @@ import org.springframework.beans.factory.DisposableBean;
...
@@ -9,6 +14,11 @@ import org.springframework.beans.factory.DisposableBean;
import
org.springframework.beans.factory.InitializingBean
;
import
org.springframework.beans.factory.InitializingBean
;
import
org.springframework.stereotype.Component
;
import
org.springframework.stereotype.Component
;
import
java.util.Map
;
import
java.util.concurrent.Executors
;
import
java.util.concurrent.ScheduledExecutorService
;
import
java.util.concurrent.TimeUnit
;
/**
/**
* @Author MUSI
* @Author MUSI
* @Date 2023/9/4 4:11 PM
* @Date 2023/9/4 4:11 PM
...
@@ -21,13 +31,23 @@ public class HoloDataSource implements InitializingBean, DisposableBean {
...
@@ -21,13 +31,23 @@ public class HoloDataSource implements InitializingBean, DisposableBean {
HoloClient
client
;
HoloClient
client
;
public
synchronized
void
init
()
{
private
final
ScheduledExecutorService
scheduler
=
Executors
.
newScheduledThreadPool
(
1
);
public
synchronized
void
init
()
{
try
{
try
{
Config
appConfig
=
ConfigService
.
getAppConfig
();
Config
appConfig
=
ConfigService
.
getAppConfig
();
String
holoUrl
=
appConfig
.
getProperty
(
"holo.url"
,
""
);
String
holoUrl
=
appConfig
.
getProperty
(
"holo.url"
,
""
);
String
holoUserName
=
appConfig
.
getProperty
(
"holo.username"
,
""
);
Pair
<
String
,
String
>
holoAuth
=
getHoloAuth
();
String
holoPassword
=
appConfig
.
getProperty
(
"holo.password"
,
""
);
if
(
holoAuth
==
null
)
{
log
.
info
(
"holo链接初始化获取授权信息失败"
);
return
;
}
if
(
this
.
client
!=
null
)
{
this
.
client
.
close
();
}
String
holoUserName
=
holoAuth
.
getKey
();
String
holoPassword
=
holoAuth
.
getValue
();
HoloConfig
holoConfig
=
new
HoloConfig
();
HoloConfig
holoConfig
=
new
HoloConfig
();
holoConfig
.
setJdbcUrl
(
holoUrl
);
holoConfig
.
setJdbcUrl
(
holoUrl
);
holoConfig
.
setUsername
(
holoUserName
);
holoConfig
.
setUsername
(
holoUserName
);
...
@@ -53,6 +73,7 @@ public class HoloDataSource implements InitializingBean, DisposableBean {
...
@@ -53,6 +73,7 @@ public class HoloDataSource implements InitializingBean, DisposableBean {
if
(
client
==
null
)
{
if
(
client
==
null
)
{
this
.
init
();
this
.
init
();
}
}
scheduler
.
scheduleAtFixedRate
(
this
::
reinitialize
,
1
,
1
,
TimeUnit
.
HOURS
);
}
}
...
@@ -62,4 +83,23 @@ public class HoloDataSource implements InitializingBean, DisposableBean {
...
@@ -62,4 +83,23 @@ public class HoloDataSource implements InitializingBean, DisposableBean {
}
}
return
this
.
client
;
return
this
.
client
;
}
}
// 重新初始化方法
public
synchronized
void
reinitialize
()
{
this
.
init
();
}
private
Pair
<
String
,
String
>
getHoloAuth
()
{
//{"appId":"ops_key","cluster":"default","namespaceName":"application","configurations":{"aliyun-key":"{\n\"LTAI5tGn2YicKmgcyTiJDV59\":\"iOp7cICESPZIvIjJRtTmLnCd4gT1Qy\"\n}"},"releaseKey":"20240412153514-b260f04ffbe11f4e"}
String
result
=
HttpUtil
.
get
(
"http://proapollo.gicdev.com:7080/configs/ops_key/default/application?key=aliyun-key"
,
10000
);
JSON
json
=
JSONUtil
.
parse
(
result
);
String
authInfo
=
json
.
getByPath
(
"configurations.aliyun-key"
,
String
.
class
);
JSON
authJson
=
JSONUtil
.
parseObj
(
authInfo
);
Map
<
String
,
String
>
map
=
authJson
.
toBean
(
new
TypeReference
<
Map
<
String
,
String
>>()
{});
for
(
Map
.
Entry
<
String
,
String
>
entry
:
map
.
entrySet
())
{
return
new
Pair
<>(
entry
.
getKey
(),
entry
.
getValue
());
}
return
null
;
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment