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
201477bb
Commit
201477bb
authored
Jul 09, 2018
by
Nepxion
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
优化版本设置策略
parent
4c9cd5a5
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
74 additions
and
11 deletions
+74
-11
discovery-plugin-admin-center/src/main/java/com/nepxion/discovery/plugin/admincenter/endpoint/VersionEndpoint.java
+2
-6
discovery-plugin-framework/src/main/java/com/nepxion/discovery/plugin/framework/event/PluginSubscriber.java
+39
-4
discovery-plugin-framework/src/main/java/com/nepxion/discovery/plugin/framework/event/VersionChangedEvent.java
+33
-1
No files found.
discovery-plugin-admin-center/src/main/java/com/nepxion/discovery/plugin/admincenter/endpoint/VersionEndpoint.java
View file @
201477bb
...
...
@@ -59,9 +59,7 @@ public class VersionEndpoint implements MvcEndpoint {
return
new
ResponseEntity
<>(
Collections
.
singletonMap
(
"Message"
,
"Discovery control is disabled"
),
HttpStatus
.
NOT_FOUND
);
}
pluginAdapter
.
setDynamicVersion
(
version
);
pluginEventWapper
.
fireVersionChanged
(
new
VersionChangedEvent
(),
true
);
pluginEventWapper
.
fireVersionChanged
(
new
VersionChangedEvent
(
VersionChangedEvent
.
EventType
.
VERSION_UPDATE
,
version
),
true
);
return
ResponseEntity
.
ok
().
body
(
"OK"
);
}
...
...
@@ -76,9 +74,7 @@ public class VersionEndpoint implements MvcEndpoint {
return
new
ResponseEntity
<>(
Collections
.
singletonMap
(
"Message"
,
"Discovery control is disabled"
),
HttpStatus
.
NOT_FOUND
);
}
pluginAdapter
.
clearDynamicVersion
();
pluginEventWapper
.
fireVersionChanged
(
new
VersionChangedEvent
(),
true
);
pluginEventWapper
.
fireVersionChanged
(
new
VersionChangedEvent
(
VersionChangedEvent
.
EventType
.
VERSION_CLEAR
),
true
);
return
ResponseEntity
.
ok
().
body
(
"OK"
);
}
...
...
discovery-plugin-framework/src/main/java/com/nepxion/discovery/plugin/framework/event/PluginSubscriber.java
View file @
201477bb
...
...
@@ -16,8 +16,10 @@ import org.slf4j.LoggerFactory;
import
org.springframework.beans.factory.annotation.Autowired
;
import
com.google.common.eventbus.Subscribe
;
import
com.nepxion.discovery.plugin.framework.adapter.PluginAdapter
;
import
com.nepxion.discovery.plugin.framework.config.PluginConfigParser
;
import
com.nepxion.discovery.plugin.framework.context.PluginContextAware
;
import
com.nepxion.discovery.plugin.framework.exception.PluginException
;
import
com.nepxion.discovery.plugin.framework.listener.loadbalance.LoadBalanceListenerExecutor
;
import
com.nepxion.eventbus.annotation.EventBus
;
import
com.netflix.loadbalancer.ZoneAwareLoadBalancer
;
...
...
@@ -30,6 +32,9 @@ public class PluginSubscriber {
private
PluginContextAware
pluginContextAware
;
@Autowired
private
PluginAdapter
pluginAdapter
;
@Autowired
private
PluginConfigParser
pluninConfigParser
;
@Autowired
...
...
@@ -54,10 +59,14 @@ public class PluginSubscriber {
LOG
.
info
(
"********** Remote config change has been subscribed **********"
);
if
(
ruleChangedEvent
==
null
)
{
throw
new
PluginException
(
"RuleChangedEvent can't be null"
);
}
InputStream
inputStream
=
ruleChangedEvent
.
getInputStream
();
pluninConfigParser
.
parse
(
inputStream
);
onVersionChanged
(
null
);
refreshLoadBalancer
(
);
}
@Subscribe
...
...
@@ -69,14 +78,39 @@ public class PluginSubscriber {
return
;
}
LOG
.
info
(
"********** Version change has been subscribed **********"
);
if
(
versionChangedEvent
==
null
)
{
throw
new
PluginException
(
"VersionChangedEvent can't be null"
);
}
VersionChangedEvent
.
EventType
eventType
=
versionChangedEvent
.
getEventType
();
switch
(
eventType
)
{
case
VERSION_UPDATE:
String
version
=
versionChangedEvent
.
getVersion
();
pluginAdapter
.
setDynamicVersion
(
version
);
LOG
.
info
(
"********** Version has been updated, new version is {} **********"
,
version
);
break
;
case
VERSION_CLEAR:
pluginAdapter
.
clearDynamicVersion
();
LOG
.
info
(
"********** Version has been cleared **********"
);
break
;
}
refreshLoadBalancer
();
}
private
void
refreshLoadBalancer
()
{
ZoneAwareLoadBalancer
<?>
loadBalancer
=
loadBalanceListenerExecutor
.
getLoadBalancer
();
if
(
loadBalancer
==
null
)
{
return
;
}
LOG
.
info
(
"********** Version change has been subscribed **********"
);
// 当版本更新后,强制刷新Ribbon缓存
// 当规则或者版本更新后,强制刷新Ribbon缓存
loadBalancer
.
updateListOfServers
();
}
}
\ No newline at end of file
discovery-plugin-framework/src/main/java/com/nepxion/discovery/plugin/framework/event/VersionChangedEvent.java
View file @
201477bb
...
...
@@ -11,10 +11,41 @@ package com.nepxion.discovery.plugin.framework.event;
import
java.io.Serializable
;
import
org.apache.commons.lang3.StringUtils
;
import
com.nepxion.discovery.plugin.framework.exception.PluginException
;
public
class
VersionChangedEvent
implements
Serializable
{
private
static
final
long
serialVersionUID
=
5079797986381461496L
;
public
VersionChangedEvent
()
{
public
enum
EventType
{
VERSION_UPDATE
,
VERSION_CLEAR
;
}
private
EventType
eventType
;
private
String
version
;
public
VersionChangedEvent
(
EventType
eventType
)
{
this
(
eventType
,
null
);
}
public
VersionChangedEvent
(
EventType
eventType
,
String
version
)
{
if
(
eventType
==
EventType
.
VERSION_UPDATE
&&
StringUtils
.
isEmpty
(
version
))
{
throw
new
PluginException
(
"Version value can't be null or empty while updating"
);
}
this
.
eventType
=
eventType
;
if
(
StringUtils
.
isNotEmpty
(
version
))
{
this
.
version
=
version
.
trim
();
}
}
public
EventType
getEventType
()
{
return
eventType
;
}
public
String
getVersion
()
{
return
version
;
}
}
\ 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