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;
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;
}
}
}
......@@ -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) {
......
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