Skip to content
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

fix loading process cannot load environment variables. #13091

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ private static <V extends Object> Map<String, V> getSubProperties(Map<String, V>
for (Map.Entry<String, V> entry : copy.entrySet()) {
String key = entry.getKey();
V val = entry.getValue();
if (StringUtils.startsWithIgnoreCase(key, prefix)
if ((StringUtils.startsWithIgnoreCase(key, prefix) || StringUtils.startsWithIgnoreCase(key, StringUtils.toOSStyleKey(prefix)))
&& key.length() > prefix.length()
&& !ConfigurationUtils.isEmptyValue(val)) {

Expand Down Expand Up @@ -317,7 +317,7 @@ public static <V extends Object> boolean hasSubProperties(Map<String, V> configM
}
for (Map.Entry<String, V> entry : copy.entrySet()) {
String key = entry.getKey();
if (StringUtils.startsWithIgnoreCase(key, prefix)
if ((StringUtils.startsWithIgnoreCase(key, prefix) || StringUtils.startsWithIgnoreCase(key, StringUtils.toOSStyleKey(prefix)))
&& key.length() > prefix.length()
&& !ConfigurationUtils.isEmptyValue(entry.getValue())) {
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ private void unRegisterShutdownHook() {
* by default is false.
*/
private boolean isRegisterConsumerInstance() {
Boolean registerConsumer = getApplication().getRegisterConsumer();
Boolean registerConsumer = getApplicationOrElseThrow().getRegisterConsumer();
if (registerConsumer == null) {
return false;
}
Expand Down Expand Up @@ -310,7 +310,7 @@ private void startMetadataCenter() {

useRegistryAsMetadataCenterIfNecessary();

ApplicationConfig applicationConfig = getApplication();
ApplicationConfig applicationConfig = getApplicationOrElseThrow();

String metadataType = applicationConfig.getMetadataType();
// FIXME, multiple metadata config support.
Expand Down Expand Up @@ -858,14 +858,18 @@ private DynamicConfiguration prepareEnvironment(ConfigCenterConfig configCenter)
if (StringUtils.isNotEmpty(configContent)) {
logger.info(String.format("Got global remote configuration from config center with key-%s and group-%s: \n %s", configCenter.getConfigFile(), configCenter.getGroup(), configContent));
}
String appGroup = getApplication().getName();
String appGroup = "";
String appConfigContent = null;
String appConfigFile = null;
if (isNotEmpty(appGroup)) {
appConfigFile = isNotEmpty(configCenter.getAppConfigFile()) ? configCenter.getAppConfigFile() : configCenter.getConfigFile();
appConfigContent = dynamicConfiguration.getProperties(appConfigFile, appGroup);
if (StringUtils.isNotEmpty(appConfigContent)) {
logger.info(String.format("Got application specific remote configuration from config center with key %s and group %s: \n %s", appConfigFile, appGroup, appConfigContent));
Optional<ApplicationConfig> applicationOptional = getApplication();
if (applicationOptional.isPresent()) {
appGroup = applicationOptional.get().getName();
if (isNotEmpty(appGroup)) {
appConfigFile = isNotEmpty(configCenter.getAppConfigFile()) ? configCenter.getAppConfigFile() : configCenter.getConfigFile();
appConfigContent = dynamicConfiguration.getProperties(appConfigFile, appGroup);
if (StringUtils.isNotEmpty(appConfigContent)) {
logger.info(String.format("Got application specific remote configuration from config center with key %s and group %s: \n %s", appConfigFile, appGroup, appConfigContent));
}
}
}
try {
Expand Down Expand Up @@ -1322,9 +1326,12 @@ private void destroyMetadataReports() {
}
}

private ApplicationConfig getApplication() {
private ApplicationConfig getApplicationOrElseThrow() {
return configManager.getApplicationOrElseThrow();
}

private Optional<ApplicationConfig> getApplication() {
return configManager.getApplication();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -917,7 +917,7 @@ private class ProviderConfigurationListener extends AbstractConfiguratorListener
public ProviderConfigurationListener(ModuleModel moduleModel) {
super(moduleModel);
this.moduleModel = moduleModel;
if (moduleModel.modelEnvironment().getConfiguration().convert(Boolean.class, ENABLE_CONFIGURATION_LISTEN, true)) {
if (moduleModel.modelEnvironment().getConfiguration().getBoolean(ENABLE_CONFIGURATION_LISTEN, true)) {
this.initWith(moduleModel.getApplicationModel().getApplicationName() + CONFIGURATORS_SUFFIX);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import org.apache.dubbo.common.extension.ExtensionLoader;
import org.apache.dubbo.common.utils.JsonUtils;
import org.apache.dubbo.common.utils.NetUtils;

import org.apache.dubbo.rpc.Exporter;
import org.apache.dubbo.rpc.Invoker;
import org.apache.dubbo.rpc.Protocol;
Expand All @@ -31,13 +30,11 @@
import org.apache.dubbo.rpc.model.ModuleServiceRepository;
import org.apache.dubbo.rpc.model.ProviderModel;
import org.apache.dubbo.rpc.model.ServiceDescriptor;

import org.apache.dubbo.rpc.protocol.rest.noannotation.NoAnnotationDemoService;
import org.apache.dubbo.rpc.protocol.rest.noannotation.NoAnnotationDemoServiceImpl;

import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;

import org.junit.jupiter.api.Test;

import java.util.Arrays;
Expand All @@ -53,6 +50,12 @@ class NoAnnotationRestProtocolTest {
public void tearDown() {
protocol.destroy();
FrameworkModel.destroyAll();
new JsonUtils() {
public void clearJson() {
setJson(null);
}
}.clearJson();
System.clearProperty(CommonConstants.PREFER_JSON_FRAMEWORK_NAME);
}

@Test
Expand Down
Loading