Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
thythm
ribbon
提交
3ece0a13
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 搜索 >>
提交
3ece0a13
编写于
8月 01, 2014
作者:
A
Allen Wang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix the problem that LoadBalancerContext unnecessarily create new Server object. Code clean up.
上级
d4020803
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
36 addition
and
59 deletion
+36
-59
build.gradle
build.gradle
+2
-16
ribbon-eureka/src/test/java/com/netflix/niws/loadbalancer/LBBuilderTest.java
...est/java/com/netflix/niws/loadbalancer/LBBuilderTest.java
+20
-18
ribbon-loadbalancer/src/main/java/com/netflix/loadbalancer/LoadBalancerContext.java
...in/java/com/netflix/loadbalancer/LoadBalancerContext.java
+14
-25
未找到文件。
build.gradle
浏览文件 @
3ece0a13
...
...
@@ -81,12 +81,12 @@ project(':ribbon-transport') {
}
project
(
':ribbon-eureka'
)
{
project
(
':ribbon-eureka'
)
{
dependencies
{
compile
project
(
':ribbon-core'
)
compile
project
(
':ribbon-loadbalancer'
)
compile
'com.netflix.eureka:eureka-client:1.1.136'
}
}
}
project
(
':ribbon-examples'
)
{
...
...
@@ -114,20 +114,6 @@ project(':ribbon-test') {
}
}
project
(
':ribbon-guice'
)
{
dependencies
{
compile
project
(
':ribbon'
)
compile
project
(
':ribbon-core'
)
compile
project
(
':ribbon-httpclient'
)
compile
project
(
':ribbon-loadbalancer'
)
compile
'com.google.inject:guice:3.0'
compile
'com.google.inject.extensions:guice-multibindings:3.0'
testCompile
project
(
':ribbon-examples'
)
}
}
project
(
':ribbon'
)
{
configurations
{
// add new configuration
...
...
ribbon-eureka/src/test/java/com/netflix/niws/loadbalancer/LBBuilderTest.java
浏览文件 @
3ece0a13
package
com.netflix.niws.loadbalancer
;
import
static
org
.
easymock
.
EasyMock
.
expect
;
import
static
org
.
junit
.
Assert
.*;
import
static
org
.
powermock
.
api
.
easymock
.
PowerMock
.
createMock
;
import
static
org
.
powermock
.
api
.
easymock
.
PowerMock
.
replay
;
import
java.util.ArrayList
;
import
java.util.List
;
import
org.apache.commons.configuration.Configuration
;
import
org.easymock.EasyMock
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.powermock.api.easymock.PowerMock
;
import
org.powermock.core.classloader.annotations.PowerMockIgnore
;
import
org.powermock.core.classloader.annotations.PrepareForTest
;
import
org.powermock.modules.junit4.PowerMockRunner
;
import
com.google.common.collect.Lists
;
import
com.netflix.appinfo.InstanceInfo
;
import
com.netflix.client.config.DefaultClientConfigImpl
;
...
...
@@ -39,6 +21,23 @@ import com.netflix.loadbalancer.ServerList;
import
com.netflix.loadbalancer.ServerListFilter
;
import
com.netflix.loadbalancer.ZoneAffinityServerListFilter
;
import
com.netflix.loadbalancer.ZoneAwareLoadBalancer
;
import
org.apache.commons.configuration.Configuration
;
import
org.easymock.EasyMock
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.powermock.api.easymock.PowerMock
;
import
org.powermock.core.classloader.annotations.PowerMockIgnore
;
import
org.powermock.core.classloader.annotations.PrepareForTest
;
import
org.powermock.modules.junit4.PowerMockRunner
;
import
java.util.ArrayList
;
import
java.util.List
;
import
static
org
.
easymock
.
EasyMock
.
expect
;
import
static
org
.
junit
.
Assert
.*;
import
static
org
.
powermock
.
api
.
easymock
.
PowerMock
.
createMock
;
import
static
org
.
powermock
.
api
.
easymock
.
PowerMock
.
replay
;
@RunWith
(
PowerMockRunner
.
class
)
@PrepareForTest
(
{
DiscoveryManager
.
class
,
DiscoveryClient
.
class
}
)
...
...
@@ -105,6 +104,9 @@ public class LBBuilderTest {
assertEquals
(
Lists
.
newArrayList
(
expected
),
lb
.
getServerList
(
false
));
assertSame
(
filter
,
lb
.
getFilter
());
assertSame
(
list
,
lb
.
getServerListImpl
());
Server
server
=
lb
.
chooseServer
();
// make sure load balancer does not recreate the server instance
assertTrue
(
server
instanceof
DiscoveryEnabledServer
);
}
@Test
...
...
ribbon-loadbalancer/src/main/java/com/netflix/loadbalancer/LoadBalancerContext.java
浏览文件 @
3ece0a13
...
...
@@ -470,15 +470,12 @@ public class LoadBalancerContext implements IClientConfigAware {
+
clientName
);
}
host
=
svc
.
getHost
();
port
=
svc
.
getPort
();
if
(
host
==
null
){
throw
new
ClientException
(
ClientException
.
ErrorType
.
GENERAL
,
"Invalid Server for :"
+
svc
);
}
if
(
logger
.
isDebugEnabled
()){
logger
.
debug
(
clientName
+
" using LB returned Server:"
+
svc
+
"for request"
);
}
logger
.
debug
(
"{} using LB returned Server: {} for request {}"
,
clientName
,
svc
,
original
);
return
svc
;
}
else
{
// No Full URL - and we dont have a LoadBalancer registered to
// obtain a server
...
...
@@ -488,12 +485,11 @@ public class LoadBalancerContext implements IClientConfigAware {
if
(
vipAddresses
!=
null
&&
vipAddresses
.
contains
(
","
))
{
throw
new
ClientException
(
ClientException
.
ErrorType
.
GENERAL
,
this
.
clientName
+
"Partial URI of ("
"Method is invoked for client "
+
clientName
+
" with partial URI of ("
+
original
+
")
has been sent in to RestClient (with no LB) to be execut
ed."
+
" Also, there are multiple vipAddresses and hence
RestClient cant pick
"
+
"
one vipAddress
to complete this partial uri"
);
+
")
with no load balancer configur
ed."
+
" Also, there are multiple vipAddresses and hence
no vip address can be chosen
"
+
" to complete this partial uri"
);
}
else
if
(
vipAddresses
!=
null
)
{
try
{
Pair
<
String
,
Integer
>
hostAndPort
=
deriveHostAndPortFromVipAddress
(
vipAddresses
);
...
...
@@ -502,13 +498,12 @@ public class LoadBalancerContext implements IClientConfigAware {
}
catch
(
URISyntaxException
e
)
{
throw
new
ClientException
(
ClientException
.
ErrorType
.
GENERAL
,
this
.
clientName
+
"Partial URI of ("
"Method is invoked for client "
+
clientName
+
" with partial URI of ("
+
original
+
")
has been sent in to RestClient (with no LB) to be executed.
"
+
")
with no load balancer configured.
"
+
" Also, the configured/registered vipAddress is unparseable (to determine host and port)"
);
}
}
else
{
}
else
{
throw
new
ClientException
(
ClientException
.
ErrorType
.
GENERAL
,
this
.
clientName
...
...
@@ -534,26 +529,20 @@ public class LoadBalancerContext implements IClientConfigAware {
Server
svc
=
lb
.
chooseServer
(
loadBalancerKey
);
if
(
svc
!=
null
){
host
=
svc
.
getHost
();
port
=
svc
.
getPort
();
if
(
host
==
null
){
throw
new
ClientException
(
ClientException
.
ErrorType
.
GENERAL
,
"Invalid Server for :"
+
svc
);
}
if
(
logger
.
isDebugEnabled
()){
logger
.
debug
(
"using LB returned Server:"
+
svc
+
"for request:"
+
original
);
}
}
else
{
logger
.
debug
(
"using LB returned Server: {} for request: {}"
,
svc
,
original
);
return
svc
;
}
else
{
// just fall back as real DNS
if
(
logger
.
isDebugEnabled
()){
logger
.
debug
(
host
+
":"
+
port
+
" assumed to be a valid VIP address or exists in the DNS"
);
}
logger
.
debug
(
"{}:{} assumed to be a valid VIP address or exists in the DNS"
,
host
,
port
);
}
}
else
{
// consult LB to obtain vipAddress backed instance given full URL
//Full URL execute request - where url!=vipAddress
if
(
logger
.
isDebugEnabled
()){
logger
.
debug
(
"Using full URL passed in by caller (not using LB/Discovery):"
+
original
);
}
logger
.
debug
(
"Using full URL passed in by caller (not using load balancer): {}"
,
original
);
}
}
// end of creating final URL
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录