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
This commit is contained in:
Dave Syer
2016-05-18 17:32:26 +02:00
parent d5252375e1
commit a0c1b4c05d

View File

@@ -123,12 +123,21 @@ public class CloudJacksonJson extends LegacyJacksonJson {
SerializerProvider provider) throws IOException {
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();
}
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 {