diff --git a/spring-platform-netflix-core/src/main/java/org/springframework/platform/netflix/eureka/event/EurekaInstanceRegisteredEvent.java b/spring-platform-netflix-core/src/main/java/org/springframework/platform/netflix/eureka/event/EurekaInstanceRegisteredEvent.java index 7bfc5e22..ef5630f6 100644 --- a/spring-platform-netflix-core/src/main/java/org/springframework/platform/netflix/eureka/event/EurekaInstanceRegisteredEvent.java +++ b/spring-platform-netflix-core/src/main/java/org/springframework/platform/netflix/eureka/event/EurekaInstanceRegisteredEvent.java @@ -1,5 +1,6 @@ package org.springframework.platform.netflix.eureka.event; +import com.netflix.appinfo.InstanceInfo; import lombok.Data; import org.springframework.context.ApplicationEvent; @@ -8,15 +9,13 @@ import org.springframework.context.ApplicationEvent; */ @Data public class EurekaInstanceRegisteredEvent extends ApplicationEvent { - private String appName; - private String vip; + private InstanceInfo instanceInfo; private int leaseDuration; boolean replication; - public EurekaInstanceRegisteredEvent(Object source, String appName, String vip, int leaseDuration, boolean replication) { + public EurekaInstanceRegisteredEvent(Object source, InstanceInfo instanceInfo, int leaseDuration, boolean replication) { super(source); - this.appName = appName; - this.vip = vip; + this.instanceInfo = instanceInfo; this.leaseDuration = leaseDuration; this.replication = replication; } diff --git a/spring-platform-netflix-core/src/main/java/org/springframework/platform/netflix/eureka/event/EurekaInstanceRenewedEvent.java b/spring-platform-netflix-core/src/main/java/org/springframework/platform/netflix/eureka/event/EurekaInstanceRenewedEvent.java index a7d8a2c2..be0d83f7 100644 --- a/spring-platform-netflix-core/src/main/java/org/springframework/platform/netflix/eureka/event/EurekaInstanceRenewedEvent.java +++ b/spring-platform-netflix-core/src/main/java/org/springframework/platform/netflix/eureka/event/EurekaInstanceRenewedEvent.java @@ -1,5 +1,6 @@ package org.springframework.platform.netflix.eureka.event; +import com.netflix.appinfo.InstanceInfo; import lombok.Data; import org.springframework.context.ApplicationEvent; @@ -10,12 +11,14 @@ import org.springframework.context.ApplicationEvent; public class EurekaInstanceRenewedEvent extends ApplicationEvent { private String appName; private String serverId; + private InstanceInfo instanceInfo; boolean replication; - public EurekaInstanceRenewedEvent(Object source, String appName, String serverId, boolean replication) { + public EurekaInstanceRenewedEvent(Object source, String appName, String serverId, InstanceInfo instanceInfo, boolean replication) { super(source); this.appName = appName; this.serverId = serverId; + this.instanceInfo = instanceInfo; this.replication = replication; } } diff --git a/spring-platform-netflix-core/src/main/java/org/springframework/platform/netflix/eureka/event/LeaseManagerMessageBroker.java b/spring-platform-netflix-core/src/main/java/org/springframework/platform/netflix/eureka/event/LeaseManagerMessageBroker.java index 26c4afff..08b6c767 100644 --- a/spring-platform-netflix-core/src/main/java/org/springframework/platform/netflix/eureka/event/LeaseManagerMessageBroker.java +++ b/spring-platform-netflix-core/src/main/java/org/springframework/platform/netflix/eureka/event/LeaseManagerMessageBroker.java @@ -1,12 +1,22 @@ package org.springframework.platform.netflix.eureka.event; +import com.google.common.base.Optional; +import com.google.common.base.Predicate; import com.netflix.appinfo.InstanceInfo; +import com.netflix.discovery.DiscoveryManager; +import com.netflix.discovery.shared.Application; +import com.netflix.eureka.PeerAwareInstanceRegistry; import com.netflix.eureka.lease.LeaseManager; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationContext; +import javax.annotation.Nullable; +import java.util.List; + +import static com.google.common.collect.Iterables.*; + /** * @author Spencer Gibb */ @@ -21,8 +31,7 @@ public class LeaseManagerMessageBroker implements LeaseManager { logger.debug("register {}, vip {}, leaseDuration {}, isReplication {}", info.getAppName(), info.getVIPAddress(), leaseDuration, isReplication); //TODO: what to publish from info (whole object?) - ctxt.publishEvent(new EurekaInstanceRegisteredEvent(this, info.getAppName(), - info.getVIPAddress(), leaseDuration, isReplication)); + ctxt.publishEvent(new EurekaInstanceRegisteredEvent(this, info, leaseDuration, isReplication)); } @Override @@ -33,9 +42,25 @@ public class LeaseManagerMessageBroker implements LeaseManager { } @Override - public boolean renew(String appName, String serverId, boolean isReplication) { + public boolean renew(final String appName, final String serverId, boolean isReplication) { logger.debug("renew {}, serverId {}, isReplication {}", appName, serverId, isReplication); - ctxt.publishEvent(new EurekaInstanceRenewedEvent(this, appName, serverId, isReplication)); + List applications = PeerAwareInstanceRegistry.getInstance().getSortedApplications(); + Optional app = tryFind(applications, new Predicate() { + @Override + public boolean apply(@Nullable Application input) { + return input.getName().equals(appName); + } + }); + + if (app.isPresent()) { + Optional info = tryFind(app.get().getInstances(), new Predicate() { + @Override + public boolean apply(@Nullable InstanceInfo input) { + return input.getHostName().equals(serverId); + } + }); + ctxt.publishEvent(new EurekaInstanceRenewedEvent(this, appName, serverId, info.orNull(), isReplication)); + } return false; }