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
9e142bf7
Commit
9e142bf7
authored
Oct 22, 2014
by
Dave Syer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
InstanceInfo unmarshalling has to be at a lower level
parent
8db14f04
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
49 additions
and
20 deletions
+49
-20
DataCenterAwareMarshallingStrategy.java
...ud/netflix/eureka/DataCenterAwareMarshallingStrategy.java
+47
-16
DomainExtractingServerList.java
...oud/netflix/ribbon/eureka/DomainExtractingServerList.java
+2
-4
No files found.
spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/eureka/DataCenterAwareMarshallingStrategy.java
View file @
9e142bf7
...
...
@@ -19,9 +19,12 @@ import com.netflix.appinfo.DataCenterInfo;
import
com.netflix.appinfo.UniqueIdentifier
;
import
com.netflix.appinfo.DataCenterInfo.Name
;
import
com.netflix.appinfo.InstanceInfo
;
import
com.netflix.discovery.converters.Converters.InstanceInfoConverter
;
import
com.thoughtworks.xstream.MarshallingStrategy
;
import
com.thoughtworks.xstream.converters.Converter
;
import
com.thoughtworks.xstream.converters.ConverterLookup
;
import
com.thoughtworks.xstream.converters.DataHolder
;
import
com.thoughtworks.xstream.converters.UnmarshallingContext
;
import
com.thoughtworks.xstream.core.TreeMarshallingStrategy
;
import
com.thoughtworks.xstream.io.HierarchicalStreamReader
;
import
com.thoughtworks.xstream.io.HierarchicalStreamWriter
;
...
...
@@ -47,20 +50,8 @@ public class DataCenterAwareMarshallingStrategy implements MarshallingStrategy {
@Override
public
Object
unmarshal
(
Object
root
,
HierarchicalStreamReader
reader
,
DataHolder
dataHolder
,
ConverterLookup
converterLookup
,
Mapper
mapper
)
{
Object
obj
=
delegate
.
unmarshal
(
root
,
reader
,
dataHolder
,
converterLookup
,
mapper
);
if
(
obj
instanceof
InstanceInfo
)
{
InstanceInfo
info
=
(
InstanceInfo
)
obj
;
String
instanceId
=
info
.
getMetadata
().
get
(
"instanceId"
);
DataCenterInfo
dataCenter
=
info
.
getDataCenterInfo
();
if
(
instanceId
!=
null
&&
Name
.
Amazon
!=
dataCenter
.
getName
())
{
String
old
=
info
.
getId
();
info
=
new
InstanceInfo
.
Builder
(
info
).
setDataCenterInfo
(
new
InstanceIdDataCenterInfo
(
old
+
":"
+
instanceId
)).
build
();
obj
=
info
;
}
}
return
obj
;
ConverterLookup
wrapped
=
new
DataCenterAwareConverterLookup
(
converterLookup
);
return
delegate
.
unmarshal
(
root
,
reader
,
dataHolder
,
wrapped
,
mapper
);
}
@Override
...
...
@@ -68,8 +59,9 @@ public class DataCenterAwareMarshallingStrategy implements MarshallingStrategy {
ConverterLookup
converterLookup
,
Mapper
mapper
,
DataHolder
dataHolder
)
{
delegate
.
marshal
(
writer
,
obj
,
converterLookup
,
mapper
,
dataHolder
);
}
public
static
class
InstanceIdDataCenterInfo
implements
DataCenterInfo
,
UniqueIdentifier
{
public
static
class
InstanceIdDataCenterInfo
implements
DataCenterInfo
,
UniqueIdentifier
{
private
String
instanceId
;
...
...
@@ -89,4 +81,43 @@ public class DataCenterAwareMarshallingStrategy implements MarshallingStrategy {
}
private
static
class
DataCenterAwareConverterLookup
implements
ConverterLookup
{
private
ConverterLookup
delegate
;
public
DataCenterAwareConverterLookup
(
ConverterLookup
delegate
)
{
this
.
delegate
=
delegate
;
}
@Override
public
Converter
lookupConverterForType
(
@SuppressWarnings
(
"rawtypes"
)
Class
type
)
{
Converter
converter
=
delegate
.
lookupConverterForType
(
type
);
if
(
InstanceInfo
.
class
==
type
)
{
return
new
DataCenterAwareConverter
();
}
return
converter
;
}
}
private
static
class
DataCenterAwareConverter
extends
InstanceInfoConverter
{
@Override
public
Object
unmarshal
(
HierarchicalStreamReader
reader
,
UnmarshallingContext
context
)
{
Object
obj
=
super
.
unmarshal
(
reader
,
context
);
InstanceInfo
info
=
(
InstanceInfo
)
obj
;
String
instanceId
=
info
.
getMetadata
().
get
(
"instanceId"
);
DataCenterInfo
dataCenter
=
info
.
getDataCenterInfo
();
if
(
instanceId
!=
null
&&
Name
.
Amazon
!=
dataCenter
.
getName
())
{
String
old
=
info
.
getId
();
info
=
new
InstanceInfo
.
Builder
(
info
).
setDataCenterInfo
(
new
InstanceIdDataCenterInfo
(
old
+
":"
+
instanceId
)).
build
();
obj
=
info
;
}
return
obj
;
}
}
}
spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/ribbon/eureka/DomainExtractingServerList.java
View file @
9e142bf7
...
...
@@ -75,10 +75,8 @@ class DomainExtractingServer extends DiscoveryEnabledServer {
public
DomainExtractingServer
(
DiscoveryEnabledServer
server
)
{
super
(
server
.
getInstanceInfo
(),
true
,
false
);
String
zone
=
extractApproximateZone
(
server
);
setZone
(
zone
);
String
id
=
extractId
(
server
);
setId
(
id
);
setZone
(
extractApproximateZone
(
server
));
setId
(
extractId
(
server
));
}
private
String
extractId
(
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