Commit 5bded8aa by Dave Syer

Make Eureka into a CF service broker

parent 49db709d
...@@ -21,7 +21,6 @@ import javax.management.MBeanServer; ...@@ -21,7 +21,6 @@ import javax.management.MBeanServer;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
...@@ -146,7 +145,7 @@ public class EurekaClientConfiguration implements SmartLifecycle, Ordered { ...@@ -146,7 +145,7 @@ public class EurekaClientConfiguration implements SmartLifecycle, Ordered {
@Bean @Bean
@ConditionalOnMissingBean @ConditionalOnMissingBean
@ConditionalOnBean(MBeanServer.class) @ConditionalOnExpression("${spring.jmx.enabled:true}")
public EurekaHealthIndicator eurekaHealthIndicator(MBeanServer server, public EurekaHealthIndicator eurekaHealthIndicator(MBeanServer server,
EurekaInstanceConfig config) { EurekaInstanceConfig config) {
return new EurekaHealthIndicator(eurekaDiscoveryClient(), return new EurekaHealthIndicator(eurekaDiscoveryClient(),
......
/*
* Copyright 2013-2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cloud.netflix.eureka.advice;
import com.netflix.appinfo.InstanceInfo;
import com.netflix.eureka.lease.LeaseManager;
/**
* @author Dave Syer
*
*/
public interface LeaseManagerLite<T> extends LeaseManager<T> {
void register(InstanceInfo info, boolean isReplication);
}
...@@ -55,10 +55,7 @@ public class PiggybackMethodInterceptor implements MethodInterceptor { ...@@ -55,10 +55,7 @@ public class PiggybackMethodInterceptor implements MethodInterceptor {
private Method getTarget(Class<?> type, Method method) { private Method getTarget(Class<?> type, Method method) {
Method target = ReflectionUtils.findMethod(type, method.getName(), Method target = ReflectionUtils.findMethod(type, method.getName(),
method.getParameterTypes()); method.getParameterTypes());
if (target != null) {
return target; return target;
} }
return null;
}
} }
...@@ -9,6 +9,7 @@ import javax.annotation.Nullable; ...@@ -9,6 +9,7 @@ import javax.annotation.Nullable;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.netflix.eureka.advice.LeaseManagerLite;
import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;
import com.google.common.base.Optional; import com.google.common.base.Optional;
...@@ -16,18 +17,23 @@ import com.google.common.base.Predicate; ...@@ -16,18 +17,23 @@ import com.google.common.base.Predicate;
import com.netflix.appinfo.InstanceInfo; import com.netflix.appinfo.InstanceInfo;
import com.netflix.discovery.shared.Application; import com.netflix.discovery.shared.Application;
import com.netflix.eureka.PeerAwareInstanceRegistry; import com.netflix.eureka.PeerAwareInstanceRegistry;
import com.netflix.eureka.lease.LeaseManager; import com.netflix.eureka.lease.Lease;
/** /**
* @author Spencer Gibb * @author Spencer Gibb
*/ */
public class LeaseManagerMessageBroker implements LeaseManager<InstanceInfo> { public class LeaseManagerMessageBroker implements LeaseManagerLite<InstanceInfo> {
private static final Logger logger = LoggerFactory.getLogger(LeaseManagerMessageBroker.class); private static final Logger logger = LoggerFactory.getLogger(LeaseManagerMessageBroker.class);
@Autowired @Autowired
private ApplicationContext ctxt; private ApplicationContext ctxt;
@Override @Override
public void register(InstanceInfo info, boolean isReplication) {
register(info, Lease.DEFAULT_DURATION_IN_SECS, isReplication);
}
@Override
public void register(InstanceInfo info, int leaseDuration, boolean isReplication) { public void register(InstanceInfo info, int leaseDuration, boolean isReplication) {
logger.debug("register {}, vip {}, leaseDuration {}, isReplication {}", logger.debug("register {}, vip {}, leaseDuration {}, isReplication {}",
info.getAppName(), info.getVIPAddress(), leaseDuration, isReplication); info.getAppName(), info.getVIPAddress(), leaseDuration, isReplication);
......
...@@ -24,7 +24,9 @@ import org.springframework.boot.autoconfigure.AutoConfigureAfter; ...@@ -24,7 +24,9 @@ import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.AutoConfigureBefore; import org.springframework.boot.autoconfigure.AutoConfigureBefore;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
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.autoconfigure.jmx.JmxAutoConfiguration;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
...@@ -38,12 +40,12 @@ import com.netflix.servo.monitor.Monitors; ...@@ -38,12 +40,12 @@ import com.netflix.servo.monitor.Monitors;
@ConditionalOnClass({ Monitors.class, MetricReader.class }) @ConditionalOnClass({ Monitors.class, MetricReader.class })
@ConditionalOnBean(MetricReader.class) @ConditionalOnBean(MetricReader.class)
@AutoConfigureBefore(EndpointAutoConfiguration.class) @AutoConfigureBefore(EndpointAutoConfiguration.class)
@AutoConfigureAfter(MetricRepositoryAutoConfiguration.class) @AutoConfigureAfter({MetricRepositoryAutoConfiguration.class, JmxAutoConfiguration.class})
@ConditionalOnExpression("${spring.jmx.enabled:true}")
public class ServoMetricsAutoConfiguration { public class ServoMetricsAutoConfiguration {
@Bean @Bean
@ConditionalOnMissingBean @ConditionalOnMissingBean
@ConditionalOnBean(MBeanServer.class)
public ServoPublicMetrics servoPublicMetrics(MetricReader reader, MBeanServer server) { public ServoPublicMetrics servoPublicMetrics(MetricReader reader, MBeanServer server) {
return new ServoPublicMetrics(reader, server); return new ServoPublicMetrics(reader, server);
} }
......
...@@ -36,6 +36,7 @@ public class EurekaServerConfiguration extends WebMvcConfigurerAdapter { ...@@ -36,6 +36,7 @@ public class EurekaServerConfiguration extends WebMvcConfigurerAdapter {
bean.setOrder(Ordered.LOWEST_PRECEDENCE); bean.setOrder(Ordered.LOWEST_PRECEDENCE);
bean.addInitParameter("com.sun.jersey.config.property.packages", bean.addInitParameter("com.sun.jersey.config.property.packages",
"com.netflix.discovery;com.netflix.eureka"); "com.netflix.discovery;com.netflix.eureka");
bean.addInitParameter(ServletContainer.FEATURE_FILTER_FORWARD_ON_404, "true");
bean.setUrlPatterns(Lists.newArrayList("/v2/*")); bean.setUrlPatterns(Lists.newArrayList("/v2/*"));
return bean; return bean;
} }
......
...@@ -32,6 +32,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean ...@@ -32,6 +32,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.cloud.netflix.eureka.DiscoveryManagerIntitializer; import org.springframework.cloud.netflix.eureka.DiscoveryManagerIntitializer;
import org.springframework.cloud.netflix.eureka.EurekaServerConfigBean; import org.springframework.cloud.netflix.eureka.EurekaServerConfigBean;
import org.springframework.cloud.netflix.eureka.advice.LeaseManagerLite;
import org.springframework.cloud.netflix.eureka.advice.PiggybackMethodInterceptor; import org.springframework.cloud.netflix.eureka.advice.PiggybackMethodInterceptor;
import org.springframework.cloud.netflix.eureka.event.EurekaRegistryAvailableEvent; import org.springframework.cloud.netflix.eureka.event.EurekaRegistryAvailableEvent;
import org.springframework.cloud.netflix.eureka.event.EurekaServerStartedEvent; import org.springframework.cloud.netflix.eureka.event.EurekaServerStartedEvent;
...@@ -50,7 +51,6 @@ import com.netflix.eureka.EurekaBootStrap; ...@@ -50,7 +51,6 @@ import com.netflix.eureka.EurekaBootStrap;
import com.netflix.eureka.EurekaServerConfig; import com.netflix.eureka.EurekaServerConfig;
import com.netflix.eureka.EurekaServerConfigurationManager; import com.netflix.eureka.EurekaServerConfigurationManager;
import com.netflix.eureka.PeerAwareInstanceRegistry; import com.netflix.eureka.PeerAwareInstanceRegistry;
import com.netflix.eureka.lease.LeaseManager;
/** /**
* @author Dave Syer * @author Dave Syer
...@@ -193,7 +193,7 @@ public class EurekaServerInitializerConfiguration implements ServletContextAware ...@@ -193,7 +193,7 @@ public class EurekaServerInitializerConfiguration implements ServletContextAware
ProxyFactory factory = new ProxyFactory(instance); ProxyFactory factory = new ProxyFactory(instance);
// ...with the LeaseManagerMessageBroker // ...with the LeaseManagerMessageBroker
factory.addAdvice(new PiggybackMethodInterceptor(leaseManagerMessageBroker(), factory.addAdvice(new PiggybackMethodInterceptor(leaseManagerMessageBroker(),
LeaseManager.class)); LeaseManagerLite.class));
factory.addAdvice(new TrafficOpener()); factory.addAdvice(new TrafficOpener());
factory.setProxyTargetClass(true); factory.setProxyTargetClass(true);
......
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