Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
spring-cloud-netflix
Project
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
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
openSource
spring-cloud-netflix
Commits
acaf2d20
Commit
acaf2d20
authored
Nov 19, 2014
by
Spencer Gibb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Only set ribbon properties if they are not already set.
fixes gh-45
parent
d2988b21
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
45 additions
and
4 deletions
+45
-4
EurekaRibbonClientPreprocessor.java
...netflix/ribbon/eureka/EurekaRibbonClientPreprocessor.java
+19
-4
EurekaRibbonClientPreprocessorTests.java
...ix/ribbon/eureka/EurekaRibbonClientPreprocessorTests.java
+26
-0
No files found.
spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/ribbon/eureka/EurekaRibbonClientPreprocessor.java
View file @
acaf2d20
...
...
@@ -6,6 +6,8 @@ import static com.netflix.client.config.CommonClientConfigKey.NFLoadBalancerRule
import
static
com
.
netflix
.
client
.
config
.
CommonClientConfigKey
.
NIWSServerListClassName
;
import
static
com
.
netflix
.
client
.
config
.
CommonClientConfigKey
.
NIWSServerListFilterClassName
;
import
com.netflix.config.DynamicPropertyFactory
;
import
com.netflix.config.DynamicStringProperty
;
import
org.springframework.cloud.netflix.ribbon.RibbonClientPreprocessor
;
import
org.springframework.cloud.netflix.ribbon.SpringClientFactory
;
...
...
@@ -29,7 +31,10 @@ import com.netflix.niws.loadbalancer.DiscoveryEnabledNIWSServerList;
*/
public
class
EurekaRibbonClientPreprocessor
implements
RibbonClientPreprocessor
{
private
EurekaClientConfig
clientConfig
;
protected
static
final
String
VALUE_NOT_SET
=
"__not__set__"
;
protected
static
final
String
DEFAULT_NAMESPACE
=
"ribbon"
;
private
EurekaClientConfig
clientConfig
;
private
SpringClientFactory
clientFactory
;
public
EurekaRibbonClientPreprocessor
(
EurekaClientConfig
clientConfig
,
SpringClientFactory
clientFactory
)
{
...
...
@@ -83,9 +88,19 @@ public class EurekaRibbonClientPreprocessor implements RibbonClientPreprocessor
protected
void
setProp
(
String
serviceId
,
String
suffix
,
String
value
)
{
// how to set the namespace properly?
String
namespace
=
"ribbon"
;
ConfigurationManager
.
getConfigInstance
().
setProperty
(
serviceId
+
"."
+
namespace
+
"."
+
suffix
,
value
);
String
key
=
getKey
(
serviceId
,
suffix
);
DynamicStringProperty
property
=
getProperty
(
key
);
if
(
property
.
get
().
equals
(
VALUE_NOT_SET
))
{
ConfigurationManager
.
getConfigInstance
().
setProperty
(
key
,
value
);
}
}
protected
DynamicStringProperty
getProperty
(
String
key
)
{
return
DynamicPropertyFactory
.
getInstance
().
getStringProperty
(
key
,
VALUE_NOT_SET
);
}
protected
String
getKey
(
String
serviceId
,
String
suffix
)
{
return
serviceId
+
"."
+
DEFAULT_NAMESPACE
+
"."
+
suffix
;
}
}
spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/ribbon/eureka/EurekaRibbonClientPreprocessorTests.java
View file @
acaf2d20
...
...
@@ -18,7 +18,9 @@ package org.springframework.cloud.netflix.ribbon.eureka;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertNotNull
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
springframework
.
cloud
.
netflix
.
ribbon
.
eureka
.
EurekaRibbonClientPreprocessor
.*;
import
com.netflix.config.DynamicStringProperty
;
import
org.junit.After
;
import
org.junit.Test
;
import
org.springframework.cloud.netflix.ribbon.SpringClientFactory
;
...
...
@@ -57,4 +59,28 @@ public class EurekaRibbonClientPreprocessorTests {
assertEquals
(
"foo"
,
ConfigurationManager
.
getDeploymentContext
().
getValue
(
ContextKey
.
zone
));
}
@Test
public
void
testSetProp
()
{
EurekaClientConfigBean
client
=
new
EurekaClientConfigBean
();
SpringClientFactory
clientFactory
=
new
SpringClientFactory
();
EurekaRibbonClientPreprocessor
preprocessor
=
new
EurekaRibbonClientPreprocessor
(
client
,
clientFactory
);
String
serviceId
=
"myService"
;
String
suffix
=
"mySuffix"
;
String
value
=
"myValue"
;
DynamicStringProperty
property
=
preprocessor
.
getProperty
(
preprocessor
.
getKey
(
serviceId
,
suffix
));
assertEquals
(
"property doesn't have default value"
,
VALUE_NOT_SET
,
property
.
get
());
preprocessor
.
setProp
(
serviceId
,
suffix
,
value
);
assertEquals
(
"property has wrong value"
,
value
,
property
.
get
());
preprocessor
.
setProp
(
serviceId
,
suffix
,
value
);
assertEquals
(
"property has wrong value"
,
value
,
property
.
get
());
}
}
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