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
6e2238f2
Commit
6e2238f2
authored
Dec 09, 2017
by
Fahim Farook
Committed by
Ryan Baxter
Dec 08, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update Eureka Server's service-urls upon EnvironmentChangeEvent. (#2455)
Fixes gh-2421
parent
f640ffd2
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
64 additions
and
2 deletions
+64
-2
EurekaServerAutoConfiguration.java
.../netflix/eureka/server/EurekaServerAutoConfiguration.java
+64
-2
RefreshablePeerEurekaNodesTests.java
...etflix/eureka/server/RefreshablePeerEurekaNodesTests.java
+0
-0
No files found.
spring-cloud-netflix-eureka-server/src/main/java/org/springframework/cloud/netflix/eureka/server/EurekaServerAutoConfiguration.java
View file @
6e2238f2
/*
/*
* Copyright 2013-201
5
the original author or authors.
* Copyright 2013-201
7
the original author or authors.
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* you may not use this file except in compliance with the License.
...
@@ -35,7 +35,9 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
...
@@ -35,7 +35,9 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import
org.springframework.boot.context.properties.EnableConfigurationProperties
;
import
org.springframework.boot.context.properties.EnableConfigurationProperties
;
import
org.springframework.boot.web.servlet.FilterRegistrationBean
;
import
org.springframework.boot.web.servlet.FilterRegistrationBean
;
import
org.springframework.cloud.client.actuator.HasFeatures
;
import
org.springframework.cloud.client.actuator.HasFeatures
;
import
org.springframework.cloud.context.environment.EnvironmentChangeEvent
;
import
org.springframework.cloud.netflix.eureka.EurekaConstants
;
import
org.springframework.cloud.netflix.eureka.EurekaConstants
;
import
org.springframework.context.ApplicationListener
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider
;
import
org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Configuration
;
...
@@ -67,6 +69,7 @@ import com.sun.jersey.spi.container.servlet.ServletContainer;
...
@@ -67,6 +69,7 @@ import com.sun.jersey.spi.container.servlet.ServletContainer;
/**
/**
* @author Gunnar Hillert
* @author Gunnar Hillert
* @author Biju Kunjummen
* @author Biju Kunjummen
* @author Fahim Farook
*/
*/
@Configuration
@Configuration
@Import
(
EurekaServerInitializerConfiguration
.
class
)
@Import
(
EurekaServerInitializerConfiguration
.
class
)
...
@@ -169,10 +172,69 @@ public class EurekaServerAutoConfiguration extends WebMvcConfigurerAdapter {
...
@@ -169,10 +172,69 @@ public class EurekaServerAutoConfiguration extends WebMvcConfigurerAdapter {
@ConditionalOnMissingBean
@ConditionalOnMissingBean
public
PeerEurekaNodes
peerEurekaNodes
(
PeerAwareInstanceRegistry
registry
,
public
PeerEurekaNodes
peerEurekaNodes
(
PeerAwareInstanceRegistry
registry
,
ServerCodecs
serverCodecs
)
{
ServerCodecs
serverCodecs
)
{
return
new
PeerEurekaNodes
(
registry
,
this
.
eurekaServerConfig
,
return
new
Refreshable
PeerEurekaNodes
(
registry
,
this
.
eurekaServerConfig
,
this
.
eurekaClientConfig
,
serverCodecs
,
this
.
applicationInfoManager
);
this
.
eurekaClientConfig
,
serverCodecs
,
this
.
applicationInfoManager
);
}
}
/**
* {@link PeerEurekaNodes} which updates peers when /refresh is invoked.
* Peers are updated only if
* <code>eureka.client.use-dns-for-fetching-service-urls</code> is
* <code>false</code> and one of following properties have changed.
* </p>
* <ul>
* <li><code>eureka.client.availability-zones</code></li>
* <li><code>eureka.client.region</code></li>
* <li><code>eureka.client.service-url.<zone></code></li>
* </ul>
*/
static
class
RefreshablePeerEurekaNodes
extends
PeerEurekaNodes
implements
ApplicationListener
<
EnvironmentChangeEvent
>
{
public
RefreshablePeerEurekaNodes
(
final
PeerAwareInstanceRegistry
registry
,
final
EurekaServerConfig
serverConfig
,
final
EurekaClientConfig
clientConfig
,
final
ServerCodecs
serverCodecs
,
final
ApplicationInfoManager
applicationInfoManager
)
{
super
(
registry
,
serverConfig
,
clientConfig
,
serverCodecs
,
applicationInfoManager
);
}
@Override
public
void
onApplicationEvent
(
final
EnvironmentChangeEvent
event
)
{
if
(
shouldUpdate
(
event
.
getKeys
()))
{
updatePeerEurekaNodes
(
resolvePeerUrls
());
}
}
/*
* Check whether specific properties have changed.
*/
protected
boolean
shouldUpdate
(
final
Set
<
String
>
changedKeys
)
{
assert
changedKeys
!=
null
;
// if eureka.client.use-dns-for-fetching-service-urls is true, then
// service-url will not be fetched from environment.
if
(
clientConfig
.
shouldUseDnsForFetchingServiceUrls
())
{
return
false
;
}
if
(
changedKeys
.
contains
(
"eureka.client.region"
))
{
return
true
;
}
for
(
final
String
key
:
changedKeys
)
{
// property keys are not expected to be null.
if
(
key
.
startsWith
(
"eureka.client.service-url."
)
||
key
.
startsWith
(
"eureka.client.availability-zones."
))
{
return
true
;
}
}
return
false
;
}
}
@Bean
@Bean
public
EurekaServerContext
eurekaServerContext
(
ServerCodecs
serverCodecs
,
public
EurekaServerContext
eurekaServerContext
(
ServerCodecs
serverCodecs
,
PeerAwareInstanceRegistry
registry
,
PeerEurekaNodes
peerEurekaNodes
)
{
PeerAwareInstanceRegistry
registry
,
PeerEurekaNodes
peerEurekaNodes
)
{
...
...
spring-cloud-netflix-eureka-server/src/test/java/org/springframework/cloud/netflix/eureka/server/RefreshablePeerEurekaNodesTests.java
0 → 100644
View file @
6e2238f2
This diff is collapsed.
Click to expand it.
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