|
|
@ -52,8 +52,7 @@ import org.springframework.util.StringUtils;
|
|
|
|
@Order(0)
|
|
|
|
@Order(0)
|
|
|
|
public class PolarisConfigFileLocator implements PropertySourceLocator {
|
|
|
|
public class PolarisConfigFileLocator implements PropertySourceLocator {
|
|
|
|
|
|
|
|
|
|
|
|
private static final Logger LOGGER = LoggerFactory
|
|
|
|
private static final Logger LOGGER = LoggerFactory.getLogger(PolarisConfigFileLocator.class);
|
|
|
|
.getLogger(PolarisConfigFileLocator.class);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static final String POLARIS_CONFIG_PROPERTY_SOURCE_NAME = "polaris-config";
|
|
|
|
private static final String POLARIS_CONFIG_PROPERTY_SOURCE_NAME = "polaris-config";
|
|
|
|
|
|
|
|
|
|
|
@ -115,7 +114,7 @@ public class PolarisConfigFileLocator implements PropertySourceLocator {
|
|
|
|
private List<ConfigFileMetadata> getInternalConfigFiles() {
|
|
|
|
private List<ConfigFileMetadata> getInternalConfigFiles() {
|
|
|
|
String namespace = polarisContextProperties.getNamespace();
|
|
|
|
String namespace = polarisContextProperties.getNamespace();
|
|
|
|
String serviceName = polarisContextProperties.getService();
|
|
|
|
String serviceName = polarisContextProperties.getService();
|
|
|
|
if (StringUtils.isEmpty(serviceName)) {
|
|
|
|
if (!StringUtils.hasText(serviceName)) {
|
|
|
|
serviceName = environment.getProperty("spring.application.name");
|
|
|
|
serviceName = environment.getProperty("spring.application.name");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -125,7 +124,7 @@ public class PolarisConfigFileLocator implements PropertySourceLocator {
|
|
|
|
String[] activeProfiles = environment.getActiveProfiles();
|
|
|
|
String[] activeProfiles = environment.getActiveProfiles();
|
|
|
|
|
|
|
|
|
|
|
|
for (String activeProfile : activeProfiles) {
|
|
|
|
for (String activeProfile : activeProfiles) {
|
|
|
|
if (StringUtils.isEmpty(activeProfile)) {
|
|
|
|
if (!StringUtils.hasText(activeProfile)) {
|
|
|
|
continue;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -137,7 +136,7 @@ public class PolarisConfigFileLocator implements PropertySourceLocator {
|
|
|
|
internalConfigFiles.add(new DefaultConfigFileMetadata(namespace, serviceName, "application.yml"));
|
|
|
|
internalConfigFiles.add(new DefaultConfigFileMetadata(namespace, serviceName, "application.yml"));
|
|
|
|
|
|
|
|
|
|
|
|
for (String activeProfile : activeProfiles) {
|
|
|
|
for (String activeProfile : activeProfiles) {
|
|
|
|
if (StringUtils.isEmpty(activeProfile)) {
|
|
|
|
if (!StringUtils.hasText(activeProfile)) {
|
|
|
|
continue;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -160,9 +159,8 @@ public class PolarisConfigFileLocator implements PropertySourceLocator {
|
|
|
|
for (ConfigFileGroup configFileGroup : configFileGroups) {
|
|
|
|
for (ConfigFileGroup configFileGroup : configFileGroups) {
|
|
|
|
String group = configFileGroup.getName();
|
|
|
|
String group = configFileGroup.getName();
|
|
|
|
|
|
|
|
|
|
|
|
if (StringUtils.isEmpty(group)) {
|
|
|
|
if (!StringUtils.hasText(group)) {
|
|
|
|
throw new IllegalArgumentException(
|
|
|
|
throw new IllegalArgumentException("polaris config group name cannot be empty.");
|
|
|
|
"polaris config group name cannot be empty.");
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
List<String> files = configFileGroup.getFiles();
|
|
|
|
List<String> files = configFileGroup.getFiles();
|
|
|
@ -171,16 +169,14 @@ public class PolarisConfigFileLocator implements PropertySourceLocator {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
for (String fileName : files) {
|
|
|
|
for (String fileName : files) {
|
|
|
|
PolarisPropertySource polarisPropertySource = loadPolarisPropertySource(
|
|
|
|
PolarisPropertySource polarisPropertySource = loadPolarisPropertySource(namespace, group, fileName);
|
|
|
|
namespace, group, fileName);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
compositePropertySource.addPropertySource(polarisPropertySource);
|
|
|
|
compositePropertySource.addPropertySource(polarisPropertySource);
|
|
|
|
|
|
|
|
|
|
|
|
polarisPropertySourceManager.addPropertySource(polarisPropertySource);
|
|
|
|
polarisPropertySourceManager.addPropertySource(polarisPropertySource);
|
|
|
|
|
|
|
|
|
|
|
|
LOGGER.info(
|
|
|
|
LOGGER.info("[SCT Config] Load and inject polaris config file success."
|
|
|
|
"[SCT Config] Load and inject polaris config file success. namespace = {}, group = {}, fileName = {}",
|
|
|
|
+ " namespace = {}, group = {}, fileName = {}", namespace, group, fileName);
|
|
|
|
namespace, group, fileName);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -189,21 +185,18 @@ public class PolarisConfigFileLocator implements PropertySourceLocator {
|
|
|
|
String group, String fileName) {
|
|
|
|
String group, String fileName) {
|
|
|
|
ConfigKVFile configKVFile;
|
|
|
|
ConfigKVFile configKVFile;
|
|
|
|
// unknown extension is resolved as properties file
|
|
|
|
// unknown extension is resolved as properties file
|
|
|
|
if (ConfigFileFormat.isPropertyFile(fileName)
|
|
|
|
if (ConfigFileFormat.isPropertyFile(fileName) || ConfigFileFormat.isUnknownFile(fileName)) {
|
|
|
|
|| ConfigFileFormat.isUnknownFile(fileName)) {
|
|
|
|
|
|
|
|
configKVFile = configFileService.getConfigPropertiesFile(namespace, group, fileName);
|
|
|
|
configKVFile = configFileService.getConfigPropertiesFile(namespace, group, fileName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (ConfigFileFormat.isYamlFile(fileName)) {
|
|
|
|
else if (ConfigFileFormat.isYamlFile(fileName)) {
|
|
|
|
configKVFile = configFileService.getConfigYamlFile(namespace, group, fileName);
|
|
|
|
configKVFile = configFileService.getConfigYamlFile(namespace, group, fileName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
else {
|
|
|
|
LOGGER.warn(
|
|
|
|
LOGGER.warn("[SCT Config] Unsupported config file. namespace = {}, group = {}, fileName = {}",
|
|
|
|
"[SCT Config] Unsupported config file. namespace = {}, group = {}, fileName = {}",
|
|
|
|
|
|
|
|
namespace, group, fileName);
|
|
|
|
namespace, group, fileName);
|
|
|
|
|
|
|
|
|
|
|
|
throw new IllegalStateException(
|
|
|
|
throw new IllegalStateException("Only configuration files in the format of properties / yaml / yaml"
|
|
|
|
"Only configuration files in the format of properties / yaml / yaml"
|
|
|
|
+ " can be injected into the spring context");
|
|
|
|
+ " can be injected into the spring context");
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Map<String, Object> map = new ConcurrentHashMap<>();
|
|
|
|
Map<String, Object> map = new ConcurrentHashMap<>();
|
|
|
@ -213,5 +206,4 @@ public class PolarisConfigFileLocator implements PropertySourceLocator {
|
|
|
|
|
|
|
|
|
|
|
|
return new PolarisPropertySource(namespace, group, fileName, configKVFile, map);
|
|
|
|
return new PolarisPropertySource(namespace, group, fileName, configKVFile, map);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|