Angel eureka clients can use brixton eureka servers.

Updates so CloudJacksonJson extension is properly recognized by Eureka Server as LegacyJacksonJson. see gh-978 fixes gh-1111
parent 9e479481
...@@ -11,7 +11,9 @@ import org.springframework.util.StringUtils; ...@@ -11,7 +11,9 @@ import org.springframework.util.StringUtils;
import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.Version; import com.fasterxml.jackson.core.Version;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ObjectReader; import com.fasterxml.jackson.databind.ObjectReader;
import com.fasterxml.jackson.databind.ObjectWriter; import com.fasterxml.jackson.databind.ObjectWriter;
...@@ -36,9 +38,13 @@ public class CloudJacksonJson extends LegacyJacksonJson { ...@@ -36,9 +38,13 @@ public class CloudJacksonJson extends LegacyJacksonJson {
protected final CloudJacksonCodec codec = new CloudJacksonCodec(); protected final CloudJacksonCodec codec = new CloudJacksonCodec();
public CloudJacksonCodec getCodec() {
return codec;
}
@Override @Override
public String codecName() { public String codecName() {
return getCodecName(this.getClass()); return getCodecName(LegacyJacksonJson.class);
} }
@Override @Override
...@@ -120,31 +126,39 @@ public class CloudJacksonJson extends LegacyJacksonJson { ...@@ -120,31 +126,39 @@ public class CloudJacksonJson extends LegacyJacksonJson {
static class CloudInstanceInfoSerializer extends InstanceInfoSerializer { static class CloudInstanceInfoSerializer extends InstanceInfoSerializer {
@Override @Override
public void serialize(InstanceInfo info, JsonGenerator jgen, public void serialize(final InstanceInfo info, JsonGenerator jgen,
SerializerProvider provider) throws IOException { SerializerProvider provider) throws IOException {
if (info.getInstanceId() == null && info.getMetadata() != null) { InstanceInfo updated = updateIfNeeded(info);
String instanceId = calculateInstanceId(info); super.serialize(updated, jgen, provider);
info = new InstanceInfo.Builder(info).setInstanceId(instanceId).build();
} }
super.serialize(info, jgen, provider);
} }
private String calculateInstanceId(InstanceInfo info) { static InstanceInfo updateIfNeeded(final InstanceInfo info) {
if (info.getInstanceId() == null && info.getMetadata() != null) {
String instanceId = info.getMetadata().get("instanceId"); String instanceId = info.getMetadata().get("instanceId");
String hostName = info.getHostName(); if (StringUtils.hasText(instanceId)) {
if (instanceId != null && StringUtils.hasText(hostName) && !instanceId.startsWith(hostName)) { // backwards compatibility for Angel
instanceId = hostName + ":" + instanceId; if (StringUtils.hasText(info.getHostName()) && !instanceId.startsWith(info.getHostName())) {
instanceId = info.getHostName()+":"+instanceId;
} }
return instanceId == null ? hostName : instanceId; return new InstanceInfo.Builder(info).setInstanceId(instanceId).build();
} }
} }
return info;
}
static class CloudInstanceInfoDeserializer extends InstanceInfoDeserializer { static class CloudInstanceInfoDeserializer extends InstanceInfoDeserializer {
protected CloudInstanceInfoDeserializer(ObjectMapper mapper) { protected CloudInstanceInfoDeserializer(ObjectMapper mapper) {
super(mapper); super(mapper);
} }
@Override
public InstanceInfo deserialize(JsonParser jp, DeserializationContext context) throws IOException {
InstanceInfo info = super.deserialize(jp, context);
InstanceInfo updated = updateIfNeeded(info);
return updated;
}
} }
} }
...@@ -52,6 +52,7 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter ...@@ -52,6 +52,7 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter
import com.netflix.appinfo.ApplicationInfoManager; import com.netflix.appinfo.ApplicationInfoManager;
import com.netflix.discovery.EurekaClient; import com.netflix.discovery.EurekaClient;
import com.netflix.discovery.EurekaClientConfig; import com.netflix.discovery.EurekaClientConfig;
import com.netflix.discovery.converters.EurekaJacksonCodec;
import com.netflix.discovery.converters.wrappers.CodecWrapper; import com.netflix.discovery.converters.wrappers.CodecWrapper;
import com.netflix.discovery.converters.wrappers.CodecWrappers; import com.netflix.discovery.converters.wrappers.CodecWrappers;
import com.netflix.eureka.DefaultEurekaServerContext; import com.netflix.eureka.DefaultEurekaServerContext;
...@@ -102,6 +103,7 @@ public class EurekaServerConfiguration extends WebMvcConfigurerAdapter { ...@@ -102,6 +103,7 @@ public class EurekaServerConfiguration extends WebMvcConfigurerAdapter {
@Value("${eureka.server.defaultOpenForTrafficCount:1}") @Value("${eureka.server.defaultOpenForTrafficCount:1}")
private int defaultOpenForTrafficCount; private int defaultOpenForTrafficCount;
public static final CloudJacksonJson JACKSON_JSON = new CloudJacksonJson();
@Bean @Bean
public HasFeatures eurekaServerFeature() { public HasFeatures eurekaServerFeature() {
...@@ -128,15 +130,19 @@ public class EurekaServerConfiguration extends WebMvcConfigurerAdapter { ...@@ -128,15 +130,19 @@ public class EurekaServerConfiguration extends WebMvcConfigurerAdapter {
return new EurekaController(this.applicationInfoManager); return new EurekaController(this.applicationInfoManager);
} }
static {
CodecWrappers.registerWrapper(JACKSON_JSON);
EurekaJacksonCodec.setInstance(JACKSON_JSON.getCodec());
}
@Bean @Bean
public ServerCodecs serverCodecs() { public ServerCodecs serverCodecs() {
CodecWrappers.registerWrapper(new CloudJacksonJson());
return new CloudServerCodecs(this.eurekaServerConfig); return new CloudServerCodecs(this.eurekaServerConfig);
} }
private static CodecWrapper getFullJson(EurekaServerConfig serverConfig) { private static CodecWrapper getFullJson(EurekaServerConfig serverConfig) {
CodecWrapper codec = CodecWrappers.getCodec(serverConfig.getJsonCodecName()); CodecWrapper codec = CodecWrappers.getCodec(serverConfig.getJsonCodecName());
return codec == null ? CodecWrappers.getCodec(CloudJacksonJson.class) : codec; return codec == null ? CodecWrappers.getCodec(JACKSON_JSON.codecName()) : codec;
} }
private static CodecWrapper getFullXml(EurekaServerConfig serverConfig) { private static CodecWrapper getFullXml(EurekaServerConfig serverConfig) {
......
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