Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
discovery
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
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
谢捷峰
discovery
Commits
337a8089
Commit
337a8089
authored
Jul 23, 2018
by
Nepxion
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
独立控制增加读取远程配置功能
parent
31f9bbca
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
54 additions
and
10 deletions
+54
-10
discovery-console-extension-nacos/src/main/java/com/nepxion/discovery/console/extension/nacos/adapter/NacosConfigAdapter.java
+15
-2
discovery-console-extension-nacos/src/main/java/com/nepxion/discovery/console/extension/nacos/constant/NacosConstant.java
+3
-0
discovery-console/src/main/java/com/nepxion/discovery/console/endpoint/ConsoleEndpoint.java
+26
-4
discovery-console/src/main/java/com/nepxion/discovery/console/remote/ConfigAdapter.java
+5
-2
discovery-plugin-config-center-extension-nacos/src/main/java/com/nepxion/discovery/plugin/configcenter/extension/nacos/adapter/NacosConfigAdapter.java
+2
-2
discovery-plugin-config-center-extension-nacos/src/main/java/com/nepxion/discovery/plugin/configcenter/extension/nacos/constant/NacosConstant.java
+3
-0
No files found.
discovery-console-extension-nacos/src/main/java/com/nepxion/discovery/console/extension/nacos/adapter/NacosConfigAdapter.java
View file @
337a8089
...
@@ -10,21 +10,33 @@ package com.nepxion.discovery.console.extension.nacos.adapter;
...
@@ -10,21 +10,33 @@ package com.nepxion.discovery.console.extension.nacos.adapter;
*/
*/
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.core.env.Environment
;
import
com.alibaba.nacos.api.config.ConfigService
;
import
com.alibaba.nacos.api.config.ConfigService
;
import
com.nepxion.discovery.console.extension.nacos.constant.NacosConstant
;
import
com.nepxion.discovery.console.remote.ConfigAdapter
;
import
com.nepxion.discovery.console.remote.ConfigAdapter
;
public
class
NacosConfigAdapter
implements
ConfigAdapter
{
public
class
NacosConfigAdapter
implements
ConfigAdapter
{
@Autowired
@Autowired
private
ConfigService
configService
;
private
ConfigService
configService
;
@Autowired
private
Environment
environment
;
@Override
@Override
public
boolean
configUpdate
(
String
group
,
String
serviceId
,
String
config
)
throws
Exception
{
public
boolean
updateConfig
(
String
group
,
String
serviceId
,
String
config
)
throws
Exception
{
return
configService
.
publishConfig
(
serviceId
,
group
,
config
);
return
configService
.
publishConfig
(
serviceId
,
group
,
config
);
}
}
@Override
@Override
public
boolean
c
onfigClear
(
String
group
,
String
serviceId
)
throws
Exception
{
public
boolean
c
learConfig
(
String
group
,
String
serviceId
)
throws
Exception
{
return
configService
.
removeConfig
(
serviceId
,
group
);
return
configService
.
removeConfig
(
serviceId
,
group
);
}
}
@Override
public
String
getConfig
(
String
group
,
String
serviceId
)
throws
Exception
{
long
timeout
=
environment
.
getProperty
(
NacosConstant
.
TIMEOUT
,
Long
.
class
,
NacosConstant
.
DEFAULT_TIMEOUT
);
return
configService
.
getConfig
(
serviceId
,
group
,
timeout
);
}
}
}
\ No newline at end of file
discovery-console-extension-nacos/src/main/java/com/nepxion/discovery/console/extension/nacos/constant/NacosConstant.java
View file @
337a8089
...
@@ -13,4 +13,6 @@ public class NacosConstant {
...
@@ -13,4 +13,6 @@ public class NacosConstant {
public
static
final
String
URL_KEY
=
"serverAddr"
;
public
static
final
String
URL_KEY
=
"serverAddr"
;
public
static
final
String
URL
=
"nacos.url"
;
public
static
final
String
URL
=
"nacos.url"
;
public
static
final
String
TIMEOUT
=
"nacos.timout"
;
public
static
final
String
TIMEOUT
=
"nacos.timout"
;
public
static
final
long
DEFAULT_TIMEOUT
=
30000
;
}
}
\ No newline at end of file
discovery-console/src/main/java/com/nepxion/discovery/console/endpoint/ConsoleEndpoint.java
View file @
337a8089
...
@@ -86,7 +86,13 @@ public class ConsoleEndpoint {
...
@@ -86,7 +86,13 @@ public class ConsoleEndpoint {
@RequestMapping
(
path
=
"/console/remote-config/clear/{group}/{serviceId}"
,
method
=
RequestMethod
.
POST
)
@RequestMapping
(
path
=
"/console/remote-config/clear/{group}/{serviceId}"
,
method
=
RequestMethod
.
POST
)
@ApiOperation
(
value
=
"清除规则配置信息到远程配置中心"
,
notes
=
""
,
response
=
ResponseEntity
.
class
,
httpMethod
=
"POST"
)
@ApiOperation
(
value
=
"清除规则配置信息到远程配置中心"
,
notes
=
""
,
response
=
ResponseEntity
.
class
,
httpMethod
=
"POST"
)
public
ResponseEntity
<?>
remoteConfigClear
(
@PathVariable
(
value
=
"group"
)
@ApiParam
(
value
=
"组名"
,
required
=
true
)
String
group
,
@PathVariable
(
value
=
"serviceId"
)
@ApiParam
(
value
=
"服务名"
,
required
=
true
)
String
serviceId
)
{
public
ResponseEntity
<?>
remoteConfigClear
(
@PathVariable
(
value
=
"group"
)
@ApiParam
(
value
=
"组名"
,
required
=
true
)
String
group
,
@PathVariable
(
value
=
"serviceId"
)
@ApiParam
(
value
=
"服务名"
,
required
=
true
)
String
serviceId
)
{
return
executeRemoteClearUpdate
(
group
,
serviceId
);
return
executeRemoteConfigClear
(
group
,
serviceId
);
}
@RequestMapping
(
path
=
"/console/remote-config/view/{group}/{serviceId}"
,
method
=
RequestMethod
.
GET
)
@ApiOperation
(
value
=
"查看远程配置中心的规则配置信息"
,
notes
=
""
,
response
=
ResponseEntity
.
class
,
httpMethod
=
"GET"
)
public
ResponseEntity
<?>
remoteConfigView
(
@PathVariable
(
value
=
"group"
)
@ApiParam
(
value
=
"组名"
,
required
=
true
)
String
group
,
@PathVariable
(
value
=
"serviceId"
)
@ApiParam
(
value
=
"服务名"
,
required
=
true
)
String
serviceId
)
{
return
executeRemoteConfigView
(
group
,
serviceId
);
}
}
@RequestMapping
(
path
=
"/console/config/update-async/{serviceId}"
,
method
=
RequestMethod
.
POST
)
@RequestMapping
(
path
=
"/console/config/update-async/{serviceId}"
,
method
=
RequestMethod
.
POST
)
...
@@ -169,7 +175,7 @@ public class ConsoleEndpoint {
...
@@ -169,7 +175,7 @@ public class ConsoleEndpoint {
}
}
try
{
try
{
boolean
result
=
configAdapter
.
configUpdate
(
group
,
serviceId
,
config
);
boolean
result
=
configAdapter
.
updateConfig
(
group
,
serviceId
,
config
);
return
ResponseEntity
.
ok
().
body
(
result
?
"OK"
:
"NO"
);
return
ResponseEntity
.
ok
().
body
(
result
?
"OK"
:
"NO"
);
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
...
@@ -177,7 +183,7 @@ public class ConsoleEndpoint {
...
@@ -177,7 +183,7 @@ public class ConsoleEndpoint {
}
}
}
}
private
ResponseEntity
<?>
executeRemoteC
learUpdate
(
String
group
,
String
serviceId
)
{
private
ResponseEntity
<?>
executeRemoteC
onfigClear
(
String
group
,
String
serviceId
)
{
if
(
configAdapter
==
null
)
{
if
(
configAdapter
==
null
)
{
LOG
.
error
(
"Remote config adapter isn't provided"
);
LOG
.
error
(
"Remote config adapter isn't provided"
);
...
@@ -185,7 +191,7 @@ public class ConsoleEndpoint {
...
@@ -185,7 +191,7 @@ public class ConsoleEndpoint {
}
}
try
{
try
{
boolean
result
=
configAdapter
.
c
onfigClear
(
group
,
serviceId
);
boolean
result
=
configAdapter
.
c
learConfig
(
group
,
serviceId
);
return
ResponseEntity
.
ok
().
body
(
result
?
"OK"
:
"NO"
);
return
ResponseEntity
.
ok
().
body
(
result
?
"OK"
:
"NO"
);
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
...
@@ -193,6 +199,22 @@ public class ConsoleEndpoint {
...
@@ -193,6 +199,22 @@ public class ConsoleEndpoint {
}
}
}
}
private
ResponseEntity
<?>
executeRemoteConfigView
(
String
group
,
String
serviceId
)
{
if
(
configAdapter
==
null
)
{
LOG
.
error
(
"Remote config adapter isn't provided"
);
return
ResponseEntity
.
status
(
HttpStatus
.
INTERNAL_SERVER_ERROR
).
body
(
"Remote config adapter isn't provided"
);
}
try
{
String
config
=
configAdapter
.
getConfig
(
group
,
serviceId
);
return
ResponseEntity
.
ok
().
body
(
config
);
}
catch
(
Exception
e
)
{
return
ResponseEntity
.
status
(
HttpStatus
.
INTERNAL_SERVER_ERROR
).
body
(
e
.
getMessage
());
}
}
private
ResponseEntity
<?>
executeConfigUpdate
(
String
serviceId
,
String
config
,
boolean
async
)
{
private
ResponseEntity
<?>
executeConfigUpdate
(
String
serviceId
,
String
config
,
boolean
async
)
{
List
<
ServiceInstance
>
serviceInstances
=
getInstances
(
serviceId
);
List
<
ServiceInstance
>
serviceInstances
=
getInstances
(
serviceId
);
...
...
discovery-console/src/main/java/com/nepxion/discovery/console/remote/ConfigAdapter.java
View file @
337a8089
...
@@ -10,7 +10,9 @@ package com.nepxion.discovery.console.remote;
...
@@ -10,7 +10,9 @@ package com.nepxion.discovery.console.remote;
*/
*/
public
interface
ConfigAdapter
{
public
interface
ConfigAdapter
{
boolean
configUpdate
(
String
group
,
String
serviceId
,
String
config
)
throws
Exception
;
boolean
updateConfig
(
String
group
,
String
serviceId
,
String
config
)
throws
Exception
;
boolean
configClear
(
String
group
,
String
serviceId
)
throws
Exception
;
boolean
clearConfig
(
String
group
,
String
serviceId
)
throws
Exception
;
String
getConfig
(
String
group
,
String
serviceId
)
throws
Exception
;
}
}
\ No newline at end of file
discovery-plugin-config-center-extension-nacos/src/main/java/com/nepxion/discovery/plugin/configcenter/extension/nacos/adapter/NacosConfigAdapter.java
View file @
337a8089
...
@@ -50,7 +50,7 @@ public class NacosConfigAdapter extends ConfigAdapter {
...
@@ -50,7 +50,7 @@ public class NacosConfigAdapter extends ConfigAdapter {
String
group
=
pluginAdapter
.
getGroup
();
String
group
=
pluginAdapter
.
getGroup
();
String
serviceId
=
pluginAdapter
.
getServiceId
();
String
serviceId
=
pluginAdapter
.
getServiceId
();
long
timeout
=
pluginContextAware
.
getEnvironment
().
getProperty
(
NacosConstant
.
TIMEOUT
,
Long
.
class
);
long
timeout
=
pluginContextAware
.
getEnvironment
().
getProperty
(
NacosConstant
.
TIMEOUT
,
Long
.
class
,
NacosConstant
.
DEFAULT_TIMEOUT
);
LOG
.
info
(
"Get remote config from Nacos server, {}={}, serviceId={}, timeout={}"
,
groupKey
,
group
,
serviceId
,
timeout
);
LOG
.
info
(
"Get remote config from Nacos server, {}={}, serviceId={}, timeout={}"
,
groupKey
,
group
,
serviceId
,
timeout
);
...
@@ -63,7 +63,7 @@ public class NacosConfigAdapter extends ConfigAdapter {
...
@@ -63,7 +63,7 @@ public class NacosConfigAdapter extends ConfigAdapter {
}
}
@PostConstruct
@PostConstruct
public
void
subscribe
()
throws
Exception
{
public
void
subscribe
Config
()
throws
Exception
{
String
groupKey
=
pluginContextAware
.
getGroupKey
();
String
groupKey
=
pluginContextAware
.
getGroupKey
();
String
group
=
pluginAdapter
.
getGroup
();
String
group
=
pluginAdapter
.
getGroup
();
String
serviceId
=
pluginAdapter
.
getServiceId
();
String
serviceId
=
pluginAdapter
.
getServiceId
();
...
...
discovery-plugin-config-center-extension-nacos/src/main/java/com/nepxion/discovery/plugin/configcenter/extension/nacos/constant/NacosConstant.java
View file @
337a8089
...
@@ -13,4 +13,6 @@ public class NacosConstant {
...
@@ -13,4 +13,6 @@ public class NacosConstant {
public
static
final
String
URL_KEY
=
"serverAddr"
;
public
static
final
String
URL_KEY
=
"serverAddr"
;
public
static
final
String
URL
=
"nacos.url"
;
public
static
final
String
URL
=
"nacos.url"
;
public
static
final
String
TIMEOUT
=
"nacos.timout"
;
public
static
final
String
TIMEOUT
=
"nacos.timout"
;
public
static
final
long
DEFAULT_TIMEOUT
=
30000
;
}
}
\ No newline at end of file
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