Commit 9e142bf7 by Dave Syer

InstanceInfo unmarshalling has to be at a lower level

parent 8db14f04
...@@ -19,9 +19,12 @@ import com.netflix.appinfo.DataCenterInfo; ...@@ -19,9 +19,12 @@ import com.netflix.appinfo.DataCenterInfo;
import com.netflix.appinfo.UniqueIdentifier; import com.netflix.appinfo.UniqueIdentifier;
import com.netflix.appinfo.DataCenterInfo.Name; import com.netflix.appinfo.DataCenterInfo.Name;
import com.netflix.appinfo.InstanceInfo; import com.netflix.appinfo.InstanceInfo;
import com.netflix.discovery.converters.Converters.InstanceInfoConverter;
import com.thoughtworks.xstream.MarshallingStrategy; import com.thoughtworks.xstream.MarshallingStrategy;
import com.thoughtworks.xstream.converters.Converter;
import com.thoughtworks.xstream.converters.ConverterLookup; import com.thoughtworks.xstream.converters.ConverterLookup;
import com.thoughtworks.xstream.converters.DataHolder; import com.thoughtworks.xstream.converters.DataHolder;
import com.thoughtworks.xstream.converters.UnmarshallingContext;
import com.thoughtworks.xstream.core.TreeMarshallingStrategy; import com.thoughtworks.xstream.core.TreeMarshallingStrategy;
import com.thoughtworks.xstream.io.HierarchicalStreamReader; import com.thoughtworks.xstream.io.HierarchicalStreamReader;
import com.thoughtworks.xstream.io.HierarchicalStreamWriter; import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
...@@ -47,20 +50,8 @@ public class DataCenterAwareMarshallingStrategy implements MarshallingStrategy { ...@@ -47,20 +50,8 @@ public class DataCenterAwareMarshallingStrategy implements MarshallingStrategy {
@Override @Override
public Object unmarshal(Object root, HierarchicalStreamReader reader, public Object unmarshal(Object root, HierarchicalStreamReader reader,
DataHolder dataHolder, ConverterLookup converterLookup, Mapper mapper) { DataHolder dataHolder, ConverterLookup converterLookup, Mapper mapper) {
Object obj = delegate ConverterLookup wrapped = new DataCenterAwareConverterLookup(converterLookup);
.unmarshal(root, reader, dataHolder, converterLookup, mapper); return delegate.unmarshal(root, reader, dataHolder, wrapped, 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;
} }
@Override @Override
...@@ -69,7 +60,8 @@ public class DataCenterAwareMarshallingStrategy implements MarshallingStrategy { ...@@ -69,7 +60,8 @@ public class DataCenterAwareMarshallingStrategy implements MarshallingStrategy {
delegate.marshal(writer, obj, converterLookup, mapper, 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; private String instanceId;
...@@ -89,4 +81,43 @@ public class DataCenterAwareMarshallingStrategy implements MarshallingStrategy { ...@@ -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;
}
}
} }
...@@ -75,10 +75,8 @@ class DomainExtractingServer extends DiscoveryEnabledServer { ...@@ -75,10 +75,8 @@ class DomainExtractingServer extends DiscoveryEnabledServer {
public DomainExtractingServer(DiscoveryEnabledServer server) { public DomainExtractingServer(DiscoveryEnabledServer server) {
super(server.getInstanceInfo(), true, false); super(server.getInstanceInfo(), true, false);
String zone = extractApproximateZone(server); setZone(extractApproximateZone(server));
setZone(zone); setId(extractId(server));
String id = extractId(server);
setId(id);
} }
private String extractId(Server server) { private String extractId(Server server) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment