-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
reload properties of remotely activated profile fixes gh-1834 #1835
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -69,14 +69,20 @@ public class ConfigServicePropertySourceLocator implements PropertySourceLocator | |
|
||
private ConfigClientProperties defaultProperties; | ||
|
||
private final String ACTIVE_PROFILES_PROPERTY_NAME = "spring.profiles.active"; | ||
|
||
public ConfigServicePropertySourceLocator(ConfigClientProperties defaultProperties) { | ||
this.defaultProperties = defaultProperties; | ||
} | ||
|
||
@Override | ||
@Retryable(interceptor = "configServerRetryInterceptor") | ||
public org.springframework.core.env.PropertySource<?> locate(org.springframework.core.env.Environment environment) { | ||
ConfigClientProperties properties = this.defaultProperties.override(environment); | ||
return locate(properties); | ||
} | ||
|
||
@Retryable(interceptor = "configServerRetryInterceptor") | ||
public org.springframework.core.env.PropertySource<?> locate(ConfigClientProperties properties) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is the only usage of this the method above? |
||
CompositePropertySource composite = new OriginTrackedCompositePropertySource("configService"); | ||
ConfigClientRequestTemplateFactory requestTemplateFactory = new ConfigClientRequestTemplateFactory(logger, | ||
properties); | ||
|
@@ -101,6 +107,17 @@ public org.springframework.core.env.PropertySource<?> locate(org.springframework | |
@SuppressWarnings("unchecked") | ||
Map<String, Object> map = translateOrigins(source.getName(), | ||
(Map<String, Object>) source.getSource()); | ||
|
||
// if different profile is activated within the default | ||
// profile | ||
boolean relocate = checkIfProfileIsActivatedInDefault(result.getProfiles(), map); | ||
if (relocate) { | ||
OriginTrackedValue newProfiles = (OriginTrackedValue) map | ||
.get(ACTIVE_PROFILES_PROPERTY_NAME); | ||
properties.setProfile(newProfiles.getValue().toString()); | ||
return this.locate(properties); // relocate again | ||
} | ||
|
||
composite.addPropertySource(new OriginTrackedMapPropertySource(source.getName(), map)); | ||
} | ||
} | ||
|
@@ -138,6 +155,15 @@ public org.springframework.core.env.PropertySource<?> locate(org.springframework | |
|
||
} | ||
|
||
// to check if different profile is activated within the default profile | ||
private boolean checkIfProfileIsActivatedInDefault(String[] profiles, Map<String, Object> map) { | ||
List<String> profilesList = Arrays.asList(profiles); | ||
return (profilesList.size() == 1 && profilesList.get(0).equalsIgnoreCase("default") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @spencergibb do you recall why this would only need to be done for the default profile? What if the default profile contains |
||
&& map.containsKey(ACTIVE_PROFILES_PROPERTY_NAME) | ||
&& !(((OriginTrackedValue) map.get(ACTIVE_PROFILES_PROPERTY_NAME))).getValue().toString() | ||
.equalsIgnoreCase("default")); | ||
} | ||
|
||
@Override | ||
@Retryable(interceptor = "configServerRetryInterceptor") | ||
public Collection<org.springframework.core.env.PropertySource<?>> locateCollection( | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it needs to stay here for some rare backwards compatibility issues since the call to
locate(properties)
wouldn't be retryable.