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
8d8f6937
Commit
8d8f6937
authored
Oct 21, 2014
by
Dave Syer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use instanceId for server id if available
parent
fa4d9700
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
41 additions
and
3 deletions
+41
-3
DomainExtractingServerList.java
...oud/netflix/ribbon/eureka/DomainExtractingServerList.java
+41
-3
No files found.
spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/ribbon/eureka/DomainExtractingServerList.java
View file @
8d8f6937
...
...
@@ -15,12 +15,18 @@
*/
package
org
.
springframework
.
cloud
.
netflix
.
ribbon
.
eureka
;
import
java.util.ArrayList
;
import
java.util.List
;
import
lombok.Getter
;
import
lombok.Setter
;
import
org.springframework.util.StringUtils
;
import
com.netflix.appinfo.InstanceInfo
;
import
com.netflix.loadbalancer.Server
;
import
com.netflix.loadbalancer.ServerList
;
import
com.netflix.niws.loadbalancer.DiscoveryEnabledServer
;
/**
* @author Dave Syer
...
...
@@ -47,11 +53,43 @@ public class DomainExtractingServerList implements ServerList<Server> {
}
private
List
<
Server
>
setZones
(
List
<
Server
>
servers
)
{
List
<
Server
>
result
=
new
ArrayList
<
Server
>();
for
(
Server
server
:
servers
)
{
String
zone
=
extractApproximateZone
(
server
);
server
.
setZone
(
zone
);
if
(
server
instanceof
DiscoveryEnabledServer
)
{
result
.
add
(
new
DomainExtractingServer
((
DiscoveryEnabledServer
)
server
));
}
else
{
result
.
add
(
server
);
}
}
return
servers
;
return
result
;
}
}
class
DomainExtractingServer
extends
DiscoveryEnabledServer
{
@Getter
@Setter
private
String
id
;
public
DomainExtractingServer
(
DiscoveryEnabledServer
server
)
{
super
(
server
.
getInstanceInfo
(),
true
,
false
);
String
zone
=
extractApproximateZone
(
server
);
setZone
(
zone
);
String
id
=
extractId
(
server
);
setId
(
id
);
}
private
String
extractId
(
Server
server
)
{
if
(
server
instanceof
DiscoveryEnabledServer
)
{
DiscoveryEnabledServer
enabled
=
(
DiscoveryEnabledServer
)
server
;
InstanceInfo
instance
=
enabled
.
getInstanceInfo
();
if
(
instance
.
getMetadata
().
containsKey
(
"instanceId"
))
{
return
instance
.
getMetadata
().
get
(
"instanceId"
);
}
}
return
server
.
getId
();
}
private
String
extractApproximateZone
(
Server
server
)
{
...
...
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