|
|
@ -18,6 +18,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
package com.tencent.cloud.polaris.config.adapter;
|
|
|
|
package com.tencent.cloud.polaris.config.adapter;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
|
|
|
import java.util.Arrays;
|
|
|
|
import java.util.LinkedList;
|
|
|
|
import java.util.LinkedList;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Map;
|
|
|
|
import java.util.Map;
|
|
|
@ -123,46 +125,49 @@ public class PolarisConfigFileLocator implements PropertySourceLocator {
|
|
|
|
|
|
|
|
|
|
|
|
// priority: application-${profile} > application > boostrap-${profile} > boostrap
|
|
|
|
// priority: application-${profile} > application > boostrap-${profile} > boostrap
|
|
|
|
String[] activeProfiles = environment.getActiveProfiles();
|
|
|
|
String[] activeProfiles = environment.getActiveProfiles();
|
|
|
|
buildInternalConfigFiles(internalConfigFiles, namespace, serviceName, activeProfiles);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Compatible with defaultProfiles configuration
|
|
|
|
|
|
|
|
if (ArrayUtils.isEmpty(activeProfiles)) {
|
|
|
|
|
|
|
|
String[] defaultProfiles = environment.getDefaultProfiles();
|
|
|
|
String[] defaultProfiles = environment.getDefaultProfiles();
|
|
|
|
buildInternalConfigFiles(internalConfigFiles, namespace, serviceName, defaultProfiles);
|
|
|
|
List<String> profileList = new ArrayList<>();
|
|
|
|
|
|
|
|
if (ArrayUtils.isNotEmpty(activeProfiles)) {
|
|
|
|
|
|
|
|
profileList.addAll(Arrays.asList(activeProfiles));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (ArrayUtils.isNotEmpty(defaultProfiles)) {
|
|
|
|
// build default config properties files .
|
|
|
|
profileList.addAll(Arrays.asList(defaultProfiles));
|
|
|
|
internalConfigFiles.add(new DefaultConfigFileMetadata(namespace, serviceName, "application.properties"));
|
|
|
|
}
|
|
|
|
internalConfigFiles.add(new DefaultConfigFileMetadata(namespace, serviceName, "application.yml"));
|
|
|
|
// build application config files
|
|
|
|
internalConfigFiles.add(new DefaultConfigFileMetadata(namespace, serviceName, "bootstrap.properties"));
|
|
|
|
buildInternalApplicationConfigFiles(internalConfigFiles, namespace, serviceName, profileList);
|
|
|
|
internalConfigFiles.add(new DefaultConfigFileMetadata(namespace, serviceName, "bootstrap.yml"));
|
|
|
|
// build bootstrap config files
|
|
|
|
|
|
|
|
buildInternalBootstrapConfigFiles(internalConfigFiles, namespace, serviceName, profileList);
|
|
|
|
|
|
|
|
|
|
|
|
return internalConfigFiles;
|
|
|
|
return internalConfigFiles;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void buildInternalConfigFiles(List<ConfigFileMetadata> internalConfigFiles, String namespace, String serviceName, String[] profiles) {
|
|
|
|
private void buildInternalApplicationConfigFiles(
|
|
|
|
|
|
|
|
List<ConfigFileMetadata> internalConfigFiles, String namespace, String serviceName, List<String> profileList) {
|
|
|
|
if (profiles != null) {
|
|
|
|
for (String profile : profileList) {
|
|
|
|
for (String profile : profiles) {
|
|
|
|
|
|
|
|
if (!StringUtils.hasText(profile)) {
|
|
|
|
if (!StringUtils.hasText(profile)) {
|
|
|
|
continue;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
internalConfigFiles.add(new DefaultConfigFileMetadata(namespace, serviceName, "application-" + profile + ".properties"));
|
|
|
|
internalConfigFiles.add(new DefaultConfigFileMetadata(namespace, serviceName, "application-" + profile + ".properties"));
|
|
|
|
internalConfigFiles.add(new DefaultConfigFileMetadata(namespace, serviceName, "application-" + profile + ".yml"));
|
|
|
|
internalConfigFiles.add(new DefaultConfigFileMetadata(namespace, serviceName, "application-" + profile + ".yml"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// build default config properties files.
|
|
|
|
|
|
|
|
internalConfigFiles.add(new DefaultConfigFileMetadata(namespace, serviceName, "application.properties"));
|
|
|
|
|
|
|
|
internalConfigFiles.add(new DefaultConfigFileMetadata(namespace, serviceName, "application.yml"));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
for (String profile : profiles) {
|
|
|
|
private void buildInternalBootstrapConfigFiles(
|
|
|
|
|
|
|
|
List<ConfigFileMetadata> internalConfigFiles, String namespace, String serviceName, List<String> profileList) {
|
|
|
|
|
|
|
|
for (String profile : profileList) {
|
|
|
|
if (!StringUtils.hasText(profile)) {
|
|
|
|
if (!StringUtils.hasText(profile)) {
|
|
|
|
continue;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
internalConfigFiles.add(new DefaultConfigFileMetadata(namespace, serviceName, "bootstrap-" + profile + ".properties"));
|
|
|
|
internalConfigFiles.add(new DefaultConfigFileMetadata(namespace, serviceName, "bootstrap-" + profile + ".properties"));
|
|
|
|
internalConfigFiles.add(new DefaultConfigFileMetadata(namespace, serviceName, "bootstrap-" + profile + ".yml"));
|
|
|
|
internalConfigFiles.add(new DefaultConfigFileMetadata(namespace, serviceName, "bootstrap-" + profile + ".yml"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// build default config properties files.
|
|
|
|
|
|
|
|
internalConfigFiles.add(new DefaultConfigFileMetadata(namespace, serviceName, "bootstrap.properties"));
|
|
|
|
|
|
|
|
internalConfigFiles.add(new DefaultConfigFileMetadata(namespace, serviceName, "bootstrap.yml"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void initCustomPolarisConfigFiles(CompositePropertySource compositePropertySource,
|
|
|
|
private void initCustomPolarisConfigFiles(CompositePropertySource compositePropertySource,
|
|
|
|
List<ConfigFileGroup> configFileGroups) {
|
|
|
|
List<ConfigFileGroup> configFileGroups) {
|
|
|
|