public static ConcurrentCompositeConfiguration createLocalConfig(List<ConfigModel> configModelList) { ConcurrentCompositeConfiguration config = new ConcurrentCompositeConfiguration(); duplicateCseConfigToServicecomb(config, new ConcurrentMapConfiguration(new SystemConfiguration()), "configFromSystem"); duplicateCseConfigToServicecomb(config, convertEnvVariable(new ConcurrentMapConfiguration(new EnvironmentConfiguration())), "configFromEnvironment"); // If there is extra configurations, add it into config. EXTRA_CONFIG_MAP.entrySet() .stream() .filter(mapEntry -> !mapEntry.getValue().isEmpty()) .forEachOrdered(configMapEntry -> duplicateCseConfigToServicecomb(config, new ConcurrentMapConfiguration(configMapEntry.getValue()), configMapEntry.getKey())); // we have already copy the cse config to the serviceComb config when we load the config from local yaml files // hence, we do not need duplicate copy it. config.addConfiguration( new DynamicConfiguration( new MicroserviceConfigurationSource(configModelList), new NeverStartPollingScheduler()), "configFromYamlFile"); duplicateCseConfigToServicecombAtFront(config, new ConcurrentMapConfiguration(ConfigMapping.getConvertedMap(config)), "configFromMapping"); return config; }
private static void createDynamicWatchedConfiguration( ConcurrentCompositeConfiguration localConfiguration, ConfigCenterConfigurationSource configCenterConfigurationSource) { ConcurrentMapConfiguration injectConfig = new ConcurrentMapConfiguration(); localConfiguration.addConfigurationAtFront(injectConfig, "extraInjectConfig"); configCenterConfigurationSource.addUpdateListener(new ServiceCombPropertyUpdateListener(injectConfig)); DynamicWatchedConfiguration configFromConfigCenter = new DynamicWatchedConfiguration(configCenterConfigurationSource); duplicateCseConfigToServicecomb(configFromConfigCenter); localConfiguration.addConfigurationAtFront(configFromConfigCenter, "configCenterConfig"); }
public EagleMailClient() { this(new ConcurrentMapConfiguration()); }
@RefreshScope @Bean public AbstractConfiguration archaiusConfiguration() throws Exception { LOGGER.info("Enable Archaius Configuration"); ConcurrentMapConfiguration concurrentMapConfiguration = new ConcurrentMapConfiguration(); return concurrentMapConfiguration; }
private void initModuleConfiguration() { if (!scanModuleConfigurations) { this.moduleDefaultConfiguration = new ConcurrentMapConfiguration(); return; } HashMap<String, Object> base = new HashMap<>(); Set<Class<?>> types = reflections .getTypesAnnotatedWith(PropertySource.class); for (Class<?> type : types) { PropertySource propertySource = type .getAnnotation(PropertySource.class); String[] propertiesFiles = propertySource.value(); for (String propertyFile : propertiesFiles) { Properties properties = new Properties(); try (InputStream is = resourceLoader.getResource(SystemPropertyUtils.resolvePlaceholders(propertyFile)) .getInputStream()) { properties.load(is); LOGGER.debug("Initializing module properties from path " + propertyFile); } catch (Exception e) { BootstrapException.resourceLoadingFailed(propertyFile, e); } join(base, properties, propertyFile, propertiesFiles); } } this.moduleDefaultConfiguration = new ConcurrentMapConfiguration(base); }
if (instance instanceof AggregatedConfiguration) { String name = getConfigName(url); ConcurrentMapConfiguration config = new ConcurrentMapConfiguration(); config.loadProperties(props); ((AggregatedConfiguration) instance).addConfiguration(config, name);
private void exportPropertiesToArchaius(String groupName, IClientConfig config, String configName) { Map<String, Object> map = config.getProperties(); Configuration configuration = ConfigurationManager.getConfigInstance(); if (configuration instanceof AggregatedConfiguration) { AggregatedConfiguration ac = (AggregatedConfiguration) configuration; configuration = ac.getConfiguration(configName); if (configuration == null) { configuration = new ConcurrentMapConfiguration(); ac.addConfiguration((AbstractConfiguration) configuration, configName); } } for (Map.Entry<String, Object> entry : map.entrySet()) { configuration.setProperty(groupName + "." + config.getNameSpace() + "." + entry.getKey(), entry.getValue()); } } }
public static void main(String[] args) { new SampleApplication(); ConcurrentCompositeConfiguration myConfiguration = (ConcurrentCompositeConfiguration) DynamicPropertyFactory.getInstance().getBackingConfigurationSource(); ConcurrentMapConfiguration subConfig = new ConcurrentMapConfiguration(); subConfig.setProperty("com.netflix.config.samples.SampleApp.SampleBean.name", "A Coffee Bean from Cuba"); myConfiguration.setProperty("com.netflix.config.samples.sampleapp.prop1", "value1"); myConfiguration.addConfiguration(subConfig); System.out.println("Started SampleApplication. Launch JConsole to inspect and update properties."); System.out.println("To see how callback work, update property com.netflix.config.samples.SampleApp.SampleBean.sensitiveBeanData from BaseConfigBean in JConsole"); SampleBean sampleBean = new SampleBean(); // this should show the bean taking properties from two different sources // property "com.netflix.config.samples.SampleApp.SampleBean.numSeeds" is from sampleapp.properites // property "com.netflix.config.samples.SampleApp.SampleBean.name" is from subConfig added above System.out.println("SampleBean:" + sampleBean); System.out.println(sampleBean.getName()); } }
public static ConcurrentCompositeConfiguration createLocalConfig(List<ConfigModel> configModelList) { ConcurrentCompositeConfiguration config = new ConcurrentCompositeConfiguration(); duplicateCseConfigToServicecomb(config, new ConcurrentMapConfiguration(new SystemConfiguration()), "configFromSystem"); duplicateCseConfigToServicecomb(config, convertEnvVariable(new ConcurrentMapConfiguration(new EnvironmentConfiguration())), "configFromEnvironment"); // If there is extra configurations, add it into config. EXTRA_CONFIG_MAP.entrySet() .stream() .filter(mapEntry -> !mapEntry.getValue().isEmpty()) .forEachOrdered(configMapEntry -> duplicateCseConfigToServicecomb(config, new ConcurrentMapConfiguration(configMapEntry.getValue()), configMapEntry.getKey())); // we have already copy the cse config to the serviceComb config when we load the config from local yaml files // hence, we do not need duplicate copy it. config.addConfiguration( new DynamicConfiguration( new MicroserviceConfigurationSource(configModelList), new NeverStartPollingScheduler()), "configFromYamlFile"); duplicateCseConfigToServicecombAtFront(config, new ConcurrentMapConfiguration(ConfigMapping.getConvertedMap(config)), "configFromMapping"); return config; }
private static String getNextLoad(Configuration propConfig, String... nextLoadPropertyKeys) { String nextLoadKeyToUse = null; for (String key: nextLoadPropertyKeys) { if (propConfig.getProperty(key) != null) { nextLoadKeyToUse = key; break; } } // there is no next load for this properties file if (nextLoadKeyToUse == null) { return null; } // make a copy of current existing properties ConcurrentMapConfiguration config = new ConcurrentMapConfiguration(); // need to have all the properties to interpolate next load property value copyProperties(ConfigurationManager.getConfigInstance(), config); copyProperties(propConfig, config); // In case this is a list of files to load, always treat the value as a list List<Object> list = config.getList(nextLoadKeyToUse); StringBuilder sb = new StringBuilder(); for (Object value: list) { sb.append(value).append(","); } String nextLoad = sb.toString(); propConfig.clearProperty(nextLoadKeyToUse); return nextLoad; }
private static String getNextLoad(Configuration propConfig, String... nextLoadPropertyKeys) { String nextLoadKeyToUse = null; for (String key: nextLoadPropertyKeys) { if (propConfig.getProperty(key) != null) { nextLoadKeyToUse = key; break; } } // there is no next load for this properties file if (nextLoadKeyToUse == null) { return null; } // make a copy of current existing properties ConcurrentMapConfiguration config = new ConcurrentMapConfiguration(); // need to have all the properties to interpolate next load property value copyProperties(ConfigurationManager.getConfigInstance(), config); copyProperties(propConfig, config); // In case this is a list of files to load, always treat the value as a list List<Object> list = config.getList(nextLoadKeyToUse); StringBuilder sb = new StringBuilder(); for (Object value: list) { sb.append(value).append(","); } String nextLoad = sb.toString(); propConfig.clearProperty(nextLoadKeyToUse); return nextLoad; } }
public static void main(String[] args) { new SampleApplication(); ConcurrentCompositeConfiguration myConfiguration = (ConcurrentCompositeConfiguration) DynamicPropertyFactory.getInstance().getBackingConfigurationSource(); ConcurrentMapConfiguration subConfig = new ConcurrentMapConfiguration(); subConfig.setProperty("com.netflix.config.samples.SampleApp.SampleBean.name", "A Coffee Bean from Cuba"); myConfiguration.setProperty("com.netflix.config.samples.sampleapp.prop1", "value1"); myConfiguration.addConfiguration(subConfig); System.out.println("Started SampleApplication. Launch JConsole to inspect and update properties."); System.out.println("To see how callback work, update property com.netflix.config.samples.SampleApp.SampleBean.sensitiveBeanData from BaseConfigBean in JConsole"); SampleBean sampleBean = new SampleBean(); // this should show the bean taking properties from two different sources // property "com.netflix.config.samples.SampleApp.SampleBean.numSeeds" is from sampleapp.properites // property "com.netflix.config.samples.SampleApp.SampleBean.name" is from subConfig added above System.out.println("SampleBean:" + sampleBean); System.out.println(sampleBean.getName()); } }
/** * Load resource configName.properties first. Then load configName-deploymentEnvironment.properties * into the system wide configuration. For example, if configName is "application", and deployment environment * is "test", this API will first load "application.properties", then load "application-test.properties" to * override any property that also exist in "application.properties". * * @param configName prefix of the properties file name. * @throws IOException * @see DeploymentContext#getDeploymentEnvironment() */ public static void loadCascadedPropertiesFromResources(String configName) throws IOException { Properties props = loadCascadedProperties(configName); if (instance instanceof AggregatedConfiguration) { ConcurrentMapConfiguration config = new ConcurrentMapConfiguration(); config.loadProperties(props); ((AggregatedConfiguration) instance).addConfiguration(config, configName); } else { ConfigurationUtils.loadProperties(props, instance); } }
/** * Load resource configName.properties first. Then load configName-deploymentEnvironment.properties * into the system wide configuration. For example, if configName is "application", and deployment environment * is "test", this API will first load "application.properties", then load "application-test.properties" to * override any property that also exist in "application.properties". * * @param configName prefix of the properties file name. * @throws IOException * @see DeploymentContext#getDeploymentEnvironment() */ public static void loadCascadedPropertiesFromResources(String configName) throws IOException { Properties props = loadCascadedProperties(configName); if (instance instanceof AggregatedConfiguration) { ConcurrentMapConfiguration config = new ConcurrentMapConfiguration(); config.loadProperties(props); ((AggregatedConfiguration) instance).addConfiguration(config, configName); } else { ConfigurationUtils.loadProperties(props, instance); } }
/** * Convert CombinedConfiguration into {@link ConcurrentCompositeConfiguration} as the later has better performance * and thread safety. * * @param config Configuration to be converted */ public static ConcurrentCompositeConfiguration convertToConcurrentCompositeConfiguration(CombinedConfiguration config) { ConcurrentCompositeConfiguration root = new ConcurrentCompositeConfiguration(); IdentityHashMap<Configuration, String> reverseMap = new IdentityHashMap<Configuration, String>(); for (String name: (Set<String>) config.getConfigurationNames()) { Configuration child = config.getConfiguration(name); reverseMap.put(child, name); } for (int i = 0; i < config.getNumberOfConfigurations(); i++) { Configuration child = config.getConfiguration(i); String name = reverseMap.get(child); if (child instanceof CombinedConfiguration) { CombinedConfiguration combinedConf = (CombinedConfiguration) child; ConcurrentCompositeConfiguration newConf = convertToConcurrentCompositeConfiguration(combinedConf); root.addConfiguration(newConf, name); } else { Configuration conf = new ConcurrentMapConfiguration(child); root.addConfiguration((AbstractConfiguration) conf, name); } } return root; }
/** * Convert CombinedConfiguration into {@link ConcurrentCompositeConfiguration} as the later has better performance * and thread safety. * * @param config Configuration to be converted */ public static ConcurrentCompositeConfiguration convertToConcurrentCompositeConfiguration(CombinedConfiguration config) { ConcurrentCompositeConfiguration root = new ConcurrentCompositeConfiguration(); IdentityHashMap<Configuration, String> reverseMap = new IdentityHashMap<Configuration, String>(); for (String name: (Set<String>) config.getConfigurationNames()) { Configuration child = config.getConfiguration(name); reverseMap.put(child, name); } for (int i = 0; i < config.getNumberOfConfigurations(); i++) { Configuration child = config.getConfiguration(i); String name = reverseMap.get(child); if (child instanceof CombinedConfiguration) { CombinedConfiguration combinedConf = (CombinedConfiguration) child; ConcurrentCompositeConfiguration newConf = convertToConcurrentCompositeConfiguration(combinedConf); root.addConfiguration(newConf, name); } else { Configuration conf = new ConcurrentMapConfiguration(child); root.addConfiguration((AbstractConfiguration) conf, name); } } return root; }
private static void createDynamicWatchedConfiguration( ConcurrentCompositeConfiguration localConfiguration, ConfigCenterConfigurationSource configCenterConfigurationSource) { ConcurrentMapConfiguration injectConfig = new ConcurrentMapConfiguration(); localConfiguration.addConfigurationAtFront(injectConfig, "extraInjectConfig"); configCenterConfigurationSource.addUpdateListener(new ServiceCombPropertyUpdateListener(injectConfig)); DynamicWatchedConfiguration configFromConfigCenter = new DynamicWatchedConfiguration(configCenterConfigurationSource); duplicateCseConfigToServicecomb(configFromConfigCenter); localConfiguration.addConfigurationAtFront(configFromConfigCenter, "configCenterConfig"); }
private ConcurrentCompositeConfiguration buildConfiguration() { ConcurrentCompositeConfiguration configuration = new ConcurrentCompositeConfiguration(); configuration.addConfiguration(new ConcurrentMapConfiguration(new SystemConfiguration())); configuration.addConfiguration(this.configuration); configuration.addConfiguration(defaults); return configuration; }
/** * Removes all child configurations and reinitializes the <em>container * configuration</em>. <strong>Attention:</strong> A new container * configuration is created; the old one is lost. */ @Override public final void clear() { fireEvent(EVENT_CLEAR, null, null, true); configList.clear(); namedConfigurations.clear(); // recreate the in memory configuration containerConfiguration = new ConcurrentMapConfiguration(); containerConfiguration.setThrowExceptionOnMissing(isThrowExceptionOnMissing()); containerConfiguration.setListDelimiter(getListDelimiter()); containerConfiguration.setDelimiterParsingDisabled(isDelimiterParsingDisabled()); containerConfiguration.addConfigurationListener(eventPropagater); configList.add(containerConfiguration); overrideProperties = new ConcurrentMapConfiguration(); overrideProperties.setThrowExceptionOnMissing(isThrowExceptionOnMissing()); overrideProperties.setListDelimiter(getListDelimiter()); overrideProperties.setDelimiterParsingDisabled(isDelimiterParsingDisabled()); overrideProperties.addConfigurationListener(eventPropagater); fireEvent(EVENT_CLEAR, null, null, false); containerConfigurationChanged = false; invalidate(); }
/** * Removes all child configurations and reinitializes the <em>container * configuration</em>. <strong>Attention:</strong> A new container * configuration is created; the old one is lost. */ @Override public final void clear() { fireEvent(EVENT_CLEAR, null, null, true); configList.clear(); namedConfigurations.clear(); // recreate the in memory configuration containerConfiguration = new ConcurrentMapConfiguration(); containerConfiguration.setThrowExceptionOnMissing(isThrowExceptionOnMissing()); containerConfiguration.setListDelimiter(getListDelimiter()); containerConfiguration.setDelimiterParsingDisabled(isDelimiterParsingDisabled()); containerConfiguration.addConfigurationListener(eventPropagater); configList.add(containerConfiguration); overrideProperties = new ConcurrentMapConfiguration(); overrideProperties.setThrowExceptionOnMissing(isThrowExceptionOnMissing()); overrideProperties.setListDelimiter(getListDelimiter()); overrideProperties.setDelimiterParsingDisabled(isDelimiterParsingDisabled()); overrideProperties.addConfigurationListener(eventPropagater); fireEvent(EVENT_CLEAR, null, null, false); containerConfigurationChanged = false; invalidate(); }