Commit a0c1b4c0 by Dave Syer

Align instanceId calculation with the one done on the client

The Angel client has an idiosyncratic way of calculating an instance id, and the Brixton client aligned with that already, but the Brixton server did not. This change should make Brixton Eureka Servers work with Angel clients. See gh-978
parent d5252375
...@@ -123,12 +123,21 @@ public class CloudJacksonJson extends LegacyJacksonJson { ...@@ -123,12 +123,21 @@ public class CloudJacksonJson extends LegacyJacksonJson {
SerializerProvider provider) throws IOException { SerializerProvider provider) throws IOException {
if (info.getInstanceId() == null && info.getMetadata() != null) { if (info.getInstanceId() == null && info.getMetadata() != null) {
String instanceId = info.getMetadata().get("instanceId"); String instanceId = calculateInstanceId(info);
info = new InstanceInfo.Builder(info).setInstanceId(instanceId).build(); info = new InstanceInfo.Builder(info).setInstanceId(instanceId).build();
} }
super.serialize(info, jgen, provider); super.serialize(info, jgen, provider);
} }
private String calculateInstanceId(InstanceInfo info) {
String instanceId = info.getMetadata().get("instanceId");
String hostName = info.getHostName();
if (instanceId != null && !instanceId.startsWith(hostName)) {
instanceId = hostName + ":" + instanceId;
}
return instanceId == null ? hostName : instanceId;
}
} }
static class CloudInstanceInfoDeserializer extends InstanceInfoDeserializer { static class CloudInstanceInfoDeserializer extends InstanceInfoDeserializer {
......
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