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
fc0312eb
Commit
fc0312eb
authored
Jul 11, 2018
by
Nepxion
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
把版本更新和清除拆分成两个事件
parent
31847c48
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
127 additions
and
48 deletions
+127
-48
discovery-plugin-admin-center/src/main/java/com/nepxion/discovery/plugin/admincenter/endpoint/VersionEndpoint.java
+4
-3
discovery-plugin-framework/src/main/java/com/nepxion/discovery/plugin/framework/event/PluginEventWapper.java
+12
-3
discovery-plugin-framework/src/main/java/com/nepxion/discovery/plugin/framework/event/PluginSubscriber.java
+51
-16
discovery-plugin-framework/src/main/java/com/nepxion/discovery/plugin/framework/event/VersionClearedEvent.java
+10
-26
discovery-plugin-framework/src/main/java/com/nepxion/discovery/plugin/framework/event/VersionUpdatedEvent.java
+50
-0
No files found.
discovery-plugin-admin-center/src/main/java/com/nepxion/discovery/plugin/admincenter/endpoint/VersionEndpoint.java
View file @
fc0312eb
...
@@ -33,7 +33,8 @@ import org.springframework.web.bind.annotation.RestController;
...
@@ -33,7 +33,8 @@ import org.springframework.web.bind.annotation.RestController;
import
com.nepxion.discovery.plugin.framework.adapter.PluginAdapter
;
import
com.nepxion.discovery.plugin.framework.adapter.PluginAdapter
;
import
com.nepxion.discovery.plugin.framework.context.PluginContextAware
;
import
com.nepxion.discovery.plugin.framework.context.PluginContextAware
;
import
com.nepxion.discovery.plugin.framework.event.PluginEventWapper
;
import
com.nepxion.discovery.plugin.framework.event.PluginEventWapper
;
import
com.nepxion.discovery.plugin.framework.event.VersionChangedEvent
;
import
com.nepxion.discovery.plugin.framework.event.VersionClearedEvent
;
import
com.nepxion.discovery.plugin.framework.event.VersionUpdatedEvent
;
@RestController
@RestController
@Api
(
tags
=
{
"版本接口"
})
@Api
(
tags
=
{
"版本接口"
})
...
@@ -58,7 +59,7 @@ public class VersionEndpoint implements MvcEndpoint {
...
@@ -58,7 +59,7 @@ public class VersionEndpoint implements MvcEndpoint {
return
ResponseEntity
.
status
(
HttpStatus
.
INTERNAL_SERVER_ERROR
).
body
(
"Discovery control is disabled"
);
return
ResponseEntity
.
status
(
HttpStatus
.
INTERNAL_SERVER_ERROR
).
body
(
"Discovery control is disabled"
);
}
}
pluginEventWapper
.
fireVersion
Changed
(
new
VersionChangedEvent
(
VersionChangedEvent
.
EventType
.
VERSION_UPDATE
,
version
),
true
);
pluginEventWapper
.
fireVersion
Updated
(
new
VersionUpdatedEvent
(
version
),
true
);
return
ResponseEntity
.
ok
().
body
(
"OK"
);
return
ResponseEntity
.
ok
().
body
(
"OK"
);
}
}
...
@@ -73,7 +74,7 @@ public class VersionEndpoint implements MvcEndpoint {
...
@@ -73,7 +74,7 @@ public class VersionEndpoint implements MvcEndpoint {
return
ResponseEntity
.
status
(
HttpStatus
.
INTERNAL_SERVER_ERROR
).
body
(
"Discovery control is disabled"
);
return
ResponseEntity
.
status
(
HttpStatus
.
INTERNAL_SERVER_ERROR
).
body
(
"Discovery control is disabled"
);
}
}
pluginEventWapper
.
fireVersionC
hanged
(
new
VersionChangedEvent
(
VersionChangedEvent
.
EventType
.
VERSION_CLEAR
),
true
);
pluginEventWapper
.
fireVersionC
leared
(
new
VersionClearedEvent
(
),
true
);
return
ResponseEntity
.
ok
().
body
(
"OK"
);
return
ResponseEntity
.
ok
().
body
(
"OK"
);
}
}
...
...
discovery-plugin-framework/src/main/java/com/nepxion/discovery/plugin/framework/event/PluginEventWapper.java
View file @
fc0312eb
...
@@ -26,11 +26,19 @@ public class PluginEventWapper {
...
@@ -26,11 +26,19 @@ public class PluginEventWapper {
}
}
}
}
public
void
fireVersion
Changed
(
VersionChangedEvent
versionChang
edEvent
,
boolean
async
)
{
public
void
fireVersion
Updated
(
VersionUpdatedEvent
versionUpdat
edEvent
,
boolean
async
)
{
if
(
async
)
{
if
(
async
)
{
pluginPublisher
.
asyncPublish
(
version
Chang
edEvent
);
pluginPublisher
.
asyncPublish
(
version
Updat
edEvent
);
}
else
{
}
else
{
pluginSubscriber
.
onVersionChanged
(
versionChangedEvent
);
pluginSubscriber
.
onVersionUpdated
(
versionUpdatedEvent
);
}
}
public
void
fireVersionCleared
(
VersionClearedEvent
versionClearedEvent
,
boolean
async
)
{
if
(
async
)
{
pluginPublisher
.
asyncPublish
(
versionClearedEvent
);
}
else
{
pluginSubscriber
.
onVersionCleared
(
versionClearedEvent
);
}
}
}
}
}
}
\ No newline at end of file
discovery-plugin-framework/src/main/java/com/nepxion/discovery/plugin/framework/event/PluginSubscriber.java
View file @
fc0312eb
...
@@ -11,6 +11,7 @@ package com.nepxion.discovery.plugin.framework.event;
...
@@ -11,6 +11,7 @@ package com.nepxion.discovery.plugin.framework.event;
import
java.io.InputStream
;
import
java.io.InputStream
;
import
org.apache.commons.lang3.StringUtils
;
import
org.slf4j.Logger
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
...
@@ -57,7 +58,7 @@ public class PluginSubscriber {
...
@@ -57,7 +58,7 @@ public class PluginSubscriber {
return
;
return
;
}
}
LOG
.
info
(
"********** Remote config chang
e has been subscrib
ed **********"
);
LOG
.
info
(
"********** Remote config chang
ing has been trigger
ed **********"
);
if
(
ruleChangedEvent
==
null
)
{
if
(
ruleChangedEvent
==
null
)
{
throw
new
PluginException
(
"RuleChangedEvent can't be null"
);
throw
new
PluginException
(
"RuleChangedEvent can't be null"
);
...
@@ -76,7 +77,7 @@ public class PluginSubscriber {
...
@@ -76,7 +77,7 @@ public class PluginSubscriber {
}
}
@Subscribe
@Subscribe
public
void
onVersion
Changed
(
VersionChangedEvent
versionChang
edEvent
)
{
public
void
onVersion
Updated
(
VersionUpdatedEvent
versionUpdat
edEvent
)
{
Boolean
discoveryControlEnabled
=
pluginContextAware
.
isDiscoveryControlEnabled
();
Boolean
discoveryControlEnabled
=
pluginContextAware
.
isDiscoveryControlEnabled
();
if
(!
discoveryControlEnabled
)
{
if
(!
discoveryControlEnabled
)
{
LOG
.
info
(
"********** Discovery control is disabled, ignore to subscribe **********"
);
LOG
.
info
(
"********** Discovery control is disabled, ignore to subscribe **********"
);
...
@@ -84,30 +85,64 @@ public class PluginSubscriber {
...
@@ -84,30 +85,64 @@ public class PluginSubscriber {
return
;
return
;
}
}
LOG
.
info
(
"********** Version
change has been subscrib
ed **********"
);
LOG
.
info
(
"********** Version
updating has been trigger
ed **********"
);
if
(
version
Chang
edEvent
==
null
)
{
if
(
version
Updat
edEvent
==
null
)
{
throw
new
PluginException
(
"Version
Chang
edEvent can't be null"
);
throw
new
PluginException
(
"Version
Updat
edEvent can't be null"
);
}
}
VersionChangedEvent
.
EventType
eventType
=
versionChangedEvent
.
getEventType
();
String
dynamicVersion
=
versionUpdatedEvent
.
getDynamicVersion
();
switch
(
eventType
)
{
String
localVersion
=
versionUpdatedEvent
.
getLocalVersion
();
case
VERSION_UPDATE:
String
version
=
versionChangedEvent
.
getVersion
();
pluginAdapter
.
setDynamicVersion
(
version
);
LOG
.
info
(
"********** Version has been updated, new version is {} **********"
,
version
);
if
(
StringUtils
.
isEmpty
(
localVersion
))
{
pluginAdapter
.
setDynamicVersion
(
dynamicVersion
);
break
;
refreshLoadBalancer
();
case
VERSION_CLEAR:
pluginAdapter
.
clearDynamicVersion
();
LOG
.
info
(
"********** Version has been cleared **********"
);
LOG
.
info
(
"********** Version has been updated, new version is {} **********"
,
dynamicVersion
);
}
else
{
if
(
StringUtils
.
equals
(
pluginAdapter
.
getLocalVersion
(),
localVersion
))
{
pluginAdapter
.
setDynamicVersion
(
dynamicVersion
);
refreshLoadBalancer
();
LOG
.
info
(
"********** Version has been updated, new version is {} **********"
,
dynamicVersion
);
}
}
}
@Subscribe
public
void
onVersionCleared
(
VersionClearedEvent
versionClearedEvent
)
{
Boolean
discoveryControlEnabled
=
pluginContextAware
.
isDiscoveryControlEnabled
();
if
(!
discoveryControlEnabled
)
{
LOG
.
info
(
"********** Discovery control is disabled, ignore to subscribe **********"
);
return
;
}
break
;
LOG
.
info
(
"********** Version clearing has been triggered **********"
);
if
(
versionClearedEvent
==
null
)
{
throw
new
PluginException
(
"VersionClearedEvent can't be null"
);
}
}
String
localVersion
=
versionClearedEvent
.
getLocalVersion
();
if
(
StringUtils
.
isEmpty
(
localVersion
))
{
pluginAdapter
.
clearDynamicVersion
();
refreshLoadBalancer
();
refreshLoadBalancer
();
LOG
.
info
(
"********** Version has been cleared **********"
);
}
else
{
if
(
StringUtils
.
equals
(
pluginAdapter
.
getLocalVersion
(),
localVersion
))
{
pluginAdapter
.
clearDynamicVersion
();
refreshLoadBalancer
();
LOG
.
info
(
"********** Version has been cleared **********"
);
}
}
}
}
private
void
refreshLoadBalancer
()
{
private
void
refreshLoadBalancer
()
{
...
...
discovery-plugin-framework/src/main/java/com/nepxion/discovery/plugin/framework/event/VersionC
hang
edEvent.java
→
discovery-plugin-framework/src/main/java/com/nepxion/discovery/plugin/framework/event/VersionC
lear
edEvent.java
View file @
fc0312eb
...
@@ -13,39 +13,22 @@ import java.io.Serializable;
...
@@ -13,39 +13,22 @@ import java.io.Serializable;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
com.nepxion.discovery.plugin.framework.exception.PluginException
;
public
class
VersionClearedEvent
implements
Serializable
{
public
class
VersionChangedEvent
implements
Serializable
{
private
static
final
long
serialVersionUID
=
5079797986381461496L
;
private
static
final
long
serialVersionUID
=
5079797986381461496L
;
public
enum
EventType
{
private
String
localVersion
;
VERSION_UPDATE
,
VERSION_CLEAR
;
}
private
EventType
eventType
;
private
String
version
;
public
VersionC
hangedEvent
(
EventType
eventType
)
{
public
VersionC
learedEvent
(
)
{
this
(
eventType
,
null
);
this
(
null
);
}
}
public
VersionC
hangedEvent
(
EventType
eventType
,
String
v
ersion
)
{
public
VersionC
learedEvent
(
String
localV
ersion
)
{
if
(
eventType
==
EventType
.
VERSION_UPDATE
&&
StringUtils
.
isEmpty
(
v
ersion
))
{
if
(
StringUtils
.
isNotEmpty
(
localV
ersion
))
{
th
row
new
PluginException
(
"Version value can't be null or empty while updating"
);
th
is
.
localVersion
=
localVersion
.
trim
(
);
}
}
this
.
eventType
=
eventType
;
if
(
StringUtils
.
isNotEmpty
(
version
))
{
this
.
version
=
version
.
trim
();
}
}
public
EventType
getEventType
()
{
return
eventType
;
}
}
public
String
getVersion
()
{
public
String
get
Local
Version
()
{
return
v
ersion
;
return
localV
ersion
;
}
}
}
}
\ No newline at end of file
discovery-plugin-framework/src/main/java/com/nepxion/discovery/plugin/framework/event/VersionUpdatedEvent.java
0 → 100644
View file @
fc0312eb
package
com
.
nepxion
.
discovery
.
plugin
.
framework
.
event
;
/**
* <p>Title: Nepxion Discovery</p>
* <p>Description: Nepxion Discovery</p>
* <p>Copyright: Copyright (c) 2017-2050</p>
* <p>Company: Nepxion</p>
* @author Haojun Ren
* @version 1.0
*/
import
java.io.Serializable
;
import
org.apache.commons.lang3.StringUtils
;
import
com.nepxion.discovery.plugin.framework.exception.PluginException
;
public
class
VersionUpdatedEvent
implements
Serializable
{
private
static
final
long
serialVersionUID
=
7749946311426379329L
;
private
String
dynamicVersion
;
private
String
localVersion
;
public
VersionUpdatedEvent
(
String
dynamicVersion
)
{
this
(
dynamicVersion
,
null
);
}
public
VersionUpdatedEvent
(
String
dynamicVersion
,
String
localVersion
)
{
if
(
StringUtils
.
isNotEmpty
(
dynamicVersion
))
{
this
.
dynamicVersion
=
dynamicVersion
.
trim
();
}
if
(
StringUtils
.
isEmpty
(
this
.
dynamicVersion
))
{
throw
new
PluginException
(
"Dynamic version can't be null or empty while updating"
);
}
if
(
StringUtils
.
isNotEmpty
(
localVersion
))
{
this
.
localVersion
=
localVersion
.
trim
();
}
}
public
String
getDynamicVersion
()
{
return
dynamicVersion
;
}
public
String
getLocalVersion
()
{
return
localVersion
;
}
}
\ 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