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
1dc932fa
Commit
1dc932fa
authored
Jul 11, 2018
by
Nepxion
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
增加批量更新和清除版本
parent
dfeb7e02
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
49 additions
and
21 deletions
+49
-21
discovery-console/src/main/java/com/nepxion/discovery/console/endpoint/ConsoleEndpoint.java
+20
-14
discovery-plugin-admin-center/src/main/java/com/nepxion/discovery/plugin/admincenter/endpoint/VersionEndpoint.java
+29
-7
No files found.
discovery-console/src/main/java/com/nepxion/discovery/console/endpoint/ConsoleEndpoint.java
View file @
1dc932fa
...
@@ -101,19 +101,19 @@ public class ConsoleEndpoint implements MvcEndpoint {
...
@@ -101,19 +101,19 @@ public class ConsoleEndpoint implements MvcEndpoint {
}
}
@RequestMapping
(
path
=
"/version/update/{serviceId}"
,
method
=
RequestMethod
.
POST
)
@RequestMapping
(
path
=
"/version/update/{serviceId}"
,
method
=
RequestMethod
.
POST
)
@ApiOperation
(
value
=
"批量更新服务的动态版本"
,
notes
=
""
,
response
=
ResponseEntity
.
class
,
httpMethod
=
"POST"
)
@ApiOperation
(
value
=
"批量更新服务的动态版本"
,
notes
=
"
根据指定的localVersion更新服务的dynamicVersion。如果输入的localVersion不匹配服务的localVersion,则忽略;如果如果输入的localVersion为空,则直接更新服务的dynamicVersion
"
,
response
=
ResponseEntity
.
class
,
httpMethod
=
"POST"
)
@ResponseBody
@ResponseBody
@ManagedOperation
@ManagedOperation
public
ResponseEntity
<?>
versionUpdate
(
@PathVariable
(
value
=
"serviceId"
)
@ApiParam
(
value
=
"服务名"
,
required
=
true
)
String
serviceId
,
@RequestBody
@ApiParam
(
value
=
"版本号"
,
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
)
{
return
executeVersionUpdate
(
serviceId
,
version
);
return
executeVersionUpdate
(
serviceId
,
version
);
}
}
@RequestMapping
(
path
=
"/version/clear/{serviceId}"
,
method
=
RequestMethod
.
GE
T
)
@RequestMapping
(
path
=
"/version/clear/{serviceId}"
,
method
=
RequestMethod
.
POS
T
)
@ApiOperation
(
value
=
"批量清除服务的动态版本"
,
notes
=
"
"
,
response
=
ResponseEntity
.
class
,
httpMethod
=
"GE
T"
)
@ApiOperation
(
value
=
"批量清除服务的动态版本"
,
notes
=
"
根据指定的localVersion清除服务的dynamicVersion。如果输入的localVersion不匹配服务的localVersion,则忽略;如果如果输入的localVersion为空,则直接清除服务的dynamicVersion"
,
response
=
ResponseEntity
.
class
,
httpMethod
=
"POS
T"
)
@ResponseBody
@ResponseBody
@ManagedOperation
@ManagedOperation
public
ResponseEntity
<?>
versionClear
(
@PathVariable
(
value
=
"serviceId"
)
@ApiParam
(
value
=
"服务名"
,
required
=
true
)
String
serviceId
)
{
public
ResponseEntity
<?>
versionClear
(
@PathVariable
(
value
=
"serviceId"
)
@ApiParam
(
value
=
"服务名"
,
required
=
true
)
String
serviceId
,
@RequestBody
@ApiParam
(
value
=
"版本号,指localVersion,可以为空"
)
String
version
)
{
return
executeVersionClear
(
serviceId
);
return
executeVersionClear
(
serviceId
,
version
);
}
}
public
List
<
String
>
getServices
()
{
public
List
<
String
>
getServices
()
{
...
@@ -171,13 +171,15 @@ public class ConsoleEndpoint implements MvcEndpoint {
...
@@ -171,13 +171,15 @@ public class ConsoleEndpoint implements MvcEndpoint {
ConsoleErrorHandler
errorHandler
=
(
ConsoleErrorHandler
)
consoleRestTemplate
.
getErrorHandler
();
ConsoleErrorHandler
errorHandler
=
(
ConsoleErrorHandler
)
consoleRestTemplate
.
getErrorHandler
();
result
=
errorHandler
.
getCause
();
result
=
errorHandler
.
getCause
();
}
}
stringBuilder
.
append
(
"
Rule sent
, serviceId="
).
append
(
serviceId
).
append
(
", url="
).
append
(
url
).
append
(
", result="
).
append
(
result
).
append
(
"\n"
);
stringBuilder
.
append
(
"
Config updated
, serviceId="
).
append
(
serviceId
).
append
(
", url="
).
append
(
url
).
append
(
", result="
).
append
(
result
).
append
(
"\n"
);
}
}
String
result
=
stringBuilder
.
toString
();
String
result
=
stringBuilder
.
toString
();
if
(
result
.
contains
(
"\n"
))
{
result
=
result
.
substring
(
0
,
result
.
lastIndexOf
(
"\n"
));
result
=
result
.
substring
(
0
,
result
.
lastIndexOf
(
"\n"
));
}
LOG
.
info
(
"\n{}"
,
result
);
LOG
.
info
(
"
Config updated result:
\n{}"
,
result
);
return
ResponseEntity
.
ok
().
body
(
result
);
return
ResponseEntity
.
ok
().
body
(
result
);
}
}
...
@@ -197,18 +199,20 @@ public class ConsoleEndpoint implements MvcEndpoint {
...
@@ -197,18 +199,20 @@ public class ConsoleEndpoint implements MvcEndpoint {
ConsoleErrorHandler
errorHandler
=
(
ConsoleErrorHandler
)
consoleRestTemplate
.
getErrorHandler
();
ConsoleErrorHandler
errorHandler
=
(
ConsoleErrorHandler
)
consoleRestTemplate
.
getErrorHandler
();
result
=
errorHandler
.
getCause
();
result
=
errorHandler
.
getCause
();
}
}
stringBuilder
.
append
(
"Version
sent
, serviceId="
).
append
(
serviceId
).
append
(
", url="
).
append
(
url
).
append
(
", result="
).
append
(
result
).
append
(
"\n"
);
stringBuilder
.
append
(
"Version
updated
, serviceId="
).
append
(
serviceId
).
append
(
", url="
).
append
(
url
).
append
(
", result="
).
append
(
result
).
append
(
"\n"
);
}
}
String
result
=
stringBuilder
.
toString
();
String
result
=
stringBuilder
.
toString
();
if
(
result
.
contains
(
"\n"
))
{
result
=
result
.
substring
(
0
,
result
.
lastIndexOf
(
"\n"
));
result
=
result
.
substring
(
0
,
result
.
lastIndexOf
(
"\n"
));
}
LOG
.
info
(
"\n{}"
,
result
);
LOG
.
info
(
"
Version updated result:
\n{}"
,
result
);
return
ResponseEntity
.
ok
().
body
(
result
);
return
ResponseEntity
.
ok
().
body
(
result
);
}
}
private
ResponseEntity
<?>
executeVersionClear
(
String
serviceId
)
{
private
ResponseEntity
<?>
executeVersionClear
(
String
serviceId
,
String
version
)
{
StringBuilder
stringBuilder
=
new
StringBuilder
();
StringBuilder
stringBuilder
=
new
StringBuilder
();
List
<
ServiceInstance
>
serviceInstances
=
getInstances
(
serviceId
);
List
<
ServiceInstance
>
serviceInstances
=
getInstances
(
serviceId
);
...
@@ -217,19 +221,21 @@ public class ConsoleEndpoint implements MvcEndpoint {
...
@@ -217,19 +221,21 @@ public class ConsoleEndpoint implements MvcEndpoint {
int
port
=
serviceInstance
.
getPort
();
int
port
=
serviceInstance
.
getPort
();
String
url
=
"http://"
+
host
+
":"
+
port
+
"/version/clear"
;
String
url
=
"http://"
+
host
+
":"
+
port
+
"/version/clear"
;
String
result
=
consoleRestTemplate
.
getForEntity
(
url
,
String
.
class
).
getBody
();
String
result
=
consoleRestTemplate
.
postForEntity
(
url
,
version
,
String
.
class
).
getBody
();
if
(!
StringUtils
.
equals
(
result
,
"OK"
))
{
if
(!
StringUtils
.
equals
(
result
,
"OK"
))
{
ConsoleErrorHandler
errorHandler
=
(
ConsoleErrorHandler
)
consoleRestTemplate
.
getErrorHandler
();
ConsoleErrorHandler
errorHandler
=
(
ConsoleErrorHandler
)
consoleRestTemplate
.
getErrorHandler
();
result
=
errorHandler
.
getCause
();
result
=
errorHandler
.
getCause
();
}
}
stringBuilder
.
append
(
"Version
sent
, serviceId="
).
append
(
serviceId
).
append
(
", url="
).
append
(
url
).
append
(
", result="
).
append
(
result
).
append
(
"\n"
);
stringBuilder
.
append
(
"Version
cleared
, serviceId="
).
append
(
serviceId
).
append
(
", url="
).
append
(
url
).
append
(
", result="
).
append
(
result
).
append
(
"\n"
);
}
}
String
result
=
stringBuilder
.
toString
();
String
result
=
stringBuilder
.
toString
();
if
(
result
.
contains
(
"\n"
))
{
result
=
result
.
substring
(
0
,
result
.
lastIndexOf
(
"\n"
));
result
=
result
.
substring
(
0
,
result
.
lastIndexOf
(
"\n"
));
}
LOG
.
info
(
"\n{}"
,
result
);
LOG
.
info
(
"
Version cleared result:
\n{}"
,
result
);
return
ResponseEntity
.
ok
().
body
(
result
);
return
ResponseEntity
.
ok
().
body
(
result
);
}
}
...
...
discovery-plugin-admin-center/src/main/java/com/nepxion/discovery/plugin/admincenter/endpoint/VersionEndpoint.java
View file @
1dc932fa
...
@@ -31,6 +31,7 @@ import org.springframework.web.bind.annotation.ResponseBody;
...
@@ -31,6 +31,7 @@ import org.springframework.web.bind.annotation.ResponseBody;
import
org.springframework.web.bind.annotation.RestController
;
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.constant.PluginConstant
;
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.VersionClearedEvent
;
import
com.nepxion.discovery.plugin.framework.event.VersionClearedEvent
;
...
@@ -50,31 +51,52 @@ public class VersionEndpoint implements MvcEndpoint {
...
@@ -50,31 +51,52 @@ public class VersionEndpoint implements MvcEndpoint {
private
PluginEventWapper
pluginEventWapper
;
private
PluginEventWapper
pluginEventWapper
;
@RequestMapping
(
path
=
"/version/update"
,
method
=
RequestMethod
.
POST
)
@RequestMapping
(
path
=
"/version/update"
,
method
=
RequestMethod
.
POST
)
@ApiOperation
(
value
=
"更新服务的动态版本"
,
notes
=
""
,
response
=
ResponseEntity
.
class
,
httpMethod
=
"POST"
)
@ApiOperation
(
value
=
"更新服务的动态版本"
,
notes
=
"
根据指定的localVersion更新服务的dynamicVersion。如果输入的localVersion不匹配服务的localVersion,则忽略;如果如果输入的localVersion为空,则直接更新服务的dynamicVersion
"
,
response
=
ResponseEntity
.
class
,
httpMethod
=
"POST"
)
@ResponseBody
@ResponseBody
@ManagedOperation
@ManagedOperation
public
ResponseEntity
<?>
update
(
@RequestBody
@ApiParam
(
value
=
"版本号"
,
required
=
true
)
String
version
)
{
public
ResponseEntity
<?>
update
(
@RequestBody
@ApiParam
(
value
=
"版本号
,格式为[dynamicVersion]或者[dynamicVersion];[localVersion]
"
,
required
=
true
)
String
version
)
{
Boolean
discoveryControlEnabled
=
pluginContextAware
.
isDiscoveryControlEnabled
();
Boolean
discoveryControlEnabled
=
pluginContextAware
.
isDiscoveryControlEnabled
();
if
(!
discoveryControlEnabled
)
{
if
(!
discoveryControlEnabled
)
{
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
.
fireVersionUpdated
(
new
VersionUpdatedEvent
(
version
),
true
);
if
(
StringUtils
.
isEmpty
(
version
))
{
return
ResponseEntity
.
status
(
HttpStatus
.
INTERNAL_SERVER_ERROR
).
body
(
"Version can't be null or empty"
);
}
String
dynamicVersion
=
null
;
String
localVersion
=
null
;
String
[]
versionArray
=
StringUtils
.
split
(
version
,
PluginConstant
.
SEPARATE
);
if
(
versionArray
.
length
==
2
)
{
dynamicVersion
=
versionArray
[
0
];
localVersion
=
versionArray
[
1
];
}
else
if
(
versionArray
.
length
==
1
)
{
dynamicVersion
=
versionArray
[
0
];
}
else
{
return
ResponseEntity
.
status
(
HttpStatus
.
INTERNAL_SERVER_ERROR
).
body
(
"Invalid version format, it must be '[dynamicVersion]' or '[dynamicVersion];[localVersion]'"
);
}
pluginEventWapper
.
fireVersionUpdated
(
new
VersionUpdatedEvent
(
dynamicVersion
,
localVersion
),
false
);
return
ResponseEntity
.
ok
().
body
(
"OK"
);
return
ResponseEntity
.
ok
().
body
(
"OK"
);
}
}
@RequestMapping
(
path
=
"/version/clear"
,
method
=
RequestMethod
.
GE
T
)
@RequestMapping
(
path
=
"/version/clear"
,
method
=
RequestMethod
.
POS
T
)
@ApiOperation
(
value
=
"清除服务的动态版本"
,
notes
=
"
"
,
response
=
ResponseEntity
.
class
,
httpMethod
=
"GE
T"
)
@ApiOperation
(
value
=
"清除服务的动态版本"
,
notes
=
"
根据指定的localVersion清除服务的dynamicVersion。如果输入的localVersion不匹配服务的localVersion,则忽略;如果如果输入的localVersion为空,则直接清除服务的dynamicVersion"
,
response
=
ResponseEntity
.
class
,
httpMethod
=
"POS
T"
)
@ResponseBody
@ResponseBody
@ManagedOperation
@ManagedOperation
public
ResponseEntity
<?>
clear
()
{
public
ResponseEntity
<?>
clear
(
@RequestBody
@ApiParam
(
value
=
"版本号,指localVersion,可以为空"
)
String
version
)
{
Boolean
discoveryControlEnabled
=
pluginContextAware
.
isDiscoveryControlEnabled
();
Boolean
discoveryControlEnabled
=
pluginContextAware
.
isDiscoveryControlEnabled
();
if
(!
discoveryControlEnabled
)
{
if
(!
discoveryControlEnabled
)
{
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
.
fireVersionCleared
(
new
VersionClearedEvent
(),
true
);
// 修复Swagger的一个Bug,当在Swagger界面不输入版本号的时候,传到后端变成了“{}”
if
(
StringUtils
.
isNotEmpty
(
version
)
&&
StringUtils
.
equals
(
version
.
trim
(),
"{}"
))
{
version
=
null
;
}
pluginEventWapper
.
fireVersionCleared
(
new
VersionClearedEvent
(
version
),
false
);
return
ResponseEntity
.
ok
().
body
(
"OK"
);
return
ResponseEntity
.
ok
().
body
(
"OK"
);
}
}
...
...
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