Move properties to new namespace.

Moving eureka.server.{expectedNumberOfRenewsPerMin,defaultOpenForTrafficCount} to eureka.instance.registry so relaxed binding can be used. Default to old values for backwards compatibility.
parent c9704d3c
...@@ -71,7 +71,7 @@ import com.sun.jersey.spi.container.servlet.ServletContainer; ...@@ -71,7 +71,7 @@ import com.sun.jersey.spi.container.servlet.ServletContainer;
@Configuration @Configuration
@Import(EurekaServerInitializerConfiguration.class) @Import(EurekaServerInitializerConfiguration.class)
@EnableDiscoveryClient @EnableDiscoveryClient
@EnableConfigurationProperties(EurekaDashboardProperties.class) @EnableConfigurationProperties({ EurekaDashboardProperties.class, InstanceRegistryProperties.class })
@PropertySource("classpath:/eureka/server.properties") @PropertySource("classpath:/eureka/server.properties")
public class EurekaServerConfiguration extends WebMvcConfigurerAdapter { public class EurekaServerConfiguration extends WebMvcConfigurerAdapter {
/** /**
...@@ -92,17 +92,9 @@ public class EurekaServerConfiguration extends WebMvcConfigurerAdapter { ...@@ -92,17 +92,9 @@ public class EurekaServerConfiguration extends WebMvcConfigurerAdapter {
@Autowired @Autowired
private EurekaClient eurekaClient; private EurekaClient eurekaClient;
/* @Autowired
* Setting expectedNumberOfRenewsPerMin to non-zero to ensure that even an isolated private InstanceRegistryProperties instanceRegistryProperties;
* server can adjust its eviction policy to the number of registrations (when it's
* zero, even a successful registration won't reset the rate threshold in
* InstanceRegistry.register()).
*/
@Value("${eureka.server.expectedNumberOfRenewsPerMin:1}")
private int expectedNumberOfRenewsPerMin;
@Value("${eureka.server.defaultOpenForTrafficCount:1}")
private int defaultOpenForTrafficCount;
public static final CloudJacksonJson JACKSON_JSON = new CloudJacksonJson(); public static final CloudJacksonJson JACKSON_JSON = new CloudJacksonJson();
@Bean @Bean
...@@ -166,8 +158,9 @@ public class EurekaServerConfiguration extends WebMvcConfigurerAdapter { ...@@ -166,8 +158,9 @@ public class EurekaServerConfiguration extends WebMvcConfigurerAdapter {
ServerCodecs serverCodecs) { ServerCodecs serverCodecs) {
this.eurekaClient.getApplications(); // force initialization this.eurekaClient.getApplications(); // force initialization
return new InstanceRegistry(this.eurekaServerConfig, this.eurekaClientConfig, return new InstanceRegistry(this.eurekaServerConfig, this.eurekaClientConfig,
serverCodecs, this.eurekaClient, this.expectedNumberOfRenewsPerMin, serverCodecs, this.eurekaClient,
this.defaultOpenForTrafficCount); this.instanceRegistryProperties.getExpectedNumberOfRenewsPerMin(),
this.instanceRegistryProperties.getDefaultOpenForTrafficCount());
} }
@Bean @Bean
......
...@@ -66,8 +66,8 @@ public class InstanceRegistry extends PeerAwareInstanceRegistryImpl ...@@ -66,8 +66,8 @@ public class InstanceRegistry extends PeerAwareInstanceRegistryImpl
/** /**
* If * If
* {@link PeerAwareInstanceRegistryImpl#openForTraffic(ApplicationInfoManager, int)} * {@link PeerAwareInstanceRegistryImpl#openForTraffic(ApplicationInfoManager, int)}
* is called with a zero * argument, it means that leases are not automatically * * is called with a zero argument, it means that leases are not automatically
* cancelled if the instance * hasn't sent any renewals recently. This happens for a * cancelled if the instance hasn't sent any renewals recently. This happens for a
* standalone server. It seems like a bad default, so we set it to the smallest * standalone server. It seems like a bad default, so we set it to the smallest
* non-zero value we can, so that any instances that subsequently register can bump up * non-zero value we can, so that any instances that subsequently register can bump up
* the threshold. * the threshold.
......
/*
* Copyright 2013-2016 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.server;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import static org.springframework.cloud.netflix.eureka.server.InstanceRegistryProperties.PREFIX;
/**
* @author Spencer Gibb
*/
@ConfigurationProperties(PREFIX)
public class InstanceRegistryProperties {
public static final String PREFIX = "eureka.instance.registry";
/* Default number of expected renews per minute, defaults to 1.
* Setting expectedNumberOfRenewsPerMin to non-zero to ensure that even an isolated
* server can adjust its eviction policy to the number of registrations (when it's
* zero, even a successful registration won't reset the rate threshold in
* InstanceRegistry.register()).
*/
@Value("${eureka.server.expectedNumberOfRenewsPerMin:1}") // for backwards compatibility
private int expectedNumberOfRenewsPerMin = 1;
/** Value used in determining when leases are cancelled, default to 1 for standalone.
* Should be set to 0 for peer replicated eurekas */
@Value("${eureka.server.defaultOpenForTrafficCount:1}") // for backwards compatibility
private int defaultOpenForTrafficCount = 1;
public int getExpectedNumberOfRenewsPerMin() {
return expectedNumberOfRenewsPerMin;
}
public void setExpectedNumberOfRenewsPerMin(int expectedNumberOfRenewsPerMin) {
this.expectedNumberOfRenewsPerMin = expectedNumberOfRenewsPerMin;
}
public int getDefaultOpenForTrafficCount() {
return defaultOpenForTrafficCount;
}
public void setDefaultOpenForTrafficCount(int defaultOpenForTrafficCount) {
this.defaultOpenForTrafficCount = defaultOpenForTrafficCount;
}
}
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