Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
thythm
ribbon
提交
53566908
R
ribbon
项目概览
thythm
/
ribbon
与 Fork 源项目一致
从无法访问的项目Fork
通知
3
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
ribbon
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
未验证
提交
53566908
编写于
5月 19, 2019
作者:
E
elandau
提交者:
GitHub
5月 19, 2019
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #420 from elandau/bugfix/overrides
config: Simplify how overrides are applied
上级
532285a0
c6e492dc
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
53 addition
and
57 deletion
+53
-57
ribbon-archaius/src/main/java/com/netflix/client/config/DefaultClientConfigImpl.java
...va/com/netflix/client/config/DefaultClientConfigImpl.java
+2
-14
ribbon-core/src/main/java/com/netflix/client/config/CommonClientConfigKey.java
...java/com/netflix/client/config/CommonClientConfigKey.java
+13
-0
ribbon-core/src/main/java/com/netflix/client/config/IClientConfig.java
...rc/main/java/com/netflix/client/config/IClientConfig.java
+0
-8
ribbon-core/src/main/java/com/netflix/client/config/ReloadableClientConfig.java
...ava/com/netflix/client/config/ReloadableClientConfig.java
+30
-31
ribbon-core/src/test/java/com/netflix/client/config/ClientConfigTest.java
...test/java/com/netflix/client/config/ClientConfigTest.java
+6
-2
ribbon-loadbalancer/src/test/java/com/netflix/loadbalancer/SubsetFilterTest.java
.../test/java/com/netflix/loadbalancer/SubsetFilterTest.java
+1
-1
ribbon-loadbalancer/src/test/java/com/netflix/loadbalancer/ZoneAwareLoadBalancerTest.java
...a/com/netflix/loadbalancer/ZoneAwareLoadBalancerTest.java
+1
-1
未找到文件。
ribbon-archaius/src/main/java/com/netflix/client/config/DefaultClientConfigImpl.java
浏览文件 @
53566908
...
...
@@ -17,7 +17,6 @@
*/
package
com.netflix.client.config
;
import
com.netflix.config.ConfigurationManager
;
import
java.util.concurrent.TimeUnit
;
...
...
@@ -302,7 +301,6 @@ public class DefaultClientConfigImpl extends AbstractDefaultClientConfigImpl {
}
public
void
loadDefaultValues
()
{
super
.
loadDefaultValues
();
set
(
CommonClientConfigKey
.
MaxHttpConnectionsPerHost
,
getDefaultMaxHttpConnectionsPerHost
());
set
(
CommonClientConfigKey
.
MaxTotalHttpConnections
,
getDefaultMaxTotalHttpConnections
());
set
(
CommonClientConfigKey
.
EnableConnectionPool
,
getDefaultEnableConnectionPool
());
...
...
@@ -319,18 +317,8 @@ public class DefaultClientConfigImpl extends AbstractDefaultClientConfigImpl {
set
(
CommonClientConfigKey
.
ConnIdleEvictTimeMilliSeconds
,
getDefaultConnectionidleTimeInMsecs
());
set
(
CommonClientConfigKey
.
ConnectionCleanerRepeatInterval
,
getDefaultConnectionIdleTimertaskRepeatInMsecs
());
set
(
CommonClientConfigKey
.
EnableGZIPContentEncodingFilter
,
getDefaultEnableGzipContentEncodingFilter
());
String
proxyHost
=
ConfigurationManager
.
getConfigInstance
().
getString
(
getDefaultPropName
(
CommonClientConfigKey
.
ProxyHost
.
key
()));
if
(
proxyHost
!=
null
&&
proxyHost
.
length
()
>
0
)
{
set
(
CommonClientConfigKey
.
ProxyHost
,
proxyHost
);
}
Integer
proxyPort
=
ConfigurationManager
.
getConfigInstance
()
.
getInteger
(
getDefaultPropName
(
CommonClientConfigKey
.
ProxyPort
),
(
Integer
.
MIN_VALUE
+
1
));
// + 1 just to avoid potential clash with user setting
if
(
proxyPort
!=
(
Integer
.
MIN_VALUE
+
1
))
{
set
(
CommonClientConfigKey
.
ProxyPort
,
proxyPort
);
}
set
(
CommonClientConfigKey
.
ProxyHost
,
null
);
set
(
CommonClientConfigKey
.
ProxyPort
,
null
);
set
(
CommonClientConfigKey
.
Port
,
getDefaultPort
());
set
(
CommonClientConfigKey
.
EnablePrimeConnections
,
getDefaultEnablePrimeConnections
());
set
(
CommonClientConfigKey
.
MaxRetriesPerServerPrimeConnection
,
getDefaultMaxRetriesPerServerPrimeConnection
());
...
...
ribbon-core/src/main/java/com/netflix/client/config/CommonClientConfigKey.java
浏览文件 @
53566908
...
...
@@ -24,6 +24,7 @@ import java.lang.reflect.Modifier;
import
java.lang.reflect.ParameterizedType
;
import
java.lang.reflect.Type
;
import
java.util.HashSet
;
import
java.util.Objects
;
import
java.util.Set
;
import
java.util.concurrent.TimeUnit
;
...
...
@@ -285,4 +286,16 @@ public abstract class CommonClientConfigKey<T> implements IClientConfigKey<T> {
@Override
public
T
defaultValue
()
{
return
defaultValue
;
}
@Override
public
boolean
equals
(
Object
o
)
{
if
(
this
==
o
)
return
true
;
if
(
o
==
null
||
getClass
()
!=
o
.
getClass
())
return
false
;
CommonClientConfigKey
<?>
that
=
(
CommonClientConfigKey
<?>)
o
;
return
Objects
.
equals
(
configKey
,
that
.
configKey
);
}
@Override
public
int
hashCode
()
{
return
Objects
.
hash
(
configKey
);
}
}
ribbon-core/src/main/java/com/netflix/client/config/IClientConfig.java
浏览文件 @
53566908
...
...
@@ -49,14 +49,6 @@ public interface IClientConfig {
Map
<
String
,
Object
>
getProperties
();
/**
* Iterate all properties and report the default value only to the consumer
* @param consumer
*/
default
void
forEachDefault
(
BiConsumer
<
IClientConfigKey
<?>,
Object
>
consumer
)
{
throw
new
UnsupportedOperationException
();
}
/**
* Iterate all properties and report the final value. Can be null if a default value is not specified.
* @param consumer
...
...
ribbon-core/src/main/java/com/netflix/client/config/ReloadableClientConfig.java
浏览文件 @
53566908
...
...
@@ -39,7 +39,7 @@ public abstract class ReloadableClientConfig implements IClientConfig {
private
static
final
String
DEFAULT_NAMESPACE
=
"ribbon"
;
// Map of raw property names (without namespace or client) to values set via code
private
final
Map
<
String
,
Object
>
internalProperties
=
new
HashMap
<>();
private
final
Map
<
IClientConfigKey
,
Object
>
internalProperties
=
new
HashMap
<>();
// Map of all seen dynamic properties. This map will hold on properties requested with the exception of
// those returned from getGlobalProperty().
...
...
@@ -57,19 +57,15 @@ public abstract class ReloadableClientConfig implements IClientConfig {
private
String
namespace
=
DEFAULT_NAMESPACE
;
private
boolean
isDynamic
;
private
boolean
isLoaded
=
false
;
protected
ReloadableClientConfig
(
PropertyResolver
resolver
)
{
this
.
clientName
=
DEFAULT_CLIENT_NAME
;
this
.
isDynamic
=
false
;
this
.
resolver
=
resolver
;
}
protected
ReloadableClientConfig
(
PropertyResolver
resolver
,
String
clientName
)
{
this
.
clientName
=
clientName
;
this
.
isDynamic
=
true
;
this
.
resolver
=
resolver
;
}
...
...
@@ -112,29 +108,24 @@ public abstract class ReloadableClientConfig implements IClientConfig {
public
void
loadProperties
(
String
clientName
)
{
Preconditions
.
checkState
(
isLoaded
==
false
,
"Config '{}' can only be loaded once"
,
clientName
);
if
(!
isLoaded
)
{
loadDefaultValues
();
this
.
isLoaded
=
true
;
resolver
.
onChange
(
this
::
reload
);
}
this
.
isDynamic
=
true
;
this
.
clientName
=
clientName
;
loadDefaultValues
();
}
@Override
public
void
loadDefaultValues
()
{
this
.
isDynamic
=
true
;
reload
();
}
@Override
public
final
Map
<
String
,
Object
>
getProperties
()
{
return
Collections
.
unmodifiableMap
(
internalProperties
);
}
@Override
public
void
forEachDefault
(
BiConsumer
<
IClientConfigKey
<?>,
Object
>
consumer
)
{
dynamicProperties
.
forEach
((
key
,
value
)
->
consumer
.
accept
(
key
,
internalProperties
.
get
(
key
.
key
())));
final
Map
<
String
,
Object
>
result
=
new
HashMap
<>(
dynamicProperties
.
size
());
dynamicProperties
.
forEach
((
key
,
value
)
->
{
Object
v
=
value
.
get
().
orElse
(
null
);
if
(
v
!=
null
)
{
result
.
put
(
key
.
key
(),
String
.
valueOf
(
v
));
}
});
return
result
;
}
@Override
...
...
@@ -150,9 +141,7 @@ public abstract class ReloadableClientConfig implements IClientConfig {
{
refresh
();
if
(
isDynamic
)
{
changeActions
.
add
(
this
::
refresh
);
}
changeActions
.
add
(
this
::
refresh
);
}
@Override
...
...
@@ -192,11 +181,7 @@ public abstract class ReloadableClientConfig implements IClientConfig {
@Override
public
final
<
T
>
T
get
(
IClientConfigKey
<
T
>
key
)
{
if
(
isLoaded
)
{
return
getOrCreateProperty
(
key
).
get
().
orElse
(
null
);
}
else
{
return
getIfSet
(
key
).
orElse
(
null
);
}
return
getOrCreateProperty
(
key
).
get
().
orElse
(
null
);
}
private
final
<
T
>
ReloadableProperty
<
T
>
getOrCreateProperty
(
IClientConfigKey
<
T
>
key
)
{
...
...
@@ -251,6 +236,12 @@ public abstract class ReloadableClientConfig implements IClientConfig {
return
getIfSet
(
key
);
}
/**
* Resolve a p
* @param key
* @param <T>
* @return
*/
private
<
T
>
Optional
<
T
>
resolverScopedProperty
(
IClientConfigKey
<
T
>
key
)
{
Optional
<
T
>
value
=
resolver
.
get
(
clientName
+
"."
+
getNameSpace
()
+
"."
+
key
.
key
(),
key
.
type
());
if
(
value
.
isPresent
())
{
...
...
@@ -262,7 +253,7 @@ public abstract class ReloadableClientConfig implements IClientConfig {
@Override
public
<
T
>
Optional
<
T
>
getIfSet
(
IClientConfigKey
<
T
>
key
)
{
return
Optional
.
ofNullable
(
internalProperties
.
get
(
key
.
key
()
))
return
Optional
.
ofNullable
(
internalProperties
.
get
(
key
))
.
map
(
value
->
{
final
Class
<
T
>
type
=
key
.
type
();
// Unfortunately there's some legacy code setting string values for typed keys. Here are do our best to parse
...
...
@@ -359,7 +350,7 @@ public abstract class ReloadableClientConfig implements IClientConfig {
if
(
value
==
null
)
{
internalProperties
.
remove
(
key
.
key
());
}
else
{
internalProperties
.
put
(
key
.
key
()
,
value
);
internalProperties
.
put
(
key
,
value
);
}
if
(
isLoaded
)
{
...
...
@@ -418,8 +409,16 @@ public abstract class ReloadableClientConfig implements IClientConfig {
return
this
;
}
this
.
internalProperties
.
putAll
(
override
.
getProperties
());
reload
();
// When overriding we only really care of picking up properties that were explicitly set in code. This is a
// bit of an optimization to avoid excessive memory allocation as requests are made and overrides are applied
if
(
override
instanceof
ReloadableClientConfig
)
{
((
ReloadableClientConfig
)
override
).
internalProperties
.
forEach
((
key
,
value
)
->
{
if
(
value
!=
null
)
{
setProperty
(
key
,
value
);
}
});
}
return
this
;
}
...
...
ribbon-core/src/test/java/com/netflix/client/config/ClientConfigTest.java
浏览文件 @
53566908
...
...
@@ -30,6 +30,8 @@ import org.junit.Rule;
import
org.junit.Test
;
import
org.junit.rules.TestName
;
import
org.junit.runners.MethodSorters
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
java.util.Properties
;
...
...
@@ -41,6 +43,8 @@ import java.util.Properties;
*/
@FixMethodOrder
(
MethodSorters
.
NAME_ASCENDING
)
public
class
ClientConfigTest
{
private
static
final
Logger
LOG
=
LoggerFactory
.
getLogger
(
ClientConfigTest
.
class
);
@Rule
public
TestName
testName
=
new
TestName
();
...
...
@@ -186,7 +190,7 @@ public class ClientConfigTest {
ConfigurationManager
.
getConfigInstance
().
setProperty
(
"testValueOf.ribbon.CustomValueOf"
,
"value"
);
DefaultClientConfigImpl
clientConfig
=
new
DefaultClientConfigImpl
();
clientConfig
.
setClientName
(
"testValueOf"
);
clientConfig
.
loadProperties
(
"testValueOf"
);
Property
<
CustomValueOf
>
prop
=
clientConfig
.
getDynamicProperty
(
CUSTOM_KEY
);
Assert
.
assertEquals
(
"value"
,
prop
.
getOrDefault
().
getValue
());
...
...
@@ -198,7 +202,7 @@ public class ClientConfigTest {
ConfigurationManager
.
getConfigInstance
().
setProperty
(
"testScopedProperty.ribbon.foo.ScopePropertyTimeout"
,
"1000"
);
DefaultClientConfigImpl
clientConfig
=
new
DefaultClientConfigImpl
();
clientConfig
.
setClientName
(
"testScopedProperty"
);
clientConfig
.
loadProperties
(
"testScopedProperty"
);
Property
<
Integer
>
prop
=
clientConfig
.
getScopedProperty
(
new
CommonClientConfigKey
<
Integer
>(
"foo.ScopePropertyTimeout"
,
0
)
{});
Assert
.
assertEquals
(
1000
,
prop
.
get
().
get
().
intValue
());
...
...
ribbon-loadbalancer/src/test/java/com/netflix/loadbalancer/SubsetFilterTest.java
浏览文件 @
53566908
...
...
@@ -84,7 +84,7 @@ public class SubsetFilterTest {
@Test
public
void
testFiltering
()
{
DefaultClientConfigImpl
config
=
new
DefaultClientConfigImpl
();
config
.
setClientName
(
"SubsetFilerTest"
);
config
.
loadProperties
(
"SubsetFilerTest"
);
ServerListSubsetFilter
<
Server
>
filter
=
new
ServerListSubsetFilter
<
Server
>(
config
);
LoadBalancerStats
stats
=
new
LoadBalancerStats
(
"default"
);
...
...
ribbon-loadbalancer/src/test/java/com/netflix/loadbalancer/ZoneAwareLoadBalancerTest.java
浏览文件 @
53566908
...
...
@@ -74,7 +74,7 @@ public class ZoneAwareLoadBalancerTest {
ConfigurationManager
.
getConfigInstance
().
setProperty
(
"niws.loadbalancer.serverStats.activeRequestsCount.effectiveWindowSeconds"
,
10
);
DefaultClientConfigImpl
config
=
new
DefaultClientConfigImpl
();
config
.
setClientName
(
"testChooseZone"
);
config
.
loadProperties
(
"testChooseZone"
);
ZoneAwareLoadBalancer
<
Server
>
balancer
=
new
ZoneAwareLoadBalancer
<
Server
>();
balancer
.
init
();
IRule
globalRule
=
new
RoundRobinRule
();
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录