Commit 714741b1 by Spencer Gibb

added serviceId to ServiceInstance;

added beginnings of a generic DiscoveryClient interface;
parent 66e0c643
...@@ -6,6 +6,7 @@ package org.springframework.cloud.client; ...@@ -6,6 +6,7 @@ package org.springframework.cloud.client;
* TODO: name? Server? HostAndPort? Instance? * TODO: name? Server? HostAndPort? Instance?
*/ */
public interface ServiceInstance { public interface ServiceInstance {
public String getServiceId();
public String getHost(); public String getHost();
public int getPort(); public int getPort();
} }
package org.springframework.cloud.client.discovery;
import org.springframework.cloud.client.ServiceInstance;
/**
* @author Spencer Gibb
*/
public interface DiscoveryClient {
/**
* @return ServiceInstance with information used to register the local service
*/
public ServiceInstance getLocalServiceInstance();
}
package org.springframework.cloud.netflix;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.cloud.netflix.eureka.EurekaInstanceConfigBean;
/**
* @author Spencer Gibb
*/
public class EurekaDiscoverClient implements DiscoveryClient {
@Autowired
private EurekaInstanceConfigBean config;
@Override
public ServiceInstance getLocalServiceInstance() {
return new ServiceInstance() {
@Override
public String getServiceId() {
return config.getAppname();
}
@Override
public String getHost() {
return config.getHostname();
}
@Override
public int getPort() {
return config.getNonSecurePort();
}
};
}
}
...@@ -27,6 +27,8 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; ...@@ -27,6 +27,8 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.embedded.EmbeddedServletContainerInitializedEvent; import org.springframework.boot.context.embedded.EmbeddedServletContainerInitializedEvent;
import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.cloud.netflix.EurekaDiscoverClient;
import org.springframework.cloud.netflix.servo.ServoMetricReader; import org.springframework.cloud.netflix.servo.ServoMetricReader;
import org.springframework.context.ApplicationListener; import org.springframework.context.ApplicationListener;
import org.springframework.context.SmartLifecycle; import org.springframework.context.SmartLifecycle;
...@@ -40,7 +42,6 @@ import org.springframework.core.Ordered; ...@@ -40,7 +42,6 @@ import org.springframework.core.Ordered;
import com.netflix.appinfo.ApplicationInfoManager; import com.netflix.appinfo.ApplicationInfoManager;
import com.netflix.appinfo.EurekaInstanceConfig; import com.netflix.appinfo.EurekaInstanceConfig;
import com.netflix.appinfo.InstanceInfo.InstanceStatus; import com.netflix.appinfo.InstanceInfo.InstanceStatus;
import com.netflix.discovery.DiscoveryClient;
import com.netflix.discovery.DiscoveryManager; import com.netflix.discovery.DiscoveryManager;
import com.netflix.discovery.EurekaClientConfig; import com.netflix.discovery.EurekaClientConfig;
...@@ -128,16 +129,21 @@ public class EurekaClientConfiguration implements SmartLifecycle, Ordered { ...@@ -128,16 +129,21 @@ public class EurekaClientConfiguration implements SmartLifecycle, Ordered {
@Bean @Bean
@Lazy @Lazy
@Scope(proxyMode = ScopedProxyMode.TARGET_CLASS) @Scope(proxyMode = ScopedProxyMode.TARGET_CLASS)
public DiscoveryClient discoveryClient() { public com.netflix.discovery.DiscoveryClient eurekaDiscoveryClient() {
return DiscoveryManager.getInstance().getDiscoveryClient(); return DiscoveryManager.getInstance().getDiscoveryClient();
} }
@Bean
public DiscoveryClient discoveryClient() {
return new EurekaDiscoverClient();
}
@Bean @Bean
@ConditionalOnMissingBean @ConditionalOnMissingBean
@ConditionalOnBean(MBeanServer.class) @ConditionalOnBean(MBeanServer.class)
public EurekaHealthIndicator eurekaHealthIndicator(MBeanServer server, public EurekaHealthIndicator eurekaHealthIndicator(MBeanServer server,
EurekaInstanceConfig config) { EurekaInstanceConfig config) {
return new EurekaHealthIndicator(discoveryClient(), return new EurekaHealthIndicator(eurekaDiscoveryClient(),
new ServoMetricReader(server), config); new ServoMetricReader(server), config);
} }
......
...@@ -22,17 +22,24 @@ public class RibbonLoadBalancerClient implements LoadBalancerClient { ...@@ -22,17 +22,24 @@ public class RibbonLoadBalancerClient implements LoadBalancerClient {
if (server == null) { if (server == null) {
throw new IllegalStateException("Unable to locate ILoadBalancer for service: "+ serviceId); throw new IllegalStateException("Unable to locate ILoadBalancer for service: "+ serviceId);
} }
return new RibbonServer(server); return new RibbonServer(serviceId, server);
} }
private class RibbonServer implements ServiceInstance { private class RibbonServer implements ServiceInstance {
private String serviceId;
private Server server; private Server server;
private RibbonServer(Server server) { private RibbonServer(String serviceId, Server server) {
this.serviceId = serviceId;
this.server = server; this.server = server;
} }
@Override @Override
public String getServiceId() {
return serviceId;
}
@Override
public String getHost() { public String getHost() {
return server.getHost(); return server.getHost();
} }
......
...@@ -4,6 +4,8 @@ import com.netflix.config.ConfigurationManager; ...@@ -4,6 +4,8 @@ import com.netflix.config.ConfigurationManager;
import com.netflix.niws.loadbalancer.DiscoveryEnabledNIWSServerList; import com.netflix.niws.loadbalancer.DiscoveryEnabledNIWSServerList;
import org.springframework.cloud.netflix.ribbon.ServerListInitializer; import org.springframework.cloud.netflix.ribbon.ServerListInitializer;
import static com.netflix.client.config.CommonClientConfigKey.*;
/** /**
* @author Spencer Gibb * @author Spencer Gibb
*/ */
...@@ -12,8 +14,9 @@ public class EurekaRibbonInitializer implements ServerListInitializer { ...@@ -12,8 +14,9 @@ public class EurekaRibbonInitializer implements ServerListInitializer {
@Override @Override
public void initialize(String serviceId) { public void initialize(String serviceId) {
//TODO: should this look more like hibernate spring boot props? //TODO: should this look more like hibernate spring boot props?
setProp(serviceId, "NIWSServerListClassName", DiscoveryEnabledNIWSServerList.class.getName()); //TODO: only set the property if it hasn't already been set?
setProp(serviceId, "DeploymentContextBasedVipAddresses", serviceId); //FIXME: what should this be? setProp(serviceId, NIWSServerListClassName.key(), DiscoveryEnabledNIWSServerList.class.getName());
setProp(serviceId, DeploymentContextBasedVipAddresses.key(), serviceId); //FIXME: what should this be?
} }
protected void setProp(String serviceId, String suffix, String value) { protected void setProp(String serviceId, String suffix, String value) {
......
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