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
57b7b9a1
Commit
57b7b9a1
authored
Jul 10, 2018
by
Nepxion
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
增强异常处理
parent
b72fdd07
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
39 additions
and
11 deletions
+39
-11
discovery-plugin-admin-center/src/main/java/com/nepxion/discovery/plugin/admincenter/endpoint/ConfigEndpoint.java
+38
-10
discovery-plugin-config-center/src/main/java/com/nepxion/discovery/plugin/configcenter/ConfigParser.java
+1
-1
No files found.
discovery-plugin-admin-center/src/main/java/com/nepxion/discovery/plugin/admincenter/endpoint/ConfigEndpoint.java
View file @
57b7b9a1
...
@@ -18,8 +18,7 @@ import java.io.InputStream;
...
@@ -18,8 +18,7 @@ import java.io.InputStream;
import
java.util.Collections
;
import
java.util.Collections
;
import
org.apache.commons.io.IOUtils
;
import
org.apache.commons.io.IOUtils
;
import
org.slf4j.Logger
;
import
org.apache.commons.lang3.exception.ExceptionUtils
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.actuate.endpoint.Endpoint
;
import
org.springframework.boot.actuate.endpoint.Endpoint
;
import
org.springframework.boot.actuate.endpoint.mvc.MvcEndpoint
;
import
org.springframework.boot.actuate.endpoint.mvc.MvcEndpoint
;
...
@@ -45,8 +44,6 @@ import com.nepxion.discovery.plugin.framework.event.RuleChangedEvent;
...
@@ -45,8 +44,6 @@ import com.nepxion.discovery.plugin.framework.event.RuleChangedEvent;
// 用法参照ServiceRegistryEndpoint和ServiceRegistryAutoConfiguration
// 用法参照ServiceRegistryEndpoint和ServiceRegistryAutoConfiguration
@ManagedResource
(
description
=
"Config Endpoint"
)
@ManagedResource
(
description
=
"Config Endpoint"
)
public
class
ConfigEndpoint
implements
MvcEndpoint
{
public
class
ConfigEndpoint
implements
MvcEndpoint
{
private
static
final
Logger
LOG
=
LoggerFactory
.
getLogger
(
ConfigEndpoint
.
class
);
@Autowired
@Autowired
private
PluginContextAware
pluginContextAware
;
private
PluginContextAware
pluginContextAware
;
...
@@ -56,11 +53,11 @@ public class ConfigEndpoint implements MvcEndpoint {
...
@@ -56,11 +53,11 @@ public class ConfigEndpoint implements MvcEndpoint {
@Autowired
@Autowired
private
RuleCache
ruleCache
;
private
RuleCache
ruleCache
;
@RequestMapping
(
path
=
"/config/send"
,
method
=
RequestMethod
.
POST
)
@RequestMapping
(
path
=
"/config/send
-async
"
,
method
=
RequestMethod
.
POST
)
@ApiOperation
(
value
=
"推送规则配置信息"
,
notes
=
""
,
response
=
ResponseEntity
.
class
,
httpMethod
=
"POST"
)
@ApiOperation
(
value
=
"
异步
推送规则配置信息"
,
notes
=
""
,
response
=
ResponseEntity
.
class
,
httpMethod
=
"POST"
)
@ResponseBody
@ResponseBody
@ManagedOperation
@ManagedOperation
public
ResponseEntity
<?>
send
(
@RequestBody
@ApiParam
(
value
=
"规则配置内容,XML格式"
,
required
=
true
)
String
config
)
{
public
ResponseEntity
<?>
send
Async
(
@RequestBody
@ApiParam
(
value
=
"规则配置内容,XML格式"
,
required
=
true
)
String
config
)
{
Boolean
discoveryControlEnabled
=
pluginContextAware
.
isDiscoveryControlEnabled
();
Boolean
discoveryControlEnabled
=
pluginContextAware
.
isDiscoveryControlEnabled
();
if
(!
discoveryControlEnabled
)
{
if
(!
discoveryControlEnabled
)
{
return
new
ResponseEntity
<>(
Collections
.
singletonMap
(
"Message"
,
"Discovery control is disabled"
),
HttpStatus
.
NOT_FOUND
);
return
new
ResponseEntity
<>(
Collections
.
singletonMap
(
"Message"
,
"Discovery control is disabled"
),
HttpStatus
.
NOT_FOUND
);
...
@@ -70,9 +67,7 @@ public class ConfigEndpoint implements MvcEndpoint {
...
@@ -70,9 +67,7 @@ public class ConfigEndpoint implements MvcEndpoint {
InputStream
inputStream
=
IOUtils
.
toInputStream
(
config
,
PluginConstant
.
ENCODING_UTF_8
);
InputStream
inputStream
=
IOUtils
.
toInputStream
(
config
,
PluginConstant
.
ENCODING_UTF_8
);
pluginEventWapper
.
fireRuleChanged
(
new
RuleChangedEvent
(
inputStream
),
true
);
pluginEventWapper
.
fireRuleChanged
(
new
RuleChangedEvent
(
inputStream
),
true
);
}
catch
(
IOException
e
)
{
}
catch
(
IOException
e
)
{
LOG
.
error
(
"Publish config failed"
,
e
);
return
toExceptionResponseEntity
(
e
,
true
);
return
new
ResponseEntity
<>(
Collections
.
singletonMap
(
"Message"
,
"Send config failed"
),
HttpStatus
.
OK
);
}
}
// return ResponseEntity.ok().build();
// return ResponseEntity.ok().build();
...
@@ -80,6 +75,26 @@ public class ConfigEndpoint implements MvcEndpoint {
...
@@ -80,6 +75,26 @@ public class ConfigEndpoint implements MvcEndpoint {
return
ResponseEntity
.
ok
().
body
(
"OK"
);
return
ResponseEntity
.
ok
().
body
(
"OK"
);
}
}
@RequestMapping
(
path
=
"/config/send-sync"
,
method
=
RequestMethod
.
POST
)
@ApiOperation
(
value
=
"同步推送规则配置信息"
,
notes
=
""
,
response
=
ResponseEntity
.
class
,
httpMethod
=
"POST"
)
@ResponseBody
@ManagedOperation
public
ResponseEntity
<?>
sendSync
(
@RequestBody
@ApiParam
(
value
=
"规则配置内容,XML格式"
,
required
=
true
)
String
config
)
{
Boolean
discoveryControlEnabled
=
pluginContextAware
.
isDiscoveryControlEnabled
();
if
(!
discoveryControlEnabled
)
{
return
new
ResponseEntity
<>(
Collections
.
singletonMap
(
"Message"
,
"Discovery control is disabled"
),
HttpStatus
.
NOT_FOUND
);
}
try
{
InputStream
inputStream
=
IOUtils
.
toInputStream
(
config
,
PluginConstant
.
ENCODING_UTF_8
);
pluginEventWapper
.
fireRuleChanged
(
new
RuleChangedEvent
(
inputStream
),
false
);
}
catch
(
IOException
e
)
{
return
toExceptionResponseEntity
(
e
,
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"
)
@ResponseBody
@ResponseBody
...
@@ -95,6 +110,19 @@ public class ConfigEndpoint implements MvcEndpoint {
...
@@ -95,6 +110,19 @@ public class ConfigEndpoint implements MvcEndpoint {
return
ResponseEntity
.
ok
().
body
(
content
);
return
ResponseEntity
.
ok
().
body
(
content
);
}
}
private
ResponseEntity
<
String
>
toExceptionResponseEntity
(
Exception
e
,
boolean
showDetail
)
{
String
message
=
null
;
if
(
showDetail
)
{
message
=
ExceptionUtils
.
getStackTrace
(
e
);
}
else
{
message
=
e
.
getMessage
();
}
message
=
"An internal error occurred while processing your request\n"
+
message
;
return
new
ResponseEntity
<
String
>(
message
,
HttpStatus
.
INTERNAL_SERVER_ERROR
);
}
@Override
@Override
public
String
getPath
()
{
public
String
getPath
()
{
return
"/"
;
return
"/"
;
...
...
discovery-plugin-config-center/src/main/java/com/nepxion/discovery/plugin/configcenter/ConfigParser.java
View file @
57b7b9a1
...
@@ -55,7 +55,7 @@ public class ConfigParser extends Dom4JParser implements PluginConfigParser {
...
@@ -55,7 +55,7 @@ public class ConfigParser extends Dom4JParser implements PluginConfigParser {
}
catch
(
NullPointerException
e
)
{
}
catch
(
NullPointerException
e
)
{
throw
new
PluginException
(
"Input stream is null"
);
throw
new
PluginException
(
"Input stream is null"
);
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
throw
new
PluginException
(
"Parse rule xml failed"
,
e
);
throw
new
PluginException
(
e
.
getMessage
()
,
e
);
}
finally
{
}
finally
{
if
(
inputStream
!=
null
)
{
if
(
inputStream
!=
null
)
{
IOUtils
.
closeQuietly
(
inputStream
);
IOUtils
.
closeQuietly
(
inputStream
);
...
...
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