Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
spring-cloud-netflix
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
openSource
spring-cloud-netflix
Commits
94c73da9
Commit
94c73da9
authored
Dec 22, 2015
by
Spencer Gibb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use new InetUtils bean to determin nic.
Allows for more fine-grained configuration of what to ignore.
parent
03f6d12e
Hide whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
111 additions
and
62 deletions
+111
-62
EurekaClientAutoConfiguration.java
...k/cloud/netflix/eureka/EurekaClientAutoConfiguration.java
+3
-2
EurekaInstanceConfigBean.java
...mework/cloud/netflix/eureka/EurekaInstanceConfigBean.java
+18
-6
DiscoveryClientConfigServiceAutoConfigurationTests.java
...g/DiscoveryClientConfigServiceAutoConfigurationTests.java
+3
-1
DiscoveryClientConfigServiceBootstrapConfigurationTests.java
...coveryClientConfigServiceBootstrapConfigurationTests.java
+3
-1
EurekaClientAutoConfigurationTests.java
...ud/netflix/eureka/EurekaClientAutoConfigurationTests.java
+10
-9
EurekaInstanceConfigBeanTests.java
...k/cloud/netflix/eureka/EurekaInstanceConfigBeanTests.java
+15
-7
InstanceInfoFactoryTests.java
...mework/cloud/netflix/eureka/InstanceInfoFactoryTests.java
+15
-10
RibbonClientPreprocessorOverridesIntegrationTests.java
...on/RibbonClientPreprocessorOverridesIntegrationTests.java
+2
-1
RibbonClientsPreprocessorIntegrationTests.java
...lix/ribbon/RibbonClientsPreprocessorIntegrationTests.java
+2
-1
EurekaRibbonClientConfigurationTests.java
...x/ribbon/eureka/EurekaRibbonClientConfigurationTests.java
+10
-4
EurekaRibbonClientPreprocessorIntegrationTests.java
...ureka/EurekaRibbonClientPreprocessorIntegrationTests.java
+2
-1
RibbonClientPreprocessorIntegrationTests.java
...bbon/eureka/RibbonClientPreprocessorIntegrationTests.java
+9
-5
RibbonClientDefaultConfigurationTestsConfig.java
...bon/test/RibbonClientDefaultConfigurationTestsConfig.java
+14
-13
SidecarConfiguration.java
...framework/cloud/netflix/sidecar/SidecarConfiguration.java
+5
-1
No files found.
spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/eureka/EurekaClientAutoConfiguration.java
View file @
94c73da9
...
...
@@ -41,6 +41,7 @@ import org.springframework.cloud.client.actuator.HasFeatures;
import
org.springframework.cloud.client.discovery.DiscoveryClient
;
import
org.springframework.cloud.client.discovery.noop.NoopDiscoveryClientAutoConfiguration
;
import
org.springframework.cloud.context.scope.refresh.RefreshScope
;
import
org.springframework.cloud.util.InetUtils
;
import
org.springframework.context.ApplicationContext
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Conditional
;
...
...
@@ -96,8 +97,8 @@ public class EurekaClientAutoConfiguration {
@Bean
@ConditionalOnMissingBean
(
value
=
EurekaInstanceConfig
.
class
,
search
=
SearchStrategy
.
CURRENT
)
public
EurekaInstanceConfigBean
eurekaInstanceConfigBean
()
{
EurekaInstanceConfigBean
instance
=
new
EurekaInstanceConfigBean
();
public
EurekaInstanceConfigBean
eurekaInstanceConfigBean
(
InetUtils
inetUtils
)
{
EurekaInstanceConfigBean
instance
=
new
EurekaInstanceConfigBean
(
inetUtils
);
instance
.
setNonSecurePort
(
this
.
nonSecurePort
);
instance
.
setInstanceId
(
getDefaultInstanceId
(
this
.
env
));
if
(
this
.
managementPort
!=
this
.
nonSecurePort
&&
this
.
managementPort
!=
0
)
{
...
...
spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/eureka/EurekaInstanceConfigBean.java
View file @
94c73da9
...
...
@@ -21,14 +21,13 @@ import java.util.Map;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.boot.context.properties.ConfigurationProperties
;
import
org.springframework.cloud.util.InetUtils
;
import
org.springframework.cloud.util.InetUtils.HostInfo
;
import
com.netflix.appinfo.DataCenterInfo
;
import
com.netflix.appinfo.InstanceInfo.InstanceStatus
;
import
com.netflix.appinfo.MyDataCenterInfo
;
import
static
org
.
springframework
.
cloud
.
util
.
InetUtils
.
getFirstNonLoopbackHostInfo
;
import
lombok.AccessLevel
;
import
lombok.Data
;
import
lombok.Getter
;
...
...
@@ -44,7 +43,11 @@ public class EurekaInstanceConfigBean implements CloudEurekaInstanceConfig {
@Getter
(
AccessLevel
.
PRIVATE
)
@Setter
(
AccessLevel
.
PRIVATE
)
private
HostInfo
hostInfo
=
getFirstNonLoopbackHostInfo
();
private
HostInfo
hostInfo
;
@Getter
(
AccessLevel
.
PRIVATE
)
@Setter
(
AccessLevel
.
PRIVATE
)
private
InetUtils
inetUtils
;
@Value
(
"${spring.application.name:unknown}"
)
private
String
appname
=
"unknown"
;
...
...
@@ -79,7 +82,7 @@ public class EurekaInstanceConfigBean implements CloudEurekaInstanceConfig {
private
DataCenterInfo
dataCenterInfo
=
new
MyDataCenterInfo
(
DataCenterInfo
.
Name
.
MyOwn
);
private
String
ipAddress
=
this
.
hostInfo
.
getIpAddress
()
;
private
String
ipAddress
;
private
String
statusPageUrlPath
=
"/info"
;
...
...
@@ -97,7 +100,7 @@ public class EurekaInstanceConfigBean implements CloudEurekaInstanceConfig {
private
String
namespace
=
"eureka"
;
private
String
hostname
=
this
.
hostInfo
.
getHostname
()
;
private
String
hostname
;
private
boolean
preferIpAddress
=
false
;
...
...
@@ -107,6 +110,15 @@ public class EurekaInstanceConfigBean implements CloudEurekaInstanceConfig {
return
getHostName
(
false
);
}
private
EurekaInstanceConfigBean
()
{}
public
EurekaInstanceConfigBean
(
InetUtils
inetUtils
)
{
this
.
inetUtils
=
inetUtils
;
this
.
hostInfo
=
this
.
inetUtils
.
findFirstNonLoopbackHostInfo
();
this
.
ipAddress
=
this
.
hostInfo
.
getIpAddress
();
this
.
hostname
=
this
.
hostInfo
.
getHostname
();
}
@Override
public
String
getInstanceId
()
{
if
(
this
.
instanceId
==
null
&&
this
.
metadataMap
!=
null
)
{
...
...
@@ -129,7 +141,7 @@ public class EurekaInstanceConfigBean implements CloudEurekaInstanceConfig {
public
String
getHostName
(
boolean
refresh
)
{
if
(
refresh
)
{
boolean
originalOverride
=
this
.
hostInfo
.
override
;
this
.
hostInfo
=
get
FirstNonLoopbackHostInfo
();
this
.
hostInfo
=
this
.
inetUtils
.
find
FirstNonLoopbackHostInfo
();
this
.
hostInfo
.
setOverride
(
originalOverride
);
this
.
ipAddress
=
this
.
hostInfo
.
getIpAddress
();
if
(!
this
.
hostInfo
.
override
)
{
...
...
spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/config/DiscoveryClientConfigServiceAutoConfigurationTests.java
View file @
94c73da9
...
...
@@ -24,6 +24,7 @@ import org.springframework.boot.test.EnvironmentTestUtils;
import
org.springframework.cloud.config.client.ConfigClientProperties
;
import
org.springframework.cloud.netflix.eureka.EurekaClientAutoConfiguration
;
import
org.springframework.cloud.netflix.eureka.EurekaDiscoveryClientConfiguration
;
import
org.springframework.cloud.util.UtilAutoConfiguration
;
import
org.springframework.context.annotation.AnnotationConfigApplicationContext
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
...
...
@@ -75,7 +76,8 @@ public class DiscoveryClientConfigServiceAutoConfigurationTests {
private
void
setup
(
String
...
env
)
{
AnnotationConfigApplicationContext
parent
=
new
AnnotationConfigApplicationContext
();
EnvironmentTestUtils
.
addEnvironment
(
parent
,
env
);
parent
.
register
(
PropertyPlaceholderAutoConfiguration
.
class
,
parent
.
register
(
UtilAutoConfiguration
.
class
,
PropertyPlaceholderAutoConfiguration
.
class
,
DiscoveryClientConfigServiceBootstrapConfiguration
.
class
,
EnvironmentKnobbler
.
class
,
ConfigClientProperties
.
class
);
parent
.
refresh
();
...
...
spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/config/DiscoveryClientConfigServiceBootstrapConfigurationTests.java
View file @
94c73da9
...
...
@@ -27,6 +27,7 @@ import org.mockito.Mockito;
import
org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration
;
import
org.springframework.boot.test.EnvironmentTestUtils
;
import
org.springframework.cloud.config.client.ConfigClientProperties
;
import
org.springframework.cloud.util.UtilAutoConfiguration
;
import
org.springframework.context.annotation.AnnotationConfigApplicationContext
;
import
com.netflix.appinfo.InstanceInfo
;
...
...
@@ -124,7 +125,8 @@ public class DiscoveryClientConfigServiceBootstrapConfigurationTests {
EnvironmentTestUtils
.
addEnvironment
(
this
.
context
,
env
);
this
.
context
.
getDefaultListableBeanFactory
().
registerSingleton
(
"eurekaClient"
,
this
.
client
);
this
.
context
.
register
(
PropertyPlaceholderAutoConfiguration
.
class
,
this
.
context
.
register
(
UtilAutoConfiguration
.
class
,
PropertyPlaceholderAutoConfiguration
.
class
,
DiscoveryClientConfigServiceBootstrapConfiguration
.
class
,
ConfigClientProperties
.
class
);
this
.
context
.
refresh
();
...
...
spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/eureka/EurekaClientAutoConfigurationTests.java
View file @
94c73da9
...
...
@@ -23,6 +23,7 @@ import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfigurati
import
org.springframework.boot.context.properties.EnableConfigurationProperties
;
import
org.springframework.boot.test.EnvironmentTestUtils
;
import
org.springframework.cloud.autoconfigure.RefreshAutoConfiguration
;
import
org.springframework.cloud.util.UtilAutoConfiguration
;
import
org.springframework.context.annotation.AnnotationConfigApplicationContext
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Import
;
...
...
@@ -66,8 +67,8 @@ public class EurekaClientAutoConfigurationTests {
@Test
public
void
nonSecurePort
()
{
testNonSecurePort
(
"PORT"
);
assertEquals
(
"eurekaClient"
,
this
.
context
.
getBeanDefinition
(
"eurekaClient"
)
.
getFactoryMethodName
());
assertEquals
(
"eurekaClient"
,
this
.
context
.
getBeanDefinition
(
"eurekaClient"
)
.
getFactoryMethodName
());
}
@Test
...
...
@@ -77,8 +78,8 @@ public class EurekaClientAutoConfigurationTests {
setupContext
(
RefreshAutoConfiguration
.
class
);
EurekaInstanceConfigBean
instance
=
this
.
context
.
getBean
(
EurekaInstanceConfigBean
.
class
);
assertTrue
(
"Wrong status page: "
+
instance
.
getStatusPageUrl
(),
instance
.
getStatusPageUrl
().
contains
(
"9999"
));
assertTrue
(
"Wrong status page: "
+
instance
.
getStatusPageUrl
(),
instance
.
getStatusPageUrl
().
contains
(
"9999"
));
}
@Test
...
...
@@ -88,15 +89,15 @@ public class EurekaClientAutoConfigurationTests {
setupContext
(
RefreshAutoConfiguration
.
class
);
EurekaInstanceConfigBean
instance
=
this
.
context
.
getBean
(
EurekaInstanceConfigBean
.
class
);
assertTrue
(
"Wrong status page: "
+
instance
.
getStatusPageUrl
(),
instance
.
getStatusPageUrl
().
contains
(
"foo"
));
assertTrue
(
"Wrong status page: "
+
instance
.
getStatusPageUrl
(),
instance
.
getStatusPageUrl
().
contains
(
"foo"
));
}
@Test
public
void
refreshScopedBeans
()
{
setupContext
(
RefreshAutoConfiguration
.
class
);
assertEquals
(
ScopedProxyFactoryBean
.
class
.
getName
(),
this
.
context
.
getBeanDefinition
(
"eurekaClient"
).
getBeanClassName
());
assertEquals
(
ScopedProxyFactoryBean
.
class
.
getName
(),
this
.
context
.
getBeanDefinition
(
"eurekaClient"
).
getBeanClassName
());
assertEquals
(
ScopedProxyFactoryBean
.
class
.
getName
(),
this
.
context
.
getBeanDefinition
(
"eurekaApplicationInfoManager"
).
getBeanClassName
());
}
...
...
@@ -113,7 +114,7 @@ public class EurekaClientAutoConfigurationTests {
@Configuration
@EnableConfigurationProperties
@Import
(
EurekaClientAutoConfiguration
.
class
)
@Import
(
{
UtilAutoConfiguration
.
class
,
EurekaClientAutoConfiguration
.
class
}
)
protected
static
class
TestConfiguration
{
}
...
...
spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/eureka/EurekaInstanceConfigBeanTests.java
View file @
94c73da9
...
...
@@ -16,25 +16,28 @@
package
org
.
springframework
.
cloud
.
netflix
.
eureka
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
springframework
.
boot
.
test
.
EnvironmentTestUtils
.
addEnvironment
;
import
static
org
.
springframework
.
cloud
.
util
.
InetUtils
.
getFirstNonLoopbackHostInfo
;
import
org.junit.After
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.springframework.beans.factory.BeanCreationException
;
import
org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration
;
import
org.springframework.boot.context.properties.EnableConfigurationProperties
;
import
org.springframework.cloud.util.InetUtils
;
import
org.springframework.cloud.util.InetUtilsProperties
;
import
org.springframework.context.annotation.AnnotationConfigApplicationContext
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.test.util.ReflectionTestUtils
;
import
com.netflix.appinfo.InstanceInfo.InstanceStatus
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
springframework
.
boot
.
test
.
EnvironmentTestUtils
.
addEnvironment
;
/**
* @author Dave Syer
* @author Spencer Gibb
*/
public
class
EurekaInstanceConfigBeanTests
{
...
...
@@ -43,7 +46,8 @@ public class EurekaInstanceConfigBeanTests {
@Before
public
void
init
()
{
this
.
hostName
=
getFirstNonLoopbackHostInfo
().
getHostname
();
this
.
hostName
=
new
InetUtils
(
new
InetUtilsProperties
())
.
findFirstNonLoopbackHostInfo
().
getHostname
();
}
@After
...
...
@@ -148,8 +152,12 @@ public class EurekaInstanceConfigBeanTests {
}
@Configuration
@EnableConfigurationProperties
(
EurekaInstanceConfigBean
.
class
)
@EnableConfigurationProperties
protected
static
class
TestConfiguration
{
@Bean
public
EurekaInstanceConfigBean
eurekaInstanceConfigBean
()
{
return
new
EurekaInstanceConfigBean
(
new
InetUtils
(
new
InetUtilsProperties
()));
}
}
...
...
spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/eureka/InstanceInfoFactoryTests.java
View file @
94c73da9
package
org
.
springframework
.
cloud
.
netflix
.
eureka
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
springframework
.
boot
.
test
.
EnvironmentTestUtils
.
addEnvironment
;
import
static
org
.
springframework
.
cloud
.
util
.
InetUtils
.
getFirstNonLoopbackHostInfo
;
import
org.junit.Test
;
import
org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration
;
import
org.springframework.boot.context.properties.EnableConfigurationProperties
;
import
org.springframework.cloud.util.InetUtils
;
import
org.springframework.cloud.util.InetUtilsProperties
;
import
org.springframework.context.annotation.AnnotationConfigApplicationContext
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
com.netflix.appinfo.InstanceInfo
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
springframework
.
boot
.
test
.
EnvironmentTestUtils
.
addEnvironment
;
public
class
InstanceInfoFactoryTests
{
private
AnnotationConfigApplicationContext
context
=
new
AnnotationConfigApplicationContext
();
@Test
public
void
instanceIdIsHostNameByDefault
()
{
InstanceInfo
instanceInfo
=
setupInstance
();
assertEquals
(
getFirstNonLoopbackHostInfo
().
getHostname
(),
instanceInfo
.
getId
());
assertEquals
(
new
InetUtils
(
new
InetUtilsProperties
())
.
findFirstNonLoopbackHostInfo
().
getHostname
(),
instanceInfo
.
getId
());
}
@Test
public
void
instanceIdIsIpWhenIpPreferred
()
throws
Exception
{
InstanceInfo
instanceInfo
=
setupInstance
(
"eureka.instance.preferIpAddress:true"
);
assertTrue
(
instanceInfo
.
getId
().
matches
(
"(\\d+\\.){3}\\d+"
));
assertTrue
(
instanceInfo
.
getId
().
matches
(
"(\\d+\\.){3}\\d+"
));
}
@Test
...
...
@@ -53,7 +54,11 @@ public class InstanceInfoFactoryTests {
}
@Configuration
@EnableConfigurationProperties
(
EurekaInstanceConfigBean
.
class
)
@EnableConfigurationProperties
protected
static
class
TestConfiguration
{
@Bean
public
EurekaInstanceConfigBean
eurekaInstanceConfigBean
()
{
return
new
EurekaInstanceConfigBean
(
new
InetUtils
(
new
InetUtilsProperties
()));
}
}
}
spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/ribbon/RibbonClientPreprocessorOverridesIntegrationTests.java
View file @
94c73da9
...
...
@@ -27,6 +27,7 @@ import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfigurati
import
org.springframework.boot.test.SpringApplicationConfiguration
;
import
org.springframework.cloud.netflix.archaius.ArchaiusAutoConfiguration
;
import
org.springframework.cloud.netflix.eureka.EurekaClientAutoConfiguration
;
import
org.springframework.cloud.util.UtilAutoConfiguration
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Import
;
...
...
@@ -80,7 +81,7 @@ public class RibbonClientPreprocessorOverridesIntegrationTests {
@RibbonClient
(
name
=
"foo"
,
configuration
=
FooConfiguration
.
class
),
@RibbonClient
(
name
=
"bar"
,
configuration
=
BarConfiguration
.
class
)
})
@Import
({
PropertyPlaceholderAutoConfiguration
.
class
,
@Import
({
UtilAutoConfiguration
.
class
,
PropertyPlaceholderAutoConfiguration
.
class
,
ArchaiusAutoConfiguration
.
class
,
EurekaClientAutoConfiguration
.
class
,
RibbonAutoConfiguration
.
class
})
protected
static
class
TestConfiguration
{
...
...
spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/ribbon/RibbonClientsPreprocessorIntegrationTests.java
View file @
94c73da9
...
...
@@ -24,6 +24,7 @@ import org.springframework.boot.test.SpringApplicationConfiguration;
import
org.springframework.cloud.netflix.archaius.ArchaiusAutoConfiguration
;
import
org.springframework.cloud.netflix.eureka.EurekaClientAutoConfiguration
;
import
org.springframework.cloud.netflix.ribbon.RibbonClientsPreprocessorIntegrationTests.TestConfiguration
;
import
org.springframework.cloud.util.UtilAutoConfiguration
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Import
;
...
...
@@ -67,7 +68,7 @@ public class RibbonClientsPreprocessorIntegrationTests {
@Configuration
@RibbonClients
(
@RibbonClient
(
name
=
"foo"
,
configuration
=
FooConfiguration
.
class
))
@Import
({
PropertyPlaceholderAutoConfiguration
.
class
,
@Import
({
UtilAutoConfiguration
.
class
,
PropertyPlaceholderAutoConfiguration
.
class
,
ArchaiusAutoConfiguration
.
class
,
EurekaClientAutoConfiguration
.
class
,
RibbonAutoConfiguration
.
class
})
protected
static
class
TestConfiguration
{
...
...
spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/ribbon/eureka/EurekaRibbonClientConfigurationTests.java
View file @
94c73da9
...
...
@@ -28,6 +28,8 @@ import org.junit.Test;
import
org.springframework.cloud.netflix.eureka.EurekaClientConfigBean
;
import
org.springframework.cloud.netflix.eureka.EurekaInstanceConfigBean
;
import
org.springframework.cloud.netflix.ribbon.SpringClientFactory
;
import
org.springframework.cloud.util.InetUtils
;
import
org.springframework.cloud.util.InetUtilsProperties
;
import
com.netflix.config.ConfigurationManager
;
import
com.netflix.config.DeploymentContext.ContextKey
;
...
...
@@ -52,7 +54,7 @@ public class EurekaRibbonClientConfigurationTests {
@Ignore
public
void
basicConfigurationCreatedForLoadBalancer
()
{
EurekaClientConfigBean
client
=
new
EurekaClientConfigBean
();
EurekaInstanceConfigBean
configBean
=
new
EurekaInstanceConfigBean
();
EurekaInstanceConfigBean
configBean
=
get
EurekaInstanceConfigBean
();
client
.
getAvailabilityZones
().
put
(
client
.
getRegion
(),
"foo"
);
SpringClientFactory
clientFactory
=
new
SpringClientFactory
();
EurekaRibbonClientConfiguration
clientPreprocessor
=
new
EurekaRibbonClientConfiguration
(
...
...
@@ -67,10 +69,14 @@ public class EurekaRibbonClientConfigurationTests {
ConfigurationManager
.
getDeploymentContext
().
getValue
(
ContextKey
.
zone
));
}
private
EurekaInstanceConfigBean
getEurekaInstanceConfigBean
()
{
return
new
EurekaInstanceConfigBean
(
new
InetUtils
(
new
InetUtilsProperties
()));
}
@Test
public
void
testSetProp
()
{
EurekaClientConfigBean
client
=
new
EurekaClientConfigBean
();
EurekaInstanceConfigBean
configBean
=
new
EurekaInstanceConfigBean
();
EurekaInstanceConfigBean
configBean
=
get
EurekaInstanceConfigBean
();
EurekaRibbonClientConfiguration
preprocessor
=
new
EurekaRibbonClientConfiguration
(
client
,
"myService"
,
configBean
,
false
);
String
serviceId
=
"myService"
;
...
...
@@ -88,7 +94,7 @@ public class EurekaRibbonClientConfigurationTests {
@Test
public
void
testDefaultZone
()
{
EurekaClientConfigBean
client
=
new
EurekaClientConfigBean
();
EurekaInstanceConfigBean
configBean
=
new
EurekaInstanceConfigBean
();
EurekaInstanceConfigBean
configBean
=
get
EurekaInstanceConfigBean
();
EurekaRibbonClientConfiguration
preprocessor
=
new
EurekaRibbonClientConfiguration
(
client
,
"myService"
,
configBean
,
false
);
preprocessor
.
preprocess
();
...
...
@@ -98,7 +104,7 @@ public class EurekaRibbonClientConfigurationTests {
@Test
public
void
testApproximateZone
()
{
EurekaClientConfigBean
client
=
new
EurekaClientConfigBean
();
EurekaInstanceConfigBean
configBean
=
new
EurekaInstanceConfigBean
();
EurekaInstanceConfigBean
configBean
=
get
EurekaInstanceConfigBean
();
configBean
.
setHostname
(
"this.is.a.test.com"
);
EurekaRibbonClientConfiguration
preprocessor
=
new
EurekaRibbonClientConfiguration
(
client
,
"myService"
,
configBean
,
true
);
...
...
spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/ribbon/eureka/EurekaRibbonClientPreprocessorIntegrationTests.java
View file @
94c73da9
...
...
@@ -28,6 +28,7 @@ import org.springframework.cloud.netflix.ribbon.RibbonClient;
import
org.springframework.cloud.netflix.ribbon.ServerIntrospector
;
import
org.springframework.cloud.netflix.ribbon.SpringClientFactory
;
import
org.springframework.cloud.netflix.ribbon.eureka.EurekaRibbonClientPreprocessorIntegrationTests.TestConfiguration
;
import
org.springframework.cloud.util.UtilAutoConfiguration
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Import
;
import
org.springframework.test.annotation.DirtiesContext
;
...
...
@@ -77,7 +78,7 @@ public class EurekaRibbonClientPreprocessorIntegrationTests {
@Configuration
@RibbonClient
(
"foo"
)
@Import
({
PropertyPlaceholderAutoConfiguration
.
class
,
@Import
({
UtilAutoConfiguration
.
class
,
PropertyPlaceholderAutoConfiguration
.
class
,
ArchaiusAutoConfiguration
.
class
,
RibbonAutoConfiguration
.
class
,
EurekaClientAutoConfiguration
.
class
,
RibbonEurekaAutoConfiguration
.
class
})
protected
static
class
TestConfiguration
{
...
...
spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/ribbon/eureka/RibbonClientPreprocessorIntegrationTests.java
View file @
94c73da9
...
...
@@ -16,8 +16,6 @@
package
org
.
springframework
.
cloud
.
netflix
.
ribbon
.
eureka
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.springframework.beans.factory.annotation.Autowired
;
...
...
@@ -30,6 +28,8 @@ import org.springframework.cloud.netflix.ribbon.RibbonClient;
import
org.springframework.cloud.netflix.ribbon.SpringClientFactory
;
import
org.springframework.cloud.netflix.ribbon.ZonePreferenceServerListFilter
;
import
org.springframework.cloud.netflix.ribbon.eureka.RibbonClientPreprocessorIntegrationTests.TestConfiguration
;
import
org.springframework.cloud.util.InetUtils
;
import
org.springframework.cloud.util.InetUtilsProperties
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Import
;
...
...
@@ -40,6 +40,8 @@ import com.netflix.loadbalancer.Server;
import
com.netflix.loadbalancer.ZoneAvoidanceRule
;
import
com.netflix.loadbalancer.ZoneAwareLoadBalancer
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
/**
* @author Dave Syer
*/
...
...
@@ -87,7 +89,8 @@ public class RibbonClientPreprocessorIntegrationTests {
@Configuration
@RibbonClient
(
name
=
"foo"
,
configuration
=
FooConfiguration
.
class
)
@Import
({
PropertyPlaceholderAutoConfiguration
.
class
,
ArchaiusAutoConfiguration
.
class
,
RibbonAutoConfiguration
.
class
,
RibbonEurekaAutoConfiguration
.
class
})
ArchaiusAutoConfiguration
.
class
,
RibbonAutoConfiguration
.
class
,
RibbonEurekaAutoConfiguration
.
class
})
protected
static
class
TestConfiguration
{
}
...
...
@@ -99,10 +102,11 @@ public class RibbonClientPreprocessorIntegrationTests {
filter
.
setZone
(
"myTestZone"
);
return
filter
;
}
@Bean
public
EurekaInstanceConfigBean
getEurekaInstanceConfigBean
()
{
EurekaInstanceConfigBean
bean
=
new
EurekaInstanceConfigBean
();
EurekaInstanceConfigBean
bean
=
new
EurekaInstanceConfigBean
(
new
InetUtils
(
new
InetUtilsProperties
()));
return
bean
;
}
}
...
...
spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/ribbon/test/RibbonClientDefaultConfigurationTestsConfig.java
View file @
94c73da9
...
...
@@ -16,32 +16,34 @@
package
org
.
springframework
.
cloud
.
netflix
.
ribbon
.
test
;
import
com.netflix.client.config.IClientConfig
;
import
com.netflix.loadbalancer.BestAvailableRule
;
import
com.netflix.loadbalancer.ConfigurationBasedServerList
;
import
com.netflix.loadbalancer.IPing
;
import
com.netflix.loadbalancer.IRule
;
import
com.netflix.loadbalancer.PingUrl
;
import
com.netflix.loadbalancer.Server
;
import
com.netflix.loadbalancer.ServerList
;
import
com.netflix.loadbalancer.ServerListSubsetFilter
;
import
org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration
;
import
org.springframework.cloud.netflix.archaius.ArchaiusAutoConfiguration
;
import
org.springframework.cloud.netflix.eureka.EurekaClientAutoConfiguration
;
import
org.springframework.cloud.netflix.ribbon.RibbonAutoConfiguration
;
import
org.springframework.cloud.netflix.ribbon.RibbonClients
;
import
org.springframework.cloud.netflix.ribbon.eureka.RibbonEurekaAutoConfiguration
;
import
org.springframework.cloud.util.UtilAutoConfiguration
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Import
;
import
com.netflix.client.config.IClientConfig
;
import
com.netflix.loadbalancer.BestAvailableRule
;
import
com.netflix.loadbalancer.ConfigurationBasedServerList
;
import
com.netflix.loadbalancer.IPing
;
import
com.netflix.loadbalancer.IRule
;
import
com.netflix.loadbalancer.PingUrl
;
import
com.netflix.loadbalancer.Server
;
import
com.netflix.loadbalancer.ServerList
;
import
com.netflix.loadbalancer.ServerListSubsetFilter
;
/**
* @author Spencer Gibb
*/
@Configuration
@Import
({
PropertyPlaceholderAutoConfiguration
.
class
,
Archaius
AutoConfiguration
.
class
,
EurekaClientAutoConfiguration
.
class
,
RibbonAutoConfiguration
.
class
,
RibbonEurekaAutoConfiguration
.
class
})
@Import
({
PropertyPlaceholderAutoConfiguration
.
class
,
ArchaiusAutoConfiguration
.
class
,
Util
AutoConfiguration
.
class
,
EurekaClientAutoConfiguration
.
class
,
RibbonAutoConfiguration
.
class
,
RibbonEurekaAutoConfiguration
.
class
})
@RibbonClients
(
defaultConfiguration
=
DefaultRibbonConfig
.
class
)
public
class
RibbonClientDefaultConfigurationTestsConfig
{
...
...
@@ -52,7 +54,6 @@ public class RibbonClientDefaultConfigurationTestsConfig {
}
}
@Configuration
class
DefaultRibbonConfig
{
...
...
spring-cloud-netflix-sidecar/src/main/java/org/springframework/cloud/netflix/sidecar/SidecarConfiguration.java
View file @
94c73da9
...
...
@@ -23,6 +23,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import
org.springframework.boot.context.properties.EnableConfigurationProperties
;
import
org.springframework.cloud.client.actuator.HasFeatures
;
import
org.springframework.cloud.netflix.eureka.EurekaInstanceConfigBean
;
import
org.springframework.cloud.util.InetUtils
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
...
...
@@ -53,6 +54,9 @@ public class SidecarConfiguration {
@Autowired
private
SidecarProperties
sidecarProperties
;
@Autowired
private
InetUtils
inetUtils
;
@Value
(
"${server.port:${SERVER_PORT:${PORT:8080}}}"
)
private
int
serverPort
=
8080
;
...
...
@@ -61,7 +65,7 @@ public class SidecarConfiguration {
@Bean
public
EurekaInstanceConfigBean
eurekaInstanceConfigBean
()
{
EurekaInstanceConfigBean
config
=
new
EurekaInstanceConfigBean
();
EurekaInstanceConfigBean
config
=
new
EurekaInstanceConfigBean
(
inetUtils
);
int
port
=
this
.
sidecarProperties
.
getPort
();
config
.
setNonSecurePort
(
port
);
String
scheme
=
config
.
getSecurePortEnabled
()
?
"https"
:
"http"
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment