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
447da0dd
Commit
447da0dd
authored
Jul 03, 2018
by
Nepxion
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
重构类结构
parent
cbac75f0
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
54 additions
and
17 deletions
+54
-17
discovery-plugin-framework-eureka/src/main/java/com/nepxion/discovery/plugin/framework/configuration/EurekaLoadBalanceConfiguration.java
+13
-2
discovery-plugin-framework-eureka/src/main/java/com/nepxion/discovery/plugin/framework/decorator/DiscoveryEnabledNIWSServerListDecorator.java
+14
-6
discovery-plugin-framework-zookeeper/src/main/java/com/nepxion/discovery/plugin/framework/configuration/ZookeeperLoadBalanceConfiguration.java
+13
-2
discovery-plugin-framework-zookeeper/src/main/java/com/nepxion/discovery/plugin/framework/decorator/ZookeeperServerListDecorator.java
+14
-7
No files found.
discovery-plugin-framework-eureka/src/main/java/com/nepxion/discovery/plugin/framework/configuration/EurekaLoadBalanceConfiguration.java
View file @
447da0dd
...
@@ -20,12 +20,13 @@ import org.springframework.cloud.netflix.ribbon.eureka.DomainExtractingServerLis
...
@@ -20,12 +20,13 @@ import org.springframework.cloud.netflix.ribbon.eureka.DomainExtractingServerLis
import
org.springframework.cloud.netflix.ribbon.eureka.EurekaRibbonClientConfiguration
;
import
org.springframework.cloud.netflix.ribbon.eureka.EurekaRibbonClientConfiguration
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.core.env.ConfigurableEnvironment
;
import
com.nepxion.discovery.plugin.framework.decorator.DiscoveryEnabledNIWSServerListDecorator
;
import
com.nepxion.discovery.plugin.framework.decorator.DiscoveryEnabledNIWSServerListDecorator
;
import
com.nepxion.discovery.plugin.framework.listener.impl.LoadBalanceListenerExecutor
;
import
com.netflix.client.config.IClientConfig
;
import
com.netflix.client.config.IClientConfig
;
import
com.netflix.discovery.EurekaClient
;
import
com.netflix.discovery.EurekaClient
;
import
com.netflix.loadbalancer.ServerList
;
import
com.netflix.loadbalancer.ServerList
;
import
com.netflix.niws.loadbalancer.DiscoveryEnabledNIWSServerList
;
@Configuration
@Configuration
@AutoConfigureAfter
(
EurekaRibbonClientConfiguration
.
class
)
@AutoConfigureAfter
(
EurekaRibbonClientConfiguration
.
class
)
...
@@ -39,6 +40,12 @@ public class EurekaLoadBalanceConfiguration {
...
@@ -39,6 +40,12 @@ public class EurekaLoadBalanceConfiguration {
@Autowired
@Autowired
private
PropertiesFactory
propertiesFactory
;
private
PropertiesFactory
propertiesFactory
;
@Autowired
private
ConfigurableEnvironment
environment
;
@Autowired
private
LoadBalanceListenerExecutor
loadBalanceListenerExecutor
;
@Bean
@Bean
@ConditionalOnMissingBean
@ConditionalOnMissingBean
public
ServerList
<?>
ribbonServerList
(
IClientConfig
config
,
Provider
<
EurekaClient
>
eurekaClientProvider
)
{
public
ServerList
<?>
ribbonServerList
(
IClientConfig
config
,
Provider
<
EurekaClient
>
eurekaClientProvider
)
{
...
@@ -46,7 +53,11 @@ public class EurekaLoadBalanceConfiguration {
...
@@ -46,7 +53,11 @@ public class EurekaLoadBalanceConfiguration {
return
this
.
propertiesFactory
.
get
(
ServerList
.
class
,
config
,
serviceId
);
return
this
.
propertiesFactory
.
get
(
ServerList
.
class
,
config
,
serviceId
);
}
}
DiscoveryEnabledNIWSServerList
discoveryServerList
=
new
DiscoveryEnabledNIWSServerListDecorator
(
config
,
eurekaClientProvider
);
DiscoveryEnabledNIWSServerListDecorator
discoveryServerList
=
new
DiscoveryEnabledNIWSServerListDecorator
(
config
,
eurekaClientProvider
);
discoveryServerList
.
setEnvironment
(
environment
);
discoveryServerList
.
setLoadBalanceListenerExecutor
(
loadBalanceListenerExecutor
);
discoveryServerList
.
setServiceId
(
config
.
getClientName
());
DomainExtractingServerList
serverList
=
new
DomainExtractingServerList
(
discoveryServerList
,
config
,
this
.
approximateZoneFromHostname
);
DomainExtractingServerList
serverList
=
new
DomainExtractingServerList
(
discoveryServerList
,
config
,
this
.
approximateZoneFromHostname
);
return
serverList
;
return
serverList
;
...
...
discovery-plugin-framework-eureka/src/main/java/com/nepxion/discovery/plugin/framework/decorator/DiscoveryEnabledNIWSServerListDecorator.java
View file @
447da0dd
...
@@ -13,7 +13,6 @@ import java.util.List;
...
@@ -13,7 +13,6 @@ import java.util.List;
import
javax.inject.Provider
;
import
javax.inject.Provider
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.core.env.ConfigurableEnvironment
;
import
org.springframework.core.env.ConfigurableEnvironment
;
import
com.nepxion.discovery.plugin.framework.context.PluginContextAware
;
import
com.nepxion.discovery.plugin.framework.context.PluginContextAware
;
...
@@ -24,14 +23,11 @@ import com.netflix.niws.loadbalancer.DiscoveryEnabledNIWSServerList;
...
@@ -24,14 +23,11 @@ import com.netflix.niws.loadbalancer.DiscoveryEnabledNIWSServerList;
import
com.netflix.niws.loadbalancer.DiscoveryEnabledServer
;
import
com.netflix.niws.loadbalancer.DiscoveryEnabledServer
;
public
class
DiscoveryEnabledNIWSServerListDecorator
extends
DiscoveryEnabledNIWSServerList
{
public
class
DiscoveryEnabledNIWSServerListDecorator
extends
DiscoveryEnabledNIWSServerList
{
@Autowired
private
ConfigurableEnvironment
environment
;
private
ConfigurableEnvironment
environment
;
@Autowired
private
LoadBalanceListenerExecutor
loadBalanceListenerExecutor
;
private
LoadBalanceListenerExecutor
loadBalanceListenerExecutor
;
@Autowired
private
String
serviceId
;
private
IClientConfig
clientConfig
;
@Deprecated
@Deprecated
public
DiscoveryEnabledNIWSServerListDecorator
()
{
public
DiscoveryEnabledNIWSServerListDecorator
()
{
...
@@ -77,8 +73,19 @@ public class DiscoveryEnabledNIWSServerListDecorator extends DiscoveryEnabledNIW
...
@@ -77,8 +73,19 @@ public class DiscoveryEnabledNIWSServerListDecorator extends DiscoveryEnabledNIW
private
void
filter
(
List
<
DiscoveryEnabledServer
>
servers
)
{
private
void
filter
(
List
<
DiscoveryEnabledServer
>
servers
)
{
Boolean
discoveryControlEnabled
=
PluginContextAware
.
isDiscoveryControlEnabled
(
environment
);
Boolean
discoveryControlEnabled
=
PluginContextAware
.
isDiscoveryControlEnabled
(
environment
);
if
(
discoveryControlEnabled
)
{
if
(
discoveryControlEnabled
)
{
String
serviceId
=
clientConfig
.
getClientName
();
loadBalanceListenerExecutor
.
onGetServers
(
serviceId
,
servers
);
loadBalanceListenerExecutor
.
onGetServers
(
serviceId
,
servers
);
}
}
}
}
public
void
setEnvironment
(
ConfigurableEnvironment
environment
)
{
this
.
environment
=
environment
;
}
public
void
setLoadBalanceListenerExecutor
(
LoadBalanceListenerExecutor
loadBalanceListenerExecutor
)
{
this
.
loadBalanceListenerExecutor
=
loadBalanceListenerExecutor
;
}
public
void
setServiceId
(
String
serviceId
)
{
this
.
serviceId
=
serviceId
;
}
}
}
\ No newline at end of file
discovery-plugin-framework-zookeeper/src/main/java/com/nepxion/discovery/plugin/framework/configuration/ZookeeperLoadBalanceConfiguration.java
View file @
447da0dd
...
@@ -12,11 +12,13 @@ package com.nepxion.discovery.plugin.framework.configuration;
...
@@ -12,11 +12,13 @@ package com.nepxion.discovery.plugin.framework.configuration;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.autoconfigure.AutoConfigureAfter
;
import
org.springframework.boot.autoconfigure.AutoConfigureAfter
;
import
org.springframework.cloud.zookeeper.discovery.ZookeeperRibbonClientConfiguration
;
import
org.springframework.cloud.zookeeper.discovery.ZookeeperRibbonClientConfiguration
;
import
org.springframework.cloud.zookeeper.discovery.ZookeeperServerList
;
import
org.springframework.cloud.zookeeper.serviceregistry.ZookeeperServiceRegistry
;
import
org.springframework.cloud.zookeeper.serviceregistry.ZookeeperServiceRegistry
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.core.env.ConfigurableEnvironment
;
import
com.nepxion.discovery.plugin.framework.decorator.ZookeeperServerListDecorator
;
import
com.nepxion.discovery.plugin.framework.listener.impl.LoadBalanceListenerExecutor
;
import
com.netflix.client.config.IClientConfig
;
import
com.netflix.client.config.IClientConfig
;
import
com.netflix.loadbalancer.ServerList
;
import
com.netflix.loadbalancer.ServerList
;
...
@@ -24,13 +26,22 @@ import com.netflix.loadbalancer.ServerList;
...
@@ -24,13 +26,22 @@ import com.netflix.loadbalancer.ServerList;
@AutoConfigureAfter
(
ZookeeperRibbonClientConfiguration
.
class
)
@AutoConfigureAfter
(
ZookeeperRibbonClientConfiguration
.
class
)
public
class
ZookeeperLoadBalanceConfiguration
{
public
class
ZookeeperLoadBalanceConfiguration
{
@Autowired
@Autowired
private
ConfigurableEnvironment
environment
;
@Autowired
private
LoadBalanceListenerExecutor
loadBalanceListenerExecutor
;
@Autowired
private
ZookeeperServiceRegistry
registry
;
private
ZookeeperServiceRegistry
registry
;
@Bean
@Bean
public
ServerList
<?>
ribbonServerList
(
IClientConfig
config
)
{
public
ServerList
<?>
ribbonServerList
(
IClientConfig
config
)
{
@SuppressWarnings
(
"deprecation"
)
@SuppressWarnings
(
"deprecation"
)
ZookeeperServerList
serverList
=
new
ZookeeperServerList
(
this
.
registry
.
getServiceDiscoveryRef
().
get
());
ZookeeperServerList
Decorator
serverList
=
new
ZookeeperServerListDecorator
(
this
.
registry
.
getServiceDiscoveryRef
().
get
());
serverList
.
initWithNiwsConfig
(
config
);
serverList
.
initWithNiwsConfig
(
config
);
serverList
.
setEnvironment
(
environment
);
serverList
.
setLoadBalanceListenerExecutor
(
loadBalanceListenerExecutor
);
serverList
.
setServiceId
(
config
.
getClientName
());
return
serverList
;
return
serverList
;
}
}
...
...
discovery-plugin-framework-zookeeper/src/main/java/com/nepxion/discovery/plugin/framework/decorator/ZookeeperServerListDecorator.java
View file @
447da0dd
...
@@ -12,7 +12,6 @@ package com.nepxion.discovery.plugin.framework.decorator;
...
@@ -12,7 +12,6 @@ package com.nepxion.discovery.plugin.framework.decorator;
import
java.util.List
;
import
java.util.List
;
import
org.apache.curator.x.discovery.ServiceDiscovery
;
import
org.apache.curator.x.discovery.ServiceDiscovery
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.cloud.zookeeper.discovery.ZookeeperInstance
;
import
org.springframework.cloud.zookeeper.discovery.ZookeeperInstance
;
import
org.springframework.cloud.zookeeper.discovery.ZookeeperServer
;
import
org.springframework.cloud.zookeeper.discovery.ZookeeperServer
;
import
org.springframework.cloud.zookeeper.discovery.ZookeeperServerList
;
import
org.springframework.cloud.zookeeper.discovery.ZookeeperServerList
;
...
@@ -20,17 +19,13 @@ import org.springframework.core.env.ConfigurableEnvironment;
...
@@ -20,17 +19,13 @@ import org.springframework.core.env.ConfigurableEnvironment;
import
com.nepxion.discovery.plugin.framework.context.PluginContextAware
;
import
com.nepxion.discovery.plugin.framework.context.PluginContextAware
;
import
com.nepxion.discovery.plugin.framework.listener.impl.LoadBalanceListenerExecutor
;
import
com.nepxion.discovery.plugin.framework.listener.impl.LoadBalanceListenerExecutor
;
import
com.netflix.client.config.IClientConfig
;
public
class
ZookeeperServerListDecorator
extends
ZookeeperServerList
{
public
class
ZookeeperServerListDecorator
extends
ZookeeperServerList
{
@Autowired
private
ConfigurableEnvironment
environment
;
private
ConfigurableEnvironment
environment
;
@Autowired
private
LoadBalanceListenerExecutor
loadBalanceListenerExecutor
;
private
LoadBalanceListenerExecutor
loadBalanceListenerExecutor
;
@Autowired
private
String
serviceId
;
private
IClientConfig
clientConfig
;
public
ZookeeperServerListDecorator
(
ServiceDiscovery
<
ZookeeperInstance
>
serviceDiscovery
)
{
public
ZookeeperServerListDecorator
(
ServiceDiscovery
<
ZookeeperInstance
>
serviceDiscovery
)
{
super
(
serviceDiscovery
);
super
(
serviceDiscovery
);
...
@@ -57,8 +52,19 @@ public class ZookeeperServerListDecorator extends ZookeeperServerList {
...
@@ -57,8 +52,19 @@ public class ZookeeperServerListDecorator extends ZookeeperServerList {
private
void
filter
(
List
<
ZookeeperServer
>
servers
)
{
private
void
filter
(
List
<
ZookeeperServer
>
servers
)
{
Boolean
discoveryControlEnabled
=
PluginContextAware
.
isDiscoveryControlEnabled
(
environment
);
Boolean
discoveryControlEnabled
=
PluginContextAware
.
isDiscoveryControlEnabled
(
environment
);
if
(
discoveryControlEnabled
)
{
if
(
discoveryControlEnabled
)
{
String
serviceId
=
clientConfig
.
getClientName
();
loadBalanceListenerExecutor
.
onGetServers
(
serviceId
,
servers
);
loadBalanceListenerExecutor
.
onGetServers
(
serviceId
,
servers
);
}
}
}
}
public
void
setEnvironment
(
ConfigurableEnvironment
environment
)
{
this
.
environment
=
environment
;
}
public
void
setLoadBalanceListenerExecutor
(
LoadBalanceListenerExecutor
loadBalanceListenerExecutor
)
{
this
.
loadBalanceListenerExecutor
=
loadBalanceListenerExecutor
;
}
public
void
setServiceId
(
String
serviceId
)
{
this
.
serviceId
=
serviceId
;
}
}
}
\ 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