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
ffde3a04
Commit
ffde3a04
authored
Jul 18, 2018
by
Nepxion
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
精简配置项
parent
b46c5bb5
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
48 additions
and
77 deletions
+48
-77
discovery-plugin-config-center/src/main/java/com/nepxion/discovery/plugin/configcenter/ConfigInitializer.java
+34
-8
discovery-plugin-config-center/src/main/java/com/nepxion/discovery/plugin/configcenter/loader/AbstractConfigLoader.java
+2
-9
discovery-plugin-config-center/src/main/java/com/nepxion/discovery/plugin/configcenter/loader/ConfigLoader.java
+3
-2
discovery-plugin-framework/src/main/java/com/nepxion/discovery/plugin/framework/constant/PluginConstant.java
+0
-2
discovery-plugin-framework/src/main/java/com/nepxion/discovery/plugin/framework/context/PluginContextAware.java
+0
-9
discovery-plugin-framework/src/main/java/com/nepxion/discovery/plugin/framework/event/PluginSubscriber.java
+0
-16
discovery-plugin-framework/src/main/java/com/nepxion/discovery/plugin/framework/listener/register/CountFilterRegisterListener.java
+1
-4
discovery-plugin-framework/src/main/java/com/nepxion/discovery/plugin/framework/listener/register/HostFilterRegisterListener.java
+1
-5
discovery-springcloud-example/src/main/java/com/nepxion/discovery/plugin/example/adapter/MyConfigAdapter.java
+6
-16
discovery-springcloud-example/src/main/resources/bootstrap.properties
+1
-6
No files found.
discovery-plugin-config-center/src/main/java/com/nepxion/discovery/plugin/configcenter/ConfigInitializer.java
View file @
ffde3a04
...
@@ -41,7 +41,6 @@ public class ConfigInitializer {
...
@@ -41,7 +41,6 @@ public class ConfigInitializer {
public
void
initialize
()
{
public
void
initialize
()
{
Boolean
registerControlEnabled
=
pluginContextAware
.
isRegisterControlEnabled
();
Boolean
registerControlEnabled
=
pluginContextAware
.
isRegisterControlEnabled
();
Boolean
discoveryControlEnabled
=
pluginContextAware
.
isDiscoveryControlEnabled
();
Boolean
discoveryControlEnabled
=
pluginContextAware
.
isDiscoveryControlEnabled
();
Boolean
remoteConfigEnabled
=
pluginContextAware
.
isRemoteConfigEnabled
();
if
(!
registerControlEnabled
&&
!
discoveryControlEnabled
)
{
if
(!
registerControlEnabled
&&
!
discoveryControlEnabled
)
{
LOG
.
info
(
"********** Register and Discovery controls are all disabled, ignore to initialize **********"
);
LOG
.
info
(
"********** Register and Discovery controls are all disabled, ignore to initialize **********"
);
...
@@ -55,14 +54,9 @@ public class ConfigInitializer {
...
@@ -55,14 +54,9 @@ public class ConfigInitializer {
return
;
return
;
}
}
LOG
.
info
(
"**********
{} config starts to initialize **********"
,
remoteConfigEnabled
?
"Remote"
:
"Local
"
);
LOG
.
info
(
"**********
Rule starts to initialize **********
"
);
InputStream
inputStream
=
null
;
InputStream
inputStream
=
getInputStream
(
configLoader
);
if
(
remoteConfigEnabled
)
{
inputStream
=
configLoader
.
getRemoteInputStream
();
}
else
{
inputStream
=
configLoader
.
getLocalInputStream
();
}
try
{
try
{
RuleEntity
ruleEntity
=
configParser
.
parse
(
inputStream
);
RuleEntity
ruleEntity
=
configParser
.
parse
(
inputStream
);
pluginAdapter
.
setLocalRule
(
ruleEntity
);
pluginAdapter
.
setLocalRule
(
ruleEntity
);
...
@@ -70,4 +64,35 @@ public class ConfigInitializer {
...
@@ -70,4 +64,35 @@ public class ConfigInitializer {
LOG
.
error
(
"Parse rule xml failed"
,
e
);
LOG
.
error
(
"Parse rule xml failed"
,
e
);
}
}
}
}
public
InputStream
getInputStream
(
ConfigLoader
configLoader
)
{
InputStream
inputStream
=
null
;
try
{
inputStream
=
configLoader
.
getRemoteInputStream
();
}
catch
(
Exception
e
)
{
LOG
.
warn
(
"Get remote input stream failed"
,
e
);
}
if
(
inputStream
!=
null
)
{
LOG
.
info
(
"********** Remote input stream is retrieved **********"
);
return
inputStream
;
}
try
{
inputStream
=
configLoader
.
getLocalInputStream
();
}
catch
(
Exception
e
)
{
LOG
.
warn
(
"Get local input stream failed"
,
e
);
}
if
(
inputStream
!=
null
)
{
LOG
.
info
(
"********** Local input stream is retrieved **********"
);
return
inputStream
;
}
LOG
.
info
(
"********** No input stream is retrieved **********"
);
return
null
;
}
}
}
\ No newline at end of file
discovery-plugin-config-center/src/main/java/com/nepxion/discovery/plugin/configcenter/loader/AbstractConfigLoader.java
View file @
ffde3a04
...
@@ -9,21 +9,18 @@ package com.nepxion.discovery.plugin.configcenter.loader;
...
@@ -9,21 +9,18 @@ package com.nepxion.discovery.plugin.configcenter.loader;
* @version 1.0
* @version 1.0
*/
*/
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.InputStream
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.context.ApplicationContext
;
import
org.springframework.context.ApplicationContext
;
import
com.nepxion.discovery.plugin.framework.exception.PluginException
;
public
abstract
class
AbstractConfigLoader
implements
ConfigLoader
{
public
abstract
class
AbstractConfigLoader
implements
ConfigLoader
{
@Autowired
@Autowired
private
ApplicationContext
applicationContext
;
private
ApplicationContext
applicationContext
;
@Override
@Override
public
InputStream
getLocalInputStream
()
{
public
InputStream
getLocalInputStream
()
throws
Exception
{
String
localContextPath
=
getLocalContextPath
();
String
localContextPath
=
getLocalContextPath
();
if
(
StringUtils
.
isEmpty
(
localContextPath
))
{
if
(
StringUtils
.
isEmpty
(
localContextPath
))
{
return
null
;
return
null
;
...
@@ -31,11 +28,7 @@ public abstract class AbstractConfigLoader implements ConfigLoader {
...
@@ -31,11 +28,7 @@ public abstract class AbstractConfigLoader implements ConfigLoader {
String
localFilePath
=
applicationContext
.
getEnvironment
().
resolvePlaceholders
(
localContextPath
);
String
localFilePath
=
applicationContext
.
getEnvironment
().
resolvePlaceholders
(
localContextPath
);
try
{
return
applicationContext
.
getResource
(
localFilePath
).
getInputStream
();
return
applicationContext
.
getResource
(
localFilePath
).
getInputStream
();
}
catch
(
IOException
e
)
{
throw
new
PluginException
(
e
);
}
}
}
protected
abstract
String
getLocalContextPath
();
protected
abstract
String
getLocalContextPath
();
...
...
discovery-plugin-config-center/src/main/java/com/nepxion/discovery/plugin/configcenter/loader/ConfigLoader.java
View file @
ffde3a04
...
@@ -12,7 +12,7 @@ package com.nepxion.discovery.plugin.configcenter.loader;
...
@@ -12,7 +12,7 @@ package com.nepxion.discovery.plugin.configcenter.loader;
import
java.io.InputStream
;
import
java.io.InputStream
;
public
interface
ConfigLoader
{
public
interface
ConfigLoader
{
InputStream
getLocalInputStream
();
InputStream
getLocalInputStream
()
throws
Exception
;
InputStream
getRemoteInputStream
();
InputStream
getRemoteInputStream
()
throws
Exception
;
}
}
\ No newline at end of file
discovery-plugin-framework/src/main/java/com/nepxion/discovery/plugin/framework/constant/PluginConstant.java
View file @
ffde3a04
...
@@ -11,9 +11,7 @@ package com.nepxion.discovery.plugin.framework.constant;
...
@@ -11,9 +11,7 @@ package com.nepxion.discovery.plugin.framework.constant;
public
class
PluginConstant
{
public
class
PluginConstant
{
public
static
final
String
SPRING_APPLICATION_REGISTER_CONTROL_ENABLED
=
"spring.application.register.control.enabled"
;
public
static
final
String
SPRING_APPLICATION_REGISTER_CONTROL_ENABLED
=
"spring.application.register.control.enabled"
;
public
static
final
String
SPRING_APPLICATION_REGISTER_FAILURE_EVENT_ENABLED
=
"spring.application.register.failure.event.enabled"
;
public
static
final
String
SPRING_APPLICATION_DISCOVERY_CONTROL_ENABLED
=
"spring.application.discovery.control.enabled"
;
public
static
final
String
SPRING_APPLICATION_DISCOVERY_CONTROL_ENABLED
=
"spring.application.discovery.control.enabled"
;
public
static
final
String
SPRING_APPLICATION_DISCOVERY_REMOTE_CONFIG_ENABLED
=
"spring.application.discovery.remote.config.enabled"
;
public
static
final
String
SPRING_APPLICATION_NAME
=
"spring.application.name"
;
public
static
final
String
SPRING_APPLICATION_NAME
=
"spring.application.name"
;
public
static
final
String
SERVICE_ID
=
"serviceId"
;
public
static
final
String
SERVICE_ID
=
"serviceId"
;
...
...
discovery-plugin-framework/src/main/java/com/nepxion/discovery/plugin/framework/context/PluginContextAware.java
View file @
ffde3a04
...
@@ -92,10 +92,6 @@ public class PluginContextAware implements ApplicationContextAware {
...
@@ -92,10 +92,6 @@ public class PluginContextAware implements ApplicationContextAware {
return
isDiscoveryControlEnabled
(
environment
);
return
isDiscoveryControlEnabled
(
environment
);
}
}
public
Boolean
isRemoteConfigEnabled
()
{
return
isRemoteConfigEnabled
(
environment
);
}
public
static
Boolean
isRegisterControlEnabled
(
Environment
environment
)
{
public
static
Boolean
isRegisterControlEnabled
(
Environment
environment
)
{
return
environment
.
getProperty
(
PluginConstant
.
SPRING_APPLICATION_REGISTER_CONTROL_ENABLED
,
Boolean
.
class
,
Boolean
.
TRUE
);
return
environment
.
getProperty
(
PluginConstant
.
SPRING_APPLICATION_REGISTER_CONTROL_ENABLED
,
Boolean
.
class
,
Boolean
.
TRUE
);
}
}
...
@@ -103,8 +99,4 @@ public class PluginContextAware implements ApplicationContextAware {
...
@@ -103,8 +99,4 @@ public class PluginContextAware implements ApplicationContextAware {
public
static
Boolean
isDiscoveryControlEnabled
(
Environment
environment
)
{
public
static
Boolean
isDiscoveryControlEnabled
(
Environment
environment
)
{
return
environment
.
getProperty
(
PluginConstant
.
SPRING_APPLICATION_DISCOVERY_CONTROL_ENABLED
,
Boolean
.
class
,
Boolean
.
TRUE
);
return
environment
.
getProperty
(
PluginConstant
.
SPRING_APPLICATION_DISCOVERY_CONTROL_ENABLED
,
Boolean
.
class
,
Boolean
.
TRUE
);
}
}
public
static
Boolean
isRemoteConfigEnabled
(
Environment
environment
)
{
return
environment
.
getProperty
(
PluginConstant
.
SPRING_APPLICATION_DISCOVERY_REMOTE_CONFIG_ENABLED
,
Boolean
.
class
,
Boolean
.
TRUE
);
}
}
}
\ No newline at end of file
discovery-plugin-framework/src/main/java/com/nepxion/discovery/plugin/framework/event/PluginSubscriber.java
View file @
ffde3a04
...
@@ -45,20 +45,12 @@ public class PluginSubscriber {
...
@@ -45,20 +45,12 @@ public class PluginSubscriber {
@Subscribe
@Subscribe
public
void
onRuleUpdated
(
RuleUpdatedEvent
ruleUpdatedEvent
)
{
public
void
onRuleUpdated
(
RuleUpdatedEvent
ruleUpdatedEvent
)
{
Boolean
discoveryControlEnabled
=
pluginContextAware
.
isDiscoveryControlEnabled
();
Boolean
discoveryControlEnabled
=
pluginContextAware
.
isDiscoveryControlEnabled
();
Boolean
remoteConfigEnabled
=
pluginContextAware
.
isRemoteConfigEnabled
();
if
(!
discoveryControlEnabled
)
{
if
(!
discoveryControlEnabled
)
{
LOG
.
info
(
"********** Discovery control is disabled, ignore to subscribe **********"
);
LOG
.
info
(
"********** Discovery control is disabled, ignore to subscribe **********"
);
return
;
return
;
}
}
if
(!
remoteConfigEnabled
)
{
LOG
.
info
(
"********** Remote config is disabled, ignore to subscribe **********"
);
return
;
}
LOG
.
info
(
"********** Remote rule updating has been triggered **********"
);
LOG
.
info
(
"********** Remote rule updating has been triggered **********"
);
if
(
ruleUpdatedEvent
==
null
)
{
if
(
ruleUpdatedEvent
==
null
)
{
...
@@ -81,20 +73,12 @@ public class PluginSubscriber {
...
@@ -81,20 +73,12 @@ public class PluginSubscriber {
@Subscribe
@Subscribe
public
void
onRuleCleared
(
RuleClearedEvent
ruleClearedEvent
)
{
public
void
onRuleCleared
(
RuleClearedEvent
ruleClearedEvent
)
{
Boolean
discoveryControlEnabled
=
pluginContextAware
.
isDiscoveryControlEnabled
();
Boolean
discoveryControlEnabled
=
pluginContextAware
.
isDiscoveryControlEnabled
();
Boolean
remoteConfigEnabled
=
pluginContextAware
.
isRemoteConfigEnabled
();
if
(!
discoveryControlEnabled
)
{
if
(!
discoveryControlEnabled
)
{
LOG
.
info
(
"********** Discovery control is disabled, ignore to subscribe **********"
);
LOG
.
info
(
"********** Discovery control is disabled, ignore to subscribe **********"
);
return
;
return
;
}
}
if
(!
remoteConfigEnabled
)
{
LOG
.
info
(
"********** Remote config is disabled, ignore to subscribe **********"
);
return
;
}
LOG
.
info
(
"********** Remote rule clearing has been triggered **********"
);
LOG
.
info
(
"********** Remote rule clearing has been triggered **********"
);
if
(
ruleClearedEvent
==
null
)
{
if
(
ruleClearedEvent
==
null
)
{
...
...
discovery-plugin-framework/src/main/java/com/nepxion/discovery/plugin/framework/listener/register/CountFilterRegisterListener.java
View file @
ffde3a04
...
@@ -76,10 +76,7 @@ public class CountFilterRegisterListener extends AbstractRegisterListener {
...
@@ -76,10 +76,7 @@ public class CountFilterRegisterListener extends AbstractRegisterListener {
private
void
onRegisterFailure
(
int
maxCount
,
String
serviceId
,
String
host
,
int
port
)
{
private
void
onRegisterFailure
(
int
maxCount
,
String
serviceId
,
String
host
,
int
port
)
{
String
description
=
host
+
" isn't allowed to register to Register server, reach max limited count="
+
maxCount
;
String
description
=
host
+
" isn't allowed to register to Register server, reach max limited count="
+
maxCount
;
Boolean
registerFailureEventEnabled
=
pluginContextAware
.
getEnvironment
().
getProperty
(
PluginConstant
.
SPRING_APPLICATION_REGISTER_FAILURE_EVENT_ENABLED
,
Boolean
.
class
,
Boolean
.
FALSE
);
pluginEventWapper
.
fireRegisterFailure
(
new
RegisterFailureEvent
(
PluginConstant
.
REACH_MAX_LIMITED_COUNT
,
description
,
serviceId
,
host
,
port
));
if
(
registerFailureEventEnabled
)
{
pluginEventWapper
.
fireRegisterFailure
(
new
RegisterFailureEvent
(
PluginConstant
.
REACH_MAX_LIMITED_COUNT
,
description
,
serviceId
,
host
,
port
));
}
throw
new
PluginException
(
description
);
throw
new
PluginException
(
description
);
}
}
...
...
discovery-plugin-framework/src/main/java/com/nepxion/discovery/plugin/framework/listener/register/HostFilterRegisterListener.java
View file @
ffde3a04
...
@@ -16,7 +16,6 @@ import java.util.Map;
...
@@ -16,7 +16,6 @@ import java.util.Map;
import
org.apache.commons.collections4.CollectionUtils
;
import
org.apache.commons.collections4.CollectionUtils
;
import
org.springframework.cloud.client.serviceregistry.Registration
;
import
org.springframework.cloud.client.serviceregistry.Registration
;
import
com.nepxion.discovery.plugin.framework.constant.PluginConstant
;
import
com.nepxion.discovery.plugin.framework.entity.FilterType
;
import
com.nepxion.discovery.plugin.framework.entity.FilterType
;
import
com.nepxion.discovery.plugin.framework.entity.HostFilterEntity
;
import
com.nepxion.discovery.plugin.framework.entity.HostFilterEntity
;
import
com.nepxion.discovery.plugin.framework.entity.RegisterEntity
;
import
com.nepxion.discovery.plugin.framework.entity.RegisterEntity
;
...
@@ -100,10 +99,7 @@ public class HostFilterRegisterListener extends AbstractRegisterListener {
...
@@ -100,10 +99,7 @@ public class HostFilterRegisterListener extends AbstractRegisterListener {
private
void
onRegisterFailure
(
FilterType
filterType
,
List
<
String
>
allFilterValueList
,
String
serviceId
,
String
host
,
int
port
)
{
private
void
onRegisterFailure
(
FilterType
filterType
,
List
<
String
>
allFilterValueList
,
String
serviceId
,
String
host
,
int
port
)
{
String
description
=
host
+
" isn't allowed to register to Register server, not match host "
+
filterType
+
"="
+
allFilterValueList
;
String
description
=
host
+
" isn't allowed to register to Register server, not match host "
+
filterType
+
"="
+
allFilterValueList
;
Boolean
registerFailureEventEnabled
=
pluginContextAware
.
getEnvironment
().
getProperty
(
PluginConstant
.
SPRING_APPLICATION_REGISTER_FAILURE_EVENT_ENABLED
,
Boolean
.
class
,
Boolean
.
FALSE
);
pluginEventWapper
.
fireRegisterFailure
(
new
RegisterFailureEvent
(
filterType
.
toString
(),
description
,
serviceId
,
host
,
port
));
if
(
registerFailureEventEnabled
)
{
pluginEventWapper
.
fireRegisterFailure
(
new
RegisterFailureEvent
(
filterType
.
toString
(),
description
,
serviceId
,
host
,
port
));
}
throw
new
PluginException
(
description
);
throw
new
PluginException
(
description
);
}
}
...
...
discovery-springcloud-example/src/main/java/com/nepxion/discovery/plugin/example/adapter/MyConfigAdapter.java
View file @
ffde3a04
...
@@ -10,7 +10,6 @@ package com.nepxion.discovery.plugin.example.adapter;
...
@@ -10,7 +10,6 @@ package com.nepxion.discovery.plugin.example.adapter;
*/
*/
import
java.io.File
;
import
java.io.File
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.InputStream
;
import
org.apache.commons.io.FileUtils
;
import
org.apache.commons.io.FileUtils
;
...
@@ -33,24 +32,14 @@ public class MyConfigAdapter extends ConfigAdapter {
...
@@ -33,24 +32,14 @@ public class MyConfigAdapter extends ConfigAdapter {
// 从远程配置中心获取规则
// 从远程配置中心获取规则
@Override
@Override
public
InputStream
getRemoteInputStream
()
{
public
InputStream
getRemoteInputStream
()
throws
Exception
{
try
{
return
FileUtils
.
openInputStream
(
new
File
(
"src/main/resources/rule.xml"
));
return
FileUtils
.
openInputStream
(
new
File
(
"src/main/resources/rule.xml"
));
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
return
null
;
}
}
// 订阅远程配置中心的规则更新(推送策略自己决定,可以所有服务都只对应一个规则信息,也可以根据服务名获取对应的规则信息)
// 订阅远程配置中心的规则更新(推送策略自己决定,可以所有服务都只对应一个规则信息,也可以根据服务名获取对应的规则信息)
/*@PostConstruct
/*@PostConstruct
public void update() {
public void update() throws Exception {
try {
InputStream inputStream = FileUtils.openInputStream(new File("src/main/resources/rule.xml"));
InputStream inputStream = FileUtils.openInputStream(new File("src/main/resources/rule.xml"));
fireRuleUpdated(new RuleUpdatedEvent(inputStream), true);
fireRuleUpdated(new RuleUpdatedEvent(inputStream), true);
} catch (IOException e) {
e.printStackTrace();
}
}*/
}*/
}
}
\ No newline at end of file
discovery-springcloud-example/src/main/resources/bootstrap.properties
View file @
ffde3a04
...
@@ -23,15 +23,10 @@ management.security.enabled=false
...
@@ -23,15 +23,10 @@ management.security.enabled=false
# management.health.consul.enabled=true
# management.health.consul.enabled=true
# Plugin config
# Plugin config
# 开启和关闭服务注册层面的控制。一旦关闭,服务注册的黑/白名单过滤功能将失效。缺失则默认为true
# 开启和关闭服务注册层面的控制。一旦关闭,服务注册的黑/白名单过滤功能将失效
,最大注册数的限制过滤功能将失效
。缺失则默认为true
spring.application.register.control.enabled
=
true
spring.application.register.control.enabled
=
true
# 开启和关闭禁止注册后发送异步事件通知。一旦关闭,禁止注册后,不会发送异步事件通知。缺失则默认为false
spring.application.register.failure.event.enabled
=
false
# 开启和关闭服务发现层面的控制。一旦关闭,服务多版本调用的控制功能将失效,动态屏蔽指定IP地址的服务实例被发现的功能将失效。缺失则默认为true
# 开启和关闭服务发现层面的控制。一旦关闭,服务多版本调用的控制功能将失效,动态屏蔽指定IP地址的服务实例被发现的功能将失效。缺失则默认为true
spring.application.discovery.control.enabled
=
true
spring.application.discovery.control.enabled
=
true
# 开启和关闭远程配置中心规则文件读取。一旦关闭,默认读取本地规则文件(例如:rule.xml)。缺失则默认为true
spring.application.discovery.remote.config.enabled
=
true
# Swagger config
# Swagger config
swagger.service.base.package
=
com.nepxion.discovery.plugin.admincenter.endpoint
swagger.service.base.package
=
com.nepxion.discovery.plugin.admincenter.endpoint
...
...
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