From 3d2a2e555f58f9eb8b67fcc41e0dc3c61358c05a Mon Sep 17 00:00:00 2001 From: Ryan Thomas Date: Fri, 14 Feb 2014 08:17:32 +1100 Subject: [PATCH] Added the UniqueIdentifier interface and modified InstanceInfo to call this getId method if this interface is implemented, rather than checking if name is Name.AMAZON. Updated AmazonInfo to use this. This change is to allow non-amazon instances to be identified by a mechanism other than their hostname - e.g. multiple docker containers on the same host, registering with Eureka with the docker-host address. --- .../src/main/java/com/netflix/appinfo/AmazonInfo.java | 7 ++++++- .../main/java/com/netflix/appinfo/InstanceInfo.java | 4 ++-- .../java/com/netflix/appinfo/UniqueIdentifier.java | 10 ++++++++++ 3 files changed, 18 insertions(+), 3 deletions(-) create mode 100644 eureka-client/src/main/java/com/netflix/appinfo/UniqueIdentifier.java diff --git a/eureka-client/src/main/java/com/netflix/appinfo/AmazonInfo.java b/eureka-client/src/main/java/com/netflix/appinfo/AmazonInfo.java index ddd4912a6..4a71f3959 100644 --- a/eureka-client/src/main/java/com/netflix/appinfo/AmazonInfo.java +++ b/eureka-client/src/main/java/com/netflix/appinfo/AmazonInfo.java @@ -41,7 +41,7 @@ * @author Karthik Ranganathan, Greg Kim * */ -public class AmazonInfo implements DataCenterInfo { +public class AmazonInfo implements DataCenterInfo, UniqueIdentifier { private Map metadata = new HashMap(); private static DynamicBooleanProperty shouldLogAWSMetadataError; @@ -217,4 +217,9 @@ public void setMetadata(Map metadataMap) { public String get(MetaDataKey key) { return metadata.get(key.getName()); } + + @Override + public String getId() { + return get(MetaDataKey.instanceId); + } } diff --git a/eureka-client/src/main/java/com/netflix/appinfo/InstanceInfo.java b/eureka-client/src/main/java/com/netflix/appinfo/InstanceInfo.java index bf88b8027..550681746 100644 --- a/eureka-client/src/main/java/com/netflix/appinfo/InstanceInfo.java +++ b/eureka-client/src/main/java/com/netflix/appinfo/InstanceInfo.java @@ -686,8 +686,8 @@ public String getSID() { * @return the unique id. */ public String getId() { - if (dataCenterInfo.getName() == Name.Amazon) { - return ((AmazonInfo) dataCenterInfo).get(MetaDataKey.instanceId); + if (dataCenterInfo instanceof UniqueIdentifier) { + return ((UniqueIdentifier) dataCenterInfo).getId(); } else { return hostName; } diff --git a/eureka-client/src/main/java/com/netflix/appinfo/UniqueIdentifier.java b/eureka-client/src/main/java/com/netflix/appinfo/UniqueIdentifier.java new file mode 100644 index 000000000..77ff93dce --- /dev/null +++ b/eureka-client/src/main/java/com/netflix/appinfo/UniqueIdentifier.java @@ -0,0 +1,10 @@ +package com.netflix.appinfo; + +/** + * Generally indicates the unique identifier of a {@link com.netflix.appinfo.DataCenterInfo}, if applicable. + * + * @author rthomas@atlassian.com + */ +public interface UniqueIdentifier { + String getId(); +}