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
65a36238
Commit
65a36238
authored
Jul 17, 2018
by
Nepxion
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
增加动态版本功能
parent
1ec065cd
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
88 additions
and
9 deletions
+88
-9
discovery-console/src/main/java/com/nepxion/discovery/console/endpoint/ConsoleEndpoint.java
+15
-0
discovery-console/src/main/java/com/nepxion/discovery/console/rest/ConfigClearRestInvoker.java
+37
-0
discovery-plugin-admin-center/src/main/java/com/nepxion/discovery/plugin/admincenter/endpoint/ConfigEndpoint.java
+34
-7
discovery-plugin-framework/src/main/java/com/nepxion/discovery/plugin/framework/cache/RuleCache.java
+2
-2
No files found.
discovery-console/src/main/java/com/nepxion/discovery/console/endpoint/ConsoleEndpoint.java
View file @
65a36238
...
@@ -30,6 +30,7 @@ import org.springframework.web.bind.annotation.RestController;
...
@@ -30,6 +30,7 @@ import org.springframework.web.bind.annotation.RestController;
import
org.springframework.web.client.RestTemplate
;
import
org.springframework.web.client.RestTemplate
;
import
com.nepxion.discovery.console.entity.InstanceEntity
;
import
com.nepxion.discovery.console.entity.InstanceEntity
;
import
com.nepxion.discovery.console.rest.ConfigClearRestInvoker
;
import
com.nepxion.discovery.console.rest.ConfigUpdateRestInvoker
;
import
com.nepxion.discovery.console.rest.ConfigUpdateRestInvoker
;
import
com.nepxion.discovery.console.rest.VersionClearRestInvoker
;
import
com.nepxion.discovery.console.rest.VersionClearRestInvoker
;
import
com.nepxion.discovery.console.rest.VersionUpdateRestInvoker
;
import
com.nepxion.discovery.console.rest.VersionUpdateRestInvoker
;
...
@@ -79,6 +80,12 @@ public class ConsoleEndpoint {
...
@@ -79,6 +80,12 @@ public class ConsoleEndpoint {
return
executeConfigUpdate
(
serviceId
,
config
,
false
);
return
executeConfigUpdate
(
serviceId
,
config
,
false
);
}
}
@RequestMapping
(
path
=
"/console/config/clear/{serviceId}"
,
method
=
RequestMethod
.
POST
)
@ApiOperation
(
value
=
"批量清除更新的规则配置信息"
,
notes
=
""
,
response
=
ResponseEntity
.
class
,
httpMethod
=
"POST"
)
public
ResponseEntity
<?>
configClear
(
@PathVariable
(
value
=
"serviceId"
)
@ApiParam
(
value
=
"服务名"
,
required
=
true
)
String
serviceId
)
{
return
executeConfigClear
(
serviceId
);
}
@RequestMapping
(
path
=
"/console/version/update/{serviceId}"
,
method
=
RequestMethod
.
POST
)
@RequestMapping
(
path
=
"/console/version/update/{serviceId}"
,
method
=
RequestMethod
.
POST
)
@ApiOperation
(
value
=
"批量更新服务的动态版本"
,
notes
=
"根据指定的localVersion更新服务的dynamicVersion。如果输入的localVersion不匹配服务的localVersion,则忽略;如果如果输入的localVersion为空,则直接更新服务的dynamicVersion"
,
response
=
ResponseEntity
.
class
,
httpMethod
=
"POST"
)
@ApiOperation
(
value
=
"批量更新服务的动态版本"
,
notes
=
"根据指定的localVersion更新服务的dynamicVersion。如果输入的localVersion不匹配服务的localVersion,则忽略;如果如果输入的localVersion为空,则直接更新服务的dynamicVersion"
,
response
=
ResponseEntity
.
class
,
httpMethod
=
"POST"
)
public
ResponseEntity
<?>
versionUpdate
(
@PathVariable
(
value
=
"serviceId"
)
@ApiParam
(
value
=
"服务名"
,
required
=
true
)
String
serviceId
,
@RequestBody
@ApiParam
(
value
=
"版本号,格式为[dynamicVersion]或者[dynamicVersion];[localVersion]"
,
required
=
true
)
String
version
)
{
public
ResponseEntity
<?>
versionUpdate
(
@PathVariable
(
value
=
"serviceId"
)
@ApiParam
(
value
=
"服务名"
,
required
=
true
)
String
serviceId
,
@RequestBody
@ApiParam
(
value
=
"版本号,格式为[dynamicVersion]或者[dynamicVersion];[localVersion]"
,
required
=
true
)
String
version
)
{
...
@@ -139,6 +146,14 @@ public class ConsoleEndpoint {
...
@@ -139,6 +146,14 @@ public class ConsoleEndpoint {
return
configUpdateRestInvoker
.
invoke
();
return
configUpdateRestInvoker
.
invoke
();
}
}
private
ResponseEntity
<?>
executeConfigClear
(
String
serviceId
)
{
List
<
ServiceInstance
>
serviceInstances
=
getInstances
(
serviceId
);
ConfigClearRestInvoker
configClearRestInvoker
=
new
ConfigClearRestInvoker
(
serviceInstances
,
consoleRestTemplate
);
return
configClearRestInvoker
.
invoke
();
}
private
ResponseEntity
<?>
executeVersionUpdate
(
String
serviceId
,
String
version
)
{
private
ResponseEntity
<?>
executeVersionUpdate
(
String
serviceId
,
String
version
)
{
List
<
ServiceInstance
>
serviceInstances
=
getInstances
(
serviceId
);
List
<
ServiceInstance
>
serviceInstances
=
getInstances
(
serviceId
);
...
...
discovery-console/src/main/java/com/nepxion/discovery/console/rest/ConfigClearRestInvoker.java
0 → 100644
View file @
65a36238
package
com
.
nepxion
.
discovery
.
console
.
rest
;
/**
* <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.util.List
;
import
org.springframework.cloud.client.ServiceInstance
;
import
org.springframework.web.client.RestTemplate
;
public
class
ConfigClearRestInvoker
extends
AbstractRestInvoker
{
public
ConfigClearRestInvoker
(
List
<
ServiceInstance
>
serviceInstances
,
RestTemplate
restTemplate
)
{
super
(
serviceInstances
,
restTemplate
);
}
@Override
protected
String
getInfo
()
{
return
"Config cleared"
;
}
@Override
protected
String
getUrl
(
String
host
,
int
port
)
{
return
"http://"
+
host
+
":"
+
port
+
"/config/clear"
;
}
@Override
protected
String
doRest
(
String
url
)
{
return
restTemplate
.
postForEntity
(
url
,
null
,
String
.
class
).
getBody
();
}
}
\ No newline at end of file
discovery-plugin-admin-center/src/main/java/com/nepxion/discovery/plugin/admincenter/endpoint/ConfigEndpoint.java
View file @
65a36238
...
@@ -15,8 +15,11 @@ import io.swagger.annotations.ApiParam;
...
@@ -15,8 +15,11 @@ import io.swagger.annotations.ApiParam;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.InputStream
;
import
java.util.ArrayList
;
import
java.util.List
;
import
org.apache.commons.io.IOUtils
;
import
org.apache.commons.io.IOUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.commons.lang3.exception.ExceptionUtils
;
import
org.apache.commons.lang3.exception.ExceptionUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.HttpStatus
;
...
@@ -31,6 +34,7 @@ import com.nepxion.discovery.plugin.framework.constant.PluginConstant;
...
@@ -31,6 +34,7 @@ import com.nepxion.discovery.plugin.framework.constant.PluginConstant;
import
com.nepxion.discovery.plugin.framework.context.PluginContextAware
;
import
com.nepxion.discovery.plugin.framework.context.PluginContextAware
;
import
com.nepxion.discovery.plugin.framework.entity.RuleEntity
;
import
com.nepxion.discovery.plugin.framework.entity.RuleEntity
;
import
com.nepxion.discovery.plugin.framework.event.PluginEventWapper
;
import
com.nepxion.discovery.plugin.framework.event.PluginEventWapper
;
import
com.nepxion.discovery.plugin.framework.event.RuleClearedEvent
;
import
com.nepxion.discovery.plugin.framework.event.RuleUpdatedEvent
;
import
com.nepxion.discovery.plugin.framework.event.RuleUpdatedEvent
;
@RestController
@RestController
...
@@ -57,17 +61,40 @@ public class ConfigEndpoint {
...
@@ -57,17 +61,40 @@ public class ConfigEndpoint {
return
update
(
config
,
false
);
return
update
(
config
,
false
);
}
}
@RequestMapping
(
path
=
"/config/clear"
,
method
=
RequestMethod
.
POST
)
@ApiOperation
(
value
=
"清除更新的规则配置信息"
,
notes
=
""
,
response
=
ResponseEntity
.
class
,
httpMethod
=
"POST"
)
public
ResponseEntity
<?>
clear
()
{
Boolean
discoveryControlEnabled
=
pluginContextAware
.
isDiscoveryControlEnabled
();
if
(!
discoveryControlEnabled
)
{
return
ResponseEntity
.
status
(
HttpStatus
.
INTERNAL_SERVER_ERROR
).
body
(
"Discovery control is disabled"
);
}
pluginEventWapper
.
fireRuleCleared
(
new
RuleClearedEvent
(),
true
);
return
ResponseEntity
.
ok
().
body
(
"OK"
);
}
@RequestMapping
(
path
=
"/config/view"
,
method
=
RequestMethod
.
GET
)
@RequestMapping
(
path
=
"/config/view"
,
method
=
RequestMethod
.
GET
)
@ApiOperation
(
value
=
"查看当前生效的规则配置信息"
,
notes
=
""
,
response
=
ResponseEntity
.
class
,
httpMethod
=
"GET"
)
@ApiOperation
(
value
=
"查看本地和更新的规则配置信息"
,
notes
=
""
,
response
=
ResponseEntity
.
class
,
httpMethod
=
"GET"
)
public
ResponseEntity
<?>
view
()
{
public
ResponseEntity
<
List
<
String
>>
view
()
{
RuleEntity
ruleEntity
=
pluginAdapter
.
getRule
();
List
<
String
>
ruleList
=
new
ArrayList
<
String
>(
2
);
if
(
ruleEntity
==
null
)
{
return
ResponseEntity
.
status
(
HttpStatus
.
INTERNAL_SERVER_ERROR
).
body
(
"No config to view"
);
String
localRuleContent
=
StringUtils
.
EMPTY
;
RuleEntity
localRuleEntity
=
pluginAdapter
.
getLocalRule
();
if
(
localRuleEntity
!=
null
&&
StringUtils
.
isNotEmpty
(
localRuleEntity
.
getContent
()))
{
localRuleContent
=
localRuleEntity
.
getContent
();
}
String
dynamicRuleContent
=
StringUtils
.
EMPTY
;
RuleEntity
dynamicRuleEntity
=
pluginAdapter
.
getDynamicRule
();
if
(
dynamicRuleEntity
!=
null
&&
StringUtils
.
isNotEmpty
(
dynamicRuleEntity
.
getContent
()))
{
dynamicRuleContent
=
dynamicRuleEntity
.
getContent
();
}
}
String
content
=
ruleEntity
.
getContent
();
ruleList
.
add
(
localRuleContent
);
ruleList
.
add
(
dynamicRuleContent
);
return
ResponseEntity
.
ok
().
body
(
conten
t
);
return
ResponseEntity
.
ok
().
body
(
ruleLis
t
);
}
}
private
ResponseEntity
<?>
update
(
String
config
,
boolean
async
)
{
private
ResponseEntity
<?>
update
(
String
config
,
boolean
async
)
{
...
...
discovery-plugin-framework/src/main/java/com/nepxion/discovery/plugin/framework/cache/RuleCache.java
View file @
65a36238
...
@@ -22,8 +22,8 @@ public class RuleCache {
...
@@ -22,8 +22,8 @@ public class RuleCache {
public
RuleCache
()
{
public
RuleCache
()
{
loadingCache
=
Caffeine
.
newBuilder
()
loadingCache
=
Caffeine
.
newBuilder
()
.
expireAfterWrite
(
365
*
100
,
TimeUnit
.
DAYS
)
.
expireAfterWrite
(
365
*
100
,
TimeUnit
.
DAYS
)
.
initialCapacity
(
1
)
.
initialCapacity
(
2
)
.
maximumSize
(
1
)
.
maximumSize
(
1
0
)
.
recordStats
()
.
recordStats
()
.
build
(
new
CacheLoader
<
String
,
RuleEntity
>()
{
.
build
(
new
CacheLoader
<
String
,
RuleEntity
>()
{
@Override
@Override
...
...
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